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

Unified Diff: tools/skdiff_utils.cpp

Issue 1788643003: Remove uses of SkImageDecoder from skdiff (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
« tools/skdiff_main.cpp ('K') | « tools/skdiff_utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skdiff_utils.cpp
diff --git a/tools/skdiff_utils.cpp b/tools/skdiff_utils.cpp
index 1e2a727945b921892404788349f391f560966528..3d4bf7ea9329a29cc068719a9f13b614190c9495 100644
--- a/tools/skdiff_utils.cpp
+++ b/tools/skdiff_utils.cpp
@@ -7,8 +7,8 @@
#include "skdiff.h"
#include "skdiff_utils.h"
#include "SkBitmap.h"
+#include "SkCodec.h"
#include "SkData.h"
-#include "SkImageDecoder.h"
#include "SkImageEncoder.h"
#include "SkStream.h"
#include "SkTypes.h"
@@ -33,20 +33,32 @@ SkData* read_file(const char* file_path) {
return data;
}
-bool get_bitmap(SkData* fileBits, DiffResource& resource, SkImageDecoder::Mode mode) {
- SkMemoryStream stream(fileBits->data(), fileBits->size());
+bool get_bitmap(SkData* fileBits, DiffResource& resource, bool sizeOnly) {
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fileBits));
+ if (!codec) {
+ SkDebugf("ERROR: could not create codec for <%s>\n", resource.fFullPath.c_str());
+ resource.fStatus = DiffResource::kCouldNotDecode_Status;
+ return false;
+ }
+
+ if (!resource.fBitmap.setInfo(codec->getInfo().makeColorType(kN32_SkColorType))) {
+ SkDebugf("ERROR: could not set bitmap info for <%s>\n", resource.fFullPath.c_str());
+ resource.fStatus = DiffResource::kCouldNotDecode_Status;
+ return false;
+ }
+
+ if (sizeOnly) {
+ return true;
+ }
- // In debug, the DLL will automatically be unloaded when this is deleted,
- // but that shouldn't be a problem in release mode.
- std::unique_ptr<SkImageDecoder> codec(SkImageDecoder::Factory(&stream));
- if (nullptr == codec) {
- SkDebugf("ERROR: no codec found for <%s>\n", resource.fFullPath.c_str());
+ if (!resource.fBitmap.tryAllocPixels()) {
+ SkDebugf("ERROR: could not allocate pixels for <%s>\n", resource.fFullPath.c_str());
resource.fStatus = DiffResource::kCouldNotDecode_Status;
return false;
}
- stream.rewind();
- if (!codec->decode(&stream, &resource.fBitmap, kN32_SkColorType, mode)) {
+ if (SkCodec::kSuccess != codec->getPixels(resource.fBitmap.info(),
+ resource.fBitmap.getPixels(), resource.fBitmap.rowBytes())) {
SkDebugf("ERROR: codec failed for basePath <%s>\n", resource.fFullPath.c_str());
resource.fStatus = DiffResource::kCouldNotDecode_Status;
return false;
« tools/skdiff_main.cpp ('K') | « tools/skdiff_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698