Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(426)

Side by Side Diff: tests/JpegTest.cpp

Issue 1340803002: discardable pixelrefs are gone, update tests accordingly (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/ImageTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « tests/ImageTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698