| 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 "SkDecodingImageGenerator.h" |
| 10 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 // Check to see that the resulting bitmap is nice | 450 // Check to see that the resulting bitmap is nice |
| 451 bool writeSuccess = (!(bm8888.empty())) && SkImageEncoder::EncodeFile( | 451 bool writeSuccess = (!(bm8888.empty())) && SkImageEncoder::EncodeFile( |
| 452 "HalfOfAJpeg.png", bm8888, SkImageEncoder::kPNG_Type, 100); | 452 "HalfOfAJpeg.png", bm8888, SkImageEncoder::kPNG_Type, 100); |
| 453 SkASSERT(writeSuccess); | 453 SkASSERT(writeSuccess); |
| 454 #endif | 454 #endif |
| 455 } | 455 } |
| 456 | 456 |
| 457 DEF_TEST(Jpeg_YUV, reporter) { | 457 DEF_TEST(Jpeg_YUV, reporter) { |
| 458 size_t len = sizeof(goodJpegImage); | 458 size_t len = sizeof(goodJpegImage); |
| 459 SkMemoryStream* stream = new SkMemoryStream(goodJpegImage, len); | 459 SkMemoryStream* stream = new SkMemoryStream(goodJpegImage, len); |
| 460 | |
| 461 SkBitmap bitmap; | |
| 462 SkDecodingImageGenerator::Options opts; | 460 SkDecodingImageGenerator::Options opts; |
| 463 bool pixelsInstalled = SkInstallDiscardablePixelRef( | 461 SkAutoTDelete<SkImageGenerator> gen(SkDecodingImageGenerator::Create(stream,
opts)); |
| 464 SkDecodingImageGenerator::Create(stream, opts), &bitmap); | 462 REPORTER_ASSERT(reporter, gen); |
| 465 REPORTER_ASSERT(reporter, pixelsInstalled); | 463 if (!gen) { |
| 466 | |
| 467 if (!pixelsInstalled) { | |
| 468 return; | 464 return; |
| 469 } | 465 } |
| 470 | 466 |
| 471 SkPixelRef* pixelRef = bitmap.pixelRef(); | |
| 472 SkISize yuvSizes[3]; | 467 SkISize yuvSizes[3]; |
| 473 bool sizesComputed = (nullptr != pixelRef) && pixelRef->getYUV8Planes(yuvSiz
es, nullptr, nullptr, nullptr); | 468 bool sizesComputed = gen->getYUV8Planes(yuvSizes, nullptr, nullptr, nullptr)
; |
| 474 REPORTER_ASSERT(reporter, sizesComputed); | 469 REPORTER_ASSERT(reporter, sizesComputed); |
| 475 | |
| 476 if (!sizesComputed) { | 470 if (!sizesComputed) { |
| 477 return; | 471 return; |
| 478 } | 472 } |
| 479 | 473 |
| 480 // Allocate the memory for YUV | 474 // Allocate the memory for YUV |
| 481 size_t totalSize(0); | 475 size_t totalSize(0); |
| 482 size_t sizes[3], rowBytes[3]; | 476 size_t sizes[3], rowBytes[3]; |
| 483 const int32_t expected_sizes[] = {128, 64, 64}; | 477 const int32_t expected_sizes[] = {128, 64, 64}; |
| 484 for (int i = 0; i < 3; ++i) { | 478 for (int i = 0; i < 3; ++i) { |
| 485 rowBytes[i] = yuvSizes[i].fWidth; | 479 rowBytes[i] = yuvSizes[i].fWidth; |
| 486 totalSize += sizes[i] = rowBytes[i] * yuvSizes[i].fHeight; | 480 totalSize += sizes[i] = rowBytes[i] * yuvSizes[i].fHeight; |
| 487 REPORTER_ASSERT(reporter, rowBytes[i] == (size_t)expected_sizes[
i]); | 481 REPORTER_ASSERT(reporter, rowBytes[i] == (size_t)expected_sizes[
i]); |
| 488 REPORTER_ASSERT(reporter, yuvSizes[i].fWidth == expected_sizes[i]); | 482 REPORTER_ASSERT(reporter, yuvSizes[i].fWidth == expected_sizes[i]); |
| 489 REPORTER_ASSERT(reporter, yuvSizes[i].fHeight == expected_sizes[i]); | 483 REPORTER_ASSERT(reporter, yuvSizes[i].fHeight == expected_sizes[i]); |
| 490 } | 484 } |
| 491 SkAutoMalloc storage(totalSize); | 485 SkAutoMalloc storage(totalSize); |
| 492 void* planes[3]; | 486 void* planes[3]; |
| 493 planes[0] = storage.get(); | 487 planes[0] = storage.get(); |
| 494 planes[1] = (uint8_t*)planes[0] + sizes[0]; | 488 planes[1] = (uint8_t*)planes[0] + sizes[0]; |
| 495 planes[2] = (uint8_t*)planes[1] + sizes[1]; | 489 planes[2] = (uint8_t*)planes[1] + sizes[1]; |
| 496 | 490 |
| 497 // Get the YUV planes | 491 // Get the YUV planes |
| 498 REPORTER_ASSERT(reporter, pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes
, nullptr)); | 492 REPORTER_ASSERT(reporter, gen->getYUV8Planes(yuvSizes, planes, rowBytes, nul
lptr)); |
| 499 } | 493 } |
| OLD | NEW |