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

Side by Side Diff: tests/CodexTest.cpp

Issue 1691823002: Test SkAndroidCodec for more types (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 otherAt = kUnpremul_SkAlphaType; 130 otherAt = kUnpremul_SkAlphaType;
131 } else { 131 } else {
132 otherAt = kPremul_SkAlphaType; 132 otherAt = kPremul_SkAlphaType;
133 } 133 }
134 // The other non-opaque alpha type should always succeed, but not ma tch. 134 // The other non-opaque alpha type should always succeed, but not ma tch.
135 test_info(r, codec, info.makeAlphaType(otherAt), expectedResult, nul lptr); 135 test_info(r, codec, info.makeAlphaType(otherAt), expectedResult, nul lptr);
136 } 136 }
137 } 137 }
138 } 138 }
139 139
140 // FIXME: SkScaledCodec is currently only supported for types used by BRD 140 static bool supports_partial_scanlines(const char path[]) {
141 // https://bug.skia.org/4428
142 static bool supports_scaled_codec(const char path[]) {
143 static const char* const exts[] = { 141 static const char* const exts[] = {
144 "jpg", "jpeg", "png", "webp" 142 "jpg", "jpeg", "png", "webp"
145 "JPG", "JPEG", "PNG", "WEBP" 143 "JPG", "JPEG", "PNG", "WEBP"
146 }; 144 };
147 145
148 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { 146 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
149 if (SkStrEndsWith(path, exts[i])) { 147 if (SkStrEndsWith(path, exts[i])) {
150 return true; 148 return true;
151 } 149 }
152 } 150 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 REPORTER_ASSERT(r, lines == 1); 221 REPORTER_ASSERT(r, lines == 1);
224 } 222 }
225 REPORTER_ASSERT(r, codec->getPixels(bm.info(), bm.getPixels(), bm.rowByt es()) 223 REPORTER_ASSERT(r, codec->getPixels(bm.info(), bm.getPixels(), bm.rowByt es())
226 == expectedResult); 224 == expectedResult);
227 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) 225 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
228 == 0); 226 == 0);
229 REPORTER_ASSERT(r, codec->skipScanlines(1) 227 REPORTER_ASSERT(r, codec->skipScanlines(1)
230 == 0); 228 == 0);
231 229
232 // Test partial scanline decodes 230 // Test partial scanline decodes
233 if (supports_scaled_codec(path) && info.width() >= 3) { 231 if (supports_partial_scanlines(path) && info.width() >= 3) {
234 SkCodec::Options options; 232 SkCodec::Options options;
235 int width = info.width(); 233 int width = info.width();
236 int height = info.height(); 234 int height = info.height();
237 SkIRect subset = SkIRect::MakeXYWH(2 * (width / 3), 0, width / 3, he ight); 235 SkIRect subset = SkIRect::MakeXYWH(2 * (width / 3), 0, width / 3, he ight);
238 options.fSubset = &subset; 236 options.fSubset = &subset;
239 237
240 const SkCodec::Result partialStartResult = codec->startScanlineDecod e(info, &options, 238 const SkCodec::Result partialStartResult = codec->startScanlineDecod e(info, &options,
241 nullptr, nullptr); 239 nullptr, nullptr);
242 REPORTER_ASSERT(r, partialStartResult == SkCodec::kSuccess); 240 REPORTER_ASSERT(r, partialStartResult == SkCodec::kSuccess);
243 241
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 REPORTER_ASSERT(r, result == expectedResult); 278 REPORTER_ASSERT(r, result == expectedResult);
281 // Webp is the only codec that supports subsets, and it will have mo dified the subset 279 // Webp is the only codec that supports subsets, and it will have mo dified the subset
282 // to have even left/top. 280 // to have even left/top.
283 REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTo p)); 281 REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTo p));
284 } else { 282 } else {
285 // No subsets will work. 283 // No subsets will work.
286 REPORTER_ASSERT(r, result == SkCodec::kUnimplemented); 284 REPORTER_ASSERT(r, result == SkCodec::kUnimplemented);
287 } 285 }
288 } 286 }
289 287
290 // SkScaledCodec tests 288 // SkAndroidCodec tests
291 if ((supportsScanlineDecoding || supportsSubsetDecoding) && supports_scaled_ codec(path)) { 289 if (supportsScanlineDecoding || supportsSubsetDecoding) {
292 290
293 SkAutoTDelete<SkStream> stream(resource(path)); 291 SkAutoTDelete<SkStream> stream(resource(path));
294 if (!stream) { 292 if (!stream) {
295 SkDebugf("Missing resource '%s'\n", path); 293 SkDebugf("Missing resource '%s'\n", path);
296 return; 294 return;
297 } 295 }
298 296
299 SkAutoTDelete<SkAndroidCodec> androidCodec(nullptr); 297 SkAutoTDelete<SkAndroidCodec> androidCodec(nullptr);
300 if (isIncomplete) { 298 if (isIncomplete) {
301 size_t size = stream->getLength(); 299 size_t size = stream->getLength();
302 SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3))); 300 SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3)));
303 androidCodec.reset(SkAndroidCodec::NewFromData(data)); 301 androidCodec.reset(SkAndroidCodec::NewFromData(data));
304 } else { 302 } else {
305 androidCodec.reset(SkAndroidCodec::NewFromStream(stream.detach())); 303 androidCodec.reset(SkAndroidCodec::NewFromStream(stream.detach()));
306 } 304 }
307 if (!androidCodec) { 305 if (!androidCodec) {
308 ERRORF(r, "Unable to decode '%s'", path); 306 ERRORF(r, "Unable to decode '%s'", path);
309 return; 307 return;
310 } 308 }
311 309
312 SkBitmap bm; 310 SkBitmap bm;
313 SkMD5::Digest scaledCodecDigest; 311 SkMD5::Digest androidCodecDigest;
314 test_codec(r, androidCodec.get(), bm, info, size, expectedResult, &scale dCodecDigest, 312 test_codec(r, androidCodec.get(), bm, info, size, expectedResult, &andro idCodecDigest,
315 &codecDigest); 313 &codecDigest);
316 } 314 }
317 315
318 // Test SkCodecImageGenerator 316 // Test SkCodecImageGenerator
319 if (!isIncomplete) { 317 if (!isIncomplete) {
320 SkAutoTDelete<SkStream> stream(resource(path)); 318 SkAutoTDelete<SkStream> stream(resource(path));
321 SkAutoTUnref<SkData> fullData(SkData::NewFromStream(stream, stream->getL ength())); 319 SkAutoTUnref<SkData> fullData(SkData::NewFromStream(stream, stream->getL ength()));
322 SkAutoTDelete<SkImageGenerator> gen(SkCodecImageGenerator::NewFromEncode dCodec(fullData)); 320 SkAutoTDelete<SkImageGenerator> gen(SkCodecImageGenerator::NewFromEncode dCodec(fullData));
323 SkBitmap bm; 321 SkBitmap bm;
324 bm.allocPixels(info); 322 bm.allocPixels(info);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream)); 509 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream));
512 test_invalid_stream(r, emptyPng, sizeof(emptyPng)); 510 test_invalid_stream(r, emptyPng, sizeof(emptyPng));
513 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg)); 511 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg));
514 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp)); 512 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp));
515 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp)); 513 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp));
516 test_invalid_stream(r, emptyIco, sizeof(emptyIco)); 514 test_invalid_stream(r, emptyIco, sizeof(emptyIco));
517 test_invalid_stream(r, emptyGif, sizeof(emptyGif)); 515 test_invalid_stream(r, emptyGif, sizeof(emptyGif));
518 } 516 }
519 517
520 DEF_TEST(Codec_null, r) { 518 DEF_TEST(Codec_null, r) {
521 // Attempting to create an SkCodec or an SkScaledCodec with null should not 519 // Attempting to create an SkCodec or an SkAndroidCodec with null should not
522 // crash. 520 // crash.
523 SkCodec* codec = SkCodec::NewFromStream(nullptr); 521 SkCodec* codec = SkCodec::NewFromStream(nullptr);
524 REPORTER_ASSERT(r, !codec); 522 REPORTER_ASSERT(r, !codec);
525 523
526 SkAndroidCodec* androidCodec = SkAndroidCodec::NewFromStream(nullptr); 524 SkAndroidCodec* androidCodec = SkAndroidCodec::NewFromStream(nullptr);
527 REPORTER_ASSERT(r, !androidCodec); 525 REPORTER_ASSERT(r, !androidCodec);
528 } 526 }
529 527
530 static void test_dimensions(skiatest::Reporter* r, const char path[]) { 528 static void test_dimensions(skiatest::Reporter* r, const char path[]) {
531 // Create the codec from the resource file 529 // Create the codec from the resource file
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 // Now test an image which is too big. Any image with a larger header (i.e. 952 // Now test an image which is too big. Any image with a larger header (i.e.
955 // has bigger width/height) is also too big. 953 // has bigger width/height) is also too big.
956 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header 954 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header
957 0x84, 0x80, 0x00, // W: 65536 955 0x84, 0x80, 0x00, // W: 65536
958 0x84, 0x80, 0x00 }; // H: 65536 956 0x84, 0x80, 0x00 }; // H: 65536
959 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); 957 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false));
960 codec.reset(SkCodec::NewFromStream(stream.detach())); 958 codec.reset(SkCodec::NewFromStream(stream.detach()));
961 959
962 REPORTER_ASSERT(r, !codec); 960 REPORTER_ASSERT(r, !codec);
963 } 961 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698