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 DEF_TEST(Codec_Png565, r) { | 1077 static void check_round_trip(skiatest::Reporter* r, const SkBitmap& bm1) { |
1078 // Create an arbitrary 565 bitmap. | 1078 SkColorType origColorType = bm1.colorType(); |
1079 const char* path = "mandrill_512_q075.jpg"; | 1079 SkAlphaType origAlphaType = bm1.alphaType(); |
1080 SkAutoTDelete<SkStream> stream(resource(path)); | |
1081 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); | |
1082 SkImageInfo info565 = codec->getInfo().makeColorType(kRGB_565_SkColorType); | |
1083 SkBitmap bm1; | |
1084 bm1.allocPixels(info565); | |
1085 SkCodec::Result result = codec->getPixels(info565, bm1.getPixels(), bm1.rowB
ytes()); | |
1086 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | |
1087 | 1080 |
1088 // Encode the image to png. | 1081 // Encode the image to png. |
1089 sk_sp<SkData> data = | 1082 sk_sp<SkData> data = |
1090 sk_sp<SkData>(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_T
ype, 100)); | 1083 sk_sp<SkData>(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_T
ype, 100)); |
1091 | 1084 |
1092 // Prepare to decode. The codec should recognize that the PNG is 565. | 1085 // Prepare to decode. The codec should recognize that the PNG is 565. |
1093 codec.reset(SkCodec::NewFromData(data.get())); | 1086 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get())); |
1094 REPORTER_ASSERT(r, kRGB_565_SkColorType == codec->getInfo().colorType()); | 1087 REPORTER_ASSERT(r, origColorType == codec->getInfo().colorType()); |
1095 REPORTER_ASSERT(r, kOpaque_SkAlphaType == codec->getInfo().alphaType()); | 1088 REPORTER_ASSERT(r, origAlphaType == codec->getInfo().alphaType()); |
1096 | 1089 |
1097 SkBitmap bm2; | 1090 SkBitmap bm2; |
1098 bm2.allocPixels(codec->getInfo()); | 1091 bm2.allocPixels(codec->getInfo()); |
1099 result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes())
; | 1092 SkCodec::Result result = codec->getPixels(codec->getInfo(), bm2.getPixels(),
bm2.rowBytes()); |
1100 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | 1093 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
1101 | 1094 |
1102 SkMD5::Digest d1, d2; | 1095 SkMD5::Digest d1, d2; |
1103 md5(bm1, &d1); | 1096 md5(bm1, &d1); |
1104 md5(bm2, &d2); | 1097 md5(bm2, &d2); |
1105 REPORTER_ASSERT(r, d1 == d2); | 1098 REPORTER_ASSERT(r, d1 == d2); |
1106 } | 1099 } |
| 1100 |
| 1101 DEF_TEST(Codec_PngRoundTrip, r) { |
| 1102 // Create an arbitrary 565 bitmap. |
| 1103 const char* path = "mandrill_512_q075.jpg"; |
| 1104 SkAutoTDelete<SkStream> stream(resource(path)); |
| 1105 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
| 1106 SkImageInfo info565 = codec->getInfo().makeColorType(kRGB_565_SkColorType); |
| 1107 SkBitmap bm1; |
| 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 |
| 1113 // Create an arbitrary gray bitmap. |
| 1114 path = "grayscale.jpg"; |
| 1115 stream.reset(resource(path)); |
| 1116 codec.reset(SkCodec::NewFromStream(stream.release())); |
| 1117 SkBitmap bm2; |
| 1118 bm2.allocPixels(codec->getInfo()); |
| 1119 result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes())
; |
| 1120 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
| 1121 check_round_trip(r, bm2); |
| 1122 } |
OLD | NEW |