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

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: Switch statement for setjmp 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/SkSampler.h ('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, bm.getPixels(),
93 bm.row Bytes()));
94
95 REPORTER_ASSERT(r, SkCodec::kSuccess == codec->incrementalDecode());
96
97 compare_to_good_digest(r, goodDigest, bm);
98 }
99
100 // Test in stripes, similar to DM's kStripe_Mode
101 static void test_in_stripes(skiatest::Reporter* r, SkCodec* codec, const SkImage Info& info,
102 const SkMD5::Digest& goodDigest) {
103 SkBitmap bm;
104 bm.allocPixels(info);
105 bm.eraseColor(SK_ColorYELLOW);
106
107 const int height = info.height();
108 // Note that if numStripes does not evenly divide height there will be an ex tra
109 // stripe.
110 const int numStripes = 4;
111
112 if (numStripes > height) {
113 // Image is too small.
114 return;
115 }
116
117 const int stripeHeight = height / numStripes;
118
119 // Iterate through the image twice. Once to decode odd stripes, and once for even.
120 for (int oddEven = 1; oddEven >= 0; oddEven--) {
121 for (int y = oddEven * stripeHeight; y < height; y += 2 * stripeHeight) {
122 SkIRect subset = SkIRect::MakeLTRB(0, y, info.width(),
123 SkTMin(y + stripeHeight, height)) ;
124 SkCodec::Options options;
125 options.fSubset = &subset;
126 if (SkCodec::kSuccess != codec->startIncrementalDecode(info, bm.getA ddr(0, y),
127 bm.rowBytes(), &options)) {
128 ERRORF(r, "failed to start incremental decode!\ttop: %i\tbottom% i\n",
129 subset.top(), subset.bottom());
130 return;
131 }
132 if (SkCodec::kSuccess != codec->incrementalDecode()) {
133 ERRORF(r, "failed incremental decode starting from line %i\n", y );
134 return;
135 }
136 }
137 }
138
139 compare_to_good_digest(r, goodDigest, bm);
140 }
141
86 template<typename Codec> 142 template<typename Codec>
87 static void test_codec(skiatest::Reporter* r, Codec* codec, SkBitmap& bm, const SkImageInfo& info, 143 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, 144 const SkISize& size, SkCodec::Result expectedResult, SkMD5::Digest* dige st,
89 const SkMD5::Digest* goodDigest) { 145 const SkMD5::Digest* goodDigest) {
90 146
91 REPORTER_ASSERT(r, info.dimensions() == size); 147 REPORTER_ASSERT(r, info.dimensions() == size);
92 bm.allocPixels(info); 148 bm.allocPixels(info);
93 SkAutoLockPixels autoLockPixels(bm); 149 SkAutoLockPixels autoLockPixels(bm);
94 150
95 SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes( )); 151 SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes( ));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 }; 200 };
145 201
146 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { 202 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
147 if (SkStrEndsWith(path, exts[i])) { 203 if (SkStrEndsWith(path, exts[i])) {
148 return true; 204 return true;
149 } 205 }
150 } 206 }
151 return false; 207 return false;
152 } 208 }
153 209
210 // FIXME: Break up this giant function
154 static void check(skiatest::Reporter* r, 211 static void check(skiatest::Reporter* r,
155 const char path[], 212 const char path[],
156 SkISize size, 213 SkISize size,
157 bool supportsScanlineDecoding, 214 bool supportsScanlineDecoding,
158 bool supportsSubsetDecoding, 215 bool supportsSubsetDecoding,
159 bool supportsIncomplete = true) { 216 bool supportsIncomplete,
217 bool supportsNewScanlineDecoding = false) {
160 218
161 SkAutoTDelete<SkStream> stream(resource(path)); 219 SkAutoTDelete<SkStream> stream(resource(path));
162 if (!stream) { 220 if (!stream) {
163 SkDebugf("Missing resource '%s'\n", path); 221 SkDebugf("Missing resource '%s'\n", path);
164 return; 222 return;
165 } 223 }
166 224
167 SkAutoTDelete<SkCodec> codec(nullptr); 225 SkAutoTDelete<SkCodec> codec(nullptr);
168 bool isIncomplete = supportsIncomplete; 226 bool isIncomplete = supportsIncomplete;
169 if (isIncomplete) { 227 if (isIncomplete) {
170 size_t size = stream->getLength(); 228 size_t size = stream->getLength();
171 SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3))) ; 229 SkAutoTUnref<SkData> data((SkData::NewFromStream(stream, 2 * size / 3))) ;
172 codec.reset(SkCodec::NewFromData(data)); 230 codec.reset(SkCodec::NewFromData(data));
173 } else { 231 } else {
174 codec.reset(SkCodec::NewFromStream(stream.release())); 232 codec.reset(SkCodec::NewFromStream(stream.release()));
175 } 233 }
176 if (!codec) { 234 if (!codec) {
177 ERRORF(r, "Unable to decode '%s'", path); 235 ERRORF(r, "Unable to decode '%s'", path);
178 return; 236 return;
179 } 237 }
180 238
181 // Test full image decodes with SkCodec 239 // Test full image decodes with SkCodec
182 SkMD5::Digest codecDigest; 240 SkMD5::Digest codecDigest;
183 const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); 241 const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
184 SkBitmap bm; 242 SkBitmap bm;
185 SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput : SkCodec::kSuccess; 243 SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput : SkCodec::kSuccess;
186 test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nul lptr); 244 test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nul lptr);
187 245
188 // Scanline decoding follows. 246 // Scanline decoding follows.
247
248 if (supportsNewScanlineDecoding && !isIncomplete) {
249 test_incremental_decode(r, codec, info, codecDigest);
250 test_in_stripes(r, codec, info, codecDigest);
251 }
252
189 // Need to call startScanlineDecode() first. 253 // Need to call startScanlineDecode() first.
190 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) 254 REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) == 0);
191 == 0); 255 REPORTER_ASSERT(r, !codec->skipScanlines(1));
192 REPORTER_ASSERT(r, codec->skipScanlines(1)
193 == 0);
194
195 const SkCodec::Result startResult = codec->startScanlineDecode(info); 256 const SkCodec::Result startResult = codec->startScanlineDecode(info);
196 if (supportsScanlineDecoding) { 257 if (supportsScanlineDecoding) {
197 bm.eraseColor(SK_ColorYELLOW); 258 bm.eraseColor(SK_ColorYELLOW);
198 259
199 REPORTER_ASSERT(r, startResult == SkCodec::kSuccess); 260 REPORTER_ASSERT(r, startResult == SkCodec::kSuccess);
200 261
201 for (int y = 0; y < info.height(); y++) { 262 for (int y = 0; y < info.height(); y++) {
202 const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0); 263 const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
203 if (!isIncomplete) { 264 if (!isIncomplete) {
204 REPORTER_ASSERT(r, 1 == lines); 265 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 340 // Webp is the only codec that supports subsets, and it will have mo dified the subset
280 // to have even left/top. 341 // to have even left/top.
281 REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTo p)); 342 REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTo p));
282 } else { 343 } else {
283 // No subsets will work. 344 // No subsets will work.
284 REPORTER_ASSERT(r, result == SkCodec::kUnimplemented); 345 REPORTER_ASSERT(r, result == SkCodec::kUnimplemented);
285 } 346 }
286 } 347 }
287 348
288 // SkAndroidCodec tests 349 // SkAndroidCodec tests
289 if (supportsScanlineDecoding || supportsSubsetDecoding) { 350 if (supportsScanlineDecoding || supportsSubsetDecoding || supportsNewScanlin eDecoding) {
290 351
291 SkAutoTDelete<SkStream> stream(resource(path)); 352 SkAutoTDelete<SkStream> stream(resource(path));
292 if (!stream) { 353 if (!stream) {
293 SkDebugf("Missing resource '%s'\n", path); 354 SkDebugf("Missing resource '%s'\n", path);
294 return; 355 return;
295 } 356 }
296 357
297 SkAutoTDelete<SkAndroidCodec> androidCodec(nullptr); 358 SkAutoTDelete<SkAndroidCodec> androidCodec(nullptr);
298 if (isIncomplete) { 359 if (isIncomplete) {
299 size_t size = stream->getLength(); 360 size_t size = stream->getLength();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 397 }
337 398
338 // If we've just tested incomplete decodes, let's run the same test again on full decodes. 399 // If we've just tested incomplete decodes, let's run the same test again on full decodes.
339 if (isIncomplete) { 400 if (isIncomplete) {
340 check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, f alse); 401 check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, f alse);
341 } 402 }
342 } 403 }
343 404
344 DEF_TEST(Codec, r) { 405 DEF_TEST(Codec, r) {
345 // WBMP 406 // WBMP
346 check(r, "mandrill.wbmp", SkISize::Make(512, 512), true, false); 407 check(r, "mandrill.wbmp", SkISize::Make(512, 512), true, false, true);
347 408
348 // WEBP 409 // WEBP
349 check(r, "baby_tux.webp", SkISize::Make(386, 395), false, true); 410 check(r, "baby_tux.webp", SkISize::Make(386, 395), false, true, true);
350 check(r, "color_wheel.webp", SkISize::Make(128, 128), false, true); 411 check(r, "color_wheel.webp", SkISize::Make(128, 128), false, true, true);
351 check(r, "yellow_rose.webp", SkISize::Make(400, 301), false, true); 412 check(r, "yellow_rose.webp", SkISize::Make(400, 301), false, true, true);
352 413
353 // BMP 414 // BMP
354 check(r, "randPixels.bmp", SkISize::Make(8, 8), true, false); 415 check(r, "randPixels.bmp", SkISize::Make(8, 8), true, false, true);
355 check(r, "rle.bmp", SkISize::Make(320, 240), true, false); 416 check(r, "rle.bmp", SkISize::Make(320, 240), true, false, true);
356 417
357 // ICO 418 // ICO
358 // FIXME: We are not ready to test incomplete ICOs 419 // FIXME: We are not ready to test incomplete ICOs
359 // These two tests examine interestingly different behavior: 420 // These two tests examine interestingly different behavior:
360 // Decodes an embedded BMP image 421 // Decodes an embedded BMP image
361 check(r, "color_wheel.ico", SkISize::Make(128, 128), true, false, false); 422 check(r, "color_wheel.ico", SkISize::Make(128, 128), true, false, false);
362 // Decodes an embedded PNG image 423 // Decodes an embedded PNG image
363 check(r, "google_chrome.ico", SkISize::Make(256, 256), true, false, false); 424 check(r, "google_chrome.ico", SkISize::Make(256, 256), false, false, false, true);
364 425
365 // GIF 426 // GIF
366 // FIXME: We are not ready to test incomplete GIFs 427 // FIXME: We are not ready to test incomplete GIFs
367 check(r, "box.gif", SkISize::Make(200, 55), true, false, false); 428 check(r, "box.gif", SkISize::Make(200, 55), true, false, false);
368 check(r, "color_wheel.gif", SkISize::Make(128, 128), true, false, false); 429 check(r, "color_wheel.gif", SkISize::Make(128, 128), true, false, false);
369 // randPixels.gif is too small to test incomplete 430 // randPixels.gif is too small to test incomplete
370 check(r, "randPixels.gif", SkISize::Make(8, 8), true, false, false); 431 check(r, "randPixels.gif", SkISize::Make(8, 8), true, false, false);
371 432
372 // JPG 433 // JPG
373 check(r, "CMYK.jpg", SkISize::Make(642, 516), true, false); 434 check(r, "CMYK.jpg", SkISize::Make(642, 516), true, false, true);
374 check(r, "color_wheel.jpg", SkISize::Make(128, 128), true, false); 435 check(r, "color_wheel.jpg", SkISize::Make(128, 128), true, false, true);
375 // grayscale.jpg is too small to test incomplete 436 // grayscale.jpg is too small to test incomplete
376 check(r, "grayscale.jpg", SkISize::Make(128, 128), true, false, false); 437 check(r, "grayscale.jpg", SkISize::Make(128, 128), true, false, false);
377 check(r, "mandrill_512_q075.jpg", SkISize::Make(512, 512), true, false); 438 check(r, "mandrill_512_q075.jpg", SkISize::Make(512, 512), true, false, true );
378 // randPixels.jpg is too small to test incomplete 439 // randPixels.jpg is too small to test incomplete
379 check(r, "randPixels.jpg", SkISize::Make(8, 8), true, false, false); 440 check(r, "randPixels.jpg", SkISize::Make(8, 8), true, false, false);
380 441
381 // PNG 442 // PNG
382 check(r, "arrow.png", SkISize::Make(187, 312), true, false, false); 443 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); 444 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); 445 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); 446 // half-transparent-white-pixel.png is too small to test incomplete
386 check(r, "mandrill_128.png", SkISize::Make(128, 128), true, false, false); 447 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); 448 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); 449 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); 450 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); 451 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); 452 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); 453 check(r, "mandrill_64.png", SkISize::Make(64, 64), false, false, true, true) ;
393 // FIXME: We are not ready to test incomplete interlaced pngs 454 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 ); 455 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); 456 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); 457 check(r, "yellow_rose.png", SkISize::Make(400, 301), false, false, true, tru e);
397 458
398 // RAW 459 // RAW
399 // Disable RAW tests for Win32. 460 // Disable RAW tests for Win32.
400 #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32)) 461 #if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32))
401 check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false); 462 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); 463 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 ); 464 check(r, "dng_with_preview.dng", SkISize::Make(600, 338), true, false, false );
404 #endif 465 #endif
405 } 466 }
406 467
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) { 468 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. 469 // 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)); 470 SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, fals e));
501 REPORTER_ASSERT(r, !codec); 471 REPORTER_ASSERT(r, !codec);
502 472
503 SkAndroidCodec* androidCodec = 473 SkAndroidCodec* androidCodec =
504 SkAndroidCodec::NewFromStream(new SkMemoryStream(stream, len, false) ); 474 SkAndroidCodec::NewFromStream(new SkMemoryStream(stream, len, false) );
505 REPORTER_ASSERT(r, !androidCodec); 475 REPORTER_ASSERT(r, !androidCodec);
506 } 476 }
507 477
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 } 601 }
632 602
633 static void test_invalid_parameters(skiatest::Reporter* r, const char path[]) { 603 static void test_invalid_parameters(skiatest::Reporter* r, const char path[]) {
634 SkAutoTDelete<SkStream> stream(resource(path)); 604 SkAutoTDelete<SkStream> stream(resource(path));
635 if (!stream) { 605 if (!stream) {
636 SkDebugf("Missing resource '%s'\n", path); 606 SkDebugf("Missing resource '%s'\n", path);
637 return; 607 return;
638 } 608 }
639 SkAutoTDelete<SkCodec> decoder(SkCodec::NewFromStream(stream.release())); 609 SkAutoTDelete<SkCodec> decoder(SkCodec::NewFromStream(stream.release()));
640 610
611 const SkImageInfo info = decoder->getInfo().makeColorType(kIndex_8_SkColorTy pe);
612
641 // This should return kSuccess because kIndex8 is supported. 613 // This should return kSuccess because kIndex8 is supported.
642 SkPMColor colorStorage[256]; 614 SkPMColor colorStorage[256];
643 int colorCount; 615 int colorCount;
644 SkCodec::Result result = decoder->startScanlineDecode( 616 SkCodec::Result result = decoder->startScanlineDecode(info, nullptr, colorSt orage,
645 decoder->getInfo().makeColorType(kIndex_8_SkColorType), nullptr, colorSt orage, &colorCount); 617 &colorCount);
646 REPORTER_ASSERT(r, SkCodec::kSuccess == result); 618 if (SkCodec::kSuccess == result) {
647 // The rest of the test is uninteresting if kIndex8 is not supported 619 // This should return kInvalidParameters because, in kIndex_8 mode, we m ust pass in a valid
648 if (SkCodec::kSuccess != result) { 620 // colorPtr and a valid colorCountPtr.
621 result = decoder->startScanlineDecode(info, nullptr, nullptr, nullptr);
622 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
623 result = decoder->startScanlineDecode(info);
624 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
625 } else if (SkCodec::kUnimplemented == result) {
626 // New method should be supported:
627 SkBitmap bm;
628 sk_sp<SkColorTable> colorTable(new SkColorTable(colorStorage, 256));
629 bm.allocPixels(info, nullptr, colorTable.get());
630 result = decoder->startIncrementalDecode(info, bm.getPixels(), bm.rowByt es(), nullptr,
631 colorStorage, &colorCount);
632 REPORTER_ASSERT(r, SkCodec::kSuccess == result);
633 result = decoder->startIncrementalDecode(info, bm.getPixels(), bm.rowByt es());
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/SkSampler.h ('K') | « tests/CodecPartial.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698