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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 if (!read_mbf(stream, &height) || height > 0xFFFF || !height) { | 61 if (!read_mbf(stream, &height) || height > 0xFFFF || !height) { |
62 return false; | 62 return false; |
63 } | 63 } |
64 if (size) { | 64 if (size) { |
65 *size = SkISize::Make(SkToS32(width), SkToS32(height)); | 65 *size = SkISize::Make(SkToS32(width), SkToS32(height)); |
66 } | 66 } |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 bool SkWbmpCodec::onRewind() { | 70 bool SkWbmpCodec::onRewind() { |
71 return read_header(this->stream(), NULL); | 71 return read_header(this->stream(), nullptr); |
72 } | 72 } |
73 | 73 |
74 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, | 74 SkSwizzler* SkWbmpCodec::initializeSwizzler(const SkImageInfo& info, |
75 const SkPMColor* ctable, const Options& opts) { | 75 const SkPMColor* ctable, const Options& opts) { |
76 // Create the swizzler based on the desired color type | 76 // Create the swizzler based on the desired color type |
77 switch (info.colorType()) { | 77 switch (info.colorType()) { |
78 case kIndex_8_SkColorType: | 78 case kIndex_8_SkColorType: |
79 case kN32_SkColorType: | 79 case kN32_SkColorType: |
80 case kRGB_565_SkColorType: | 80 case kRGB_565_SkColorType: |
81 case kGray_8_SkColorType: | 81 case kGray_8_SkColorType: |
82 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op
ts.fZeroInitialized, | 82 return SkSwizzler::CreateSwizzler(SkSwizzler::kBit, ctable, info, op
ts.fZeroInitialized, |
83 this->getInfo()); | 83 this->getInfo()); |
84 default: | 84 default: |
85 return NULL; | 85 return nullptr; |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { | 89 SkCodec::Result SkWbmpCodec::readRow(uint8_t* row) { |
90 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { | 90 if (this->stream()->read(row, fSrcRowBytes) != fSrcRowBytes) { |
91 return kIncompleteInput; | 91 return kIncompleteInput; |
92 } | 92 } |
93 return kSuccess; | 93 return kSuccess; |
94 } | 94 } |
95 | 95 |
(...skipping 26 matching lines...) Expand all Loading... |
122 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { | 122 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { |
123 return SkCodec::kInvalidConversion; | 123 return SkCodec::kInvalidConversion; |
124 } | 124 } |
125 | 125 |
126 // Prepare a color table if necessary | 126 // Prepare a color table if necessary |
127 setup_color_table(info.colorType(), ctable, ctableCount); | 127 setup_color_table(info.colorType(), ctable, ctableCount); |
128 | 128 |
129 | 129 |
130 // Initialize the swizzler | 130 // Initialize the swizzler |
131 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op
tions)); | 131 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op
tions)); |
132 if (NULL == swizzler.get()) { | 132 if (nullptr == swizzler.get()) { |
133 return kInvalidConversion; | 133 return kInvalidConversion; |
134 } | 134 } |
135 | 135 |
136 // Perform the decode | 136 // Perform the decode |
137 SkISize size = info.dimensions(); | 137 SkISize size = info.dimensions(); |
138 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); | 138 SkAutoTMalloc<uint8_t> src(fSrcRowBytes); |
139 void* dstRow = dst; | 139 void* dstRow = dst; |
140 for (int y = 0; y < size.height(); ++y) { | 140 for (int y = 0; y < size.height(); ++y) { |
141 Result rowResult = this->readRow(src.get()); | 141 Result rowResult = this->readRow(src.get()); |
142 if (kSuccess != rowResult) { | 142 if (kSuccess != rowResult) { |
143 return rowResult; | 143 return rowResult; |
144 } | 144 } |
145 swizzler->swizzle(dstRow, src.get()); | 145 swizzler->swizzle(dstRow, src.get()); |
146 dstRow = SkTAddOffset<void>(dstRow, rowBytes); | 146 dstRow = SkTAddOffset<void>(dstRow, rowBytes); |
147 } | 147 } |
148 return kSuccess; | 148 return kSuccess; |
149 } | 149 } |
150 | 150 |
151 bool SkWbmpCodec::IsWbmp(SkStream* stream) { | 151 bool SkWbmpCodec::IsWbmp(SkStream* stream) { |
152 return read_header(stream, NULL); | 152 return read_header(stream, nullptr); |
153 } | 153 } |
154 | 154 |
155 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { | 155 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { |
156 SkAutoTDelete<SkStream> streamDeleter(stream); | 156 SkAutoTDelete<SkStream> streamDeleter(stream); |
157 SkISize size; | 157 SkISize size; |
158 if (!read_header(stream, &size)) { | 158 if (!read_header(stream, &size)) { |
159 return NULL; | 159 return nullptr; |
160 } | 160 } |
161 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), | 161 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), |
162 kGray_8_SkColorType, kOpaque_SkAlphaType); | 162 kGray_8_SkColorType, kOpaque_SkAlphaType); |
163 return new SkWbmpCodec(info, streamDeleter.detach()); | 163 return new SkWbmpCodec(info, streamDeleter.detach()); |
164 } | 164 } |
165 | 165 |
166 class SkWbmpScanlineDecoder : public SkScanlineDecoder { | 166 class SkWbmpScanlineDecoder : public SkScanlineDecoder { |
167 public: | 167 public: |
168 /* | 168 /* |
169 * Takes ownership of all pointer paramters. | 169 * Takes ownership of all pointer paramters. |
170 */ | 170 */ |
171 SkWbmpScanlineDecoder(SkWbmpCodec* codec) | 171 SkWbmpScanlineDecoder(SkWbmpCodec* codec) |
172 : INHERITED(codec->getInfo()) | 172 : INHERITED(codec->getInfo()) |
173 , fCodec(codec) | 173 , fCodec(codec) |
174 , fColorTable(NULL) | 174 , fColorTable(nullptr) |
175 , fSwizzler(NULL) | 175 , fSwizzler(nullptr) |
176 , fSrcBuffer(codec->fSrcRowBytes) | 176 , fSrcBuffer(codec->fSrcRowBytes) |
177 {} | 177 {} |
178 | 178 |
179 SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) ove
rride { | 179 SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) ove
rride { |
180 void* dstRow = dst; | 180 void* dstRow = dst; |
181 for (int y = 0; y < count; ++y) { | 181 for (int y = 0; y < count; ++y) { |
182 SkCodec::Result rowResult = fCodec->readRow(fSrcBuffer.get()); | 182 SkCodec::Result rowResult = fCodec->readRow(fSrcBuffer.get()); |
183 if (SkCodec::kSuccess != rowResult) { | 183 if (SkCodec::kSuccess != rowResult) { |
184 return rowResult; | 184 return rowResult; |
185 } | 185 } |
(...skipping 27 matching lines...) Expand all Loading... |
213 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount)
; | 213 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount)
; |
214 | 214 |
215 // Copy the color table to a pointer that can be owned by the scanline d
ecoder | 215 // Copy the color table to a pointer that can be owned by the scanline d
ecoder |
216 if (kIndex_8_SkColorType == dstInfo.colorType()) { | 216 if (kIndex_8_SkColorType == dstInfo.colorType()) { |
217 fColorTable.reset(new SkColorTable(inputColorTable, 2)); | 217 fColorTable.reset(new SkColorTable(inputColorTable, 2)); |
218 } | 218 } |
219 | 219 |
220 // Initialize the swizzler | 220 // Initialize the swizzler |
221 fSwizzler.reset(fCodec->initializeSwizzler(dstInfo, | 221 fSwizzler.reset(fCodec->initializeSwizzler(dstInfo, |
222 get_color_ptr(fColorTable.get()), options)); | 222 get_color_ptr(fColorTable.get()), options)); |
223 if (NULL == fSwizzler.get()) { | 223 if (nullptr == fSwizzler.get()) { |
224 return SkCodec::kInvalidConversion; | 224 return SkCodec::kInvalidConversion; |
225 } | 225 } |
226 | 226 |
227 return SkCodec::kSuccess; | 227 return SkCodec::kSuccess; |
228 } | 228 } |
229 | 229 |
230 SkEncodedFormat onGetEncodedFormat() const { | 230 SkEncodedFormat onGetEncodedFormat() const { |
231 return kWBMP_SkEncodedFormat; | 231 return kWBMP_SkEncodedFormat; |
232 } | 232 } |
233 | 233 |
234 private: | 234 private: |
235 SkAutoTDelete<SkWbmpCodec> fCodec; | 235 SkAutoTDelete<SkWbmpCodec> fCodec; |
236 SkAutoTUnref<SkColorTable> fColorTable; | 236 SkAutoTUnref<SkColorTable> fColorTable; |
237 SkAutoTDelete<SkSwizzler> fSwizzler; | 237 SkAutoTDelete<SkSwizzler> fSwizzler; |
238 SkAutoTMalloc<uint8_t> fSrcBuffer; | 238 SkAutoTMalloc<uint8_t> fSrcBuffer; |
239 | 239 |
240 typedef SkScanlineDecoder INHERITED; | 240 typedef SkScanlineDecoder INHERITED; |
241 }; | 241 }; |
242 | 242 |
243 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { | 243 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { |
244 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( | 244 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( |
245 SkWbmpCodec::NewFromStream(stream))); | 245 SkWbmpCodec::NewFromStream(stream))); |
246 if (!codec) { | 246 if (!codec) { |
247 return NULL; | 247 return nullptr; |
248 } | 248 } |
249 | 249 |
250 // Return the new scanline decoder | 250 // Return the new scanline decoder |
251 return new SkWbmpScanlineDecoder(codec.detach()); | 251 return new SkWbmpScanlineDecoder(codec.detach()); |
252 } | 252 } |
OLD | NEW |