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; |