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" |
11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
12 #include "SkCodecImageGenerator.h" | 12 #include "SkCodecImageGenerator.h" |
13 #include "SkData.h" | 13 #include "SkData.h" |
| 14 #include "SkImageEncoder.h" |
14 #include "SkFrontBufferedStream.h" | 15 #include "SkFrontBufferedStream.h" |
15 #include "SkMD5.h" | 16 #include "SkMD5.h" |
16 #include "SkRandom.h" | 17 #include "SkRandom.h" |
17 #include "SkStream.h" | 18 #include "SkStream.h" |
18 #include "SkStreamPriv.h" | 19 #include "SkStreamPriv.h" |
19 #include "SkPngChunkReader.h" | 20 #include "SkPngChunkReader.h" |
20 #include "Test.h" | 21 #include "Test.h" |
21 | 22 |
22 #include "png.h" | 23 #include "png.h" |
23 | 24 |
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 // Perform a sampled decode. | 1036 // Perform a sampled decode. |
1036 SkAndroidCodec::AndroidOptions opts; | 1037 SkAndroidCodec::AndroidOptions opts; |
1037 opts.fSampleSize = 12; | 1038 opts.fSampleSize = 12; |
1038 codec->getAndroidPixels(codec->getInfo().makeWH(width / 12, height / 12), pi
xelStorage.get(), | 1039 codec->getAndroidPixels(codec->getInfo().makeWH(width / 12, height / 12), pi
xelStorage.get(), |
1039 rowBytes, &opts); | 1040 rowBytes, &opts); |
1040 | 1041 |
1041 // Rewind the codec and perform a full image decode. | 1042 // Rewind the codec and perform a full image decode. |
1042 SkCodec::Result result = codec->getPixels(codec->getInfo(), pixelStorage.get
(), rowBytes); | 1043 SkCodec::Result result = codec->getPixels(codec->getInfo(), pixelStorage.get
(), rowBytes); |
1043 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | 1044 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
1044 } | 1045 } |
| 1046 |
| 1047 DEF_TEST(Codec_Png565, r) { |
| 1048 // Create an arbitrary 565 bitmap. |
| 1049 const char* path = "mandrill_512_q075.jpg"; |
| 1050 SkAutoTDelete<SkStream> stream(resource(path)); |
| 1051 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); |
| 1052 SkImageInfo info565 = codec->getInfo().makeColorType(kRGB_565_SkColorType); |
| 1053 SkBitmap bm1; |
| 1054 bm1.allocPixels(info565); |
| 1055 SkCodec::Result result = codec->getPixels(info565, bm1.getPixels(), bm1.rowB
ytes()); |
| 1056 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
| 1057 |
| 1058 // Encode the image to png. |
| 1059 sk_sp<SkData> data = |
| 1060 sk_sp<SkData>(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_T
ype, 100)); |
| 1061 |
| 1062 // Prepare to decode. The codec should recognize that the PNG is 565. |
| 1063 codec.reset(SkCodec::NewFromData(data.get())); |
| 1064 REPORTER_ASSERT(r, kRGB_565_SkColorType == codec->getInfo().colorType()); |
| 1065 REPORTER_ASSERT(r, kOpaque_SkAlphaType == codec->getInfo().alphaType()); |
| 1066 |
| 1067 SkBitmap bm2; |
| 1068 bm2.allocPixels(codec->getInfo()); |
| 1069 result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes())
; |
| 1070 REPORTER_ASSERT(r, SkCodec::kSuccess == result); |
| 1071 |
| 1072 SkMD5::Digest d1, d2; |
| 1073 md5(bm1, &d1); |
| 1074 md5(bm2, &d2); |
| 1075 REPORTER_ASSERT(r, d1 == d2); |
| 1076 } |
OLD | NEW |