| Index: tests/CodecTest.cpp
|
| diff --git a/tests/CodecTest.cpp b/tests/CodecTest.cpp
|
| index b01750d41074a42b7b4d4e9139f9bc42b741e1b5..babf901a15685aa8754a9e491d3089be1e5d9970 100644
|
| --- a/tests/CodecTest.cpp
|
| +++ b/tests/CodecTest.cpp
|
| @@ -1074,22 +1074,45 @@ DEF_TEST(Codec_ColorXform, r) {
|
| check_color_xform(r, "mandrill_512.png");
|
| }
|
|
|
| -static void check_round_trip(skiatest::Reporter* r, const SkBitmap& bm1) {
|
| - SkColorType origColorType = bm1.colorType();
|
| - SkAlphaType origAlphaType = bm1.alphaType();
|
| +static bool color_type_match(SkColorType origColorType, SkColorType codecColorType) {
|
| + switch (origColorType) {
|
| + case kRGBA_8888_SkColorType:
|
| + case kBGRA_8888_SkColorType:
|
| + return kRGBA_8888_SkColorType == codecColorType ||
|
| + kBGRA_8888_SkColorType == codecColorType;
|
| + default:
|
| + return origColorType == codecColorType;
|
| + }
|
| +}
|
| +
|
| +static bool alpha_type_match(SkAlphaType origAlphaType, SkAlphaType codecAlphaType) {
|
| + switch (origAlphaType) {
|
| + case kUnpremul_SkAlphaType:
|
| + case kPremul_SkAlphaType:
|
| + return kUnpremul_SkAlphaType == codecAlphaType ||
|
| + kPremul_SkAlphaType == codecAlphaType;
|
| + default:
|
| + return origAlphaType == codecAlphaType;
|
| + }
|
| +}
|
| +
|
| +static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const SkImageInfo& info) {
|
| + SkBitmap bm1;
|
| + bm1.allocPixels(info);
|
| + SkCodec::Result result = origCodec->getPixels(info, bm1.getPixels(), bm1.rowBytes());
|
| + REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
| // 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.
|
| SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get()));
|
| - REPORTER_ASSERT(r, origColorType == codec->getInfo().colorType());
|
| - REPORTER_ASSERT(r, origAlphaType == codec->getInfo().alphaType());
|
| + REPORTER_ASSERT(r, color_type_match(info.colorType(), codec->getInfo().colorType()));
|
| + REPORTER_ASSERT(r, alpha_type_match(info.alphaType(), codec->getInfo().alphaType()));
|
|
|
| SkBitmap bm2;
|
| - bm2.allocPixels(codec->getInfo());
|
| - SkCodec::Result result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes());
|
| + bm2.allocPixels(info);
|
| + result = codec->getPixels(info, bm2.getPixels(), bm2.rowBytes());
|
| REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
| SkMD5::Digest d1, d2;
|
| @@ -1099,26 +1122,49 @@ static void check_round_trip(skiatest::Reporter* r, const SkBitmap& bm1) {
|
| }
|
|
|
| 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()));
|
| +
|
| + // Test 565
|
| 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);
|
| + check_round_trip(r, codec.get(), info565);
|
| +
|
| + // Test RGBA opaque
|
| + SkImageInfo infoRGBA = codec->getInfo().makeColorType(kRGBA_8888_SkColorType);
|
| + check_round_trip(r, codec.get(), infoRGBA);
|
|
|
| - // Create an arbitrary gray bitmap.
|
| + // Test BGRA opaque
|
| + SkImageInfo infoBGRA = codec->getInfo().makeColorType(kBGRA_8888_SkColorType);
|
| + check_round_trip(r, codec.get(), infoBGRA);
|
| +
|
| + // Test Gray
|
| 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);
|
| + check_round_trip(r, codec.get(), codec->getInfo());
|
| +
|
| + path = "arrow.png";
|
| + stream.reset(resource(path));
|
| + codec.reset(SkCodec::NewFromStream(stream.release()));
|
| +
|
| + // Test RGBA/BGRA with alpha
|
| + SkImageInfo infoRGBAPremul = codec->getInfo().makeColorType(kRGBA_8888_SkColorType)
|
| + .makeAlphaType(kPremul_SkAlphaType)
|
| + .makeColorSpace(nullptr);
|
| + check_round_trip(r, codec.get(), infoRGBAPremul);
|
| + SkImageInfo infoBGRAPremul = codec->getInfo().makeColorType(kBGRA_8888_SkColorType)
|
| + .makeAlphaType(kPremul_SkAlphaType)
|
| + .makeColorSpace(nullptr);
|
| + check_round_trip(r, codec.get(), infoBGRAPremul);
|
| + SkImageInfo infoRGBAUnpremul = codec->getInfo().makeColorType(kRGBA_8888_SkColorType)
|
| + .makeAlphaType(kUnpremul_SkAlphaType)
|
| + .makeColorSpace(nullptr);
|
| + check_round_trip(r, codec.get(), infoRGBAUnpremul);
|
| + SkImageInfo infoBGRAUnpremul = codec->getInfo().makeColorType(kBGRA_8888_SkColorType)
|
| + .makeAlphaType(kUnpremul_SkAlphaType)
|
| + .makeColorSpace(nullptr);
|
| + check_round_trip(r, codec.get(), infoBGRAUnpremul);
|
| }
|
|
|
| static void test_conversion_possible(skiatest::Reporter* r, const char* path,
|
|
|