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 "DMSrcSink.h" | 8 #include "DMSrcSink.h" |
9 #include "SkAndroidCodec.h" | 9 #include "SkAndroidCodec.h" |
10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 // No need to premultiply kGray or k565 outputs. | 307 // No need to premultiply kGray or k565 outputs. |
308 break; | 308 break; |
309 } | 309 } |
310 | 310 |
311 // In the kIndex_8 case, the canvas won't even try to draw unless we mark th e | 311 // In the kIndex_8 case, the canvas won't even try to draw unless we mark th e |
312 // bitmap as kPremul. | 312 // bitmap as kPremul. |
313 bitmap.setAlphaType(kPremul_SkAlphaType); | 313 bitmap.setAlphaType(kPremul_SkAlphaType); |
314 } | 314 } |
315 | 315 |
316 static bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType , | 316 static bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType , |
317 CodecSrc::DstColorType dstColorType) { | 317 CodecSrc::DstColorType dstColorType, SkAlphaType dst AlphaType) { |
318 switch (dstColorType) { | 318 switch (dstColorType) { |
319 case CodecSrc::kIndex8_Always_DstColorType: | 319 case CodecSrc::kIndex8_Always_DstColorType: |
320 if (kRGB_565_SkColorType == canvasColorType) { | 320 if (kRGB_565_SkColorType == canvasColorType) { |
321 return false; | 321 return false; |
322 } | 322 } |
323 *decodeInfo = decodeInfo->makeColorType(kIndex_8_SkColorType); | 323 *decodeInfo = decodeInfo->makeColorType(kIndex_8_SkColorType); |
324 break; | 324 break; |
325 case CodecSrc::kGrayscale_Always_DstColorType: | 325 case CodecSrc::kGrayscale_Always_DstColorType: |
326 if (kRGB_565_SkColorType == canvasColorType || | 326 if (kRGB_565_SkColorType == canvasColorType || |
327 kOpaque_SkAlphaType != decodeInfo->alphaType()) { | 327 kOpaque_SkAlphaType != decodeInfo->alphaType()) { |
msarett
2016/05/20 20:52:22
Don't we need to fix this?
scroggo
2016/05/20 20:55:03
Nope. We're now comparing against the SkCodec's al
| |
328 return false; | 328 return false; |
329 } | 329 } |
330 *decodeInfo = decodeInfo->makeColorType(kGray_8_SkColorType); | 330 *decodeInfo = decodeInfo->makeColorType(kGray_8_SkColorType); |
331 break; | 331 break; |
332 case CodecSrc::kNonNative8888_Always_DstColorType: | 332 case CodecSrc::kNonNative8888_Always_DstColorType: |
333 if (kRGB_565_SkColorType == canvasColorType) { | 333 if (kRGB_565_SkColorType == canvasColorType) { |
334 return false; | 334 return false; |
335 } | 335 } |
336 #ifdef SK_PMCOLOR_IS_RGBA | 336 #ifdef SK_PMCOLOR_IS_RGBA |
337 *decodeInfo = decodeInfo->makeColorType(kBGRA_8888_SkColorType); | 337 *decodeInfo = decodeInfo->makeColorType(kBGRA_8888_SkColorType); |
338 #else | 338 #else |
339 *decodeInfo = decodeInfo->makeColorType(kRGBA_8888_SkColorType); | 339 *decodeInfo = decodeInfo->makeColorType(kRGBA_8888_SkColorType); |
340 #endif | 340 #endif |
341 break; | 341 break; |
342 default: | 342 default: |
343 if (kRGB_565_SkColorType == canvasColorType && | 343 if (kRGB_565_SkColorType == canvasColorType && |
344 kOpaque_SkAlphaType != decodeInfo->alphaType()) { | 344 kOpaque_SkAlphaType != decodeInfo->alphaType()) { |
msarett
2016/05/20 20:52:22
Don't we need to fix this?
scroggo
2016/05/20 20:55:03
Similarly, we don't want to try decoding non-opaqu
| |
345 return false; | 345 return false; |
346 } | 346 } |
347 *decodeInfo = decodeInfo->makeColorType(canvasColorType); | 347 *decodeInfo = decodeInfo->makeColorType(canvasColorType); |
348 break; | 348 break; |
349 } | 349 } |
350 | 350 |
351 *decodeInfo = decodeInfo->makeAlphaType(dstAlphaType); | |
351 return true; | 352 return true; |
352 } | 353 } |
353 | 354 |
354 static void draw_to_canvas(SkCanvas* canvas, const SkImageInfo& info, void* pixe ls, size_t rowBytes, | 355 static void draw_to_canvas(SkCanvas* canvas, const SkImageInfo& info, void* pixe ls, size_t rowBytes, |
355 SkPMColor* colorPtr, int colorCount, CodecSrc::DstCol orType dstColorType, | 356 SkPMColor* colorPtr, int colorCount, CodecSrc::DstCol orType dstColorType, |
356 SkScalar left = 0, SkScalar top = 0) { | 357 SkScalar left = 0, SkScalar top = 0) { |
357 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colorPtr, colorCount) ); | 358 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colorPtr, colorCount) ); |
358 SkBitmap bitmap; | 359 SkBitmap bitmap; |
359 bitmap.installPixels(info, pixels, rowBytes, colorTable.get(), nullptr, null ptr); | 360 bitmap.installPixels(info, pixels, rowBytes, colorTable.get(), nullptr, null ptr); |
360 premultiply_if_necessary(bitmap); | 361 premultiply_if_necessary(bitmap); |
361 swap_rb_if_necessary(bitmap, dstColorType); | 362 swap_rb_if_necessary(bitmap, dstColorType); |
362 canvas->drawBitmap(bitmap, left, top); | 363 canvas->drawBitmap(bitmap, left, top); |
363 } | 364 } |
364 | 365 |
365 Error CodecSrc::draw(SkCanvas* canvas) const { | 366 Error CodecSrc::draw(SkCanvas* canvas) const { |
366 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 367 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
367 if (!encoded) { | 368 if (!encoded) { |
368 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 369 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
369 } | 370 } |
370 | 371 |
371 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 372 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
372 if (nullptr == codec.get()) { | 373 if (nullptr == codec.get()) { |
373 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); | 374 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
374 } | 375 } |
375 | 376 |
376 SkImageInfo decodeInfo = codec->getInfo().makeAlphaType(fDstAlphaType); | 377 SkImageInfo decodeInfo = codec->getInfo(); |
377 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor Type)) { | 378 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor Type, |
379 fDstAlphaType)) { | |
378 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); | 380 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
379 } | 381 } |
380 | 382 |
381 // Try to scale the image if it is desired | 383 // Try to scale the image if it is desired |
382 SkISize size = codec->getScaledDimensions(fScale); | 384 SkISize size = codec->getScaledDimensions(fScale); |
383 if (size == decodeInfo.dimensions() && 1.0f != fScale) { | 385 if (size == decodeInfo.dimensions() && 1.0f != fScale) { |
384 return Error::Nonfatal("Test without scaling is uninteresting."); | 386 return Error::Nonfatal("Test without scaling is uninteresting."); |
385 } | 387 } |
386 | 388 |
387 // Visually inspecting very small output images is not necessary. We will | 389 // Visually inspecting very small output images is not necessary. We will |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { | 651 Error AndroidCodecSrc::draw(SkCanvas* canvas) const { |
650 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 652 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
651 if (!encoded) { | 653 if (!encoded) { |
652 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 654 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
653 } | 655 } |
654 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); | 656 SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); |
655 if (nullptr == codec.get()) { | 657 if (nullptr == codec.get()) { |
656 return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_s tr()); | 658 return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_s tr()); |
657 } | 659 } |
658 | 660 |
659 SkImageInfo decodeInfo = codec->getInfo().makeAlphaType(fDstAlphaType); | 661 SkImageInfo decodeInfo = codec->getInfo(); |
660 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor Type)) { | 662 if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColor Type, |
663 fDstAlphaType)) { | |
661 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); | 664 return Error::Nonfatal("Testing non-565 to 565 is uninteresting."); |
662 } | 665 } |
663 | 666 |
664 // Scale the image if it is desired. | 667 // Scale the image if it is desired. |
665 SkISize size = codec->getSampledDimensions(fSampleSize); | 668 SkISize size = codec->getSampledDimensions(fSampleSize); |
666 | 669 |
667 // Visually inspecting very small output images is not necessary. We will | 670 // Visually inspecting very small output images is not necessary. We will |
668 // cover these cases in unit testing. | 671 // cover these cases in unit testing. |
669 if ((size.width() <= 10 || size.height() <= 10) && 1 != fSampleSize) { | 672 if ((size.width() <= 10 || size.height() <= 10) && 1 != fSampleSize) { |
670 return Error::Nonfatal("Scaling very small images is uninteresting."); | 673 return Error::Nonfatal("Scaling very small images is uninteresting."); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 if (!image) { | 789 if (!image) { |
787 return "Could not create image from codec image generator."; | 790 return "Could not create image from codec image generator."; |
788 } | 791 } |
789 canvas->drawImage(image, 0, 0); | 792 canvas->drawImage(image, 0, 0); |
790 return ""; | 793 return ""; |
791 } | 794 } |
792 | 795 |
793 // Test various color and alpha types on CPU | 796 // Test various color and alpha types on CPU |
794 SkImageInfo decodeInfo = gen->getInfo().makeAlphaType(fDstAlphaType); | 797 SkImageInfo decodeInfo = gen->getInfo().makeAlphaType(fDstAlphaType); |
795 | 798 |
796 if (kGray_8_SkColorType == decodeInfo.colorType() && | |
797 kOpaque_SkAlphaType != decodeInfo.alphaType()) { | |
798 return Error::Nonfatal("Avoid requesting non-opaque kGray8 decodes."); | |
799 } | |
800 | |
801 int bpp = SkColorTypeBytesPerPixel(decodeInfo.colorType()); | 799 int bpp = SkColorTypeBytesPerPixel(decodeInfo.colorType()); |
802 size_t rowBytes = decodeInfo.width() * bpp; | 800 size_t rowBytes = decodeInfo.width() * bpp; |
803 SkAutoMalloc pixels(decodeInfo.height() * rowBytes); | 801 SkAutoMalloc pixels(decodeInfo.height() * rowBytes); |
804 SkPMColor colorPtr[256]; | 802 SkPMColor colorPtr[256]; |
805 int colorCount = 256; | 803 int colorCount = 256; |
806 | 804 |
807 if (!gen->getPixels(decodeInfo, pixels.get(), rowBytes, colorPtr, &colorCoun t)) { | 805 if (!gen->getPixels(decodeInfo, pixels.get(), rowBytes, colorPtr, &colorCoun t)) { |
808 return SkStringPrintf("Image generator could not getPixels() for %s\n", fPath.c_str()); | 806 return SkStringPrintf("Image generator could not getPixels() for %s\n", fPath.c_str()); |
809 } | 807 } |
810 | 808 |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1459 skr.visit(i, drawsAsSingletonPictures); | 1457 skr.visit(i, drawsAsSingletonPictures); |
1460 } | 1458 } |
1461 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1459 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
1462 | 1460 |
1463 canvas->drawPicture(macroPic); | 1461 canvas->drawPicture(macroPic); |
1464 return check_against_reference(bitmap, src, fSink); | 1462 return check_against_reference(bitmap, src, fSink); |
1465 }); | 1463 }); |
1466 } | 1464 } |
1467 | 1465 |
1468 } // namespace DM | 1466 } // namespace DM |
OLD | NEW |