aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar sugoi <sugoi@chromium.org>2014-10-15 11:04:17 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-15 11:04:18 -0700
commit8e6c3b93a39e19111662a760ede97df55e51d39f (patch)
treec063ae61138c6cfd30cf0238eecb2c879d38db4e /tests
parent6251d17dfadbbeba8a7e72affde5cbdbd0c0c95f (diff)
JPEG YUV Decoding
Enabling JPEG YUV Decoding in Skia BUG=skia:3005, skia:1674 Review URL: https://codereview.chromium.org/399683007
Diffstat (limited to 'tests')
-rw-r--r--tests/JpegTest.cpp49
1 files changed, 47 insertions, 2 deletions
diff --git a/tests/JpegTest.cpp b/tests/JpegTest.cpp
index f8784a2d26..8828926ef9 100644
--- a/tests/JpegTest.cpp
+++ b/tests/JpegTest.cpp
@@ -6,11 +6,12 @@
*/
#include "SkBitmap.h"
-#include "SkData.h"
+#include "SkDecodingImageGenerator.h"
#include "SkForceLinking.h"
-#include "SkImage.h"
#include "SkImageDecoder.h"
+#include "SkPixelRef.h"
#include "SkStream.h"
+#include "SkTemplates.h"
#include "Test.h"
__SK_FORCE_IMAGE_DECODER_LINKING;
@@ -452,3 +453,47 @@ DEF_TEST(Jpeg, reporter) {
SkASSERT(writeSuccess);
#endif
}
+
+DEF_TEST(Jpeg_YUV, reporter) {
+ size_t len = sizeof(goodJpegImage);
+ SkMemoryStream* stream = SkNEW_ARGS(SkMemoryStream, (goodJpegImage, len));
+
+ SkBitmap bitmap;
+ SkDecodingImageGenerator::Options opts;
+ bool pixelsInstalled = SkInstallDiscardablePixelRef(
+ SkDecodingImageGenerator::Create(stream, opts), &bitmap);
+ REPORTER_ASSERT(reporter, pixelsInstalled);
+
+ if (!pixelsInstalled) {
+ return;
+ }
+
+ SkPixelRef* pixelRef = bitmap.pixelRef();
+ SkISize yuvSizes[3];
+ bool sizesComputed = (NULL != pixelRef) && pixelRef->getYUV8Planes(yuvSizes, NULL, NULL, NULL);
+ REPORTER_ASSERT(reporter, sizesComputed);
+
+ if (!sizesComputed) {
+ return;
+ }
+
+ // Allocate the memory for YUV
+ size_t totalSize(0);
+ size_t sizes[3], rowBytes[3];
+ const int32_t expected_sizes[] = {128, 64, 64};
+ for (int i = 0; i < 3; ++i) {
+ rowBytes[i] = yuvSizes[i].fWidth;
+ totalSize += sizes[i] = rowBytes[i] * yuvSizes[i].fHeight;
+ REPORTER_ASSERT(reporter, rowBytes[i] == (size_t)expected_sizes[i]);
+ REPORTER_ASSERT(reporter, yuvSizes[i].fWidth == expected_sizes[i]);
+ REPORTER_ASSERT(reporter, yuvSizes[i].fHeight == expected_sizes[i]);
+ }
+ SkAutoMalloc storage(totalSize);
+ void* planes[3];
+ planes[0] = storage.get();
+ planes[1] = (uint8_t*)planes[0] + sizes[0];
+ planes[2] = (uint8_t*)planes[1] + sizes[1];
+
+ // Get the YUV planes
+ REPORTER_ASSERT(reporter, pixelRef->getYUV8Planes(yuvSizes, planes, rowBytes, NULL));
+}