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