aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2015-04-09 12:43:10 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-04-09 12:43:10 -0700
commit438b2adefb9e9213e0ddaf0609405d3087a1cf0a (patch)
tree34b6c116c074d5f24f8e37a45db0e8404de8d83f /dm
parent16b254a200f63e85041cac9a283ff0ff14d94ba1 (diff)
***Disables swizzles to 565.
We may want to enable swizzles to 565 for images that are encoded in a format similar to 565, however, we do not want to take images that decode naturally to kN32 and then convert them to 565. ***Enable swizzles to kIndex_8. For images encoded in a color table format, we suggest that they be decoded to kIndex_8. When we decode, we only allow conversion to kIndex_8 if it matches the suggested color type (except wbmp which seems good as is). ***Modify dm to test images that decode to kIndex_8. BUG=skia:3257 BUG=skia:3440 Review URL: https://codereview.chromium.org/1055743003
Diffstat (limited to 'dm')
-rw-r--r--dm/DM.cpp46
-rw-r--r--dm/DMSrcSink.cpp46
-rw-r--r--dm/DMSrcSink.h13
3 files changed, 90 insertions, 15 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 296b7c88d7..2a71500605 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -178,6 +178,46 @@ static void push_src(const char* tag, const char* options, Src* s) {
}
}
+static void push_codec_srcs(Path path) {
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
+ if (!encoded) {
+ SkDebugf("Couldn't read %s.", path.c_str());
+ return;
+ }
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ if (NULL == codec.get()) {
+ SkDebugf("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 kGray_8_SkColorType:
+ push_src("image", "codec kGray8", new CodecSrc(path, CodecSrc::kNormal_Mode,
+ CodecSrc::kGrayscale_Always_DstColorType));
+ push_src("image", "scanline kGray8", new CodecSrc(path, CodecSrc::kScanline_Mode,
+ CodecSrc::kGrayscale_Always_DstColorType));
+ // Intentional fall through
+ // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
+ // Further discussion on this topic is at skbug.com/3683
+ case kIndex_8_SkColorType:
+ push_src("image", "codec kIndex8", new CodecSrc(path, CodecSrc::kNormal_Mode,
+ CodecSrc::kIndex8_Always_DstColorType));
+ push_src("image", "scanline kIndex8", new CodecSrc(path, CodecSrc::kScanline_Mode,
+ CodecSrc::kIndex8_Always_DstColorType));
+ 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));
+ 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 +263,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 +271,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);
}
}
}
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index de9ee76c80..9e9a77c271 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -52,7 +52,11 @@ Name GMSrc::name() const {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-CodecSrc::CodecSrc(Path path, Mode mode) : fPath(path), fMode(mode) {}
+CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType)
+ : fPath(path)
+ , fMode(mode)
+ , fDstColorType(dstColorType)
+{}
Error CodecSrc::draw(SkCanvas* canvas) const {
SkImageInfo canvasInfo;
@@ -66,27 +70,53 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
if (!encoded) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
}
-
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
- if (!codec) {
- return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
+ if (NULL == codec.get()) {
+ return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
+ }
+
+ // Choose the color type to decode to
+ SkImageInfo decodeInfo = codec->getInfo();
+ SkColorType canvasColorType = canvasInfo.colorType();
+ switch (fDstColorType) {
+ case kIndex8_Always_DstColorType:
+ case kGrayscale_Always_DstColorType:
+ if (kRGB_565_SkColorType == canvasColorType) {
+ return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
+ }
+ break;
+ default:
+ decodeInfo = decodeInfo.makeColorType(canvasColorType);
+ break;
+ }
+
+ // Construct a color table for the decode if necessary
+ SkAutoTUnref<SkColorTable> colorTable(NULL);
+ SkPMColor* colorPtr = NULL;
+ int* colorCountPtr = NULL;
+ int maxColors = 256;
+ if (kIndex_8_SkColorType == decodeInfo.colorType()) {
+ SkPMColor colors[256];
+ colorTable.reset(SkNEW_ARGS(SkColorTable, (colors, maxColors)));
+ colorPtr = const_cast<SkPMColor*>(colorTable->readColors());
+ colorCountPtr = &maxColors;
}
- SkImageInfo decodeInfo = codec->getInfo().makeColorType(canvasInfo.colorType());
+ // FIXME: Currently we cannot draw unpremultiplied sources.
if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) {
- // FIXME: Currently we cannot draw unpremultiplied sources.
decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType);
}
SkBitmap bitmap;
- if (!bitmap.tryAllocPixels(decodeInfo)) {
+ if (!bitmap.tryAllocPixels(decodeInfo, NULL, colorTable.get())) {
return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(),
decodeInfo.width(), decodeInfo.height());
}
switch (fMode) {
case kNormal_Mode:
- switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes())) {
+ switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(), NULL,
+ colorPtr, colorCountPtr)) {
case SkImageGenerator::kSuccess:
// We consider incomplete to be valid, since we should still decode what is
// available.
diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h
index 57af911062..0807cb6644 100644
--- a/dm/DMSrcSink.h
+++ b/dm/DMSrcSink.h
@@ -13,6 +13,7 @@
#include "SkBBoxHierarchy.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
+#include "SkCodec.h"
#include "SkData.h"
#include "SkGPipe.h"
#include "SkPicture.h"
@@ -94,14 +95,20 @@ public:
kNormal_Mode,
kScanline_Mode,
};
- CodecSrc(Path, Mode);
+ enum DstColorType {
+ kGetFromCanvas_DstColorType,
+ kIndex8_Always_DstColorType,
+ kGrayscale_Always_DstColorType,
+ };
+ CodecSrc(Path, Mode, DstColorType);
Error draw(SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
private:
- Path fPath;
- Mode fMode;
+ Path fPath;
+ Mode fMode;
+ DstColorType fDstColorType;
};