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 "Test.h" | 8 #include "Test.h" |
9 #include "TestClassDef.h" | 9 #include "TestClassDef.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 case kAlpha_8_SkColorType: return "Alpha_8"; | 403 case kAlpha_8_SkColorType: return "Alpha_8"; |
404 case kRGB_565_SkColorType: return "RGB_565"; | 404 case kRGB_565_SkColorType: return "RGB_565"; |
405 case kARGB_4444_SkColorType: return "ARGB_4444"; | 405 case kARGB_4444_SkColorType: return "ARGB_4444"; |
406 case kPMColor_SkColorType: return "PMColor"; | 406 case kPMColor_SkColorType: return "PMColor"; |
407 case kBackwards_SkColorType: return "Backwards"; | 407 case kBackwards_SkColorType: return "Backwards"; |
408 case kIndex_8_SkColorType: return "Index_8"; | 408 case kIndex_8_SkColorType: return "Index_8"; |
409 default: return "ERROR"; | 409 default: return "ERROR"; |
410 } | 410 } |
411 } | 411 } |
412 | 412 |
| 413 static inline const char* options_colorType( |
| 414 const SkDecodingImageGenerator::Options& opts) { |
| 415 if (opts.fUseRequestedColorType) { |
| 416 return SkColorType_to_string(opts.fRequestedColorType); |
| 417 } else { |
| 418 return "(none)"; |
| 419 } |
| 420 } |
| 421 |
| 422 static inline const char* yn(bool value) { |
| 423 if (value) { |
| 424 return "yes"; |
| 425 } else { |
| 426 return "no"; |
| 427 } |
| 428 } |
| 429 |
413 /** | 430 /** |
414 * Given either a SkStream or a SkData, try to decode the encoded | 431 * Given either a SkStream or a SkData, try to decode the encoded |
415 * image using the specified options and report errors. | 432 * image using the specified options and report errors. |
416 */ | 433 */ |
417 static void test_options(skiatest::Reporter* reporter, | 434 static void test_options(skiatest::Reporter* reporter, |
418 const SkDecodingImageGenerator::Options& opts, | 435 const SkDecodingImageGenerator::Options& opts, |
419 SkStreamRewindable* encodedStream, | 436 SkStreamRewindable* encodedStream, |
420 SkData* encodedData, | 437 SkData* encodedData, |
421 bool useData, | 438 bool useData, |
422 const SkString& path) { | 439 const SkString& path) { |
(...skipping 13 matching lines...) Expand all Loading... |
436 SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts), | 453 SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts), |
437 &bm, NULL); | 454 &bm, NULL); |
438 } | 455 } |
439 if (!success) { | 456 if (!success) { |
440 if (opts.fUseRequestedColorType | 457 if (opts.fUseRequestedColorType |
441 && (kARGB_4444_SkColorType == opts.fRequestedColorType)) { | 458 && (kARGB_4444_SkColorType == opts.fRequestedColorType)) { |
442 return; // Ignore known conversion inabilities. | 459 return; // Ignore known conversion inabilities. |
443 } | 460 } |
444 // If we get here, it's a failure and we will need more | 461 // If we get here, it's a failure and we will need more |
445 // information about why it failed. | 462 // information about why it failed. |
446 reporter->reportFailed(SkStringPrintf( | 463 ERRORF(reporter, "Bounds decode failed [sampleSize=%d dither=%s " |
447 "Bounds decode failed " | 464 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), |
448 "[sampleSize=%d dither=%s colorType=%s %s] %s:%d", | 465 options_colorType(opts), path.c_str()); |
449 opts.fSampleSize, (opts.fDitherImage ? "yes" : "no"), | |
450 (opts.fUseRequestedColorType | |
451 ? SkColorType_to_string(opts.fRequestedColorType) : "(none)"), | |
452 path.c_str(), __FILE__, __LINE__)); | |
453 return; | 466 return; |
454 } | 467 } |
455 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) | 468 #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX) |
456 // Android is the only system that use Skia's image decoders in | 469 // Android is the only system that use Skia's image decoders in |
457 // production. For now, we'll only verify that samplesize works | 470 // production. For now, we'll only verify that samplesize works |
458 // on systems where it already is known to work. | 471 // on systems where it already is known to work. |
459 REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight, | 472 REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight, |
460 opts.fSampleSize)); | 473 opts.fSampleSize)); |
461 REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth, | 474 REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth, |
462 opts.fSampleSize)); | 475 opts.fSampleSize)); |
463 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX | 476 #endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX |
464 SkAutoLockPixels alp(bm); | 477 SkAutoLockPixels alp(bm); |
465 if (bm.getPixels() == NULL) { | 478 if (bm.getPixels() == NULL) { |
466 reporter->reportFailed(SkStringPrintf( | 479 ERRORF(reporter, "Pixel decode failed [sampleSize=%d dither=%s " |
467 "Pixel decode failed " | 480 "colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage), |
468 "[sampleSize=%d dither=%s colorType=%s %s] %s:%d", | 481 options_colorType(opts), path.c_str()); |
469 opts.fSampleSize, (opts.fDitherImage ? "yes" : "no"), | |
470 (opts.fUseRequestedColorType | |
471 ? SkColorType_to_string(opts.fRequestedColorType) : "(none)"), | |
472 path.c_str(), __FILE__, __LINE__)); | |
473 return; | 482 return; |
474 } | 483 } |
475 | 484 |
476 SkBitmap::Config requestedConfig | 485 SkBitmap::Config requestedConfig |
477 = SkColorTypeToBitmapConfig(opts.fRequestedColorType); | 486 = SkColorTypeToBitmapConfig(opts.fRequestedColorType); |
478 REPORTER_ASSERT(reporter, | 487 REPORTER_ASSERT(reporter, |
479 (!opts.fUseRequestedColorType) | 488 (!opts.fUseRequestedColorType) |
480 || (bm.config() == requestedConfig)); | 489 || (bm.config() == requestedConfig)); |
481 | 490 |
482 // Condition under which we should check the decoding results: | 491 // Condition under which we should check the decoding results: |
483 if ((SkBitmap::kARGB_8888_Config == bm.config()) | 492 if ((SkBitmap::kARGB_8888_Config == bm.config()) |
484 && (!path.endsWith(".jpg")) // lossy | 493 && (!path.endsWith(".jpg")) // lossy |
485 && (opts.fSampleSize == 1)) { // scaled | 494 && (opts.fSampleSize == 1)) { // scaled |
486 const SkColor* correctPixels = kExpectedPixels; | 495 const SkColor* correctPixels = kExpectedPixels; |
487 SkASSERT(bm.height() == kExpectedHeight); | 496 SkASSERT(bm.height() == kExpectedHeight); |
488 SkASSERT(bm.width() == kExpectedWidth); | 497 SkASSERT(bm.width() == kExpectedWidth); |
489 int pixelErrors = 0; | 498 int pixelErrors = 0; |
490 for (int y = 0; y < bm.height(); ++y) { | 499 for (int y = 0; y < bm.height(); ++y) { |
491 for (int x = 0; x < bm.width(); ++x) { | 500 for (int x = 0; x < bm.width(); ++x) { |
492 if (*correctPixels != bm.getColor(x, y)) { | 501 if (*correctPixels != bm.getColor(x, y)) { |
493 ++pixelErrors; | 502 ++pixelErrors; |
494 } | 503 } |
495 ++correctPixels; | 504 ++correctPixels; |
496 } | 505 } |
497 } | 506 } |
498 if (pixelErrors != 0) { | 507 if (pixelErrors != 0) { |
499 reporter->reportFailed(SkStringPrintf( | 508 ERRORF(reporter, "Pixel-level mismatch (%d of %d) " |
500 "Pixel-level mismatch (%d of %d) [sampleSize=%d " | 509 "[sampleSize=%d dither=%s colorType=%s %s]", |
501 "dither=%s colorType=%s %s] %s:%d", | 510 pixelErrors, kExpectedHeight * kExpectedWidth, |
502 pixelErrors, kExpectedHeight * kExpectedWidth, | 511 opts.fSampleSize, yn(opts.fDitherImage), |
503 opts.fSampleSize, (opts.fDitherImage ? "yes" : "no"), | 512 options_colorType(opts), path.c_str()); |
504 (opts.fUseRequestedColorType | |
505 ? SkColorType_to_string(opts.fRequestedColorType) | |
506 : "(none)"), path.c_str(), __FILE__, __LINE__)); | |
507 } | 513 } |
508 } | 514 } |
509 } | 515 } |
510 | 516 |
511 /** | 517 /** |
512 * SkDecodingImageGenerator has an Options struct which lets the | 518 * SkDecodingImageGenerator has an Options struct which lets the |
513 * client of the generator set sample size, dithering, and bitmap | 519 * client of the generator set sample size, dithering, and bitmap |
514 * config. This test loops through many possible options and tries | 520 * config. This test loops through many possible options and tries |
515 * them on a set of 5 small encoded images (each in a different | 521 * them on a set of 5 small encoded images (each in a different |
516 * format). We test both SkData and SkStreamRewindable decoding. | 522 * format). We test both SkData and SkStreamRewindable decoding. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 SkDecodingImageGenerator::Options options(scaleList[i], | 577 SkDecodingImageGenerator::Options options(scaleList[i], |
572 ditherList[j]); | 578 ditherList[j]); |
573 test_options(reporter, options, encodedStream, encodedData, | 579 test_options(reporter, options, encodedStream, encodedData, |
574 useDataList[m], path); | 580 useDataList[m], path); |
575 } | 581 } |
576 } | 582 } |
577 } | 583 } |
578 } | 584 } |
579 } | 585 } |
580 //////////////////////////////////////////////////////////////////////////////// | 586 //////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |