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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 * 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 |
496 * image using the specified options and report errors. | 496 * image using the specified options and report errors. |
497 */ | 497 */ |
498 static void test_options(skiatest::Reporter* reporter, | 498 static void test_options(skiatest::Reporter* reporter, |
499 const SkDecodingImageGenerator::Options& opts, | 499 const SkDecodingImageGenerator::Options& opts, |
500 SkStreamRewindable* encodedStream, | 500 SkStreamRewindable* encodedStream, |
501 SkData* encodedData, | 501 SkData* encodedData, |
502 bool useData, | 502 bool useData, |
503 const SkString& path) { | 503 const SkString& path) { |
504 SkBitmap bm; | 504 SkBitmap bm; |
505 SkImageGenerator* gen; | 505 SkAutoTDelete<SkImageGenerator> gen; |
506 | 506 |
507 if (useData) { | 507 if (useData) { |
508 if (nullptr == encodedData) { | 508 if (nullptr == encodedData) { |
509 return; | 509 return; |
510 } | 510 } |
511 gen = SkDecodingImageGenerator::Create(encodedData, opts); | 511 gen.reset(SkDecodingImageGenerator::Create(encodedData, opts)); |
512 } else { | 512 } else { |
513 if (nullptr == encodedStream) { | 513 if (nullptr == encodedStream) { |
514 return; | 514 return; |
515 } | 515 } |
516 gen = SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts)
; | 516 gen.reset(SkDecodingImageGenerator::Create(encodedStream->duplicate(), o
pts)); |
517 } | 517 } |
518 if (!gen) { | 518 if (!gen) { |
519 if (opts.fUseRequestedColorType && (kARGB_4444_SkColorType == opts.fRequ
estedColorType)) { | 519 if (opts.fUseRequestedColorType && (kARGB_4444_SkColorType == opts.fRequ
estedColorType)) { |
520 return; // Ignore known conversion inabilities. | 520 return; // Ignore known conversion inabilities. |
521 } | 521 } |
522 // 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 |
523 // information about why it failed. | 523 // information about why it failed. |
524 ERRORF(reporter, "Bounds decode failed [sampleSize=%d dither=%s " | 524 ERRORF(reporter, "Bounds decode failed [sampleSize=%d dither=%s " |
525 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), | 525 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), |
526 options_colorType(opts), path.c_str()); | 526 options_colorType(opts), path.c_str()); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 } | 644 } |
645 | 645 |
646 DEF_TEST(DecodingImageGenerator_ColorTableCheck, r) { | 646 DEF_TEST(DecodingImageGenerator_ColorTableCheck, r) { |
647 SkString resourceDir = GetResourcePath(); | 647 SkString resourceDir = GetResourcePath(); |
648 SkString path = SkOSPath::Join(resourceDir.c_str(), "randPixels.gif"); | 648 SkString path = SkOSPath::Join(resourceDir.c_str(), "randPixels.gif"); |
649 if (!sk_exists(path.c_str())) { | 649 if (!sk_exists(path.c_str())) { |
650 return; | 650 return; |
651 } | 651 } |
652 SkAutoDataUnref encoded(SkData::NewFromFileName(path.c_str())); | 652 SkAutoDataUnref encoded(SkData::NewFromFileName(path.c_str())); |
653 SkBitmap bitmap; | 653 SkBitmap bitmap; |
654 SkImageGenerator* gen = SkDecodingImageGenerator::Create(encoded, | 654 SkAutoTDelete<SkImageGenerator> gen(SkDecodingImageGenerator::Create(encoded
, |
655 SkDecodingImageGene
rator::Options()); | 655 SkDecodingImageGene
rator::Options())); |
656 if (!gen) { | 656 if (!gen) { |
657 REPORTER_ASSERT(r, false); | 657 REPORTER_ASSERT(r, false); |
658 return; | 658 return; |
659 } | 659 } |
660 if (!gen->tryGenerateBitmap(&bitmap)) { | 660 if (!gen->tryGenerateBitmap(&bitmap)) { |
661 REPORTER_ASSERT(r, false); | 661 REPORTER_ASSERT(r, false); |
662 return; | 662 return; |
663 } | 663 } |
664 if (kIndex_8_SkColorType != bitmap.colorType()) { | 664 if (kIndex_8_SkColorType != bitmap.colorType()) { |
665 return; | 665 return; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 new SingleAllocator((void*)pixels.get(), sizeof(uint16_t) * pixelCou
nt)); | 722 new SingleAllocator((void*)pixels.get(), sizeof(uint16_t) * pixelCou
nt)); |
723 decoder->setAllocator(allocator); | 723 decoder->setAllocator(allocator); |
724 decoder->setSampleSize(2); | 724 decoder->setSampleSize(2); |
725 SkBitmap bitmap; | 725 SkBitmap bitmap; |
726 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, | 726 bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType, |
727 SkImageDecoder::kDecodePixels_Mode) != SkImag
eDecoder::kFailure; | 727 SkImageDecoder::kDecodePixels_Mode) != SkImag
eDecoder::kFailure; |
728 REPORTER_ASSERT(r, success); | 728 REPORTER_ASSERT(r, success); |
729 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory | 729 REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory |
730 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); | 730 REPORTER_ASSERT(r, sentinal == pixels[pixelCount]); |
731 } | 731 } |
OLD | NEW |