OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Resources.h" | 8 #include "Resources.h" |
9 #include "SkAndroidCodec.h" | 9 #include "SkAndroidCodec.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1067 SkAutoMalloc pixelStorage(dstInfo.getSafeSize(rowBytes)); | 1067 SkAutoMalloc pixelStorage(dstInfo.getSafeSize(rowBytes)); |
1068 SkCodec::Result result = codec->getAndroidPixels(dstInfo, pixelStorage.get() , rowBytes, &opts); | 1068 SkCodec::Result result = codec->getAndroidPixels(dstInfo, pixelStorage.get() , rowBytes, &opts); |
1069 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | 1069 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
1070 } | 1070 } |
1071 | 1071 |
1072 DEF_TEST(Codec_ColorXform, r) { | 1072 DEF_TEST(Codec_ColorXform, r) { |
1073 check_color_xform(r, "mandrill_512_q075.jpg"); | 1073 check_color_xform(r, "mandrill_512_q075.jpg"); |
1074 check_color_xform(r, "mandrill_512.png"); | 1074 check_color_xform(r, "mandrill_512.png"); |
1075 } | 1075 } |
1076 | 1076 |
1077 static void check_round_trip(skiatest::Reporter* r, const SkBitmap& bm1) { | 1077 static bool color_type_match(SkColorType origColorType, SkColorType codecColorTy pe) { |
1078 SkColorType origColorType = bm1.colorType(); | 1078 switch (origColorType) { |
1079 SkAlphaType origAlphaType = bm1.alphaType(); | 1079 case kRGBA_8888_SkColorType: |
1080 case kBGRA_8888_SkColorType: | |
1081 return kRGBA_8888_SkColorType == codecColorType || | |
1082 kBGRA_8888_SkColorType == codecColorType; | |
1083 default: | |
1084 return origColorType == codecColorType; | |
1085 } | |
1086 } | |
1087 | |
1088 static bool alpha_type_match(SkAlphaType origAlphaType, SkAlphaType codecAlphaTy pe) { | |
1089 switch (origAlphaType) { | |
1090 case kUnpremul_SkAlphaType: | |
1091 case kPremul_SkAlphaType: | |
1092 return kUnpremul_SkAlphaType == codecAlphaType || | |
1093 kPremul_SkAlphaType == codecAlphaType; | |
1094 default: | |
1095 return origAlphaType == codecAlphaType; | |
1096 } | |
1097 } | |
1098 | |
1099 static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const Sk ImageInfo& info) { | |
1100 SkBitmap bm1; | |
1101 SkPMColor colors[256]; | |
1102 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, 256)); | |
1103 bm1.allocPixels(info, nullptr, colorTable.get()); | |
1104 int numColors; | |
1105 SkCodec::Result result = origCodec->getPixels(info, bm1.getPixels(), bm1.row Bytes(), nullptr, | |
scroggo
2016/09/12 17:16:50
Won't this leave colorTable (which the bitmap poin
msarett
2016/09/12 19:39:20
Yes, it's just irrelevant because the digest compa
| |
1106 colors, &numColors); | |
1107 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | |
1080 | 1108 |
1081 // Encode the image to png. | 1109 // Encode the image to png. |
1082 sk_sp<SkData> data = | 1110 sk_sp<SkData> data = |
1083 sk_sp<SkData>(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_T ype, 100)); | 1111 sk_sp<SkData>(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_T ype, 100)); |
1084 | 1112 |
1085 // Prepare to decode. The codec should recognize that the PNG is 565. | |
1086 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get())); | 1113 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get())); |
1087 REPORTER_ASSERT(r, origColorType == codec->getInfo().colorType()); | 1114 REPORTER_ASSERT(r, color_type_match(info.colorType(), codec->getInfo().color Type())); |
1088 REPORTER_ASSERT(r, origAlphaType == codec->getInfo().alphaType()); | 1115 REPORTER_ASSERT(r, alpha_type_match(info.alphaType(), codec->getInfo().alpha Type())); |
1089 | 1116 |
1090 SkBitmap bm2; | 1117 SkBitmap bm2; |
1091 bm2.allocPixels(codec->getInfo()); | 1118 bm2.allocPixels(info, nullptr, colorTable.get()); |
1092 SkCodec::Result result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes()); | 1119 result = codec->getPixels(info, bm2.getPixels(), bm2.rowBytes(), nullptr, co lors, &numColors); |
scroggo
2016/09/12 17:16:50
Once again, bm2's colorTable will remain uninitial
msarett
2016/09/12 19:39:20
I had thought that the md5 would be comparing the
| |
1093 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | 1120 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
1094 | 1121 |
1095 SkMD5::Digest d1, d2; | 1122 SkMD5::Digest d1, d2; |
1096 md5(bm1, &d1); | 1123 md5(bm1, &d1); |
1097 md5(bm2, &d2); | 1124 md5(bm2, &d2); |
1098 REPORTER_ASSERT(r, d1 == d2); | 1125 REPORTER_ASSERT(r, d1 == d2); |
1099 } | 1126 } |
1100 | 1127 |
1101 DEF_TEST(Codec_PngRoundTrip, r) { | 1128 DEF_TEST(Codec_PngRoundTrip, r) { |
1102 // Create an arbitrary 565 bitmap. | |
1103 const char* path = "mandrill_512_q075.jpg"; | 1129 const char* path = "mandrill_512_q075.jpg"; |
1104 SkAutoTDelete<SkStream> stream(resource(path)); | 1130 SkAutoTDelete<SkStream> stream(resource(path)); |
1105 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); | 1131 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
1132 | |
1133 // Test 565 | |
1106 SkImageInfo info565 = codec->getInfo().makeColorType(kRGB_565_SkColorType); | 1134 SkImageInfo info565 = codec->getInfo().makeColorType(kRGB_565_SkColorType); |
scroggo
2016/09/12 17:16:50
nit: Can you fold these three into one for loop? S
msarett
2016/09/12 19:39:20
Done.
| |
1107 SkBitmap bm1; | 1135 check_round_trip(r, codec.get(), info565); |
1108 bm1.allocPixels(info565); | |
1109 SkCodec::Result result = codec->getPixels(info565, bm1.getPixels(), bm1.rowB ytes()); | |
1110 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | |
1111 check_round_trip(r, bm1); | |
1112 | 1136 |
1113 // Create an arbitrary gray bitmap. | 1137 // Test RGBA opaque |
1138 SkImageInfo infoRGBA = codec->getInfo().makeColorType(kRGBA_8888_SkColorType ); | |
1139 check_round_trip(r, codec.get(), infoRGBA); | |
1140 | |
1141 // Test BGRA opaque | |
1142 SkImageInfo infoBGRA = codec->getInfo().makeColorType(kBGRA_8888_SkColorType ); | |
1143 check_round_trip(r, codec.get(), infoBGRA); | |
1144 | |
1145 // Test Gray | |
1114 path = "grayscale.jpg"; | 1146 path = "grayscale.jpg"; |
1115 stream.reset(resource(path)); | 1147 stream.reset(resource(path)); |
1116 codec.reset(SkCodec::NewFromStream(stream.release())); | 1148 codec.reset(SkCodec::NewFromStream(stream.release())); |
1117 SkBitmap bm2; | 1149 check_round_trip(r, codec.get(), codec->getInfo()); |
1118 bm2.allocPixels(codec->getInfo()); | 1150 |
1119 result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes()) ; | 1151 path = "yellow_rose.png"; |
1120 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | 1152 stream.reset(resource(path)); |
1121 check_round_trip(r, bm2); | 1153 codec.reset(SkCodec::NewFromStream(stream.release())); |
1154 | |
1155 // Test RGBA/BGRA with alpha | |
scroggo
2016/09/12 17:16:50
Can this be another for loop?
msarett
2016/09/12 19:39:20
Done.
| |
1156 SkImageInfo infoRGBAPremul = codec->getInfo().makeColorType(kRGBA_8888_SkCol orType) | |
1157 .makeAlphaType(kPremul_SkAlphaT ype) | |
1158 .makeColorSpace(nullptr); | |
scroggo
2016/09/12 17:16:50
I'm guessing the color space needs to be removed b
msarett
2016/09/12 19:39:20
Yes, uggh...
| |
1159 check_round_trip(r, codec.get(), infoRGBAPremul); | |
1160 SkImageInfo infoBGRAPremul = codec->getInfo().makeColorType(kBGRA_8888_SkCol orType) | |
1161 .makeAlphaType(kPremul_SkAlphaT ype) | |
1162 .makeColorSpace(nullptr); | |
1163 check_round_trip(r, codec.get(), infoBGRAPremul); | |
1164 SkImageInfo infoRGBAUnpremul = codec->getInfo().makeColorType(kRGBA_8888_SkC olorType) | |
1165 .makeAlphaType(kUnpremul_SkAl phaType) | |
1166 .makeColorSpace(nullptr); | |
1167 check_round_trip(r, codec.get(), infoRGBAUnpremul); | |
1168 SkImageInfo infoBGRAUnpremul = codec->getInfo().makeColorType(kBGRA_8888_SkC olorType) | |
1169 .makeAlphaType(kUnpremul_SkAl phaType) | |
1170 .makeColorSpace(nullptr); | |
1171 check_round_trip(r, codec.get(), infoBGRAUnpremul); | |
1172 | |
1173 path = "index8.png"; | |
1174 stream.reset(resource(path)); | |
1175 codec.reset(SkCodec::NewFromStream(stream.release())); | |
1176 | |
1177 // Text Index8 | |
1178 SkImageInfo infoIndex8Unpremul = codec->getInfo().makeAlphaType(kUnpremul_Sk AlphaType) | |
1179 .makeColorSpace(nullptr); | |
1180 check_round_trip(r, codec.get(), infoIndex8Unpremul); | |
1181 //SkImageInfo infoIndex8Premul = codec->getInfo().makeAlphaType(kPremul_SkAl phaType) | |
scroggo
2016/09/12 17:16:50
Comment explaining why this one is commented out?
msarett
2016/09/12 19:39:20
Because I forgot to comment it back in :).
| |
1182 // .makeColorSpace(nullptr); | |
1183 //check_round_trip(r, codec.get(), infoIndex8Premul); | |
1122 } | 1184 } |
1123 | 1185 |
1124 static void test_conversion_possible(skiatest::Reporter* r, const char* path, | 1186 static void test_conversion_possible(skiatest::Reporter* r, const char* path, |
1125 bool testScanlineDecoder) { | 1187 bool testScanlineDecoder) { |
1126 SkAutoTDelete<SkStream> stream(resource(path)); | 1188 SkAutoTDelete<SkStream> stream(resource(path)); |
1127 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); | 1189 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
1128 SkImageInfo infoF16 = codec->getInfo().makeColorType(kRGBA_F16_SkColorType); | 1190 SkImageInfo infoF16 = codec->getInfo().makeColorType(kRGBA_F16_SkColorType); |
1129 | 1191 |
1130 SkBitmap bm; | 1192 SkBitmap bm; |
1131 bm.allocPixels(infoF16); | 1193 bm.allocPixels(infoF16); |
(...skipping 11 matching lines...) Expand all Loading... | |
1143 result = codec->startScanlineDecode(infoF16); | 1205 result = codec->startScanlineDecode(infoF16); |
1144 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | 1206 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
1145 } | 1207 } |
1146 } | 1208 } |
1147 | 1209 |
1148 DEF_TEST(Codec_F16ConversionPossible, r) { | 1210 DEF_TEST(Codec_F16ConversionPossible, r) { |
1149 test_conversion_possible(r, "color_wheel.webp", false); | 1211 test_conversion_possible(r, "color_wheel.webp", false); |
1150 test_conversion_possible(r, "mandrill_512_q075.jpg", true); | 1212 test_conversion_possible(r, "mandrill_512_q075.jpg", true); |
1151 test_conversion_possible(r, "yellow_rose.png", true); | 1213 test_conversion_possible(r, "yellow_rose.png", true); |
1152 } | 1214 } |
OLD | NEW |