| 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 "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "Resources.h" | 9 #include "Resources.h" |
| 10 #include "SkStream.h" | 10 #include "SkStream.h" |
| 11 #include "SkTemplates.h" | 11 #include "SkTemplates.h" |
| 12 #include "SkYUVSizeInfo.h" | |
| 13 #include "Test.h" | 12 #include "Test.h" |
| 14 | 13 |
| 15 static SkStreamAsset* resource(const char path[]) { | 14 static SkStreamAsset* resource(const char path[]) { |
| 16 SkString fullPath = GetResourcePath(path); | 15 SkString fullPath = GetResourcePath(path); |
| 17 return SkStream::NewFromFile(fullPath.c_str()); | 16 return SkStream::NewFromFile(fullPath.c_str()); |
| 18 } | 17 } |
| 19 | 18 |
| 20 static void codec_yuv(skiatest::Reporter* reporter, | 19 static void codec_yuv(skiatest::Reporter* reporter, |
| 21 const char path[], | 20 const char path[], |
| 22 SkISize expectedSizes[3]) { | 21 SkISize expectedSizes[3]) { |
| 23 SkAutoTDelete<SkStream> stream(resource(path)); | 22 SkAutoTDelete<SkStream> stream(resource(path)); |
| 24 if (!stream) { | 23 if (!stream) { |
| 25 INFOF(reporter, "Missing resource '%s'\n", path); | 24 INFOF(reporter, "Missing resource '%s'\n", path); |
| 26 return; | 25 return; |
| 27 } | 26 } |
| 28 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); | 27 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
| 29 REPORTER_ASSERT(reporter, codec); | 28 REPORTER_ASSERT(reporter, codec); |
| 30 if (!codec) { | 29 if (!codec) { |
| 31 return; | 30 return; |
| 32 } | 31 } |
| 33 | 32 |
| 34 // Test queryYUV8() | 33 // Test queryYUV8() |
| 35 SkYUVSizeInfo info; | 34 SkCodec::YUVSizeInfo info; |
| 36 bool success = codec->queryYUV8(nullptr, nullptr); | 35 bool success = codec->queryYUV8(nullptr, nullptr); |
| 37 REPORTER_ASSERT(reporter, !success); | 36 REPORTER_ASSERT(reporter, !success); |
| 38 success = codec->queryYUV8(&info, nullptr); | 37 success = codec->queryYUV8(&info, nullptr); |
| 39 REPORTER_ASSERT(reporter, (expectedSizes == nullptr) == !success); | 38 REPORTER_ASSERT(reporter, (expectedSizes == nullptr) == !success); |
| 40 if (!success) { | 39 if (!success) { |
| 41 return; | 40 return; |
| 42 } | 41 } |
| 43 REPORTER_ASSERT(reporter, | 42 REPORTER_ASSERT(reporter, |
| 44 0 == memcmp((const void*) &info, (const void*) expectedSizes, 3 * si
zeof(SkISize))); | 43 0 == memcmp((const void*) &info, (const void*) expectedSizes, 3 * si
zeof(SkISize))); |
| 45 REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kY] == | 44 REPORTER_ASSERT(reporter, info.fYWidthBytes == (uint32_t) SkAlign8(info.fYSi
ze.width())); |
| 46 (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kY].width())); | 45 REPORTER_ASSERT(reporter, info.fUWidthBytes == (uint32_t) SkAlign8(info.fUSi
ze.width())); |
| 47 REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kU] == | 46 REPORTER_ASSERT(reporter, info.fVWidthBytes == (uint32_t) SkAlign8(info.fVSi
ze.width())); |
| 48 (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kU].width())); | |
| 49 REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kV] == | |
| 50 (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kV].width())); | |
| 51 SkYUVColorSpace colorSpace; | 47 SkYUVColorSpace colorSpace; |
| 52 success = codec->queryYUV8(&info, &colorSpace); | 48 success = codec->queryYUV8(&info, &colorSpace); |
| 53 REPORTER_ASSERT(reporter, | 49 REPORTER_ASSERT(reporter, |
| 54 0 == memcmp((const void*) &info, (const void*) expectedSizes, 3 * si
zeof(SkISize))); | 50 0 == memcmp((const void*) &info, (const void*) expectedSizes, 3 * si
zeof(SkISize))); |
| 55 REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kY] == | 51 REPORTER_ASSERT(reporter, info.fYWidthBytes == (uint32_t) SkAlign8(info.fYSi
ze.width())); |
| 56 (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kY].width())); | 52 REPORTER_ASSERT(reporter, info.fUWidthBytes == (uint32_t) SkAlign8(info.fUSi
ze.width())); |
| 57 REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kU] == | 53 REPORTER_ASSERT(reporter, info.fVWidthBytes == (uint32_t) SkAlign8(info.fVSi
ze.width())); |
| 58 (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kU].width())); | |
| 59 REPORTER_ASSERT(reporter, info.fWidthBytes[SkYUVSizeInfo::kV] == | |
| 60 (uint32_t) SkAlign8(info.fSizes[SkYUVSizeInfo::kV].width())); | |
| 61 REPORTER_ASSERT(reporter, kJPEG_SkYUVColorSpace == colorSpace); | 54 REPORTER_ASSERT(reporter, kJPEG_SkYUVColorSpace == colorSpace); |
| 62 | 55 |
| 63 // Allocate the memory for the YUV decode | 56 // Allocate the memory for the YUV decode |
| 64 size_t totalBytes = | 57 size_t totalBytes = info.fYWidthBytes * info.fYSize.height() + |
| 65 info.fWidthBytes[SkYUVSizeInfo::kY] * info.fSizes[SkYUVSizeInfo::kY]
.height() + | 58 info.fUWidthBytes * info.fUSize.height() + |
| 66 info.fWidthBytes[SkYUVSizeInfo::kU] * info.fSizes[SkYUVSizeInfo::kU]
.height() + | 59 info.fVWidthBytes * info.fVSize.height(); |
| 67 info.fWidthBytes[SkYUVSizeInfo::kV] * info.fSizes[SkYUVSizeInfo::kV]
.height(); | |
| 68 SkAutoMalloc storage(totalBytes); | 60 SkAutoMalloc storage(totalBytes); |
| 69 void* planes[3]; | 61 void* planes[3]; |
| 70 planes[0] = storage.get(); | 62 planes[0] = storage.get(); |
| 71 planes[1] = SkTAddOffset<void>(planes[0], | 63 planes[1] = SkTAddOffset<void>(planes[0], info.fYWidthBytes * info.fYSize.he
ight()); |
| 72 info.fWidthBytes[SkYUVSizeInfo::kY] * info.fSizes[SkYUVSizeInfo::kY]
.height()); | 64 planes[2] = SkTAddOffset<void>(planes[1], info.fUWidthBytes * info.fUSize.he
ight()); |
| 73 planes[2] = SkTAddOffset<void>(planes[1], | |
| 74 info.fWidthBytes[SkYUVSizeInfo::kU] * info.fSizes[SkYUVSizeInfo::kU]
.height()); | |
| 75 | 65 |
| 76 // Test getYUV8Planes() | 66 // Test getYUV8Planes() |
| 77 REPORTER_ASSERT(reporter, SkCodec::kInvalidInput == | 67 REPORTER_ASSERT(reporter, SkCodec::kInvalidInput == |
| 78 codec->getYUV8Planes(info, nullptr)); | 68 codec->getYUV8Planes(info, nullptr)); |
| 79 REPORTER_ASSERT(reporter, SkCodec::kSuccess == | 69 REPORTER_ASSERT(reporter, SkCodec::kSuccess == |
| 80 codec->getYUV8Planes(info, planes)); | 70 codec->getYUV8Planes(info, planes)); |
| 81 } | 71 } |
| 82 | 72 |
| 83 DEF_TEST(Jpeg_YUV_Codec, r) { | 73 DEF_TEST(Jpeg_YUV_Codec, r) { |
| 84 SkISize sizes[3]; | 74 SkISize sizes[3]; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 codec_yuv(r, "brickwork-texture.jpg", sizes); | 112 codec_yuv(r, "brickwork-texture.jpg", sizes); |
| 123 codec_yuv(r, "brickwork_normal-map.jpg", sizes); | 113 codec_yuv(r, "brickwork_normal-map.jpg", sizes); |
| 124 | 114 |
| 125 // A CMYK encoded image should fail. | 115 // A CMYK encoded image should fail. |
| 126 codec_yuv(r, "CMYK.jpg", nullptr); | 116 codec_yuv(r, "CMYK.jpg", nullptr); |
| 127 // A grayscale encoded image should fail. | 117 // A grayscale encoded image should fail. |
| 128 codec_yuv(r, "grayscale.jpg", nullptr); | 118 codec_yuv(r, "grayscale.jpg", nullptr); |
| 129 // A PNG should fail. | 119 // A PNG should fail. |
| 130 codec_yuv(r, "arrow.png", nullptr); | 120 codec_yuv(r, "arrow.png", nullptr); |
| 131 } | 121 } |
| OLD | NEW |