Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(839)

Side by Side Diff: tests/CodecTest.cpp

Issue 2212563003: Modify SkPngCodec to recognize 565 images from the sBIT chunk (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Allow SkPngCodec to set SkImageInfo directly Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/codec/SkPngCodec.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « src/codec/SkPngCodec.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698