| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if (size) { | 63 if (size) { |
| 64 *size = SkISize::Make(SkToS32(width), SkToS32(height)); | 64 *size = SkISize::Make(SkToS32(width), SkToS32(height)); |
| 65 } | 65 } |
| 66 return true; | 66 return true; |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool SkWbmpCodec::onRewind() { | 69 bool SkWbmpCodec::onRewind() { |
| 70 return read_header(this->stream(), nullptr); | 70 return read_header(this->stream(), nullptr); |
| 71 } | 71 } |
| 72 | 72 |
| 73 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, | 73 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, const SkPMC
olor* ctable, |
| 74 const SkPMColor* ctable, const Options& opts) { | 74 const Options& opts, int subsetLeft, int subsetWidth) { |
| 75 // Create the swizzler based on the desired color type | 75 // Create the swizzler based on the desired color type |
| 76 switch (info.colorType()) { | 76 switch (info.colorType()) { |
| 77 case kIndex_8_SkColorType: | 77 case kIndex_8_SkColorType: |
| 78 case kN32_SkColorType: | 78 case kN32_SkColorType: |
| 79 case kRGB_565_SkColorType: | 79 case kRGB_565_SkColorType: |
| 80 case kGray_8_SkColorType: | 80 case kGray_8_SkColorType: |
| 81 break; | 81 break; |
| 82 default: | 82 default: |
| 83 return nullptr; | 83 return nullptr; |
| 84 } | 84 } |
| 85 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, | 85 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, opts.fZero
Initialized, |
| 86 opts.fZeroInitialized); | 86 subsetLeft, subsetWidth); |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool SkWbmpCodec::readRow(uint8_t* row) { | 89 bool SkWbmpCodec::readRow(uint8_t* row) { |
| 90 return this->stream()->read(row, fSrcRowBytes) == fSrcRowBytes; | 90 return this->stream()->read(row, fSrcRowBytes) == fSrcRowBytes; |
| 91 } | 91 } |
| 92 | 92 |
| 93 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) | 93 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) |
| 94 : INHERITED(info, stream) | 94 : INHERITED(info, stream) |
| 95 , fSrcRowBytes(get_src_row_bytes(this->getInfo().width())) | 95 , fSrcRowBytes(get_src_row_bytes(this->getInfo().width())) |
| 96 , fColorTable(nullptr) | 96 , fColorTable(nullptr) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 114 } | 114 } |
| 115 | 115 |
| 116 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { | 116 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { |
| 117 return kInvalidConversion; | 117 return kInvalidConversion; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Prepare a color table if necessary | 120 // Prepare a color table if necessary |
| 121 setup_color_table(info.colorType(), ctable, ctableCount); | 121 setup_color_table(info.colorType(), ctable, ctableCount); |
| 122 | 122 |
| 123 // Initialize the swizzler | 123 // Initialize the swizzler |
| 124 fSwizzler.reset(this->initializeSwizzler(info, ctable, options)); | 124 fSwizzler.reset(this->initializeSwizzler(info, ctable, options, 0,info.width
())); |
| 125 if (nullptr == fSwizzler.get()) { | 125 if (nullptr == fSwizzler.get()) { |
| 126 return kInvalidConversion; | 126 return kInvalidConversion; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Perform the decode | 129 // Perform the decode |
| 130 SkISize size = info.dimensions(); | 130 SkISize size = info.dimensions(); |
| 131 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); | 131 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); |
| 132 void* dstRow = dst; | 132 void* dstRow = dst; |
| 133 for (int y = 0; y < size.height(); ++y) { | 133 for (int y = 0; y < size.height(); ++y) { |
| 134 if (!this->readRow(src.get())) { | 134 if (!this->readRow(src.get())) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 162 if (!this->readRow(fSrcBuffer.get())) { | 162 if (!this->readRow(fSrcBuffer.get())) { |
| 163 return y; | 163 return y; |
| 164 } | 164 } |
| 165 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); | 165 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); |
| 166 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); | 166 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); |
| 167 } | 167 } |
| 168 return count; | 168 return count; |
| 169 } | 169 } |
| 170 | 170 |
| 171 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, | 171 SkCodec::Result SkWbmpCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
| 172 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun
t) { | 172 const Options& options, SkPMColor inputColorTable[], int* inputColorCoun
t, int subsetLeft, |
| 173 int subsetWidth) { |
| 173 if (options.fSubset) { | 174 if (options.fSubset) { |
| 174 // Subsets are not supported. | 175 // Subsets are not supported. |
| 175 return kUnimplemented; | 176 return kUnimplemented; |
| 176 } | 177 } |
| 177 | 178 |
| 178 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { | 179 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { |
| 179 return kInvalidConversion; | 180 return kInvalidConversion; |
| 180 } | 181 } |
| 181 | 182 |
| 182 // Fill in the color table | 183 // Fill in the color table |
| 183 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount); | 184 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount); |
| 184 | 185 |
| 185 // Copy the color table to a pointer that can be owned by the scanline decod
er | 186 // Copy the color table to a pointer that can be owned by the scanline decod
er |
| 186 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 187 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
| 187 fColorTable.reset(new SkColorTable(inputColorTable, 2)); | 188 fColorTable.reset(new SkColorTable(inputColorTable, 2)); |
| 188 } | 189 } |
| 189 | 190 |
| 190 // Initialize the swizzler | 191 // Initialize the swizzler |
| 191 fSwizzler.reset(this->initializeSwizzler(dstInfo, | 192 fSwizzler.reset(this->initializeSwizzler(dstInfo, get_color_ptr(fColorTable.
get()), options, |
| 192 get_color_ptr(fColorTable.get()), options)); | 193 subsetLeft, subsetWidth)); |
| 193 if (nullptr == fSwizzler.get()) { | 194 if (nullptr == fSwizzler.get()) { |
| 194 return kInvalidConversion; | 195 return kInvalidConversion; |
| 195 } | 196 } |
| 196 | 197 |
| 197 fSrcBuffer.reset(fSrcRowBytes); | 198 fSrcBuffer.reset(fSrcRowBytes); |
| 198 | 199 |
| 199 return kSuccess; | 200 return kSuccess; |
| 200 } | 201 } |
| OLD | NEW |