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

Unified Diff: samplecode/DecodeFile.h

Issue 1812323003: Remove uses of SkImageDecoder from samplecode (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 | « no previous file | samplecode/SampleAll.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/DecodeFile.h
diff --git a/samplecode/DecodeFile.h b/samplecode/DecodeFile.h
new file mode 100644
index 0000000000000000000000000000000000000000..26d5d2dc2631407b524ced92c462c189e6a4c4ae
--- /dev/null
+++ b/samplecode/DecodeFile.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBitmap.h"
+#include "SkCodec.h"
+#include "SkData.h"
+
+inline bool decode_file(const char* filename, SkBitmap* bitmap,
+ SkColorType colorType = kN32_SkColorType, bool requireUnpremul = false) {
+ SkASSERT(kIndex_8_SkColorType != colorType);
+ SkAutoTUnref<SkData> data(SkData::NewFromFileName(filename));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data));
+ if (!codec) {
+ return false;
+ }
+
+ SkImageInfo info = codec->getInfo().makeColorType(colorType);
+ if (requireUnpremul && kPremul_SkAlphaType == info.alphaType()) {
+ info = info.makeAlphaType(kUnpremul_SkAlphaType);
+ }
+
+ if (!bitmap->tryAllocPixels(info)) {
+ return false;
+ }
+
+ return SkCodec::kSuccess == codec->getPixels(info, bitmap->getPixels(), bitmap->rowBytes());
+}
« no previous file with comments | « no previous file | samplecode/SampleAll.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698