| 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 "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 static inline void setup_color_table(SkColorType colorType, | 24 static inline void setup_color_table(SkColorType colorType, |
| 25 SkPMColor* colorPtr, int* colorCount) { | 25 SkPMColor* colorPtr, int* colorCount) { |
| 26 if (kIndex_8_SkColorType == colorType) { | 26 if (kIndex_8_SkColorType == colorType) { |
| 27 colorPtr[0] = SK_ColorBLACK; | 27 colorPtr[0] = SK_ColorBLACK; |
| 28 colorPtr[1] = SK_ColorWHITE; | 28 colorPtr[1] = SK_ColorWHITE; |
| 29 *colorCount = 2; | 29 *colorCount = 2; |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 static inline bool valid_color_type(SkColorType colorType, SkAlphaType alphaType
) { | 33 static inline bool valid_color_type(SkColorType colorType) { |
| 34 switch (colorType) { | 34 switch (colorType) { |
| 35 case kRGBA_8888_SkColorType: | 35 case kRGBA_8888_SkColorType: |
| 36 case kBGRA_8888_SkColorType: | 36 case kBGRA_8888_SkColorType: |
| 37 case kIndex_8_SkColorType: | 37 case kIndex_8_SkColorType: |
| 38 return true; | |
| 39 case kGray_8_SkColorType: | 38 case kGray_8_SkColorType: |
| 40 case kRGB_565_SkColorType: | 39 case kRGB_565_SkColorType: |
| 41 return kOpaque_SkAlphaType == alphaType; | 40 return true; |
| 42 default: | 41 default: |
| 43 return false; | 42 return false; |
| 44 } | 43 } |
| 45 } | 44 } |
| 46 | 45 |
| 47 static bool read_byte(SkStream* stream, uint8_t* data) | 46 static bool read_byte(SkStream* stream, uint8_t* data) |
| 48 { | 47 { |
| 49 return stream->read(data, 1) == 1; | 48 return stream->read(data, 1) == 1; |
| 50 } | 49 } |
| 51 | 50 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 size_t rowBytes, | 120 size_t rowBytes, |
| 122 const Options& options, | 121 const Options& options, |
| 123 SkPMColor ctable[], | 122 SkPMColor ctable[], |
| 124 int* ctableCount, | 123 int* ctableCount, |
| 125 int* rowsDecoded) { | 124 int* rowsDecoded) { |
| 126 if (options.fSubset) { | 125 if (options.fSubset) { |
| 127 // Subsets are not supported. | 126 // Subsets are not supported. |
| 128 return kUnimplemented; | 127 return kUnimplemented; |
| 129 } | 128 } |
| 130 | 129 |
| 131 if (!valid_color_type(info.colorType(), info.alphaType()) || | 130 if (!valid_color_type(info.colorType()) || |
| 132 !valid_alpha(info.alphaType(), this->getInfo().alphaType())) { | 131 !valid_alpha(info.alphaType(), this->getInfo().alphaType())) { |
| 133 return kInvalidConversion; | 132 return kInvalidConversion; |
| 134 } | 133 } |
| 135 | 134 |
| 136 // Prepare a color table if necessary | 135 // Prepare a color table if necessary |
| 137 setup_color_table(info.colorType(), ctable, ctableCount); | 136 setup_color_table(info.colorType(), ctable, ctableCount); |
| 138 | 137 |
| 139 // Initialize the swizzler | 138 // Initialize the swizzler |
| 140 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op
tions)); | 139 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op
tions)); |
| 141 SkASSERT(swizzler); | 140 SkASSERT(swizzler); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 return this->stream()->skip(bytesToSkip) == bytesToSkip; | 188 return this->stream()->skip(bytesToSkip) == bytesToSkip; |
| 190 } | 189 } |
| 191 | 190 |
| 192 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, | 191 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
| 193 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun
t) { | 192 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun
t) { |
| 194 if (options.fSubset) { | 193 if (options.fSubset) { |
| 195 // Subsets are not supported. | 194 // Subsets are not supported. |
| 196 return kUnimplemented; | 195 return kUnimplemented; |
| 197 } | 196 } |
| 198 | 197 |
| 199 if (!valid_color_type(dstInfo.colorType(), dstInfo.alphaType()) || | 198 if (!valid_color_type(dstInfo.colorType()) || |
| 200 !valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { | 199 !valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { |
| 201 return kInvalidConversion; | 200 return kInvalidConversion; |
| 202 } | 201 } |
| 203 | 202 |
| 204 // Fill in the color table | 203 // Fill in the color table |
| 205 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount); | 204 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount); |
| 206 | 205 |
| 207 // Copy the color table to a pointer that can be owned by the scanline decod
er | 206 // Copy the color table to a pointer that can be owned by the scanline decod
er |
| 208 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 207 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
| 209 fColorTable.reset(new SkColorTable(inputColorTable, 2)); | 208 fColorTable.reset(new SkColorTable(inputColorTable, 2)); |
| 210 } | 209 } |
| 211 | 210 |
| 212 // Initialize the swizzler | 211 // Initialize the swizzler |
| 213 fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable.
get()), options)); | 212 fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable.
get()), options)); |
| 214 SkASSERT(fSwizzler); | 213 SkASSERT(fSwizzler); |
| 215 | 214 |
| 216 fSrcBuffer.reset(fSrcRowBytes); | 215 fSrcBuffer.reset(fSrcRowBytes); |
| 217 | 216 |
| 218 return kSuccess; | 217 return kSuccess; |
| 219 } | 218 } |
| OLD | NEW |