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

Unified Diff: src/core/SkImageGenerator.cpp

Issue 1334033004: formalize generate->bitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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/core/SkImageGenerator.cpp
diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp
index 33da50a41d54d9f818610f79d83d7176c33a8562..6fe9f84a08821b8e78fc714e1045b7b264818baf 100644
--- a/src/core/SkImageGenerator.cpp
+++ b/src/core/SkImageGenerator.cpp
@@ -125,6 +125,46 @@ bool SkImageGenerator::onGetPixels(const SkImageInfo& info, void* dst, size_t rb
///////////////////////////////////////////////////////////////////////////////////////////////////
+#include "SkBitmap.h"
+#include "SkColorTable.h"
+
+static void release_malloc_proc(void* pixels, void* ctx) {
+ sk_free(pixels);
+}
+
+bool SkImageGenerator::tryGenerateBitmap(SkBitmap* bitmap, const SkImageInfo* infoPtr) {
+ const SkImageInfo info = infoPtr ? *infoPtr : this->getInfo();
+ const size_t rowBytes = info.minRowBytes();
+ const size_t pixelSize = info.getSafeSize(rowBytes);
+ if (0 == pixelSize) {
+ return false;
+ }
+
+ SkAutoFree pixelStorage(sk_malloc_flags(pixelSize, 0));
+ void* pixels = pixelStorage.get();
+ if (!pixels) {
+ return false;
+ }
+
+ SkPMColor ctStorage[256];
+ int ctCount = 0;
+
+ if (!this->getPixels(info, pixels, rowBytes, ctStorage, &ctCount)) {
+ return false;
+ }
+
+ SkAutoTUnref<SkColorTable> ctable;
+ if (ctCount > 0) {
+ SkASSERT(kIndex_8_SkColorType == info.colorType());
+ ctable.reset(new SkColorTable(ctStorage, ctCount));
+ } else {
+ SkASSERT(kIndex_8_SkColorType != info.colorType());
+ }
+
+ return bitmap->installPixels(info, pixelStorage.detach(), rowBytes, ctable,
+ release_malloc_proc, nullptr);
+}
+
#include "SkGraphics.h"
static SkGraphics::ImageGeneratorFromEncodedFactory gFactory;
« no previous file with comments | « src/core/SkImageCacherator.cpp ('k') | tools/Resources.cpp » ('j') | tools/Resources.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698