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

Side by Side Diff: tests/CodecTest.cpp

Issue 1997703003: Make SkPngCodec decode progressively. (Closed) Base URL: https://skia.googlesource.com/skia.git@foil
Patch Set: Fixes for ICO, Incomplete, comments Created 4 years, 7 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
« src/codec/SkSampledCodec.cpp ('K') | « tests/CodecPartial.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"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 do { 76 do {
77 rect.fLeft = rand->nextRangeU(0, w); 77 rect.fLeft = rand->nextRangeU(0, w);
78 rect.fTop = rand->nextRangeU(0, h); 78 rect.fTop = rand->nextRangeU(0, h);
79 rect.fRight = rand->nextRangeU(0, w); 79 rect.fRight = rand->nextRangeU(0, w);
80 rect.fBottom = rand->nextRangeU(0, h); 80 rect.fBottom = rand->nextRangeU(0, h);
81 rect.sort(); 81 rect.sort();
82 } while (rect.isEmpty()); 82 } while (rect.isEmpty());
83 return rect; 83 return rect;
84 } 84 }
85 85
86 static void test_incremental_decode(skiatest::Reporter* r, SkCodec* codec, const SkImageInfo& info,
87 const SkMD5::Digest& goodDigest) {
88 SkBitmap bm;
89 bm.allocPixels(info);
90 SkAutoLockPixels autoLockPixels(bm);
91
92 REPORTER_ASSERT(r, SkCodec::kSuccess == codec->startIncrementalDecode(info)) ;
93
94 REPORTER_ASSERT(r, SkCodec::kSuccess == codec->incrementalDecode(
95 [&bm](int rowNum) -> void* {
96 return bm.getAddr(0, rowNum);
97 }));
98
99 compare_to_good_digest(r, goodDigest, bm);
100 }
101
102 // Test in stripes, similar to DM's kStripe_Mode
103 static void test_in_stripes(skiatest::Reporter* r, SkCodec* codec, const SkImage Info& info,
104 const SkMD5::Digest& goodDigest) {
105 SkBitmap bm;
106 bm.allocPixels(info);
107 bm.eraseColor(SK_ColorYELLOW);
108
109 const int height = info.height();
110 // Note that if numStripes does not evenly divide height there will be an ex tra
111 // stripe.
112 const int numStripes = 4;
113
114 if (numStripes > height) {
115 // Image is too small.
116 return;
117 }
118
119 const int stripeHeight = height / numStripes;
120
121 // Iterate through the image twice. Once to decode odd stripes, and once for even.
122 for (int oddEven = 1; oddEven >= 0; oddEven--) {
123 for (int y = oddEven * stripeHeight; y < height; y += 2 * stripeHeight) {
124 SkIRect subset = SkIRect::MakeLTRB(0, y, info.width(),
125 SkTMin(y + stripeHeight, height)) ;
126 SkCodec::Options options;
127 options.fSubset = &subset;
128 if (SkCodec::kSuccess != codec->startIncrementalDecode(info, &option s)) {
129 ERRORF(r, "failed to start incremental decode!\ttop: %i\tbottom% i\n",
130 subset.top(), subset.bottom());
131 return;
132 }
133 if (SkCodec::kSuccess != codec->incrementalDecode(
134 [&bm](int rowNum) -> void* {
135 return bm.getAddr(0, rowNum);
136 })) {
137 ERRORF(r, "failed incremental decode starting from line %i\n", y );
138 return;
139 }
140 }
141 }
142
143 compare_to_good_digest(r, goodDigest, bm);
144 }
145
86 template<typename Codec> 146 template<typename Codec>
87 static void test_codec(skiatest::Reporter* r, Codec* codec, SkBitmap& bm, const SkImageInfo& info, 147 static void test_codec(skiatest::Reporter* r, Codec* codec, SkBitmap& bm, const SkImageInfo& info,
88 const SkISize& size, SkCodec::Result expectedResult, SkMD5::Digest* dige st, 148 const SkISize& size, SkCodec::Result expectedResult, SkMD5::Digest* dige st,
89 const SkMD5::Digest* goodDigest) { 149 const SkMD5::Digest* goodDigest) {
90 150
91 REPORTER_ASSERT(r, info.dimensions() == size); 151 REPORTER_ASSERT(r, info.dimensions() == size);
92 bm.allocPixels(info); 152 bm.allocPixels(info);
93 SkAutoLockPixels autoLockPixels(bm); 153 SkAutoLockPixels autoLockPixels(bm);
94 154
95 SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes( )); 155 SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes( ));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 }; 204 };
145 205
146 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { 206 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
147 if (SkStrEndsWith(path, exts[i])) { 207 if (SkStrEndsWith(path, exts[i])) {
148 return true; 208 return true;
149 } 209 }
150 } 210 }
151 return false; 211 return false;
152 } 212 }
153 213
214 // FIXME: Break up this giant function
154 static void check(skiatest::Reporter* r, 215 static void check(skiatest::Reporter* r,
155 const char path[], 216 const char path[],
156 SkISize size, 217 SkISize size,
157 bool supportsScanlineDecoding, 218 bool supportsScanlineDecoding,
158 bool supportsSubsetDecoding, 219 bool supportsSubsetDecoding,
159 bool supportsIncomplete = true) { 220 bool supportsIncomplete,
221 bool supportsNewScanlineDecoding = false) {
160 222
161 SkAutoTDelete<SkStream> stream(resource(path)); 223 SkAutoTDelete<SkStream> stream(resource(path));
162 if (!stream) { 224 if (!stream) {
163 SkDebugf("Missing resource '%s'\n", path); 225 SkDebugf("Missing resource '%s'\n", path);
164 return; 226 return;
165 } 227 }
166 228
167 SkAutoTDelete<SkCodec> codec(nullptr); 229 SkAutoTDelete<SkCodec> codec(nullptr);
168 bool isIncomplete = supportsIncomplete; 230 bool isIncomplete = supportsIncomplete;
169 if (isIncomplete) { 231 if (isIncomplete) {
170 size_t size = stream->getLength(); 232 size_t size = stream->getLength();
171 SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3))) ; 233 SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3))) ;
172 codec.reset(SkCodec::NewFromData(data)); 234 codec.reset(SkCodec::NewFromData(data));
173 } else { 235 } else {
174 codec.reset(SkCodec::NewFromStream(stream.release())); 236 codec.reset(SkCodec::NewFromStream(stream.release()));
175 } 237 }
176 if (!codec) { 238 if (!codec) {
177 ERRORF(r, "Unable to decode '%s'", path); 239 ERRORF(r, "Unable to decode '%s'", path);
178 return; 240 return;
179 } 241 }
180 242
181 // Test full image decodes with SkCodec 243 // Test full image decodes with SkCodec
182 SkMD5::Digest codecDigest; 244 SkMD5::Digest codecDigest;
183 const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); 245 const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
184 SkBitmap bm; 246 SkBitmap bm;
185 SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput : SkCodec::kSuccess; 247 SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput : SkCodec::kSuccess;
186 test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nul lptr); 248 test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nul lptr);
187 249
188 // Scanline decoding follows. 250 // Scanline decoding follows.
251
252 if (supportsNewScanlineDecoding && !isIncomplete) {
253 test_incremental_decode(r, codec, info, codecDigest);
254 test_in_stripes(r, codec, info, codecDigest);
255 }
256
189 // Need to call startScanlineDecode() first. 257 // Need to call startScanlineDecode() first.
190 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) 258 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) == 0);
191 == 0); 259 REPORTER_ASSERT(r, !codec->skipScanlines(1));
192 REPORTER_ASSERT(r, codec->skipScanlines(1)
193 == 0);
194
195 const SkCodec::Result startResult = codec->startScanlineDecode(info); 260 const SkCodec::Result startResult = codec->startScanlineDecode(info);
196 if (supportsScanlineDecoding) { 261 if (supportsScanlineDecoding) {
197 bm.eraseColor(SK_ColorYELLOW); 262 bm.eraseColor(SK_ColorYELLOW);
198 263
199 REPORTER_ASSERT(r, startResult == SkCodec::kSuccess); 264 REPORTER_ASSERT(r, startResult == SkCodec::kSuccess);
200 265
201 for (int y = 0; y < info.height(); y++) { 266 for (int y = 0; y < info.height(); y++) {
202 const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0); 267 const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
203 if (!isIncomplete) { 268 if (!isIncomplete) {
204 REPORTER_ASSERT(r, 1 == lines); 269 REPORTER_ASSERT(r, 1 == lines);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 // Webp is the only codec that supports subsets, and it will have mo dified the subset 344 // Webp is the only codec that supports subsets, and it will have mo dified the subset
280 // to have even left/top. 345 // to have even left/top.
281 REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTo p)); 346 REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTo p));
282 } else { 347 } else {
283 // No subsets will work. 348 // No subsets will work.
284 REPORTER_ASSERT(r, result == SkCodec::kUnimplemented); 349 REPORTER_ASSERT(r, result == SkCodec::kUnimplemented);
285 } 350 }
286 } 351 }
287 352
288 // SkAndroidCodec tests 353 // SkAndroidCodec tests
289 if (supportsScanlineDecoding || supportsSubsetDecoding) { 354 if (supportsScanlineDecoding || supportsSubsetDecoding || supportsNewScanlin eDecoding) {
290 355
291 SkAutoTDelete<SkStream> stream(resource(path)); 356 SkAutoTDelete<SkStream> stream(resource(path));
292 if (!stream) { 357 if (!stream) {
293 SkDebugf("Missing resource '%s'\n", path); 358 SkDebugf("Missing resource '%s'\n", path);
294 return; 359 return;
295 } 360 }
296 361
297 SkAutoTDelete<SkAndroidCodec> androidCodec(nullptr); 362 SkAutoTDelete<SkAndroidCodec> androidCodec(nullptr);
298 if (isIncomplete) { 363 if (isIncomplete) {
299 size_t size = stream->getLength(); 364 size_t size = stream->getLength();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 401 }
337 402
338 // If we've just tested incomplete decodes, let's run the same test again on full decodes. 403 // If we've just tested incomplete decodes, let's run the same test again on full decodes.
339 if (isIncomplete) { 404 if (isIncomplete) {
340 check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, f alse); 405 check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, f alse);
341 } 406 }
342 } 407 }
343 408
344 DEF_TEST(Codec, r) { 409 DEF_TEST(Codec, r) {
345 // WBMP 410 // WBMP
346 check(r, "mandrill.wbmp", SkISize::Make(512, 512), true, false); 411 check(r, "mandrill.wbmp", SkISize::Make(512, 512), true, false, true);
347 412
348 // WEBP 413 // WEBP
349 check(r, "baby_tux.webp", SkISize::Make(386, 395), false, true); 414 check(r, "baby_tux.webp", SkISize::Make(386, 395), false, true, true);
350 check(r, "color_wheel.webp", SkISize::Make(128, 128), false, true); 415 check(r, "color_wheel.webp", SkISize::Make(128, 128), false, true, true);
351 check(r, "yellow_rose.webp", SkISize::Make(400, 301), false, true); 416 check(r, "yellow_rose.webp", SkISize::Make(400, 301), false, true, true);
352 417
353 // BMP 418 // BMP
354 check(r, "randPixels.bmp", SkISize::Make(8, 8), true, false); 419 check(r, "randPixels.bmp", SkISize::Make(8, 8), true, false, true);
355 check(r, "rle.bmp", SkISize::Make(320, 240), true, false); 420 check(r, "rle.bmp", SkISize::Make(320, 240), true, false, true);
356 421
357 // ICO 422 // ICO
358 // FIXME: We are not ready to test incomplete ICOs 423 // FIXME: We are not ready to test incomplete ICOs
359 // These two tests examine interestingly different behavior: 424 // These two tests examine interestingly different behavior:
360 // Decodes an embedded BMP image 425 // Decodes an embedded BMP image
361 check(r, "color_wheel.ico", SkISize::Make(128, 128), true, false, false); 426 check(r, "color_wheel.ico", SkISize::Make(128, 128), true, false, false);
362 // Decodes an embedded PNG image 427 // Decodes an embedded PNG image
363 check(r, "google_chrome.ico", SkISize::Make(256, 256), true, false, false); 428 check(r, "google_chrome.ico", SkISize::Make(256, 256), false, false, false, true);
364 429
365 // GIF 430 // GIF
366 // FIXME: We are not ready to test incomplete GIFs 431 // FIXME: We are not ready to test incomplete GIFs
367 check(r, "box.gif", SkISize::Make(200, 55), true, false, false); 432 check(r, "box.gif", SkISize::Make(200, 55), true, false, false);
368 check(r, "color_wheel.gif", SkISize::Make(128, 128), true, false, false); 433 check(r, "color_wheel.gif", SkISize::Make(128, 128), true, false, false);
369 // randPixels.gif is too small to test incomplete 434 // randPixels.gif is too small to test incomplete
370 check(r, "randPixels.gif", SkISize::Make(8, 8), true, false, false); 435 check(r, "randPixels.gif", SkISize::Make(8, 8), true, false, false);
371 436
372 // JPG 437 // JPG
373 check(r, "CMYK.jpg", SkISize::Make(642, 516), true, false); 438 check(r, "CMYK.jpg", SkISize::Make(642, 516), true, false, true);
374 check(r, "color_wheel.jpg", SkISize::Make(128, 128), true, false); 439 check(r, "color_wheel.jpg", SkISize::Make(128, 128), true, false, true);
375 // grayscale.jpg is too small to test incomplete 440 // grayscale.jpg is too small to test incomplete
376 check(r, "grayscale.jpg", SkISize::Make(128, 128), true, false, false); 441 check(r, "grayscale.jpg", SkISize::Make(128, 128), true, false, false);
377 check(r, "mandrill_512_q075.jpg", SkISize::Make(512, 512), true, false); 442 check(r, "mandrill_512_q075.jpg", SkISize::Make(512, 512), true, false, true );
378 // randPixels.jpg is too small to test incomplete 443 // randPixels.jpg is too small to test incomplete
379 check(r, "randPixels.jpg", SkISize::Make(8, 8), true, false, false); 444 check(r, "randPixels.jpg", SkISize::Make(8, 8), true, false, false);
380 445
381 // PNG 446 // PNG
382 check(r, "arrow.png", SkISize::Make(187, 312), true, false, false); 447 check(r, "arrow.png", SkISize::Make(187, 312), false, false, true, true);
383 check(r, "baby_tux.png", SkISize::Make(240, 246), true, false, false); 448 check(r, "baby_tux.png", SkISize::Make(240, 246), false, false, true, true);
384 check(r, "color_wheel.png", SkISize::Make(128, 128), true, false, false); 449 check(r, "color_wheel.png", SkISize::Make(128, 128), false, false, true, tru e);
385 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), true, fals e, false); 450 // half-transparent-white-pixel.png is too small to test incomplete
386 check(r, "mandrill_128.png", SkISize::Make(128, 128), true, false, false); 451 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), false, fal se, false, true);
387 check(r, "mandrill_16.png", SkISize::Make(16, 16), true, false, false); 452 check(r, "mandrill_128.png", SkISize::Make(128, 128), false, false, true, tr ue);
388 check(r, "mandrill_256.png", SkISize::Make(256, 256), true, false, false); 453 check(r, "mandrill_16.png", SkISize::Make(16, 16), false, false, true, true) ;
389 check(r, "mandrill_32.png", SkISize::Make(32, 32), true, false, false); 454 check(r, "mandrill_256.png", SkISize::Make(256, 256), false, false, true, tr ue);
390 check(r, "mandrill_512.png", SkISize::Make(512, 512), true, false, false); 455 check(r, "mandrill_32.png", SkISize::Make(32, 32), false, false, true, true) ;
391 check(r, "mandrill_64.png", SkISize::Make(64, 64), true, false, false); 456 check(r, "mandrill_512.png", SkISize::Make(512, 512), false, false, true, tr ue);
392 check(r, "plane.png", SkISize::Make(250, 126), true, false, false); 457 check(r, "mandrill_64.png", SkISize::Make(64, 64), false, false, true, true) ;
393 // FIXME: We are not ready to test incomplete interlaced pngs 458 check(r, "plane.png", SkISize::Make(250, 126), false, false, true, true);
394 check(r, "plane_interlaced.png", SkISize::Make(250, 126), true, false, false ); 459 check(r, "plane_interlaced.png", SkISize::Make(250, 126), false, false, true , true);
395 check(r, "randPixels.png", SkISize::Make(8, 8), true, false, false); 460 check(r, "randPixels.png", SkISize::Make(8, 8), false, false, true, true);
396 check(r, "yellow_rose.png", SkISize::Make(400, 301), true, false, false); 461 check(r, "yellow_rose.png", SkISize::Make(400, 301), false, false, true, tru e);
397 462
398 // RAW 463 // RAW
399 // Disable RAW tests for Win32. 464 // Disable RAW tests for Win32.
400 #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32)) 465 #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32))
401 check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false); 466 check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false);
402 check(r, "sample_1mp_rotated.dng", SkISize::Make(600, 338), false, false, fa lse); 467 check(r, "sample_1mp_rotated.dng", SkISize::Make(600, 338), false, false, fa lse);
403 check(r, "dng_with_preview.dng", SkISize::Make(600, 338), true, false, false ); 468 check(r, "dng_with_preview.dng", SkISize::Make(600, 338), true, false, false );
404 #endif 469 #endif
405 } 470 }
406 471
407 // Test interlaced PNG in stripes, similar to DM's kStripe_Mode
408 DEF_TEST(Codec_stripes, r) {
409 const char * path = "plane_interlaced.png";
410 SkAutoTDelete<SkStream> stream(resource(path));
411 if (!stream) {
412 SkDebugf("Missing resource '%s'\n", path);
413 }
414
415 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
416 REPORTER_ASSERT(r, codec);
417
418 if (!codec) {
419 return;
420 }
421
422 switch (codec->getScanlineOrder()) {
423 case SkCodec::kBottomUp_SkScanlineOrder:
424 case SkCodec::kOutOfOrder_SkScanlineOrder:
425 ERRORF(r, "This scanline order will not match the original.");
426 return;
427 default:
428 break;
429 }
430
431 // Baseline for what the image should look like, using N32.
432 const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
433
434 SkBitmap bm;
435 bm.allocPixels(info);
436 SkAutoLockPixels autoLockPixels(bm);
437 SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes( ));
438 REPORTER_ASSERT(r, result == SkCodec::kSuccess);
439
440 SkMD5::Digest digest;
441 md5(bm, &digest);
442
443 // Now decode in stripes
444 const int height = info.height();
445 const int numStripes = 4;
446 int stripeHeight;
447 int remainingLines;
448 SkTDivMod(height, numStripes, &stripeHeight, &remainingLines);
449
450 bm.eraseColor(SK_ColorYELLOW);
451
452 result = codec->startScanlineDecode(info);
453 REPORTER_ASSERT(r, result == SkCodec::kSuccess);
454
455 // Odd stripes
456 for (int i = 1; i < numStripes; i += 2) {
457 // Skip the even stripes
458 bool skipResult = codec->skipScanlines(stripeHeight);
459 REPORTER_ASSERT(r, skipResult);
460
461 int linesDecoded = codec->getScanlines(bm.getAddr(0, i * stripeHeight), stripeHeight,
462 bm.rowBytes());
463 REPORTER_ASSERT(r, linesDecoded == stripeHeight);
464 }
465
466 // Even stripes
467 result = codec->startScanlineDecode(info);
468 REPORTER_ASSERT(r, result == SkCodec::kSuccess);
469
470 for (int i = 0; i < numStripes; i += 2) {
471 int linesDecoded = codec->getScanlines(bm.getAddr(0, i * stripeHeight), stripeHeight,
472 bm.rowBytes());
473 REPORTER_ASSERT(r, linesDecoded == stripeHeight);
474
475 // Skip the odd stripes
476 if (i + 1 < numStripes) {
477 bool skipResult = codec->skipScanlines(stripeHeight);
478 REPORTER_ASSERT(r, skipResult);
479 }
480 }
481
482 // Remainder at the end
483 if (remainingLines > 0) {
484 result = codec->startScanlineDecode(info);
485 REPORTER_ASSERT(r, result == SkCodec::kSuccess);
486
487 bool skipResult = codec->skipScanlines(height - remainingLines);
488 REPORTER_ASSERT(r, skipResult);
489
490 int linesDecoded = codec->getScanlines(bm.getAddr(0, height - remainingL ines),
491 remainingLines, bm.rowBytes());
492 REPORTER_ASSERT(r, linesDecoded == remainingLines);
493 }
494
495 compare_to_good_digest(r, digest, bm);
496 }
497
498 static void test_invalid_stream(skiatest::Reporter* r, const void* stream, size_ t len) { 472 static void test_invalid_stream(skiatest::Reporter* r, const void* stream, size_ t len) {
499 // Neither of these calls should return a codec. Bots should catch us if we leaked anything. 473 // Neither of these calls should return a codec. Bots should catch us if we leaked anything.
500 SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, fals e)); 474 SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, fals e));
501 REPORTER_ASSERT(r, !codec); 475 REPORTER_ASSERT(r, !codec);
502 476
503 SkAndroidCodec* androidCodec = 477 SkAndroidCodec* androidCodec =
504 SkAndroidCodec::NewFromStream(new SkMemoryStream(stream, len, false) ); 478 SkAndroidCodec::NewFromStream(new SkMemoryStream(stream, len, false) );
505 REPORTER_ASSERT(r, !androidCodec); 479 REPORTER_ASSERT(r, !androidCodec);
506 } 480 }
507 481
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 } 605 }
632 606
633 static void test_invalid_parameters(skiatest::Reporter* r, const char path[]) { 607 static void test_invalid_parameters(skiatest::Reporter* r, const char path[]) {
634 SkAutoTDelete<SkStream> stream(resource(path)); 608 SkAutoTDelete<SkStream> stream(resource(path));
635 if (!stream) { 609 if (!stream) {
636 SkDebugf("Missing resource '%s'\n", path); 610 SkDebugf("Missing resource '%s'\n", path);
637 return; 611 return;
638 } 612 }
639 SkAutoTDelete<SkCodec> decoder(SkCodec::NewFromStream(stream.release())); 613 SkAutoTDelete<SkCodec> decoder(SkCodec::NewFromStream(stream.release()));
640 614
615 const SkImageInfo info = decoder->getInfo().makeColorType(kIndex_8_SkColorTy pe);
616
641 // This should return kSuccess because kIndex8 is supported. 617 // This should return kSuccess because kIndex8 is supported.
642 SkPMColor colorStorage[256]; 618 SkPMColor colorStorage[256];
643 int colorCount; 619 int colorCount;
644 SkCodec::Result result = decoder->startScanlineDecode( 620 SkCodec::Result result = decoder->startScanlineDecode(info, nullptr, colorSt orage,
645 decoder->getInfo().makeColorType(kIndex_8_SkColorType), nullptr, colorSt orage, &colorCount); 621 &colorCount);
646 REPORTER_ASSERT(r, SkCodec::kSuccess == result); 622 if (SkCodec::kSuccess == result) {
647 // The rest of the test is uninteresting if kIndex8 is not supported 623 // This should return kInvalidParameters because, in kIndex_8 mode, we m ust pass in a valid
648 if (SkCodec::kSuccess != result) { 624 // colorPtr and a valid colorCountPtr.
625 result = decoder->startScanlineDecode(info, nullptr, nullptr, nullptr);
626 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
627 result = decoder->startScanlineDecode(info);
628 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
629 } else if (SkCodec::kUnimplemented == result) {
630 // New method should be supported:
631 result = decoder->startIncrementalDecode(info, nullptr, colorStorage, &c olorCount);
632 REPORTER_ASSERT(r, SkCodec::kSuccess == result);
633 result = decoder->startIncrementalDecode(info);
634 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
635 } else {
636 // The test is uninteresting if kIndex8 is not supported
637 ERRORF(r, "Should not call test_invalid_parameters for non-Index8 file: %s\n", path);
649 return; 638 return;
650 } 639 }
651 640
652 // This should return kInvalidParameters because, in kIndex_8 mode, we must pass in a valid
653 // colorPtr and a valid colorCountPtr.
654 result = decoder->startScanlineDecode(
655 decoder->getInfo().makeColorType(kIndex_8_SkColorType), nullptr, nullptr , nullptr);
656 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
657 result = decoder->startScanlineDecode(
658 decoder->getInfo().makeColorType(kIndex_8_SkColorType));
659 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
660 } 641 }
661 642
662 DEF_TEST(Codec_Params, r) { 643 DEF_TEST(Codec_Params, r) {
663 test_invalid_parameters(r, "index8.png"); 644 test_invalid_parameters(r, "index8.png");
664 test_invalid_parameters(r, "mandrill.wbmp"); 645 test_invalid_parameters(r, "mandrill.wbmp");
665 } 646 }
666 647
667 static void codex_test_write_fn(png_structp png_ptr, png_bytep data, png_size_t len) { 648 static void codex_test_write_fn(png_structp png_ptr, png_bytep data, png_size_t len) {
668 SkWStream* sk_stream = (SkWStream*)png_get_io_ptr(png_ptr); 649 SkWStream* sk_stream = (SkWStream*)png_get_io_ptr(png_ptr);
669 if (!sk_stream->write(data, len)) { 650 if (!sk_stream->write(data, len)) {
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 // Now test an image which is too big. Any image with a larger header (i.e. 946 // Now test an image which is too big. Any image with a larger header (i.e.
966 // has bigger width/height) is also too big. 947 // has bigger width/height) is also too big.
967 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header 948 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header
968 0x84, 0x80, 0x00, // W: 65536 949 0x84, 0x80, 0x00, // W: 65536
969 0x84, 0x80, 0x00 }; // H: 65536 950 0x84, 0x80, 0x00 }; // H: 65536
970 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); 951 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false));
971 codec.reset(SkCodec::NewFromStream(stream.release())); 952 codec.reset(SkCodec::NewFromStream(stream.release()));
972 953
973 REPORTER_ASSERT(r, !codec); 954 REPORTER_ASSERT(r, !codec);
974 } 955 }
OLDNEW
« src/codec/SkSampledCodec.cpp ('K') | « tests/CodecPartial.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698