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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
96 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) | 96 SkWbmpCodec::SkWbmpCodec(const SkImageInfo& info, SkStream* stream) |
97 : INHERITED(info, stream) | 97 : INHERITED(info, stream) |
98 , fSrcRowBytes(get_src_row_bytes(this->getInfo().width())) | 98 , fSrcRowBytes(get_src_row_bytes(this->getInfo().width())) |
99 , fColorTable(nullptr) | |
100 , fSwizzler(nullptr) | |
99 {} | 101 {} |
100 | 102 |
101 SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const { | 103 SkEncodedFormat SkWbmpCodec::onGetEncodedFormat() const { |
102 return kWBMP_SkEncodedFormat; | 104 return kWBMP_SkEncodedFormat; |
103 } | 105 } |
104 | 106 |
105 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, | 107 SkCodec::Result SkWbmpCodec::onGetPixels(const SkImageInfo& info, |
106 void* dst, | 108 void* dst, |
107 size_t rowBytes, | 109 size_t rowBytes, |
108 const Options& options, | 110 const Options& options, |
109 SkPMColor ctable[], | 111 SkPMColor ctable[], |
110 int* ctableCount) { | 112 int* ctableCount) { |
111 if (!this->rewindIfNeeded()) { | 113 if (!this->rewindIfNeeded()) { |
112 return kCouldNotRewind; | 114 return kCouldNotRewind; |
113 } | 115 } |
114 if (options.fSubset) { | 116 if (options.fSubset) { |
115 // Subsets are not supported. | 117 // Subsets are not supported. |
116 return kUnimplemented; | 118 return kUnimplemented; |
117 } | 119 } |
118 if (info.dimensions() != this->getInfo().dimensions()) { | 120 if (info.dimensions() != this->getInfo().dimensions()) { |
119 return kInvalidScale; | 121 return kInvalidScale; |
120 } | 122 } |
121 | 123 |
122 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { | 124 if (!valid_alpha(info.alphaType(), this->getInfo().alphaType())) { |
123 return SkCodec::kInvalidConversion; | 125 return kInvalidConversion; |
124 } | 126 } |
125 | 127 |
126 // Prepare a color table if necessary | 128 // Prepare a color table if necessary |
127 setup_color_table(info.colorType(), ctable, ctableCount); | 129 setup_color_table(info.colorType(), ctable, ctableCount); |
128 | 130 |
129 | 131 |
130 // Initialize the swizzler | 132 // Initialize the swizzler |
131 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op tions)); | 133 SkAutoTDelete<SkSwizzler> swizzler(this->initializeSwizzler(info, ctable, op tions)); |
132 if (nullptr == swizzler.get()) { | 134 if (nullptr == swizzler.get()) { |
133 return kInvalidConversion; | 135 return kInvalidConversion; |
(...skipping 22 matching lines...) Expand all Loading... | |
156 SkAutoTDelete<SkStream> streamDeleter(stream); | 158 SkAutoTDelete<SkStream> streamDeleter(stream); |
157 SkISize size; | 159 SkISize size; |
158 if (!read_header(stream, &size)) { | 160 if (!read_header(stream, &size)) { |
159 return nullptr; | 161 return nullptr; |
160 } | 162 } |
161 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), | 163 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), |
162 kGray_8_SkColorType, kOpaque_SkAlphaType); | 164 kGray_8_SkColorType, kOpaque_SkAlphaType); |
163 return new SkWbmpCodec(info, streamDeleter.detach()); | 165 return new SkWbmpCodec(info, streamDeleter.detach()); |
164 } | 166 } |
165 | 167 |
166 class SkWbmpScanlineDecoder : public SkScanlineDecoder { | 168 SkCodec::Result SkWbmpCodec::onGetScanlines(void* dst, int count, size_t dstRowB ytes) { |
167 public: | 169 void* dstRow = dst; |
168 /* | 170 for (int y = 0; y < count; ++y) { |
169 * Takes ownership of all pointer paramters. | 171 Result rowResult = this->readRow(fSrcBuffer.get()); |
scroggo
2015/09/25 16:07:50
The performance of SkWbmpCodec should not be a hig
msarett
2015/09/28 14:48:50
Yes agreed. We should implement on onSkipScanline
| |
170 */ | 172 if (kSuccess != rowResult) { |
171 SkWbmpScanlineDecoder(SkWbmpCodec* codec) | 173 return rowResult; |
172 : INHERITED(codec->getInfo()) | 174 } |
173 , fCodec(codec) | 175 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); |
174 , fColorTable(nullptr) | 176 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); |
175 , fSwizzler(nullptr) | 177 } |
176 , fSrcBuffer(codec->fSrcRowBytes) | 178 return kSuccess; |
177 {} | 179 } |
178 | 180 |
179 SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) ove rride { | 181 SkCodec::Result SkWbmpCodec::onStart(const SkImageInfo& dstInfo, const Options& options, |
180 void* dstRow = dst; | 182 SkPMColor inputColorTable[], int* inputColorCount) { |
181 for (int y = 0; y < count; ++y) { | 183 if (!this->rewindIfNeeded()) { |
182 SkCodec::Result rowResult = fCodec->readRow(fSrcBuffer.get()); | 184 return kCouldNotRewind; |
183 if (SkCodec::kSuccess != rowResult) { | 185 } |
184 return rowResult; | 186 if (options.fSubset) { |
185 } | 187 // Subsets are not supported. |
186 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); | 188 return kUnimplemented; |
187 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); | 189 } |
190 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | |
191 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstI nfo)) { | |
192 return kInvalidScale; | |
188 } | 193 } |
189 return SkCodec::kSuccess; | |
190 } | 194 } |
191 | 195 |
192 SkCodec::Result onStart(const SkImageInfo& dstInfo, | 196 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { |
193 const SkCodec::Options& options, SkPMColor inputColorTable[], | 197 return kInvalidConversion; |
194 int* inputColorCount) { | |
195 if (!fCodec->rewindIfNeeded()) { | |
196 return SkCodec::kCouldNotRewind; | |
197 } | |
198 if (options.fSubset) { | |
199 // Subsets are not supported. | |
200 return SkCodec::kUnimplemented; | |
201 } | |
202 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | |
203 if (!SkScaledCodec::DimensionsSupportedForSampling(this->getInfo(), dstInfo)) { | |
204 return SkCodec::kInvalidScale; | |
205 } | |
206 } | |
207 | |
208 if (!valid_alpha(dstInfo.alphaType(), this->getInfo().alphaType())) { | |
209 return SkCodec::kInvalidConversion; | |
210 } | |
211 | |
212 // Fill in the color table | |
213 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount) ; | |
214 | |
215 // Copy the color table to a pointer that can be owned by the scanline d ecoder | |
216 if (kIndex_8_SkColorType == dstInfo.colorType()) { | |
217 fColorTable.reset(new SkColorTable(inputColorTable, 2)); | |
218 } | |
219 | |
220 // Initialize the swizzler | |
221 fSwizzler.reset(fCodec->initializeSwizzler(dstInfo, | |
222 get_color_ptr(fColorTable.get()), options)); | |
223 if (nullptr == fSwizzler.get()) { | |
224 return SkCodec::kInvalidConversion; | |
225 } | |
226 | |
227 return SkCodec::kSuccess; | |
228 } | 198 } |
229 | 199 |
230 SkEncodedFormat onGetEncodedFormat() const { | 200 // Fill in the color table |
231 return kWBMP_SkEncodedFormat; | 201 setup_color_table(dstInfo.colorType(), inputColorTable, inputColorCount); |
202 | |
203 // Copy the color table to a pointer that can be owned by the scanline decod er | |
204 if (kIndex_8_SkColorType == dstInfo.colorType()) { | |
205 fColorTable.reset(new SkColorTable(inputColorTable, 2)); | |
232 } | 206 } |
233 | 207 |
234 private: | 208 // Initialize the swizzler |
235 SkAutoTDelete<SkWbmpCodec> fCodec; | 209 fSwizzler.reset(this->initializeSwizzler(dstInfo, |
236 SkAutoTUnref<SkColorTable> fColorTable; | 210 get_color_ptr(fColorTable.get()), options)); |
237 SkAutoTDelete<SkSwizzler> fSwizzler; | 211 if (nullptr == fSwizzler.get()) { |
238 SkAutoTMalloc<uint8_t> fSrcBuffer; | 212 return kInvalidConversion; |
239 | |
240 typedef SkScanlineDecoder INHERITED; | |
241 }; | |
242 | |
243 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { | |
244 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( | |
245 SkWbmpCodec::NewFromStream(stream))); | |
246 if (!codec) { | |
247 return nullptr; | |
248 } | 213 } |
249 | 214 |
250 // Return the new scanline decoder | 215 fSrcBuffer.reset(fSrcRowBytes); |
251 return new SkWbmpScanlineDecoder(codec.detach()); | 216 |
217 return kSuccess; | |
252 } | 218 } |
219 | |
OLD | NEW |