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