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

Unified Diff: src/image/SkImage.cpp

Issue 1208993017: Add image->bitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 5 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 d3533a9a4a58cd7ab7d87ada6ec5bc4931314f65..2152010c749e18a9a6ca3ac20f4675f2e4f8662a 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -263,6 +263,21 @@ SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
return SkNewImageFromRasterBitmap(bm, false, NULL);
}
+bool SkImage::asBitmap(SkBitmap* bitmap, AsBitmapMode mode) const {
+ return as_IB(this)->onAsBitmap(bitmap, mode);
+}
+
+bool SkImage_Base::onAsBitmap(SkBitmap* bitmap, AsBitmapMode) const {
+ // As the base-class, all we can do is make a copy (regardless of mode).
+ // Subclasses that want to be more optimal should override.
+ SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(),
+ this->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
+ if (!bitmap->tryAllocPixels(info)) {
+ return false;
+ }
+ return this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0);
+}
+
//////////////////////////////////////////////////////////////////////////////////////
#if !SK_SUPPORT_GPU
« include/core/SkImage.h ('K') | « include/core/SkImage.h ('k') | src/image/SkImage_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698