OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 0xff6fac98, 0xff941d27, 0xff5fe411, 0xfffbb283, | 354 0xff6fac98, 0xff941d27, 0xff5fe411, 0xfffbb283, |
355 0xffd86e99, 0xff169162, 0xff71128c, 0xff39cab4, | 355 0xffd86e99, 0xff169162, 0xff71128c, 0xff39cab4, |
356 0xffa7fe63, 0xff4c956b, 0xffbc22e0, 0xffb272e4, | 356 0xffa7fe63, 0xff4c956b, 0xffbc22e0, 0xffb272e4, |
357 0xff129f4a, 0xffe34513, 0xff3d3742, 0xffbd190a, | 357 0xff129f4a, 0xffe34513, 0xff3d3742, 0xffbd190a, |
358 0xffb07222, 0xff2e23f8, 0xfff089d9, 0xffb35738, | 358 0xffb07222, 0xff2e23f8, 0xfff089d9, 0xffb35738, |
359 0xffa86022, 0xff3340fe, 0xff95fe71, 0xff6a71df | 359 0xffa86022, 0xff3340fe, 0xff95fe71, 0xff6a71df |
360 }; | 360 }; |
361 static_assert((kExpectedWidth * kExpectedHeight) == SK_ARRAY_COUNT(kExpectedPixe
ls), | 361 static_assert((kExpectedWidth * kExpectedHeight) == SK_ARRAY_COUNT(kExpectedPixe
ls), |
362 "array_size_mismatch"); | 362 "array_size_mismatch"); |
363 | 363 |
| 364 static bool decode_into_bitmap(skiatest::Reporter* r, SkBitmap* bm, SkData* enco
ded) { |
| 365 SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromEncoded(encoded
)); |
| 366 if (!gen) { |
| 367 REPORTER_ASSERT(r, false); |
| 368 return false; |
| 369 } |
| 370 if (!gen->tryGenerateBitmap(bm)) { |
| 371 REPORTER_ASSERT(r, false); |
| 372 return false; |
| 373 } |
| 374 return true; |
| 375 } |
| 376 |
364 DEF_TEST(WebP, reporter) { | 377 DEF_TEST(WebP, reporter) { |
365 const unsigned char encodedWebP[] = { | 378 const unsigned char encodedWebP[] = { |
366 0x52, 0x49, 0x46, 0x46, 0x2c, 0x01, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50, | 379 0x52, 0x49, 0x46, 0x46, 0x2c, 0x01, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50, |
367 0x56, 0x50, 0x38, 0x4c, 0x20, 0x01, 0x00, 0x00, 0x2f, 0x07, 0xc0, 0x01, | 380 0x56, 0x50, 0x38, 0x4c, 0x20, 0x01, 0x00, 0x00, 0x2f, 0x07, 0xc0, 0x01, |
368 0x00, 0xff, 0x01, 0x45, 0x03, 0x00, 0xe2, 0xd5, 0xae, 0x60, 0x2b, 0xad, | 381 0x00, 0xff, 0x01, 0x45, 0x03, 0x00, 0xe2, 0xd5, 0xae, 0x60, 0x2b, 0xad, |
369 0xd9, 0x68, 0x76, 0xb6, 0x8d, 0x6a, 0x1d, 0xc0, 0xe6, 0x19, 0xd6, 0x16, | 382 0xd9, 0x68, 0x76, 0xb6, 0x8d, 0x6a, 0x1d, 0xc0, 0xe6, 0x19, 0xd6, 0x16, |
370 0xb7, 0xb4, 0xef, 0xcf, 0xc3, 0x15, 0x6c, 0xb3, 0xbd, 0x77, 0x0d, 0x85, | 383 0xb7, 0xb4, 0xef, 0xcf, 0xc3, 0x15, 0x6c, 0xb3, 0xbd, 0x77, 0x0d, 0x85, |
371 0x6d, 0x1b, 0xa9, 0xb1, 0x2b, 0xdc, 0x3d, 0x83, 0xdb, 0x00, 0x00, 0xc8, | 384 0x6d, 0x1b, 0xa9, 0xb1, 0x2b, 0xdc, 0x3d, 0x83, 0xdb, 0x00, 0x00, 0xc8, |
372 0x26, 0xe5, 0x01, 0x99, 0x8a, 0xd5, 0xdd, 0xfc, 0x82, 0xcd, 0xcd, 0x9a, | 385 0x26, 0xe5, 0x01, 0x99, 0x8a, 0xd5, 0xdd, 0xfc, 0x82, 0xcd, 0xcd, 0x9a, |
373 0x8c, 0x13, 0xcc, 0x1b, 0xba, 0xf5, 0x05, 0xdb, 0xee, 0x6a, 0xdb, 0x38, | 386 0x8c, 0x13, 0xcc, 0x1b, 0xba, 0xf5, 0x05, 0xdb, 0xee, 0x6a, 0xdb, 0x38, |
374 0x60, 0xfe, 0x43, 0x2c, 0xd4, 0x6a, 0x99, 0x4d, 0xc6, 0xc0, 0xd3, 0x28, | 387 0x60, 0xfe, 0x43, 0x2c, 0xd4, 0x6a, 0x99, 0x4d, 0xc6, 0xc0, 0xd3, 0x28, |
375 0x1b, 0xc1, 0xb1, 0x17, 0x4e, 0x43, 0x0e, 0x3d, 0x27, 0xe9, 0xe4, 0x84, | 388 0x1b, 0xc1, 0xb1, 0x17, 0x4e, 0x43, 0x0e, 0x3d, 0x27, 0xe9, 0xe4, 0x84, |
376 0x4f, 0x24, 0x62, 0x69, 0x85, 0x43, 0x8d, 0xc2, 0x04, 0x00, 0x07, 0x59, | 389 0x4f, 0x24, 0x62, 0x69, 0x85, 0x43, 0x8d, 0xc2, 0x04, 0x00, 0x07, 0x59, |
377 0x60, 0xfd, 0x8b, 0x4d, 0x60, 0x32, 0x72, 0xcf, 0x88, 0x0c, 0x2f, 0x2f, | 390 0x60, 0xfd, 0x8b, 0x4d, 0x60, 0x32, 0x72, 0xcf, 0x88, 0x0c, 0x2f, 0x2f, |
378 0xad, 0x62, 0xbd, 0x27, 0x09, 0x16, 0x70, 0x78, 0x6c, 0xd9, 0x82, 0xef, | 391 0xad, 0x62, 0xbd, 0x27, 0x09, 0x16, 0x70, 0x78, 0x6c, 0xd9, 0x82, 0xef, |
379 0x1a, 0xa2, 0xcc, 0xf0, 0xf1, 0x6f, 0xd8, 0x78, 0x2e, 0x39, 0xa1, 0xcf, | 392 0x1a, 0xa2, 0xcc, 0xf0, 0xf1, 0x6f, 0xd8, 0x78, 0x2e, 0x39, 0xa1, 0xcf, |
380 0x14, 0x4b, 0x89, 0xb4, 0x1b, 0x48, 0x15, 0x7c, 0x48, 0x6f, 0x8c, 0x20, | 393 0x14, 0x4b, 0x89, 0xb4, 0x1b, 0x48, 0x15, 0x7c, 0x48, 0x6f, 0x8c, 0x20, |
381 0xb7, 0x00, 0xcf, 0xfc, 0xdb, 0xd0, 0xe9, 0xe7, 0x42, 0x09, 0xa4, 0x03, | 394 0xb7, 0x00, 0xcf, 0xfc, 0xdb, 0xd0, 0xe9, 0xe7, 0x42, 0x09, 0xa4, 0x03, |
382 0x40, 0xac, 0xda, 0x40, 0x01, 0x00, 0x5f, 0xa1, 0x3d, 0x64, 0xe1, 0xf4, | 395 0x40, 0xac, 0xda, 0x40, 0x01, 0x00, 0x5f, 0xa1, 0x3d, 0x64, 0xe1, 0xf4, |
383 0x03, 0x45, 0x29, 0xe0, 0xe2, 0x4a, 0xc3, 0xa2, 0xe8, 0xe0, 0x25, 0x12, | 396 0x03, 0x45, 0x29, 0xe0, 0xe2, 0x4a, 0xc3, 0xa2, 0xe8, 0xe0, 0x25, 0x12, |
384 0x74, 0xc6, 0xe8, 0xfb, 0x93, 0x4f, 0x9f, 0x5e, 0xc0, 0xa6, 0x91, 0x1b, | 397 0x74, 0xc6, 0xe8, 0xfb, 0x93, 0x4f, 0x9f, 0x5e, 0xc0, 0xa6, 0x91, 0x1b, |
385 0xa4, 0x24, 0x82, 0xc3, 0x61, 0x07, 0x4c, 0x49, 0x4f, 0x53, 0xae, 0x5f, | 398 0xa4, 0x24, 0x82, 0xc3, 0x61, 0x07, 0x4c, 0x49, 0x4f, 0x53, 0xae, 0x5f, |
386 0x5d, 0x39, 0x36, 0xc0, 0x5b, 0x57, 0x54, 0x60, 0x10, 0x00, 0x00, 0xd1, | 399 0x5d, 0x39, 0x36, 0xc0, 0x5b, 0x57, 0x54, 0x60, 0x10, 0x00, 0x00, 0xd1, |
387 0x68, 0xb6, 0x6d, 0xdb, 0x36, 0x22, 0xfa, 0x1f, 0x35, 0x75, 0x22, 0xec, | 400 0x68, 0xb6, 0x6d, 0xdb, 0x36, 0x22, 0xfa, 0x1f, 0x35, 0x75, 0x22, 0xec, |
388 0x31, 0xbc, 0x5d, 0x8f, 0x87, 0x53, 0xa2, 0x05, 0x8c, 0x2f, 0xcd, 0xa8, | 401 0x31, 0xbc, 0x5d, 0x8f, 0x87, 0x53, 0xa2, 0x05, 0x8c, 0x2f, 0xcd, 0xa8, |
389 0xa7, 0xf3, 0xa3, 0xbd, 0x83, 0x8b, 0x2a, 0xc8, 0x58, 0xf5, 0xac, 0x80, | 402 0xa7, 0xf3, 0xa3, 0xbd, 0x83, 0x8b, 0x2a, 0xc8, 0x58, 0xf5, 0xac, 0x80, |
390 0xe3, 0xfe, 0x66, 0xa4, 0x7c, 0x1b, 0x6c, 0xd1, 0xa9, 0xd8, 0x14, 0xd0, | 403 0xe3, 0xfe, 0x66, 0xa4, 0x7c, 0x1b, 0x6c, 0xd1, 0xa9, 0xd8, 0x14, 0xd0, |
391 0xc5, 0xb5, 0x39, 0x71, 0x97, 0x19, 0x19, 0x1b | 404 0xc5, 0xb5, 0x39, 0x71, 0x97, 0x19, 0x19, 0x1b |
392 }; | 405 }; |
393 SkAutoDataUnref encoded(SkData::NewWithCopy(encodedWebP, | 406 |
394 sizeof(encodedWebP))); | |
395 SkBitmap bm; | 407 SkBitmap bm; |
396 | 408 SkAutoDataUnref encoded(SkData::NewWithoutCopy(encodedWebP, sizeof(encodedWe
bP))); |
397 bool success = SkInstallDiscardablePixelRef(encoded, &bm); | 409 if (!decode_into_bitmap(reporter, &bm, encoded)) { |
398 | |
399 REPORTER_ASSERT(reporter, success); | |
400 if (!success) { | |
401 return; | 410 return; |
402 } | 411 } |
403 SkAutoLockPixels alp(bm); | 412 if (kExpectedWidth != bm.width() || kExpectedHeight != bm.height()) { |
| 413 REPORTER_ASSERT(reporter, false); |
| 414 return; |
| 415 } |
404 | 416 |
405 bool rightSize = ((kExpectedWidth == bm.width()) | 417 bool error = false; |
406 && (kExpectedHeight == bm.height())); | 418 const SkColor* correctPixel = kExpectedPixels; |
407 REPORTER_ASSERT(reporter, rightSize); | 419 for (int y = 0; y < bm.height(); ++y) { |
408 if (rightSize) { | 420 for (int x = 0; x < bm.width(); ++x) { |
409 bool error = false; | 421 error |= (*correctPixel != bm.getColor(x, y)); |
410 const SkColor* correctPixel = kExpectedPixels; | 422 ++correctPixel; |
411 for (int y = 0; y < bm.height(); ++y) { | |
412 for (int x = 0; x < bm.width(); ++x) { | |
413 error |= (*correctPixel != bm.getColor(x, y)); | |
414 ++correctPixel; | |
415 } | |
416 } | 423 } |
417 REPORTER_ASSERT(reporter, !error); | 424 } |
| 425 REPORTER_ASSERT(reporter, !error); |
| 426 } |
| 427 |
| 428 //////////////////////////////////////////////////////////////////////////////// |
| 429 |
| 430 /** |
| 431 * A test for the SkDecodingImageGenerator::Create |
| 432 */ |
| 433 DEF_TEST(ImprovedBitmapFactory, reporter) { |
| 434 SkString pngFilename = GetResourcePath("randPixels.png"); |
| 435 SkAutoTDelete<SkStreamRewindable> stream(SkStream::NewFromFile(pngFilename.c
_str())); |
| 436 if (sk_exists(pngFilename.c_str())) { |
| 437 // example of how Android will do this inside their BitmapFactory |
| 438 SkDecodingImageGenerator::Options opts(1, true, kN32_SkColorType); |
| 439 SkBitmap bm; |
| 440 SkImageGenerator* gen = SkDecodingImageGenerator::Create(stream, opts); |
| 441 REPORTER_ASSERT(reporter, gen->tryGenerateBitmap(&bm)); |
418 } | 442 } |
419 } | 443 } |
420 | 444 |
421 //////////////////////////////////////////////////////////////////////////////// | 445 //////////////////////////////////////////////////////////////////////////////// |
422 | 446 |
423 // example of how Android will do this inside their BitmapFactory | |
424 static SkPixelRef* install_pixel_ref(SkBitmap* bitmap, | |
425 SkStreamRewindable* stream, | |
426 int sampleSize, bool ditherImage) { | |
427 SkASSERT(bitmap != nullptr); | |
428 SkASSERT(stream != nullptr); | |
429 SkASSERT(stream->rewind()); | |
430 SkColorType colorType = bitmap->colorType(); | |
431 SkDecodingImageGenerator::Options opts(sampleSize, ditherImage, colorType); | |
432 if (SkInstallDiscardablePixelRef( | |
433 SkDecodingImageGenerator::Create(stream, opts), bitmap)) { | |
434 return bitmap->pixelRef(); | |
435 } | |
436 return nullptr; | |
437 } | |
438 /** | |
439 * A test for the SkDecodingImageGenerator::Create and | |
440 * SkInstallDiscardablePixelRef functions. | |
441 */ | |
442 DEF_TEST(ImprovedBitmapFactory, reporter) { | |
443 SkString pngFilename = GetResourcePath("randPixels.png"); | |
444 SkAutoTDelete<SkStreamRewindable> stream(SkStream::NewFromFile(pngFilename.c
_str())); | |
445 if (sk_exists(pngFilename.c_str())) { | |
446 SkBitmap bm; | |
447 SkAssertResult(bm.setInfo(SkImageInfo::MakeN32Premul(1, 1))); | |
448 REPORTER_ASSERT(reporter, | |
449 install_pixel_ref(&bm, stream.detach(), 1, true)); | |
450 SkAutoLockPixels alp(bm); | |
451 REPORTER_ASSERT(reporter, bm.getPixels()); | |
452 } | |
453 } | |
454 | |
455 | |
456 //////////////////////////////////////////////////////////////////////////////// | |
457 | |
458 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) | 447 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) |
459 static inline bool check_rounding(int value, int dividend, int divisor) { | 448 static inline bool check_rounding(int value, int dividend, int divisor) { |
460 // returns true if the value is greater than floor(dividend/divisor) | 449 // returns true if the value is greater than floor(dividend/divisor) |
461 // and less than SkNextPow2(ceil(dividend - divisor)) | 450 // and less than SkNextPow2(ceil(dividend - divisor)) |
462 return (((divisor * value) > (dividend - divisor)) | 451 return (((divisor * value) > (dividend - divisor)) |
463 && value <= SkNextPow2(((dividend - 1) / divisor) + 1)); | 452 && value <= SkNextPow2(((dividend - 1) / divisor) + 1)); |
464 } | 453 } |
465 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX | 454 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX |
466 | 455 |
467 | 456 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 * Given either a SkStream or a SkData, try to decode the encoded | 495 * Given either a SkStream or a SkData, try to decode the encoded |
507 * image using the specified options and report errors. | 496 * image using the specified options and report errors. |
508 */ | 497 */ |
509 static void test_options(skiatest::Reporter* reporter, | 498 static void test_options(skiatest::Reporter* reporter, |
510 const SkDecodingImageGenerator::Options& opts, | 499 const SkDecodingImageGenerator::Options& opts, |
511 SkStreamRewindable* encodedStream, | 500 SkStreamRewindable* encodedStream, |
512 SkData* encodedData, | 501 SkData* encodedData, |
513 bool useData, | 502 bool useData, |
514 const SkString& path) { | 503 const SkString& path) { |
515 SkBitmap bm; | 504 SkBitmap bm; |
516 bool success = false; | 505 SkImageGenerator* gen; |
| 506 |
517 if (useData) { | 507 if (useData) { |
518 if (nullptr == encodedData) { | 508 if (nullptr == encodedData) { |
519 return; | 509 return; |
520 } | 510 } |
521 success = SkInstallDiscardablePixelRef( | 511 gen = SkDecodingImageGenerator::Create(encodedData, opts); |
522 SkDecodingImageGenerator::Create(encodedData, opts), &bm); | |
523 } else { | 512 } else { |
524 if (nullptr == encodedStream) { | 513 if (nullptr == encodedStream) { |
525 return; | 514 return; |
526 } | 515 } |
527 success = SkInstallDiscardablePixelRef( | 516 gen = SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts)
; |
528 SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts),
&bm); | |
529 } | 517 } |
530 if (!success) { | 518 if (!gen) { |
531 if (opts.fUseRequestedColorType | 519 if (opts.fUseRequestedColorType && (kARGB_4444_SkColorType == opts.fRequ
estedColorType)) { |
532 && (kARGB_4444_SkColorType == opts.fRequestedColorType)) { | |
533 return; // Ignore known conversion inabilities. | 520 return; // Ignore known conversion inabilities. |
534 } | 521 } |
535 // If we get here, it's a failure and we will need more | 522 // If we get here, it's a failure and we will need more |
536 // information about why it failed. | 523 // information about why it failed. |
537 ERRORF(reporter, "Bounds decode failed [sampleSize=%d dither=%s " | 524 ERRORF(reporter, "Bounds decode failed [sampleSize=%d dither=%s " |
538 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), | 525 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), |
539 options_colorType(opts), path.c_str()); | 526 options_colorType(opts), path.c_str()); |
540 return; | 527 return; |
541 } | 528 } |
| 529 if (!gen->tryGenerateBitmap(&bm)) { |
| 530 return; |
| 531 } |
| 532 |
542 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) | 533 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) |
543 // Android is the only system that use Skia's image decoders in | 534 // Android is the only system that use Skia's image decoders in |
544 // production. For now, we'll only verify that samplesize works | 535 // production. For now, we'll only verify that samplesize works |
545 // on systems where it already is known to work. | 536 // on systems where it already is known to work. |
546 REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight, | 537 REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight, opts.
fSampleSize)); |
547 opts.fSampleSize)); | 538 REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth, opts.fS
ampleSize)); |
548 REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth, | |
549 opts.fSampleSize)); | |
550 // The ImageDecoder API doesn't guarantee that SampleSize does | 539 // The ImageDecoder API doesn't guarantee that SampleSize does |
551 // anything at all, but the decoders that this test excercises all | 540 // anything at all, but the decoders that this test excercises all |
552 // produce an output size in the following range: | 541 // produce an output size in the following range: |
553 // (((sample_size * out_size) > (in_size - sample_size)) | 542 // (((sample_size * out_size) > (in_size - sample_size)) |
554 // && out_size <= SkNextPow2(((in_size - 1) / sample_size) + 1)); | 543 // && out_size <= SkNextPow2(((in_size - 1) / sample_size) + 1)); |
555 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX | 544 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX |
556 SkAutoLockPixels alp(bm); | |
557 if (bm.getPixels() == nullptr) { | |
558 ERRORF(reporter, "Pixel decode failed [sampleSize=%d dither=%s " | |
559 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), | |
560 options_colorType(opts), path.c_str()); | |
561 return; | |
562 } | |
563 | 545 |
564 SkColorType requestedColorType = opts.fRequestedColorType; | 546 SkColorType requestedColorType = opts.fRequestedColorType; |
565 REPORTER_ASSERT(reporter, | 547 REPORTER_ASSERT(reporter, |
566 (!opts.fUseRequestedColorType) | 548 (!opts.fUseRequestedColorType) |
567 || (bm.colorType() == requestedColorType)); | 549 || (bm.colorType() == requestedColorType)); |
568 | 550 |
569 // Condition under which we should check the decoding results: | 551 // Condition under which we should check the decoding results: |
570 if ((kN32_SkColorType == bm.colorType()) | 552 if ((kN32_SkColorType == bm.colorType()) |
571 && (!path.endsWith(".jpg")) // lossy | 553 && (!path.endsWith(".jpg")) // lossy |
572 && (opts.fSampleSize == 1)) { // scaled | 554 && (opts.fSampleSize == 1)) { // scaled |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
654 SkDecodingImageGenerator::Options options(scaleList[i], | 636 SkDecodingImageGenerator::Options options(scaleList[i], |
655 ditherList[j]); | 637 ditherList[j]); |
656 test_options(reporter, options, encodedStream, encodedData, | 638 test_options(reporter, options, encodedStream, encodedData, |
657 useDataList[m], path); | 639 useDataList[m], path); |
658 } | 640 } |
659 } | 641 } |
660 } | 642 } |
661 } | 643 } |
662 } | 644 } |
663 | 645 |
664 DEF_TEST(DiscardablePixelRef_SecondLockColorTableCheck, r) { | 646 DEF_TEST(DecodingImageGenerator_ColorTableCheck, r) { |
665 SkString resourceDir = GetResourcePath(); | 647 SkString resourceDir = GetResourcePath(); |
666 SkString path = SkOSPath::Join(resourceDir.c_str(), "randPixels.gif"); | 648 SkString path = SkOSPath::Join(resourceDir.c_str(), "randPixels.gif"); |
667 if (!sk_exists(path.c_str())) { | 649 if (!sk_exists(path.c_str())) { |
668 return; | 650 return; |
669 } | 651 } |
670 SkAutoDataUnref encoded(SkData::NewFromFileName(path.c_str())); | 652 SkAutoDataUnref encoded(SkData::NewFromFileName(path.c_str())); |
671 SkBitmap bitmap; | 653 SkBitmap bitmap; |
672 if (!SkInstallDiscardablePixelRef( | 654 SkImageGenerator* gen = SkDecodingImageGenerator::Create(encoded, |
673 SkDecodingImageGenerator::Create( | 655 SkDecodingImageGene
rator::Options()); |
674 encoded, SkDecodingImageGenerator::Options()), &bitmap)) { | 656 if (!gen) { |
675 #ifndef SK_BUILD_FOR_WIN | 657 REPORTER_ASSERT(r, false); |
676 ERRORF(r, "SkInstallDiscardablePixelRef [randPixels.gif] failed."); | 658 return; |
677 #endif | 659 } |
| 660 if (!gen->tryGenerateBitmap(&bitmap)) { |
| 661 REPORTER_ASSERT(r, false); |
678 return; | 662 return; |
679 } | 663 } |
680 if (kIndex_8_SkColorType != bitmap.colorType()) { | 664 if (kIndex_8_SkColorType != bitmap.colorType()) { |
681 return; | 665 return; |
682 } | 666 } |
683 { | 667 REPORTER_ASSERT(r, bitmap.getColorTable()); |
684 SkAutoLockPixels alp(bitmap); | |
685 REPORTER_ASSERT(r, bitmap.getColorTable() && "first pass"); | |
686 } | |
687 { | |
688 SkAutoLockPixels alp(bitmap); | |
689 REPORTER_ASSERT(r, bitmap.getColorTable() && "second pass"); | |
690 } | |
691 } | 668 } |
692 | 669 |
693 | 670 |
694 //////////////////////////////////////////////////////////////////////////////// | 671 //////////////////////////////////////////////////////////////////////////////// |
695 namespace { | 672 namespace { |
696 class SingleAllocator : public SkBitmap::Allocator { | 673 class SingleAllocator : public SkBitmap::Allocator { |
697 public: | 674 public: |
698 SingleAllocator(void* p, size_t s) : fPixels(p), fSize(s) { } | 675 SingleAllocator(void* p, size_t s) : fPixels(p), fSize(s) { } |
699 ~SingleAllocator() {} | 676 ~SingleAllocator() {} |
700 // If the pixels in fPixels are big enough, use them. | 677 // If the pixels in fPixels are big enough, use them. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 new SingleAllocator((void*)pixels.get(), sizeof(uint16_t) * pixelCou
nt)); | 722 new SingleAllocator((void*)pixels.get(), sizeof(uint16_t) * pixelCou
nt)); |
746 decoder->setAllocator(allocator); | 723 decoder->setAllocator(allocator); |
747 decoder->setSampleSize(2); | 724 decoder->setSampleSize(2); |
748 SkBitmap bitmap; | 725 SkBitmap bitmap; |
749 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, | 726 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, |
750 SkImageDecoder::kDecodePixels_Mode) != SkImag
eDecoder::kFailure; | 727 SkImageDecoder::kDecodePixels_Mode) != SkImag
eDecoder::kFailure; |
751 REPORTER_ASSERT(r, success); | 728 REPORTER_ASSERT(r, success); |
752 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory | 729 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory |
753 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); | 730 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); |
754 } | 731 } |
OLD | NEW |