Index: dm/DM.cpp |
diff --git a/dm/DM.cpp b/dm/DM.cpp |
index 5d85e22b3a8e989d30ff358ead3f1098df882c37..fdf952cfeb00abd686e3709b77c12099d750fa48 100644 |
--- a/dm/DM.cpp |
+++ b/dm/DM.cpp |
@@ -178,6 +178,47 @@ static void push_src(const char* tag, const char* options, Src* s) { |
} |
} |
+static void push_codec_srcs(Path path) { |
+ // These are the extensions for images that might be natively kIndex8. For these images, |
+ // we should test decoding to kIndex8 and also to the canvas color type. |
+ // All gifs are natively kIndex8 compatible. Only some bmps and rarely icos (when they |
+ // contain a kIndex8 bmp) can be decoded to kIndex8. In the case that we try to decode |
+ // incompatible images to kIndex8, we will fail gracefully in CodecSrc::draw(). |
+ static const char* const indexExts[] = { |
+ "bmp", "gif", "ico", |
+ "BMP", "GIF", "ICO", |
+ }; |
+ |
+ // The same applies to natively kGray images. |
+ static const char* const grayExts[] = { |
+ "wbmp", "WBMP", |
+ }; |
+ |
+ // Push sources that we want to try to decode to kIndex8 |
+ for (uint32_t i = 0; i < SK_ARRAY_COUNT(indexExts); i++) { |
+ if (path.endsWith(indexExts[i])) { |
scroggo
2015/04/07 21:15:34
Here's how I imagined this working:
SkAutoTDelete
msarett
2015/04/08 13:59:10
What you've described is how I originally thought
scroggo
2015/04/08 17:21:26
That seems okay, although it seems like you call c
msarett
2015/04/08 19:35:39
That was my disappointment with this approach. We
|
+ push_src("image", "codec kIndex8", new CodecSrc( |
+ path, CodecSrc::kNormal_Mode, CodecSrc::kIndex8_Always_DstColorType)); |
+ break; |
+ } |
+ } |
+ |
+ // Push sources that we want to try to decode to kGray8 |
+ for (uint32_t i = 0; i < SK_ARRAY_COUNT(grayExts); i++) { |
+ if (path.endsWith(grayExts[i])) { |
+ push_src("image", "codec kGray8", new CodecSrc( |
+ path, CodecSrc::kNormal_Mode, CodecSrc::kGrayscale_Always_DstColorType)); |
+ break; |
+ } |
+ } |
+ |
+ // Decode all sources to the canvas color type |
+ push_src("image", "codec", new CodecSrc( |
+ path, CodecSrc::kNormal_Mode, CodecSrc::kGetFromCanvas_DstColorType)); |
+ push_src("image", "scanline", new CodecSrc( |
+ path, CodecSrc::kScanline_Mode, CodecSrc::kGetFromCanvas_DstColorType)); |
+} |
+ |
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); |
} |
} |
} |