| 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 "SamplePipeControllers.h" | 9 #include "SamplePipeControllers.h" |
| 10 #include "SkCommonFlags.h" | 10 #include "SkCommonFlags.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 return gm->getISize(); | 45 return gm->getISize(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 Name GMSrc::name() const { | 48 Name GMSrc::name() const { |
| 49 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); | 49 SkAutoTDelete<skiagm::GM> gm(fFactory(NULL)); |
| 50 return gm->getName(); | 50 return gm->getName(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 53 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 54 | 54 |
| 55 CodecSrc::CodecSrc(Path path, Mode mode) : fPath(path), fMode(mode) {} | 55 CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType) |
| 56 : fPath(path) |
| 57 , fMode(mode) |
| 58 , fDstColorType(dstColorType) |
| 59 {} |
| 56 | 60 |
| 57 Error CodecSrc::draw(SkCanvas* canvas) const { | 61 Error CodecSrc::draw(SkCanvas* canvas) const { |
| 58 SkImageInfo canvasInfo; | 62 SkImageInfo canvasInfo; |
| 59 if (NULL == canvas->peekPixels(&canvasInfo, NULL)) { | 63 if (NULL == canvas->peekPixels(&canvasInfo, NULL)) { |
| 60 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a de
ferred decode to | 64 // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a de
ferred decode to |
| 61 // let the GPU handle it. | 65 // let the GPU handle it. |
| 62 return Error::Nonfatal("No need to test decoding to non-raster backend."
); | 66 return Error::Nonfatal("No need to test decoding to non-raster backend."
); |
| 63 } | 67 } |
| 64 | 68 |
| 65 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 69 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
| 66 if (!encoded) { | 70 if (!encoded) { |
| 67 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 71 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
| 68 } | 72 } |
| 69 | |
| 70 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 73 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
| 71 if (!codec) { | 74 if (NULL == codec.get()) { |
| 72 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | 75 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
| 73 } | 76 } |
| 74 | 77 |
| 75 SkImageInfo decodeInfo = codec->getInfo().makeColorType(canvasInfo.colorType
()); | 78 // Choose the color type to decode to |
| 79 SkImageInfo decodeInfo = codec->getInfo(); |
| 80 SkColorType canvasColorType = canvasInfo.colorType(); |
| 81 switch (fDstColorType) { |
| 82 case kIndex8_Always_DstColorType: |
| 83 case kGrayscale_Always_DstColorType: |
| 84 if (kRGB_565_SkColorType == canvasColorType) { |
| 85 return Error::Nonfatal("Testing non-565 to 565 is uninteresting.
"); |
| 86 } |
| 87 break; |
| 88 default: |
| 89 decodeInfo = decodeInfo.makeColorType(canvasColorType); |
| 90 break; |
| 91 } |
| 92 |
| 93 // Construct a color table for the decode if necessary |
| 94 SkAutoTUnref<SkColorTable> colorTable(NULL); |
| 95 SkPMColor* colorPtr = NULL; |
| 96 int* colorCountPtr = NULL; |
| 97 int maxColors = 256; |
| 98 if (kIndex_8_SkColorType == decodeInfo.colorType()) { |
| 99 SkPMColor colors[256]; |
| 100 colorTable.reset(SkNEW_ARGS(SkColorTable, (colors, maxColors))); |
| 101 colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); |
| 102 colorCountPtr = &maxColors; |
| 103 } |
| 104 |
| 105 // FIXME: Currently we cannot draw unpremultiplied sources. |
| 76 if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) { | 106 if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) { |
| 77 // FIXME: Currently we cannot draw unpremultiplied sources. | |
| 78 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType); | 107 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType); |
| 79 } | 108 } |
| 80 | 109 |
| 81 SkBitmap bitmap; | 110 SkBitmap bitmap; |
| 82 if (!bitmap.tryAllocPixels(decodeInfo)) { | 111 if (!bitmap.tryAllocPixels(decodeInfo, NULL, colorTable.get())) { |
| 83 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(
), | 112 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(
), |
| 84 decodeInfo.width(), decodeInfo.height()); | 113 decodeInfo.width(), decodeInfo.height()); |
| 85 } | 114 } |
| 86 | 115 |
| 87 switch (fMode) { | 116 switch (fMode) { |
| 88 case kNormal_Mode: | 117 case kNormal_Mode: |
| 89 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB
ytes())) { | 118 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB
ytes(), NULL, |
| 119 colorPtr, colorCountPtr)) { |
| 90 case SkImageGenerator::kSuccess: | 120 case SkImageGenerator::kSuccess: |
| 91 // We consider incomplete to be valid, since we should still
decode what is | 121 // We consider incomplete to be valid, since we should still
decode what is |
| 92 // available. | 122 // available. |
| 93 case SkImageGenerator::kIncompleteInput: | 123 case SkImageGenerator::kIncompleteInput: |
| 94 break; | 124 break; |
| 95 case SkImageGenerator::kInvalidConversion: | 125 case SkImageGenerator::kInvalidConversion: |
| 96 return Error::Nonfatal("Incompatible colortype conversion"); | 126 return Error::Nonfatal("Incompatible colortype conversion"); |
| 97 default: | 127 default: |
| 98 // Everything else is considered a failure. | 128 // Everything else is considered a failure. |
| 99 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); | 129 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str(
)); |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 canvas->drawPicture(pic); | 695 canvas->drawPicture(pic); |
| 666 return ""; | 696 return ""; |
| 667 } | 697 } |
| 668 SkISize size() const override { return fSrc.size(); } | 698 SkISize size() const override { return fSrc.size(); } |
| 669 Name name() const override { sk_throw(); return ""; } // No one should
be calling this. | 699 Name name() const override { sk_throw(); return ""; } // No one should
be calling this. |
| 670 } proxy(src); | 700 } proxy(src); |
| 671 return fSink->draw(proxy, bitmap, stream, log); | 701 return fSink->draw(proxy, bitmap, stream, log); |
| 672 } | 702 } |
| 673 | 703 |
| 674 } // namespace DM | 704 } // namespace DM |
| OLD | NEW |