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 | 73 |
70 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 74 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
71 if (!codec) { | 75 if (!codec) { |
72 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | 76 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); |
73 } | 77 } |
74 | 78 |
75 SkImageInfo decodeInfo = codec->getInfo().makeColorType(canvasInfo.colorType ()); | 79 // Choose the color type to decode to |
80 SkImageInfo decodeInfo; | |
81 SkColorType canvasColorType = canvasInfo.colorType(); | |
82 switch (fDstColorType) { | |
83 case kGetFromCanvas_DstColorType: | |
84 decodeInfo = codec->getInfo().makeColorType(canvasColorType); | |
85 break; | |
86 case kIndex8_Always_DstColorType: | |
87 if (kRGB_565_SkColorType == canvasColorType) { | |
88 return Error::Nonfatal("Do not test decoding to kIndex8 when the canvas is 565."); | |
89 } else if (kIndex_8_SkColorType != codec->getInfo().colorType()) { | |
scroggo
2015/04/07 21:15:34
nit: This may be a matter of preference, but I don
msarett
2015/04/08 13:59:10
Done.
| |
90 return Error::Nonfatal("Do not test decoding to kIndex8 when the image is not " | |
91 "natively kIndex8."); | |
92 } | |
93 decodeInfo = codec->getInfo(); | |
scroggo
2015/04/07 21:15:34
nit: You could move this into the declaration of d
msarett
2015/04/08 13:59:10
Done.
| |
94 break; | |
95 case kGrayscale_Always_DstColorType: | |
96 if (kRGB_565_SkColorType == canvasColorType) { | |
97 return Error::Nonfatal("Do not test decoding to kGray when the c anvas is 565."); | |
98 } else if (kGray_8_SkColorType != codec->getInfo().colorType()) { | |
99 return Error::Nonfatal("Do not test decoding to kGray when the i mage is not " | |
100 "natively kGray."); | |
101 } | |
102 decodeInfo = codec->getInfo(); | |
103 break; | |
104 } | |
105 | |
106 // Construct a color table for the decode if necessary | |
107 SkAutoTUnref<SkColorTable> colorTable(NULL); | |
108 SkPMColor* colorPtr = NULL; | |
109 int* colorCountPtr = NULL; | |
110 int maxColors = 256; | |
111 if (kIndex_8_SkColorType == decodeInfo.colorType()) { | |
112 SkPMColor colors[maxColors]; | |
113 colorTable.reset(SkNEW_ARGS(SkColorTable, (colors, maxColors))); | |
114 colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); | |
115 colorCountPtr = &maxColors; | |
116 } | |
117 | |
118 // FIXME: Currently we cannot draw unpremultiplied sources. | |
76 if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) { | 119 if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) { |
77 // FIXME: Currently we cannot draw unpremultiplied sources. | |
78 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType); | 120 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType); |
79 } | 121 } |
80 | 122 |
81 SkBitmap bitmap; | 123 SkBitmap bitmap; |
82 if (!bitmap.tryAllocPixels(decodeInfo)) { | 124 if (!bitmap.tryAllocPixels(decodeInfo, NULL, colorTable.get())) { |
83 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str( ), | 125 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str( ), |
84 decodeInfo.width(), decodeInfo.height()); | 126 decodeInfo.width(), decodeInfo.height()); |
85 } | 127 } |
86 | 128 |
87 switch (fMode) { | 129 switch (fMode) { |
88 case kNormal_Mode: | 130 case kNormal_Mode: |
89 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB ytes())) { | 131 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB ytes(), NULL, |
132 colorPtr, colorCountPtr)) { | |
90 case SkImageGenerator::kSuccess: | 133 case SkImageGenerator::kSuccess: |
91 // We consider incomplete to be valid, since we should still decode what is | 134 // We consider incomplete to be valid, since we should still decode what is |
92 // available. | 135 // available. |
93 case SkImageGenerator::kIncompleteInput: | 136 case SkImageGenerator::kIncompleteInput: |
94 break; | 137 break; |
95 case SkImageGenerator::kInvalidConversion: | 138 case SkImageGenerator::kInvalidConversion: |
96 return Error::Nonfatal("Incompatible colortype conversion"); | 139 return Error::Nonfatal("Incompatible colortype conversion"); |
97 default: | 140 default: |
98 // Everything else is considered a failure. | 141 // Everything else is considered a failure. |
99 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); | 142 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); | 708 canvas->drawPicture(pic); |
666 return ""; | 709 return ""; |
667 } | 710 } |
668 SkISize size() const override { return fSrc.size(); } | 711 SkISize size() const override { return fSrc.size(); } |
669 Name name() const override { sk_throw(); return ""; } // No one should be calling this. | 712 Name name() const override { sk_throw(); return ""; } // No one should be calling this. |
670 } proxy(src); | 713 } proxy(src); |
671 return fSink->draw(proxy, bitmap, stream, log); | 714 return fSink->draw(proxy, bitmap, stream, log); |
672 } | 715 } |
673 | 716 |
674 } // namespace DM | 717 } // namespace DM |
OLD | NEW |