Chromium Code Reviews| 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 #if !defined(SK_BUILD_FOR_WIN) && !defined(SK_BUILD_FOR_MAC) && !defined(SK_BUIL D_FOR_IOS) | |
| 1048 | |
| 1049 // We need to disable this test on Mac and Windows because CG and WIC do not enc ode 565 as 565. | |
|
mtklein
2016/08/04 17:52:51
encode -> tag?
We can't ask them to nicely can we
msarett
2016/08/04 19:04:10
I would be in favor of using our encoder as the de
| |
| 1050 DEF_TEST(Codec_Png565, r) { | |
| 1051 // Create an arbitrary 565 bitmap. | |
| 1052 const char* path = "mandrill_512_q075.jpg"; | |
| 1053 SkAutoTDelete<SkStream> stream(resource(path)); | |
| 1054 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); | |
| 1055 SkImageInfo info565 = codec->getInfo().makeColorType(kRGB_565_SkColorType); | |
| 1056 SkBitmap bm1; | |
| 1057 bm1.allocPixels(info565); | |
| 1058 SkCodec::Result result = codec->getPixels(info565, bm1.getPixels(), bm1.rowB ytes()); | |
| 1059 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | |
| 1060 | |
| 1061 // Encode the image to png. | |
| 1062 sk_sp<SkData> data = | |
| 1063 sk_sp<SkData>(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_T ype, 100)); | |
| 1064 | |
| 1065 // Prepare to decode. The codec should recognize that the PNG is 565. | |
| 1066 codec.reset(SkCodec::NewFromData(data.get())); | |
| 1067 REPORTER_ASSERT(r, kRGB_565_SkColorType == codec->getInfo().colorType()); | |
| 1068 REPORTER_ASSERT(r, kOpaque_SkAlphaType == codec->getInfo().alphaType()); | |
| 1069 | |
| 1070 SkBitmap bm2; | |
| 1071 bm2.allocPixels(codec->getInfo()); | |
| 1072 result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes()) ; | |
| 1073 REPORTER_ASSERT(r, SkCodec::kSuccess == result); | |
| 1074 | |
| 1075 SkMD5::Digest d1, d2; | |
| 1076 md5(bm1, &d1); | |
| 1077 md5(bm2, &d2); | |
| 1078 REPORTER_ASSERT(r, d1 == d2); | |
| 1079 } | |
| 1080 | |
| 1081 #endif | |
| OLD | NEW |