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

Side by Side Diff: tests/ImageDecodingTest.cpp

Issue 278033002: Revert "Flatten resources directory" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: 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 | Annotate | Revision Log
« 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 path = SkOSPath::SkPathJoin( 515 SkString directory = SkOSPath::SkPathJoin(resourcePath.c_str(), "encoding");
516 resourcePath.c_str(), "randPixels.png"); 516 SkString path = SkOSPath::SkPathJoin(directory.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 the value is greater than floor(dividend/divisor) 534 // returns true if (dividend/divisor) rounds up OR down to value
535 // and less than SkNextPow2(ceil(dividend - divisor))
536 return (((divisor * value) > (dividend - divisor)) 535 return (((divisor * value) > (dividend - divisor))
537 && value <= SkNextPow2(((dividend - 1) / divisor) + 1)); 536 && ((divisor * value) < (dividend + divisor)));
538 } 537 }
539 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX 538 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX
540 539
541 540
542 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) 541 #if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
543 #define kBackwards_SkColorType kRGBA_8888_SkColorType 542 #define kBackwards_SkColorType kRGBA_8888_SkColorType
544 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) 543 #elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
545 #define kBackwards_SkColorType kBGRA_8888_SkColorType 544 #define kBackwards_SkColorType kBGRA_8888_SkColorType
546 #else 545 #else
547 #error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order" 546 #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
615 return; 614 return;
616 } 615 }
617 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) 616 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
618 // Android is the only system that use Skia's image decoders in 617 // Android is the only system that use Skia's image decoders in
619 // production. For now, we'll only verify that samplesize works 618 // production. For now, we'll only verify that samplesize works
620 // on systems where it already is known to work. 619 // on systems where it already is known to work.
621 REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight, 620 REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight,
622 opts.fSampleSize)); 621 opts.fSampleSize));
623 REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth, 622 REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth,
624 opts.fSampleSize)); 623 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));
630 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX 624 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX
631 SkAutoLockPixels alp(bm); 625 SkAutoLockPixels alp(bm);
632 if (bm.getPixels() == NULL) { 626 if (bm.getPixels() == NULL) {
633 ERRORF(reporter, "Pixel decode failed [sampleSize=%d dither=%s " 627 ERRORF(reporter, "Pixel decode failed [sampleSize=%d dither=%s "
634 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), 628 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage),
635 options_colorType(opts), path.c_str()); 629 options_colorType(opts), path.c_str());
636 return; 630 return;
637 } 631 }
638 632
639 SkBitmap::Config requestedConfig 633 SkBitmap::Config requestedConfig
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 "randPixels.jpg", 675 "randPixels.jpg",
682 "randPixels.png", 676 "randPixels.png",
683 "randPixels.webp", 677 "randPixels.webp",
684 #if !defined(SK_BUILD_FOR_WIN) 678 #if !defined(SK_BUILD_FOR_WIN)
685 // TODO(halcanary): Find out why this fails sometimes. 679 // TODO(halcanary): Find out why this fails sometimes.
686 "randPixels.gif", 680 "randPixels.gif",
687 #endif 681 #endif
688 }; 682 };
689 683
690 SkString resourceDir = skiatest::Test::GetResourcePath(); 684 SkString resourceDir = skiatest::Test::GetResourcePath();
691 if (!sk_exists(resourceDir.c_str())) { 685 SkString directory = SkOSPath::SkPathJoin(resourceDir.c_str(), "encoding");
686 if (!sk_exists(directory.c_str())) {
692 return; 687 return;
693 } 688 }
694 689
695 int scaleList[] = {1, 2, 3, 4}; 690 int scaleList[] = {1, 2, 3, 4};
696 bool ditherList[] = {true, false}; 691 bool ditherList[] = {true, false};
697 SkColorType colorList[] = { 692 SkColorType colorList[] = {
698 kAlpha_8_SkColorType, 693 kAlpha_8_SkColorType,
699 kRGB_565_SkColorType, 694 kRGB_565_SkColorType,
700 kARGB_4444_SkColorType, // Most decoders will fail on 4444. 695 kARGB_4444_SkColorType, // Most decoders will fail on 4444.
701 kN32_SkColorType 696 kN32_SkColorType
702 // Note that indexed color is left out of the list. Lazy 697 // Note that indexed color is left out of the list. Lazy
703 // decoding doesn't do indexed color. 698 // decoding doesn't do indexed color.
704 }; 699 };
705 const bool useDataList[] = {true, false}; 700 const bool useDataList[] = {true, false};
706 701
707 for (size_t fidx = 0; fidx < SK_ARRAY_COUNT(files); ++fidx) { 702 for (size_t fidx = 0; fidx < SK_ARRAY_COUNT(files); ++fidx) {
708 SkString path = SkOSPath::SkPathJoin(resourceDir.c_str(), files[fidx]); 703 SkString path = SkOSPath::SkPathJoin(directory.c_str(), files[fidx]);
709 if (!sk_exists(path.c_str())) { 704 if (!sk_exists(path.c_str())) {
710 continue; 705 continue;
711 } 706 }
712 707
713 SkAutoDataUnref encodedData(SkData::NewFromFileName(path.c_str())); 708 SkAutoDataUnref encodedData(SkData::NewFromFileName(path.c_str()));
714 REPORTER_ASSERT(reporter, encodedData.get() != NULL); 709 REPORTER_ASSERT(reporter, encodedData.get() != NULL);
715 SkAutoTUnref<SkStreamRewindable> encodedStream( 710 SkAutoTUnref<SkStreamRewindable> encodedStream(
716 SkStream::NewFromFile(path.c_str())); 711 SkStream::NewFromFile(path.c_str()));
717 REPORTER_ASSERT(reporter, encodedStream.get() != NULL); 712 REPORTER_ASSERT(reporter, encodedStream.get() != NULL);
718 713
(...skipping 10 matching lines...) Expand all
729 } 724 }
730 SkDecodingImageGenerator::Options options(scaleList[i], 725 SkDecodingImageGenerator::Options options(scaleList[i],
731 ditherList[j]); 726 ditherList[j]);
732 test_options(reporter, options, encodedStream, encodedData, 727 test_options(reporter, options, encodedStream, encodedData,
733 useDataList[m], path); 728 useDataList[m], path);
734 } 729 }
735 } 730 }
736 } 731 }
737 } 732 }
738 } 733 }
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