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

Side by Side Diff: tests/ImageDecodingTest.cpp

Issue 264583007: flatten resources directory (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet Created 6 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
« no previous file with comments | « resources/randPixels.webp ('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 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 return bitmap->pixelRef(); 505 return bitmap->pixelRef();
506 } 506 }
507 return NULL; 507 return NULL;
508 } 508 }
509 /** 509 /**
510 * A test for the SkDecodingImageGenerator::Create and 510 * A test for the SkDecodingImageGenerator::Create and
511 * SkInstallDiscardablePixelRef functions. 511 * SkInstallDiscardablePixelRef functions.
512 */ 512 */
513 DEF_TEST(ImprovedBitmapFactory, reporter) { 513 DEF_TEST(ImprovedBitmapFactory, reporter) {
514 SkString resourcePath = skiatest::Test::GetResourcePath(); 514 SkString resourcePath = skiatest::Test::GetResourcePath();
515 SkString directory = SkOSPath::SkPathJoin(resourcePath.c_str(), "encoding"); 515 SkString path = SkOSPath::SkPathJoin(
516 SkString path = SkOSPath::SkPathJoin(directory.c_str(), "randPixels.png"); 516 resourcePath.c_str(), "randPixels.png");
517 SkAutoTUnref<SkStreamRewindable> stream( 517 SkAutoTUnref<SkStreamRewindable> stream(
518 SkStream::NewFromFile(path.c_str())); 518 SkStream::NewFromFile(path.c_str()));
519 if (sk_exists(path.c_str())) { 519 if (sk_exists(path.c_str())) {
520 SkBitmap bm; 520 SkBitmap bm;
521 SkAssertResult(bm.setConfig(SkImageInfo::MakeN32Premul(1, 1))); 521 SkAssertResult(bm.setConfig(SkImageInfo::MakeN32Premul(1, 1)));
522 REPORTER_ASSERT(reporter, 522 REPORTER_ASSERT(reporter,
523 NULL != install_pixel_ref(&bm, stream.detach(), 1, true)); 523 NULL != install_pixel_ref(&bm, stream.detach(), 1, true));
524 SkAutoLockPixels alp(bm); 524 SkAutoLockPixels alp(bm);
525 REPORTER_ASSERT(reporter, NULL != bm.getPixels()); 525 REPORTER_ASSERT(reporter, NULL != bm.getPixels());
526 } 526 }
527 } 527 }
528 528
529 529
530 //////////////////////////////////////////////////////////////////////////////// 530 ////////////////////////////////////////////////////////////////////////////////
531 531
532 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) 532 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
533 static inline bool check_rounding(int value, int dividend, int divisor) { 533 static inline bool check_rounding(int value, int dividend, int divisor) {
534 // returns true if (dividend/divisor) rounds up OR down to value 534 // returns true if the value is greater than floor(dividend/divisor)
535 // and less than SkNextPow2(ceil(dividend - divisor))
535 return (((divisor * value) > (dividend - divisor)) 536 return (((divisor * value) > (dividend - divisor))
536 && ((divisor * value) < (dividend + divisor))); 537 && value <= SkNextPow2(((dividend - 1) / divisor) + 1));
537 } 538 }
538 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX 539 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX
539 540
540 541
541 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) 542 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
542 #define kBackwards_SkColorType kRGBA_8888_SkColorType 543 #define kBackwards_SkColorType kRGBA_8888_SkColorType
543 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) 544 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
544 #define kBackwards_SkColorType kBGRA_8888_SkColorType 545 #define kBackwards_SkColorType kBGRA_8888_SkColorType
545 #else 546 #else
546 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" 547 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 return; 615 return;
615 } 616 }
616 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) 617 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
617 // Android is the only system that use Skia's image decoders in 618 // Android is the only system that use Skia's image decoders in
618 // production. For now, we'll only verify that samplesize works 619 // production. For now, we'll only verify that samplesize works
619 // on systems where it already is known to work. 620 // on systems where it already is known to work.
620 REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight, 621 REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight,
621 opts.fSampleSize)); 622 opts.fSampleSize));
622 REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth, 623 REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth,
623 opts.fSampleSize)); 624 opts.fSampleSize));
625 // The ImageDecoder API doesn't guarantee that SampleSize does
626 // anything at all, but the decoders that this test excercises all
627 // produce an output size in the following range:
628 // (((sample_size * out_size) > (in_size - sample_size))
629 // && out_size <= SkNextPow2(((in_size - 1) / sample_size) + 1));
624 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX 630 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX
625 SkAutoLockPixels alp(bm); 631 SkAutoLockPixels alp(bm);
626 if (bm.getPixels() == NULL) { 632 if (bm.getPixels() == NULL) {
627 ERRORF(reporter, "Pixel decode failed [sampleSize=%d dither=%s " 633 ERRORF(reporter, "Pixel decode failed [sampleSize=%d dither=%s "
628 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), 634 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage),
629 options_colorType(opts), path.c_str()); 635 options_colorType(opts), path.c_str());
630 return; 636 return;
631 } 637 }
632 638
633 SkBitmap::Config requestedConfig 639 SkBitmap::Config requestedConfig
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 "randPixels.jpg", 681 "randPixels.jpg",
676 "randPixels.png", 682 "randPixels.png",
677 "randPixels.webp", 683 "randPixels.webp",
678 #if !defined(SK_BUILD_FOR_WIN) 684 #if !defined(SK_BUILD_FOR_WIN)
679 // TODO(halcanary): Find out why this fails sometimes. 685 // TODO(halcanary): Find out why this fails sometimes.
680 "randPixels.gif", 686 "randPixels.gif",
681 #endif 687 #endif
682 }; 688 };
683 689
684 SkString resourceDir = skiatest::Test::GetResourcePath(); 690 SkString resourceDir = skiatest::Test::GetResourcePath();
685 SkString directory = SkOSPath::SkPathJoin(resourceDir.c_str(), "encoding"); 691 if (!sk_exists(resourceDir.c_str())) {
686 if (!sk_exists(directory.c_str())) {
687 return; 692 return;
688 } 693 }
689 694
690 int scaleList[] = {1, 2, 3, 4}; 695 int scaleList[] = {1, 2, 3, 4};
691 bool ditherList[] = {true, false}; 696 bool ditherList[] = {true, false};
692 SkColorType colorList[] = { 697 SkColorType colorList[] = {
693 kAlpha_8_SkColorType, 698 kAlpha_8_SkColorType,
694 kRGB_565_SkColorType, 699 kRGB_565_SkColorType,
695 kARGB_4444_SkColorType, // Most decoders will fail on 4444. 700 kARGB_4444_SkColorType, // Most decoders will fail on 4444.
696 kN32_SkColorType 701 kN32_SkColorType
697 // Note that indexed color is left out of the list. Lazy 702 // Note that indexed color is left out of the list. Lazy
698 // decoding doesn't do indexed color. 703 // decoding doesn't do indexed color.
699 }; 704 };
700 const bool useDataList[] = {true, false}; 705 const bool useDataList[] = {true, false};
701 706
702 for (size_t fidx = 0; fidx < SK_ARRAY_COUNT(files); ++fidx) { 707 for (size_t fidx = 0; fidx < SK_ARRAY_COUNT(files); ++fidx) {
703 SkString path = SkOSPath::SkPathJoin(directory.c_str(), files[fidx]); 708 SkString path = SkOSPath::SkPathJoin(resourceDir.c_str(), files[fidx]);
704 if (!sk_exists(path.c_str())) { 709 if (!sk_exists(path.c_str())) {
705 continue; 710 continue;
706 } 711 }
707 712
708 SkAutoDataUnref encodedData(SkData::NewFromFileName(path.c_str())); 713 SkAutoDataUnref encodedData(SkData::NewFromFileName(path.c_str()));
709 REPORTER_ASSERT(reporter, encodedData.get() != NULL); 714 REPORTER_ASSERT(reporter, encodedData.get() != NULL);
710 SkAutoTUnref<SkStreamRewindable> encodedStream( 715 SkAutoTUnref<SkStreamRewindable> encodedStream(
711 SkStream::NewFromFile(path.c_str())); 716 SkStream::NewFromFile(path.c_str()));
712 REPORTER_ASSERT(reporter, encodedStream.get() != NULL); 717 REPORTER_ASSERT(reporter, encodedStream.get() != NULL);
713 718
(...skipping 10 matching lines...) Expand all
724 } 729 }
725 SkDecodingImageGenerator::Options options(scaleList[i], 730 SkDecodingImageGenerator::Options options(scaleList[i],
726 ditherList[j]); 731 ditherList[j]);
727 test_options(reporter, options, encodedStream, encodedData, 732 test_options(reporter, options, encodedStream, encodedData,
728 useDataList[m], path); 733 useDataList[m], path);
729 } 734 }
730 } 735 }
731 } 736 }
732 } 737 }
733 } 738 }
OLDNEW
« no previous file with comments | « resources/randPixels.webp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698