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 "CrashHandler.h" | 8 #include "CrashHandler.h" |
9 #include "DMJsonWriter.h" | 9 #include "DMJsonWriter.h" |
10 #include "DMSrcSink.h" | 10 #include "DMSrcSink.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } | 219 } |
220 } | 220 } |
221 | 221 |
222 static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorTyp
e dstColorType, | 222 static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorTyp
e dstColorType, |
223 float scale) { | 223 float scale) { |
224 SkString folder; | 224 SkString folder; |
225 switch (mode) { | 225 switch (mode) { |
226 case CodecSrc::kCodec_Mode: | 226 case CodecSrc::kCodec_Mode: |
227 folder.append("codec"); | 227 folder.append("codec"); |
228 break; | 228 break; |
229 case CodecSrc::kScaledCodec_Mode: | |
230 folder.append("scaled_codec"); | |
231 break; | |
232 case CodecSrc::kScanline_Mode: | 229 case CodecSrc::kScanline_Mode: |
233 folder.append("scanline"); | 230 folder.append("scanline"); |
234 break; | 231 break; |
235 case CodecSrc::kScanline_Subset_Mode: | 232 case CodecSrc::kScanline_Subset_Mode: |
236 folder.append("scanline_subset"); | 233 folder.append("scanline_subset"); |
237 break; | 234 break; |
238 case CodecSrc::kStripe_Mode: | 235 case CodecSrc::kStripe_Mode: |
239 folder.append("stripe"); | 236 folder.append("stripe"); |
240 break; | 237 break; |
241 case CodecSrc::kSubset_Mode: | 238 case CodecSrc::kSubset_Mode: |
(...skipping 13 matching lines...) Expand all Loading... |
255 } | 252 } |
256 | 253 |
257 if (1.0f != scale) { | 254 if (1.0f != scale) { |
258 folder.appendf("_%.3f", scale); | 255 folder.appendf("_%.3f", scale); |
259 } | 256 } |
260 | 257 |
261 CodecSrc* src = new CodecSrc(path, mode, dstColorType, scale); | 258 CodecSrc* src = new CodecSrc(path, mode, dstColorType, scale); |
262 push_src("image", folder, src); | 259 push_src("image", folder, src); |
263 } | 260 } |
264 | 261 |
| 262 static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode, |
| 263 CodecSrc::DstColorType dstColorType, int sampleSize) { |
| 264 SkString folder; |
| 265 switch (mode) { |
| 266 case AndroidCodecSrc::kFullImage_Mode: |
| 267 folder.append("scaled_codec"); |
| 268 break; |
| 269 case AndroidCodecSrc::kDivisor_Mode: |
| 270 folder.append("scaled_codec_divisor"); |
| 271 break; |
| 272 } |
| 273 |
| 274 switch (dstColorType) { |
| 275 case CodecSrc::kGrayscale_Always_DstColorType: |
| 276 folder.append("_kGray8"); |
| 277 break; |
| 278 case CodecSrc::kIndex8_Always_DstColorType: |
| 279 folder.append("_kIndex8"); |
| 280 break; |
| 281 default: |
| 282 break; |
| 283 } |
| 284 |
| 285 if (1 != sampleSize) { |
| 286 folder.appendf("_%.3f", get_scale_from_sample_size(sampleSize)); |
| 287 } |
| 288 |
| 289 AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, sampleS
ize); |
| 290 push_src("image", folder, src); |
| 291 } |
| 292 |
265 static void push_codec_srcs(Path path) { | 293 static void push_codec_srcs(Path path) { |
266 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | 294 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
267 if (!encoded) { | 295 if (!encoded) { |
268 SkDebugf("Couldn't read %s.", path.c_str()); | 296 SkDebugf("Couldn't read %s.", path.c_str()); |
269 return; | 297 return; |
270 } | 298 } |
271 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 299 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
272 if (nullptr == codec.get()) { | 300 if (nullptr == codec.get()) { |
273 SkDebugf("Couldn't create codec for %s.", path.c_str()); | 301 SkDebugf("Couldn't create codec for %s.", path.c_str()); |
274 return; | 302 return; |
275 } | 303 } |
276 | 304 |
277 // Native Scales | 305 // Native Scales |
278 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to co
mpare with these | 306 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to co
mpare with these |
279 // tests. SkImageDecoder supports downscales by integer fac
tors. | 307 // tests. SkImageDecoder supports downscales by integer fac
tors. |
280 // SkJpegCodec natively supports scaling to: 0.125, 0.25, 0.375, 0.5, 0.625,
0.75, 0.875 | 308 // SkJpegCodec natively supports scaling to: 0.125, 0.25, 0.375, 0.5, 0.625,
0.75, 0.875 |
281 const float nativeScales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f,
0.875f, 1.0f }; | 309 const float nativeScales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f,
0.875f, 1.0f }; |
282 | 310 |
283 const CodecSrc::Mode nativeModes[] = { CodecSrc::kCodec_Mode, CodecSrc::kSca
nline_Mode, | 311 const CodecSrc::Mode nativeModes[] = { CodecSrc::kCodec_Mode, CodecSrc::kSca
nline_Mode, |
284 CodecSrc::kScanline_Subset_Mode, CodecSrc::kStripe_Mode, CodecSrc::k
Subset_Mode }; | 312 CodecSrc::kScanline_Subset_Mode, CodecSrc::kStripe_Mode, CodecSrc::k
Subset_Mode }; |
285 | 313 |
286 CodecSrc::DstColorType colorTypes[3]; | 314 CodecSrc::DstColorType colorTypes[3]; |
287 uint32_t numColorTypes; | 315 uint32_t numColorTypes; |
288 switch (codec->getInfo().colorType()) { | 316 switch (codec->getInfo().colorType()) { |
289 case kGray_8_SkColorType: | 317 case kGray_8_SkColorType: |
290 // FIXME: Is this a long term solution for testing wbmps decodes to
kIndex8? | 318 // FIXME: Is this a long term solution for testing wbmps decodes to
kIndex8? |
291 // Further discussion on this topic is at skbug.com/3683 | 319 // Further discussion on this topic is at skbug.com/3683. |
| 320 // This causes us to try to convert grayscale jpegs to kIndex8. We
currently |
| 321 // fail non-fatally in this case. |
292 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; | 322 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; |
293 colorTypes[1] = CodecSrc::kGrayscale_Always_DstColorType; | 323 colorTypes[1] = CodecSrc::kGrayscale_Always_DstColorType; |
294 colorTypes[2] = CodecSrc::kIndex8_Always_DstColorType; | 324 colorTypes[2] = CodecSrc::kIndex8_Always_DstColorType; |
295 numColorTypes = 3; | 325 numColorTypes = 3; |
296 break; | 326 break; |
297 case kIndex_8_SkColorType: | 327 case kIndex_8_SkColorType: |
298 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; | 328 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; |
299 colorTypes[1] = CodecSrc::kIndex8_Always_DstColorType; | 329 colorTypes[1] = CodecSrc::kIndex8_Always_DstColorType; |
300 numColorTypes = 2; | 330 numColorTypes = 2; |
301 break; | 331 break; |
302 default: | 332 default: |
303 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; | 333 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType; |
304 numColorTypes = 1; | 334 numColorTypes = 1; |
305 break; | 335 break; |
306 } | 336 } |
307 | 337 |
308 for (float scale : nativeScales) { | 338 for (float scale : nativeScales) { |
309 for (CodecSrc::Mode mode : nativeModes) { | 339 for (CodecSrc::Mode mode : nativeModes) { |
310 for (uint32_t i = 0; i < numColorTypes; i++) { | 340 for (uint32_t i = 0; i < numColorTypes; i++) { |
311 push_codec_src(path, mode, colorTypes[i], scale); | 341 push_codec_src(path, mode, colorTypes[i], scale); |
312 } | 342 } |
313 } | 343 } |
314 } | 344 } |
315 | 345 |
316 if (path.endsWith(".ico") || path.endsWith(".ICO")) { | 346 // skbug.com/4428 |
317 // FIXME: skbug.com/4404: ICO does not have the ability to decode scanli
nes, so we cannot | 347 static const char* const exts[] = { |
318 // use SkScaledCodec with it. | 348 "jpg", "jpeg", "png", "webp", |
| 349 "JPG", "JPEG", "PNG", "WEBP", |
| 350 }; |
| 351 bool supported = false; |
| 352 for (const char* ext : exts) { |
| 353 if (path.endsWith(ext)) { |
| 354 supported = true; |
| 355 break; |
| 356 } |
| 357 } |
| 358 if (!supported) { |
319 return; | 359 return; |
320 } | 360 } |
321 | 361 |
322 // SkScaledCodec Scales | 362 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
323 // The native scales are included to make sure that SkScaledCodec defaults t
o the native | |
324 // scaling strategy when possible. | |
325 // 0.1, 0.16, 0.2 etc allow us to test SkScaledCodec with sampleSize 10, 6,
5, etc. | |
326 // 0.4, 0.7 etc allow to test what happens when the client requests a scale
that | |
327 // does not exactly match a sampleSize or native scaling capability. | |
328 const float samplingScales[] = { 0.1f, 0.125f, 0.167f, 0.2f, 0.25f, 0.333f,
0.375f, 0.4f, 0.5f, | |
329 0.6f, 0.625f, 0.750f, 0.8f, 0.875f, 1.0f }; | |
330 | 363 |
331 for (float scale : samplingScales) { | 364 const AndroidCodecSrc::Mode androidModes[] = { |
332 for (uint32_t i = 0; i < numColorTypes; i++) { | 365 AndroidCodecSrc::kFullImage_Mode, |
333 push_codec_src(path, CodecSrc::kScaledCodec_Mode, colorTypes[i], sca
le); | 366 AndroidCodecSrc::kDivisor_Mode, |
| 367 }; |
| 368 |
| 369 for (int sampleSize : sampleSizes) { |
| 370 for (AndroidCodecSrc::Mode mode : androidModes) { |
| 371 for (uint32_t i = 0; i < numColorTypes; i++) { |
| 372 push_android_codec_src(path, mode, colorTypes[i], sampleSize); |
| 373 } |
334 } | 374 } |
335 } | 375 } |
336 } | 376 } |
337 | 377 |
338 static bool brd_color_type_supported(SkBitmapRegionDecoderInterface::Strategy st
rategy, | 378 static bool brd_color_type_supported(SkBitmapRegionDecoderInterface::Strategy st
rategy, |
339 CodecSrc::DstColorType dstColorType) { | 379 CodecSrc::DstColorType dstColorType) { |
340 switch (strategy) { | 380 switch (strategy) { |
341 case SkBitmapRegionDecoderInterface::kCanvas_Strategy: | 381 case SkBitmapRegionDecoderInterface::kCanvas_Strategy: |
342 if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) { | 382 if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) { |
343 return true; | 383 return true; |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 #endif // SK_PDF_IMAGE_STATS | 1148 #endif // SK_PDF_IMAGE_STATS |
1109 return 0; | 1149 return 0; |
1110 } | 1150 } |
1111 | 1151 |
1112 #if !defined(SK_BUILD_FOR_IOS) | 1152 #if !defined(SK_BUILD_FOR_IOS) |
1113 int main(int argc, char** argv) { | 1153 int main(int argc, char** argv) { |
1114 SkCommandLineFlags::Parse(argc, argv); | 1154 SkCommandLineFlags::Parse(argc, argv); |
1115 return dm_main(); | 1155 return dm_main(); |
1116 } | 1156 } |
1117 #endif | 1157 #endif |
OLD | NEW |