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

Unified Diff: src/image/SkImage.cpp

Issue 821083002: add newImage API (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add SkFilterQuality option Created 5 years, 12 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
Index: src/image/SkImage.cpp
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 1acff3e4ed5ff7bad77e7bc63643c5bda0f39974..9af9727cc32c884a4f94de8a913a902559884bf8 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -78,6 +78,22 @@ SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr
return as_IB(this)->onNewSurface(info, *props);
}
+SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset,
+ SkFilterQuality quality) const {
+ if (newWidth < 0 || newHeight < 0) {
+ return NULL;
+ }
+ if (subset && !SkIRect::MakeWH(this->width(), this->height()).contains(*subset)) {
+ return NULL;
+ }
+
+ 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) {
@@ -110,3 +126,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);
scroggo 2015/01/05 16:15:33 If this image is unpremul, does this work properly
reed1 2015/01/05 21:58:14 This is the "base" implementation, which may chang
scroggo 2015/01/05 22:12:02 +1 to the more optimal subclass overrides. In the
reed1 2015/01/20 22:23:08 unpremul : good point, have to think about that ca
+ SkAutoTUnref<SkSurface> surface(this->newSurface(info, NULL));
+ if (!surface.get()) {
+ return NULL;
+ }
+
+ SkRect src;
+ if (subset) {
+ src.set(*subset);
+ } else {
+ src = SkRect::MakeWH(SkIntToScalar(this->width()), SkIntToScalar(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();
+}
+
+
« include/core/SkPaint.h ('K') | « include/core/SkPaint.h ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698