| 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 "SkDecodingImageGenerator.h" | 9 #include "SkData.h" |
| 10 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
| 11 #include "SkImage.h" |
| 11 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
| 12 #include "SkPixelRef.h" | |
| 13 #include "SkStream.h" | 13 #include "SkStream.h" |
| 14 #include "SkTemplates.h" | |
| 15 #include "Test.h" | 14 #include "Test.h" |
| 16 | 15 |
| 17 __SK_FORCE_IMAGE_DECODER_LINKING; | 16 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 18 | 17 |
| 19 #define JPEG_TEST_WRITE_TO_FILE_FOR_DEBUGGING 0 // do not do this for | 18 #define JPEG_TEST_WRITE_TO_FILE_FOR_DEBUGGING 0 // do not do this for |
| 20 // normal unit testing. | 19 // normal unit testing. |
| 21 static unsigned char goodJpegImage[] = { | 20 static unsigned char goodJpegImage[] = { |
| 22 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, | 21 0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, |
| 23 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, 0x8F, | 22 0x49, 0x46, 0x00, 0x01, 0x01, 0x01, 0x00, 0x8F, |
| 24 0x00, 0x8F, 0x00, 0x00, 0xFF, 0xDB, 0x00, 0x43, | 23 0x00, 0x8F, 0x00, 0x00, 0xFF, 0xDB, 0x00, 0x43, |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 REPORTER_ASSERT(reporter, bm8888.getColor(127, 127) == SK_ColorWHITE); | 445 REPORTER_ASSERT(reporter, bm8888.getColor(127, 127) == SK_ColorWHITE); |
| 447 #endif | 446 #endif |
| 448 | 447 |
| 449 #if JPEG_TEST_WRITE_TO_FILE_FOR_DEBUGGING | 448 #if JPEG_TEST_WRITE_TO_FILE_FOR_DEBUGGING |
| 450 // Check to see that the resulting bitmap is nice | 449 // Check to see that the resulting bitmap is nice |
| 451 bool writeSuccess = (!(bm8888.empty())) && SkImageEncoder::EncodeFile( | 450 bool writeSuccess = (!(bm8888.empty())) && SkImageEncoder::EncodeFile( |
| 452 "HalfOfAJpeg.png", bm8888, SkImageEncoder::kPNG_Type, 100); | 451 "HalfOfAJpeg.png", bm8888, SkImageEncoder::kPNG_Type, 100); |
| 453 SkASSERT(writeSuccess); | 452 SkASSERT(writeSuccess); |
| 454 #endif | 453 #endif |
| 455 } | 454 } |
| 456 | |
| 457 DEF_TEST(Jpeg_YUV, reporter) { | |
| 458 size_t len = sizeof(goodJpegImage); | |
| 459 SkMemoryStream* stream = SkNEW_ARGS(SkMemoryStream, (goodJpegImage, len)); | |
| 460 | |
| 461 SkBitmap bitmap; | |
| 462 SkDecodingImageGenerator::Options opts; | |
| 463 bool pixelsInstalled = SkInstallDiscardablePixelRef( | |
| 464 SkDecodingImageGenerator::Create(stream, opts), &bitmap); | |
| 465 REPORTER_ASSERT(reporter, pixelsInstalled); | |
| 466 | |
| 467 if (!pixelsInstalled) { | |
| 468 return; | |
| 469 } | |
| 470 | |
| 471 SkPixelRef* pixelRef = bitmap.pixelRef(); | |
| 472 SkISize yuvSizes[3]; | |
| 473 bool sizesComputed = (NULL != pixelRef) && pixelRef->getYUV8Planes(yuvSizes,
NULL, NULL, NULL); | |
| 474 REPORTER_ASSERT(reporter, sizesComputed); | |
| 475 | |
| 476 if (!sizesComputed) { | |
| 477 return; | |
| 478 } | |
| 479 | |
| 480 // Allocate the memory for YUV | |
| 481 size_t totalSize(0); | |
| 482 size_t sizes[3], rowBytes[3]; | |
| 483 const int32_t expected_sizes[] = {128, 64, 64}; | |
| 484 for (int i = 0; i < 3; ++i) { | |
| 485 rowBytes[i] = yuvSizes[i].fWidth; | |
| 486 totalSize += sizes[i] = rowBytes[i] * yuvSizes[i].fHeight; | |
| 487 REPORTER_ASSERT(reporter, rowBytes[i] == (size_t)expected_sizes[
i]); | |
| 488 REPORTER_ASSERT(reporter, yuvSizes[i].fWidth == expected_sizes[i]); | |
| 489 REPORTER_ASSERT(reporter, yuvSizes[i].fHeight == expected_sizes[i]); | |
| 490 } | |
| 491 SkAutoMalloc storage(totalSize); | |
| 492 void* planes[3]; | |
| 493 planes[0] = storage.get(); | |
| 494 planes[1] = (uint8_t*)planes[0] + sizes[0]; | |
| 495 planes[2] = (uint8_t*)planes[1] + sizes[1]; | |
| 496 | |
| 497 // Get the YUV planes | |
| 498 REPORTER_ASSERT(reporter, pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes
, NULL)); | |
| 499 } | |
| OLD | NEW |