aboutsummaryrefslogtreecommitdiff
path: root/tests/CodecTest.cpp
diff options
context:
space:
mode:
authormsarett <msarett@google.com>2016-08-29 14:47:49 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-29 14:47:49 -0700
commit9b09cd8372ad0b25da20a50d9967bb02f9f2f9d8 (patch)
tree48d8e47ebf862764509620b9af2e6954241d753d /tests/CodecTest.cpp
parente4d6a1be481fab631022b90788fa079317aba75b (diff)
Add Gray support to SkPNGImageEncoder
BUG=skia:5616 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2290843002 Review-Url: https://codereview.chromium.org/2290843002
Diffstat (limited to 'tests/CodecTest.cpp')
-rw-r--r--tests/CodecTest.cpp44
1 files changed, 30 insertions, 14 deletions
diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
index 8023ff219d..fcbfadd068 100644
--- a/tests/CodecTest.cpp
+++ b/tests/CodecTest.cpp
@@ -1074,29 +1074,22 @@ DEF_TEST(Codec_ColorXform, r) {
check_color_xform(r, "mandrill_512.png");
}
-DEF_TEST(Codec_Png565, r) {
- // Create an arbitrary 565 bitmap.
- const char* path = "mandrill_512_q075.jpg";
- SkAutoTDelete<SkStream> stream(resource(path));
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
- SkImageInfo info565 = codec->getInfo().makeColorType(kRGB_565_SkColorType);
- SkBitmap bm1;
- bm1.allocPixels(info565);
- SkCodec::Result result = codec->getPixels(info565, bm1.getPixels(), bm1.rowBytes());
- REPORTER_ASSERT(r, SkCodec::kSuccess == result);
+static void check_round_trip(skiatest::Reporter* r, const SkBitmap& bm1) {
+ SkColorType origColorType = bm1.colorType();
+ SkAlphaType origAlphaType = bm1.alphaType();
// Encode the image to png.
sk_sp<SkData> data =
sk_sp<SkData>(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_Type, 100));
// Prepare to decode. The codec should recognize that the PNG is 565.
- codec.reset(SkCodec::NewFromData(data.get()));
- REPORTER_ASSERT(r, kRGB_565_SkColorType == codec->getInfo().colorType());
- REPORTER_ASSERT(r, kOpaque_SkAlphaType == codec->getInfo().alphaType());
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get()));
+ REPORTER_ASSERT(r, origColorType == codec->getInfo().colorType());
+ REPORTER_ASSERT(r, origAlphaType == codec->getInfo().alphaType());
SkBitmap bm2;
bm2.allocPixels(codec->getInfo());
- result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes());
+ SkCodec::Result result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes());
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
SkMD5::Digest d1, d2;
@@ -1104,3 +1097,26 @@ DEF_TEST(Codec_Png565, r) {
md5(bm2, &d2);
REPORTER_ASSERT(r, d1 == d2);
}
+
+DEF_TEST(Codec_PngRoundTrip, r) {
+ // Create an arbitrary 565 bitmap.
+ const char* path = "mandrill_512_q075.jpg";
+ SkAutoTDelete<SkStream> stream(resource(path));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
+ SkImageInfo info565 = codec->getInfo().makeColorType(kRGB_565_SkColorType);
+ SkBitmap bm1;
+ bm1.allocPixels(info565);
+ SkCodec::Result result = codec->getPixels(info565, bm1.getPixels(), bm1.rowBytes());
+ REPORTER_ASSERT(r, SkCodec::kSuccess == result);
+ check_round_trip(r, bm1);
+
+ // Create an arbitrary gray bitmap.
+ path = "grayscale.jpg";
+ stream.reset(resource(path));
+ codec.reset(SkCodec::NewFromStream(stream.release()));
+ SkBitmap bm2;
+ bm2.allocPixels(codec->getInfo());
+ result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes());
+ REPORTER_ASSERT(r, SkCodec::kSuccess == result);
+ check_round_trip(r, bm2);
+}