Index: dm/DM.cpp |
diff --git a/dm/DM.cpp b/dm/DM.cpp |
index 5d85e22b3a8e989d30ff358ead3f1098df882c37..4f7fe682d34246e1eebdde0cac110b57ee51cf8e 100644 |
--- a/dm/DM.cpp |
+++ b/dm/DM.cpp |
@@ -13,6 +13,7 @@ |
#include "ProcStats.h" |
#include "SkBBHFactory.h" |
#include "SkChecksum.h" |
+#include "SkCodecPriv.h" |
#include "SkCommonFlags.h" |
#include "SkForceLinking.h" |
#include "SkGraphics.h" |
@@ -178,6 +179,46 @@ static void push_src(const char* tag, const char* options, Src* s) { |
} |
} |
+static SkCodec* create_codec(Path path) { |
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
+ if (!encoded) { |
+ SkCodecPrintf(return SkStringPrintf("Couldn't read %s.", path.c_str())); |
scroggo
2015/04/08 17:21:27
SkCodecPrintf (which I think is defined in src/cod
msarett
2015/04/08 19:35:40
Yeah that is what I meant.
|
+ return NULL; |
+ } |
+ |
+ return SkCodec::NewFromData(encoded); |
+} |
+ |
+static void push_codec_srcs(Path path) { |
+ // Create a codec |
+ SkCodec* codec = create_codec(path); |
+ if (NULL == codec) { |
+ SkCodecPrintf(return SkStringPrintf("Couldn't create codec for %s.", path.c_str())); |
+ return; |
+ } |
+ |
+ // Build additional test cases for images that decode natively to non-canvas types |
+ switch(codec->getInfo().colorType()) { |
+ case kIndex_8_SkColorType: |
+ push_src("image", "codec kIndex8", new CodecSrc(path, CodecSrc::kNormal_Mode, |
scroggo
2015/04/08 17:21:27
We should probably add a src for kScanline_Mode as
msarett
2015/04/08 19:35:40
Done.
|
+ CodecSrc::kIndex8_Always_DstColorType, create_codec(path))); |
msarett
2015/04/08 13:59:10
Can we assume that if create_codec succeeds once,
scroggo
2015/04/08 17:21:27
If it does not, that is a bug (or a disk read erro
msarett
2015/04/08 19:35:40
Acknowledged.
|
+ break; |
+ case kGray_8_SkColorType: |
+ push_src("image", "codec kGray8", new CodecSrc(path, CodecSrc::kNormal_Mode, |
+ CodecSrc::kGrayscale_Always_DstColorType, create_codec(path))); |
+ break; |
+ default: |
+ // Do nothing |
+ break; |
+ } |
+ |
+ // Decode all images to the canvas color type |
+ push_src("image", "codec", new CodecSrc(path, CodecSrc::kNormal_Mode, |
+ CodecSrc::kGetFromCanvas_DstColorType, create_codec(path))); |
+ push_src("image", "scanline", new CodecSrc( |
+ path, CodecSrc::kScanline_Mode, CodecSrc::kGetFromCanvas_DstColorType, codec)); |
+} |
+ |
static bool codec_supported(const char* ext) { |
// FIXME: Once other versions of SkCodec are available, we can add them to this |
// list (and eventually we can remove this check once they are all supported). |
@@ -223,8 +264,7 @@ static void gather_srcs() { |
push_src("image", "decode", new ImageSrc(path)); // Decode entire image |
push_src("image", "subset", new ImageSrc(path, 2)); // Decode into 2x2 subsets |
if (codec_supported(exts[j])) { |
- push_src("image", "codec", new CodecSrc(path, CodecSrc::kNormal_Mode)); |
- push_src("image", "scanline", new CodecSrc(path, CodecSrc::kScanline_Mode)); |
+ push_codec_srcs(path); |
} |
} |
} |
@@ -232,8 +272,7 @@ static void gather_srcs() { |
// assume that FLAGS_images[i] is a valid image if it is a file. |
push_src("image", "decode", new ImageSrc(flag)); // Decode entire image. |
push_src("image", "subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets |
- push_src("image", "codec", new CodecSrc(flag, CodecSrc::kNormal_Mode)); |
- push_src("image", "scanline", new CodecSrc(flag, CodecSrc::kScanline_Mode)); |
+ push_codec_srcs(flag); |
} |
} |
} |