OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 OwnPtr<JPEGImageDecoder> decoder = createDecoder(maxDecodedBytes); | 72 OwnPtr<JPEGImageDecoder> decoder = createDecoder(maxDecodedBytes); |
73 decoder->setData(data.get(), true); | 73 decoder->setData(data.get(), true); |
74 | 74 |
75 ImageFrame* frame = decoder->frameBufferAtIndex(0); | 75 ImageFrame* frame = decoder->frameBufferAtIndex(0); |
76 ASSERT_TRUE(frame); | 76 ASSERT_TRUE(frame); |
77 *outputWidth = frame->getSkBitmap().width(); | 77 *outputWidth = frame->getSkBitmap().width(); |
78 *outputHeight = frame->getSkBitmap().height(); | 78 *outputHeight = frame->getSkBitmap().height(); |
79 EXPECT_EQ(IntSize(*outputWidth, *outputHeight), decoder->decodedSize()); | 79 EXPECT_EQ(IntSize(*outputWidth, *outputHeight), decoder->decodedSize()); |
80 } | 80 } |
81 | 81 |
82 void readYUV(size_t maxDecodedBytes, unsigned* outputYWidth, unsigned* outputYHe ight, unsigned* outputUVWidth, unsigned* outputUVHeight, const char* imageFilePa th) | |
83 { | |
84 RefPtr<SharedBuffer> data = readFile(imageFilePath); | |
85 ASSERT_TRUE(data.get()); | |
86 | |
87 OwnPtr<JPEGImageDecoder> decoder = createDecoder(maxDecodedBytes); | |
88 decoder->setData(data.get(), true); | |
89 | |
90 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes()); | |
91 decoder->setImagePlanes(imagePlanes); | |
92 bool sizeIsAvailable = decoder->isSizeAvailable(); | |
93 ASSERT_TRUE(sizeIsAvailable); | |
94 | |
95 IntSize size = decoder->decodedSize(); | |
96 IntSize ySize = decoder->decodedYUVSize(0); | |
97 IntSize uSize = decoder->decodedYUVSize(1); | |
98 IntSize vSize = decoder->decodedYUVSize(2); | |
99 | |
100 ASSERT_TRUE(size.width() == ySize.width()); | |
101 ASSERT_TRUE(size.height() == ySize.height()); | |
102 ASSERT_TRUE(uSize.width() == vSize.width()); | |
103 ASSERT_TRUE(uSize.height() == vSize.height()); | |
104 | |
105 *outputYWidth = ySize.width(); | |
106 *outputYHeight = ySize.height(); | |
107 *outputUVWidth = uSize.width(); | |
108 *outputUVHeight = uSize.height(); | |
109 } | |
110 | |
82 // Tests failure on a too big image. | 111 // Tests failure on a too big image. |
83 TEST(JPEGImageDecoderTest, tooBig) | 112 TEST(JPEGImageDecoderTest, tooBig) |
84 { | 113 { |
85 OwnPtr<JPEGImageDecoder> decoder = createDecoder(100); | 114 OwnPtr<JPEGImageDecoder> decoder = createDecoder(100); |
86 EXPECT_FALSE(decoder->setSize(10000, 10000)); | 115 EXPECT_FALSE(decoder->setSize(10000, 10000)); |
87 EXPECT_TRUE(decoder->failed()); | 116 EXPECT_TRUE(decoder->failed()); |
88 } | 117 } |
89 | 118 |
90 // Tests that JPEG decoder can downsample image whose width and height are multi ple of 8, | 119 // Tests that JPEG decoder can downsample image whose width and height are multi ple of 8, |
91 // to ensure we compute the correct decodedSize and pass correct parameters to l ibjpeg to | 120 // to ensure we compute the correct decodedSize and pass correct parameters to l ibjpeg to |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 | 205 |
177 // Tests that upsampling is not allowed. | 206 // Tests that upsampling is not allowed. |
178 TEST(JPEGImageDecoderTest, upsample) | 207 TEST(JPEGImageDecoderTest, upsample) |
179 { | 208 { |
180 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256 | 209 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256 |
181 unsigned outputWidth, outputHeight; | 210 unsigned outputWidth, outputHeight; |
182 downsample(1000 * 1000, &outputWidth, &outputHeight, jpegFile); | 211 downsample(1000 * 1000, &outputWidth, &outputHeight, jpegFile); |
183 EXPECT_EQ(256u, outputWidth); | 212 EXPECT_EQ(256u, outputWidth); |
184 EXPECT_EQ(256u, outputHeight); | 213 EXPECT_EQ(256u, outputHeight); |
185 } | 214 } |
215 | |
216 TEST(JPEGImageDecoderTest, yuv) | |
217 { | |
218 const char* jpegFile = "/LayoutTests/fast/images/resources/lenna.jpg"; // 25 6x256, YUV 4:2:0 | |
219 unsigned outputYWidth, outputYHeight, outputUVWidth, outputUVHeight; | |
220 readYUV(1000 * 1000, &outputYWidth, &outputYHeight, &outputUVWidth, &outputU VHeight, jpegFile); | |
Stephen White
2014/07/25 18:25:10
Let's pull that out into a constant at the top-of-
| |
221 EXPECT_EQ(256u, outputYWidth); | |
222 EXPECT_EQ(256u, outputYHeight); | |
223 EXPECT_EQ(128u, outputUVWidth); | |
224 EXPECT_EQ(128u, outputUVHeight); | |
225 } | |
OLD | NEW |