OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "Resources.h" | 8 #include "Resources.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // Decodes an embedded BMP image | 97 // Decodes an embedded BMP image |
98 check(r, "color_wheel.ico", SkISize::Make(128, 128), false); | 98 check(r, "color_wheel.ico", SkISize::Make(128, 128), false); |
99 // Decodes an embedded PNG image | 99 // Decodes an embedded PNG image |
100 check(r, "google_chrome.ico", SkISize::Make(256, 256), false); | 100 check(r, "google_chrome.ico", SkISize::Make(256, 256), false); |
101 | 101 |
102 // GIF | 102 // GIF |
103 check(r, "box.gif", SkISize::Make(200, 55), false); | 103 check(r, "box.gif", SkISize::Make(200, 55), false); |
104 check(r, "color_wheel.gif", SkISize::Make(128, 128), false); | 104 check(r, "color_wheel.gif", SkISize::Make(128, 128), false); |
105 check(r, "randPixels.gif", SkISize::Make(8, 8), false); | 105 check(r, "randPixels.gif", SkISize::Make(8, 8), false); |
106 | 106 |
| 107 // JPG |
| 108 check(r, "CMYK.jpg", SkISize::Make(642, 516), false); |
| 109 check(r, "color_wheel.jpg", SkISize::Make(128, 128), false); |
| 110 check(r, "grayscale.jpg", SkISize::Make(128, 128), false); |
| 111 check(r, "mandrill_512_q075.jpg", SkISize::Make(512, 512), false); |
| 112 check(r, "randPixels.jpg", SkISize::Make(8, 8), false); |
| 113 |
107 // PNG | 114 // PNG |
108 check(r, "arrow.png", SkISize::Make(187, 312), true); | 115 check(r, "arrow.png", SkISize::Make(187, 312), true); |
109 check(r, "baby_tux.png", SkISize::Make(240, 246), true); | 116 check(r, "baby_tux.png", SkISize::Make(240, 246), true); |
110 check(r, "color_wheel.png", SkISize::Make(128, 128), true); | 117 check(r, "color_wheel.png", SkISize::Make(128, 128), true); |
111 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), true); | 118 check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), true); |
112 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); | 119 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); |
113 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); | 120 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); |
114 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); | 121 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); |
115 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); | 122 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); |
116 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); | 123 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); |
(...skipping 24 matching lines...) Expand all Loading... |
141 const char emptyGif[] = "GIFVER"; | 148 const char emptyGif[] = "GIFVER"; |
142 | 149 |
143 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream)); | 150 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream)); |
144 test_invalid_stream(r, emptyPng, sizeof(emptyPng)); | 151 test_invalid_stream(r, emptyPng, sizeof(emptyPng)); |
145 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg)); | 152 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg)); |
146 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp)); | 153 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp)); |
147 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp)); | 154 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp)); |
148 test_invalid_stream(r, emptyIco, sizeof(emptyIco)); | 155 test_invalid_stream(r, emptyIco, sizeof(emptyIco)); |
149 test_invalid_stream(r, emptyGif, sizeof(emptyGif)); | 156 test_invalid_stream(r, emptyGif, sizeof(emptyGif)); |
150 } | 157 } |
| 158 |
| 159 static void test_dimensions(skiatest::Reporter* r, const char path[]) { |
| 160 // Create the codec from the resource file |
| 161 SkAutoTDelete<SkStream> stream(resource(path)); |
| 162 if (!stream) { |
| 163 SkDebugf("Missing resource '%s'\n", path); |
| 164 return; |
| 165 } |
| 166 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
| 167 if (!codec) { |
| 168 ERRORF(r, "Unable to create codec '%s'", path); |
| 169 return; |
| 170 } |
| 171 |
| 172 // Check that the decode is successful for a variety of scales |
| 173 for (float scale = -0.05f; scale < 2.0f; scale += 0.05f) { |
| 174 // Scale the output dimensions |
| 175 SkISize scaledDims = codec->getScaledDimensions(scale); |
| 176 SkImageInfo scaledInfo = codec->getInfo().makeWH(scaledDims.width(), sca
ledDims.height()); |
| 177 |
| 178 // Set up for the decode |
| 179 size_t rowBytes = scaledDims.width() * sizeof(SkPMColor); |
| 180 size_t totalBytes = scaledInfo.getSafeSize(rowBytes); |
| 181 SkAutoTMalloc<SkPMColor> pixels(totalBytes); |
| 182 |
| 183 SkImageGenerator::Result result = |
| 184 codec->getPixels(scaledInfo, pixels.get(), rowBytes, NULL, NULL,
NULL); |
| 185 REPORTER_ASSERT(r, SkImageGenerator::kSuccess == result); |
| 186 } |
| 187 } |
| 188 |
| 189 // Ensure that onGetScaledDimensions returns valid image dimensions to use for d
ecodes |
| 190 DEF_TEST(Codec_Dimensions, r) { |
| 191 // JPG |
| 192 test_dimensions(r, "CMYK.jpg"); |
| 193 test_dimensions(r, "color_wheel.jpg"); |
| 194 test_dimensions(r, "grayscale.jpg"); |
| 195 test_dimensions(r, "mandrill_512_q075.jpg"); |
| 196 test_dimensions(r, "randPixels.jpg"); |
| 197 } |
| 198 |
| 199 |
| 200 |
OLD | NEW |