Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: src/image/SkImage.cpp

Issue 821083002: add newImage API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: check when subset == bounds Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkPaint.cpp ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage.cpp
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 97e7475a34ff28dc49b6499d5ecaef86c3c8d7fa..109808842efde1a1dda5b36b5a5221d6e2991f5e 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -94,6 +94,30 @@ const char* SkImage::toString(SkString* str) const {
return str->c_str();
}
+SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset,
+ SkFilterQuality quality) const {
+ if (newWidth <= 0 || newHeight <= 0) {
+ return NULL;
+ }
+
+ const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
+
+ if (subset) {
+ if (!bounds.contains(*subset)) {
+ return NULL;
+ }
+ if (bounds == *subset) {
+ subset = NULL; // and fall through to check below
+ }
+ }
+
+ if (NULL == subset && this->width() == newWidth && this->height() == newHeight) {
+ return SkRef(const_cast<SkImage*>(this));
+ }
+
+ return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality);
+}
+
///////////////////////////////////////////////////////////////////////////////
static bool raster_canvas_supports(const SkImageInfo& info) {
@@ -126,3 +150,32 @@ bool SkImage_Base::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, siz
return true;
}
+
+SkImage* SkImage_Base::onNewImage(int newWidth, int newHeight, const SkIRect* subset,
+ SkFilterQuality quality) const {
+ const bool opaque = this->isOpaque();
+ const SkImageInfo info = SkImageInfo::Make(newWidth, newHeight, kN32_SkColorType,
+ opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
+ SkAutoTUnref<SkSurface> surface(this->newSurface(info, NULL));
+ if (!surface.get()) {
+ return NULL;
+ }
+
+ SkRect src;
+ if (subset) {
+ src.set(*subset);
+ } else {
+ src = SkRect::MakeIWH(this->width(), this->height());
+ }
+
+ surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height());
+ surface->getCanvas()->translate(-src.x(), -src.y());
+
+ SkPaint paint;
+ paint.setXfermodeMode(SkXfermode::kSrc_Mode);
+ paint.setFilterQuality(quality);
+ surface->getCanvas()->drawImage(this, 0, 0, &paint);
+ return surface->newImageSnapshot();
+}
+
+
« no previous file with comments | « src/core/SkPaint.cpp ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698