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

Unified Diff: src/core/SkPixmap.cpp

Issue 1463373002: scaling API on SkPixmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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/SkImageCacherator.cpp ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPixmap.cpp
diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp
index c63bef9c7d6c01e0973b12297a97888a885def6a..718be88c57a826bdda276f8e214330b8484da6df 100644
--- a/src/core/SkPixmap.cpp
+++ b/src/core/SkPixmap.cpp
@@ -205,6 +205,44 @@ bool SkPixmap::erase(SkColor color, const SkIRect& inArea) const {
return true;
}
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkSurface.h"
+#include "SkXfermode.h"
+
+bool SkPixmap::scalePixels(const SkPixmap& dst, SkFilterQuality quality) const {
+ // Can't do anthing with empty src or dst
+ if (this->width() <= 0 || this->height() <= 0 || dst.width() <= 0 || dst.height() <= 0) {
+ return false;
+ }
+
+ // no scaling involved?
+ if (dst.width() == this->width() && dst.height() == this->height()) {
+ return this->readPixels(dst);
+ }
+
+ SkBitmap bitmap;
+ // we will only ready from this pixmap, but the bitmap setting takes void*, hence the cast
+ void* readOnlyAddr = const_cast<void*>(this->addr());
+ if (!bitmap.installPixels(this->info(), readOnlyAddr, this->rowBytes())) {
+ return false;
+ }
+ bitmap.setIsVolatile(true); // so we don't try to cache it
+
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(dst.info(), dst.writable_addr(),
+ dst.rowBytes()));
+ if (!surface) {
+ return false;
+ }
+
+ SkPaint paint;
+ paint.setFilterQuality(quality);
+ paint.setXfermodeMode(SkXfermode::kSrc_Mode);
+ surface->getCanvas()->drawBitmapRect(bitmap, SkRect::MakeIWH(dst.width(), dst.height()),
+ &paint);
+ return true;
+}
+
//////////////////////////////////////////////////////////////////////////////////////////////////
SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(nullptr) {}
« no previous file with comments | « src/core/SkImageCacherator.cpp ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698