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

Side by Side Diff: tests/CodecTest.cpp

Issue 2247743002: Fix color xform width bug when scaling/subsetting (Closed) Base URL: https://skia.googlesource.com/skia.git@skipstuff
Patch Set: Rebase Created 4 years, 3 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/SkSwizzler.h ('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"
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 SkAndroidCodec::AndroidOptions opts; 1037 SkAndroidCodec::AndroidOptions opts;
1038 opts.fSampleSize = 12; 1038 opts.fSampleSize = 12;
1039 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(),
1040 rowBytes, &opts); 1040 rowBytes, &opts);
1041 1041
1042 // Rewind the codec and perform a full image decode. 1042 // Rewind the codec and perform a full image decode.
1043 SkCodec::Result result = codec->getPixels(codec->getInfo(), pixelStorage.get (), rowBytes); 1043 SkCodec::Result result = codec->getPixels(codec->getInfo(), pixelStorage.get (), rowBytes);
1044 REPORTER_ASSERT(r, SkCodec::kSuccess == result); 1044 REPORTER_ASSERT(r, SkCodec::kSuccess == result);
1045 } 1045 }
1046 1046
1047 static void check_color_xform(skiatest::Reporter* r, const char* path) {
1048 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(resource(p ath)));
1049
1050 SkAndroidCodec::AndroidOptions opts;
1051 opts.fSampleSize = 3;
1052 const int subsetWidth = codec->getInfo().width() / 2;
1053 const int subsetHeight = codec->getInfo().height() / 2;
1054 SkIRect subset = SkIRect::MakeWH(subsetWidth, subsetHeight);
1055 opts.fSubset = &subset;
1056
1057 const int dstWidth = subsetWidth / opts.fSampleSize;
1058 const int dstHeight = subsetHeight / opts.fSampleSize;
1059 sk_sp<SkData> data = SkData::MakeFromFileName(
1060 GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
1061 sk_sp<SkColorSpace> colorSpace = SkColorSpace::NewICC(data->data(), data->si ze());
1062 SkImageInfo dstInfo = codec->getInfo().makeWH(dstWidth, dstHeight)
1063 .makeColorType(kN32_SkColorType)
1064 .makeColorSpace(colorSpace);
1065
1066 size_t rowBytes = dstInfo.minRowBytes();
1067 SkAutoMalloc pixelStorage(dstInfo.getSafeSize(rowBytes));
1068 SkCodec::Result result = codec->getAndroidPixels(dstInfo, pixelStorage.get() , rowBytes, &opts);
1069 REPORTER_ASSERT(r, SkCodec::kSuccess == result);
1070 }
1071
1072 DEF_TEST(Codec_ColorXform, r) {
1073 check_color_xform(r, "mandrill_512_q075.jpg");
1074 check_color_xform(r, "mandrill_512.png");
1075 }
1076
1047 DEF_TEST(Codec_Png565, r) { 1077 DEF_TEST(Codec_Png565, r) {
1048 // Create an arbitrary 565 bitmap. 1078 // Create an arbitrary 565 bitmap.
1049 const char* path = "mandrill_512_q075.jpg"; 1079 const char* path = "mandrill_512_q075.jpg";
1050 SkAutoTDelete<SkStream> stream(resource(path)); 1080 SkAutoTDelete<SkStream> stream(resource(path));
1051 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release())); 1081 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
1052 SkImageInfo info565 = codec->getInfo().makeColorType(kRGB_565_SkColorType); 1082 SkImageInfo info565 = codec->getInfo().makeColorType(kRGB_565_SkColorType);
1053 SkBitmap bm1; 1083 SkBitmap bm1;
1054 bm1.allocPixels(info565); 1084 bm1.allocPixels(info565);
1055 SkCodec::Result result = codec->getPixels(info565, bm1.getPixels(), bm1.rowB ytes()); 1085 SkCodec::Result result = codec->getPixels(info565, bm1.getPixels(), bm1.rowB ytes());
1056 REPORTER_ASSERT(r, SkCodec::kSuccess == result); 1086 REPORTER_ASSERT(r, SkCodec::kSuccess == result);
(...skipping 10 matching lines...) Expand all
1067 SkBitmap bm2; 1097 SkBitmap bm2;
1068 bm2.allocPixels(codec->getInfo()); 1098 bm2.allocPixels(codec->getInfo());
1069 result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes()) ; 1099 result = codec->getPixels(codec->getInfo(), bm2.getPixels(), bm2.rowBytes()) ;
1070 REPORTER_ASSERT(r, SkCodec::kSuccess == result); 1100 REPORTER_ASSERT(r, SkCodec::kSuccess == result);
1071 1101
1072 SkMD5::Digest d1, d2; 1102 SkMD5::Digest d1, d2;
1073 md5(bm1, &d1); 1103 md5(bm1, &d1);
1074 md5(bm2, &d2); 1104 md5(bm2, &d2);
1075 REPORTER_ASSERT(r, d1 == d2); 1105 REPORTER_ASSERT(r, d1 == d2);
1076 } 1106 }
OLDNEW
« no previous file with comments | « src/codec/SkSwizzler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698