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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkCodec.h" |
9 #include "SkDecodingImageGenerator.h" | 10 #include "SkDecodingImageGenerator.h" |
10 #include "SkForceLinking.h" | 11 #include "SkForceLinking.h" |
11 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
12 #include "SkPixelRef.h" | 13 #include "SkPixelRef.h" |
| 14 #include "Resources.h" |
13 #include "SkStream.h" | 15 #include "SkStream.h" |
14 #include "SkTemplates.h" | 16 #include "SkTemplates.h" |
15 #include "Test.h" | 17 #include "Test.h" |
16 | 18 |
17 __SK_FORCE_IMAGE_DECODER_LINKING; | 19 __SK_FORCE_IMAGE_DECODER_LINKING; |
18 | 20 |
19 #define JPEG_TEST_WRITE_TO_FILE_FOR_DEBUGGING 0 // do not do this for | 21 #define JPEG_TEST_WRITE_TO_FILE_FOR_DEBUGGING 0 // do not do this for |
20 // normal unit testing. | 22 // normal unit testing. |
21 static unsigned char goodJpegImage[] = { | 23 static unsigned char goodJpegImage[] = { |
22 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, | 24 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 486 } |
485 SkAutoMalloc storage(totalSize); | 487 SkAutoMalloc storage(totalSize); |
486 void* planes[3]; | 488 void* planes[3]; |
487 planes[0] = storage.get(); | 489 planes[0] = storage.get(); |
488 planes[1] = (uint8_t*)planes[0] + sizes[0]; | 490 planes[1] = (uint8_t*)planes[0] + sizes[0]; |
489 planes[2] = (uint8_t*)planes[1] + sizes[1]; | 491 planes[2] = (uint8_t*)planes[1] + sizes[1]; |
490 | 492 |
491 // Get the YUV planes | 493 // Get the YUV planes |
492 REPORTER_ASSERT(reporter, gen->getYUV8Planes(yuvSizes, planes, rowBytes, nul
lptr)); | 494 REPORTER_ASSERT(reporter, gen->getYUV8Planes(yuvSizes, planes, rowBytes, nul
lptr)); |
493 } | 495 } |
| 496 |
| 497 static SkStreamAsset* resource(const char path[]) { |
| 498 SkString fullPath = GetResourcePath(path); |
| 499 return SkStream::NewFromFile(fullPath.c_str()); |
| 500 } |
| 501 |
| 502 static void codec_yuv(skiatest::Reporter* reporter, |
| 503 const char path[], |
| 504 SkISize expectedSizes[3]) { |
| 505 SkAutoTDelete<SkStream> stream(resource(path)); |
| 506 if (!stream) { |
| 507 SkDebugf("Missing resource '%s'\n", path); |
| 508 return; |
| 509 } |
| 510 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
| 511 REPORTER_ASSERT(reporter, codec); |
| 512 if (!codec) { |
| 513 return; |
| 514 } |
| 515 |
| 516 // Test queryYUV8() |
| 517 SkCodec::YUVSizeInfo info; |
| 518 bool success = codec->queryYUV8(nullptr, nullptr); |
| 519 REPORTER_ASSERT(reporter, !success); |
| 520 success = codec->queryYUV8(&info, nullptr); |
| 521 REPORTER_ASSERT(reporter, (expectedSizes == nullptr) == !success); |
| 522 if (!success) { |
| 523 return; |
| 524 } |
| 525 REPORTER_ASSERT(reporter, |
| 526 0 == memcmp((const void*) &info, (const void*) expectedSizes, 3 * si
zeof(SkISize))); |
| 527 REPORTER_ASSERT(reporter, info.fYWidthBytes == (uint32_t) SkAlign8(info.fYSi
ze.width())); |
| 528 REPORTER_ASSERT(reporter, info.fUWidthBytes == (uint32_t) SkAlign8(info.fUSi
ze.width())); |
| 529 REPORTER_ASSERT(reporter, info.fVWidthBytes == (uint32_t) SkAlign8(info.fVSi
ze.width())); |
| 530 SkYUVColorSpace colorSpace; |
| 531 success = codec->queryYUV8(&info, &colorSpace); |
| 532 REPORTER_ASSERT(reporter, |
| 533 0 == memcmp((const void*) &info, (const void*) expectedSizes, 3 * si
zeof(SkISize))); |
| 534 REPORTER_ASSERT(reporter, info.fYWidthBytes == (uint32_t) SkAlign8(info.fYSi
ze.width())); |
| 535 REPORTER_ASSERT(reporter, info.fUWidthBytes == (uint32_t) SkAlign8(info.fUSi
ze.width())); |
| 536 REPORTER_ASSERT(reporter, info.fVWidthBytes == (uint32_t) SkAlign8(info.fVSi
ze.width())); |
| 537 REPORTER_ASSERT(reporter, kJPEG_SkYUVColorSpace == colorSpace); |
| 538 |
| 539 // Allocate the memory for the YUV decode |
| 540 size_t totalBytes = info.fYWidthBytes * info.fYSize.height() + |
| 541 info.fUWidthBytes * info.fUSize.height() + |
| 542 info.fVWidthBytes * info.fVSize.height(); |
| 543 SkAutoMalloc storage(totalBytes); |
| 544 void* planes[3]; |
| 545 planes[0] = storage.get(); |
| 546 planes[1] = SkTAddOffset<void>(planes[0], info.fYWidthBytes * info.fYSize.he
ight()); |
| 547 planes[2] = SkTAddOffset<void>(planes[1], info.fUWidthBytes * info.fUSize.he
ight()); |
| 548 |
| 549 // Test getYUV8Planes() |
| 550 REPORTER_ASSERT(reporter, SkCodec::kInvalidInput == |
| 551 codec->getYUV8Planes(info, nullptr)); |
| 552 REPORTER_ASSERT(reporter, SkCodec::kSuccess == |
| 553 codec->getYUV8Planes(info, planes)); |
| 554 } |
| 555 |
| 556 DEF_TEST(Jpeg_YUV_Codec, r) { |
| 557 SkISize sizes[3]; |
| 558 |
| 559 sizes[0].set(128, 128); |
| 560 sizes[1].set(64, 64); |
| 561 sizes[2].set(64, 64); |
| 562 codec_yuv(r, "color_wheel.jpg", sizes); |
| 563 |
| 564 // H2V2 |
| 565 sizes[0].set(512, 512); |
| 566 sizes[1].set(256, 256); |
| 567 sizes[2].set(256, 256); |
| 568 codec_yuv(r, "mandrill_512_q075.jpg", sizes); |
| 569 |
| 570 // H1V1 |
| 571 sizes[1].set(512, 512); |
| 572 sizes[2].set(512, 512); |
| 573 codec_yuv(r, "mandrill_h1v1.jpg", sizes); |
| 574 |
| 575 // H2V1 |
| 576 sizes[1].set(256, 512); |
| 577 sizes[2].set(256, 512); |
| 578 codec_yuv(r, "mandrill_h2v1.jpg", sizes); |
| 579 |
| 580 // Non-power of two dimensions |
| 581 sizes[0].set(439, 154); |
| 582 sizes[1].set(220, 77); |
| 583 sizes[2].set(220, 77); |
| 584 codec_yuv(r, "cropped_mandrill.jpg", sizes); |
| 585 |
| 586 sizes[0].set(8, 8); |
| 587 sizes[1].set(4, 4); |
| 588 sizes[2].set(4, 4); |
| 589 codec_yuv(r, "randPixels.jpg", sizes); |
| 590 |
| 591 // Progressive images |
| 592 sizes[0].set(512, 512); |
| 593 sizes[1].set(512, 512); |
| 594 sizes[2].set(512, 512); |
| 595 codec_yuv(r, "brickwork-texture.jpg", sizes); |
| 596 codec_yuv(r, "brickwork_normal-map.jpg", sizes); |
| 597 |
| 598 // A CMYK encoded image should fail. |
| 599 codec_yuv(r, "CMYK.jpg", nullptr); |
| 600 // A grayscale encoded image should fail. |
| 601 codec_yuv(r, "grayscale.jpg", nullptr); |
| 602 // A PNG should fail. |
| 603 codec_yuv(r, "arrow.png", nullptr); |
| 604 } |
OLD | NEW |