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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 65 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
66 if (!encoded) { | 66 if (!encoded) { |
67 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 67 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
68 } | 68 } |
69 | 69 |
70 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 70 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
71 if (!codec) { | 71 if (!codec) { |
72 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); | 72 return SkStringPrintf("Couldn't decode %s.", fPath.c_str()); |
73 } | 73 } |
74 | 74 |
75 // Process the decode info to prepare for the decode | |
75 SkImageInfo decodeInfo = codec->getInfo().makeColorType(canvasInfo.colorType ()); | 76 SkImageInfo decodeInfo = codec->getInfo().makeColorType(canvasInfo.colorType ()); |
77 | |
78 // Construct a color table for the decode if necessary | |
79 SkAutoTUnref<SkColorTable> colorTable(NULL); | |
80 SkPMColor* colorPtr = NULL; | |
81 int* colorCountPtr = NULL; | |
82 int maxColors = 256; | |
83 if (kIndex_8_SkColorType == decodeInfo.colorType()) { | |
84 SkPMColor colors[maxColors]; | |
mtklein
2015/04/07 14:26:42
colors needs to live outside the if, right?
msarett
2015/04/07 16:58:47
The constructor for SkColorTable copies the color
| |
85 colorTable.reset(SkNEW_ARGS(SkColorTable, (colors, maxColors))); | |
86 colorPtr = const_cast<SkPMColor*>(colorTable->readColors()); | |
mtklein
2015/04/07 14:26:41
== &colors, right?
msarett
2015/04/07 16:58:47
Per the comment above, it actually does not.
| |
87 colorCountPtr = &maxColors; | |
88 } | |
89 | |
90 // FIXME: Currently we cannot draw unpremultiplied sources. | |
76 if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) { | 91 if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) { |
77 // FIXME: Currently we cannot draw unpremultiplied sources. | |
78 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType); | 92 decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType); |
79 } | 93 } |
80 | 94 |
81 SkBitmap bitmap; | 95 SkBitmap bitmap; |
82 if (!bitmap.tryAllocPixels(decodeInfo)) { | 96 if (!bitmap.tryAllocPixels(decodeInfo, NULL, colorTable.get())) { |
83 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str( ), | 97 return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str( ), |
84 decodeInfo.width(), decodeInfo.height()); | 98 decodeInfo.width(), decodeInfo.height()); |
85 } | 99 } |
86 | 100 |
87 switch (fMode) { | 101 switch (fMode) { |
88 case kNormal_Mode: | 102 case kNormal_Mode: |
89 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB ytes())) { | 103 switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowB ytes(), NULL, |
104 colorPtr, colorCountPtr)) { | |
90 case SkImageGenerator::kSuccess: | 105 case SkImageGenerator::kSuccess: |
91 // We consider incomplete to be valid, since we should still decode what is | 106 // We consider incomplete to be valid, since we should still decode what is |
92 // available. | 107 // available. |
93 case SkImageGenerator::kIncompleteInput: | 108 case SkImageGenerator::kIncompleteInput: |
94 break; | 109 break; |
95 case SkImageGenerator::kInvalidConversion: | 110 case SkImageGenerator::kInvalidConversion: |
96 return Error::Nonfatal("Incompatible colortype conversion"); | 111 return Error::Nonfatal("Incompatible colortype conversion"); |
97 default: | 112 default: |
98 // Everything else is considered a failure. | 113 // Everything else is considered a failure. |
99 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); | 114 return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str( )); |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 surfaces.unrefAll(); | 647 surfaces.unrefAll(); |
633 return ""; | 648 return ""; |
634 } | 649 } |
635 SkISize size() const override { return fSize; } | 650 SkISize size() const override { return fSize; } |
636 Name name() const override { sk_throw(); return ""; } // No one should be calling this. | 651 Name name() const override { sk_throw(); return ""; } // No one should be calling this. |
637 } proxy(fW, fH, pic, src.size()); | 652 } proxy(fW, fH, pic, src.size()); |
638 return fSink->draw(proxy, bitmap, stream, log); | 653 return fSink->draw(proxy, bitmap, stream, log); |
639 } | 654 } |
640 | 655 |
641 } // namespace DM | 656 } // namespace DM |
OLD | NEW |