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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 this->setIncompleteScanlines(size.height() - y); |
143 return rowResult; | 144 return rowResult; |
144 } | 145 } |
145 swizzler->swizzle(dstRow, src.get()); | 146 swizzler->swizzle(dstRow, src.get()); |
146 dstRow = SkTAddOffset<void>(dstRow, rowBytes); | 147 dstRow = SkTAddOffset<void>(dstRow, rowBytes); |
147 } | 148 } |
148 return kSuccess; | 149 return kSuccess; |
149 } | 150 } |
150 | 151 |
151 bool SkWbmpCodec::IsWbmp(SkStream* stream) { | 152 bool SkWbmpCodec::IsWbmp(SkStream* stream) { |
152 return read_header(stream, nullptr); | 153 return read_header(stream, nullptr); |
153 } | 154 } |
154 | 155 |
155 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { | 156 SkCodec* SkWbmpCodec::NewFromStream(SkStream* stream) { |
156 SkAutoTDelete<SkStream> streamDeleter(stream); | 157 SkAutoTDelete<SkStream> streamDeleter(stream); |
157 SkISize size; | 158 SkISize size; |
158 if (!read_header(stream, &size)) { | 159 if (!read_header(stream, &size)) { |
159 return nullptr; | 160 return nullptr; |
160 } | 161 } |
161 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), | 162 SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), |
162 kGray_8_SkColorType, kOpaque_SkAlphaType); | 163 kGray_8_SkColorType, kOpaque_SkAlphaType); |
163 return new SkWbmpCodec(info, streamDeleter.detach()); | 164 return new SkWbmpCodec(info, streamDeleter.detach()); |
164 } | 165 } |
165 | 166 |
166 class SkWbmpScanlineDecoder : public SkScanlineDecoder { | 167 class SkWbmpScanlineDecoder : public SkScanlineDecoder { |
167 public: | 168 public: |
168 /* | 169 /* |
169 * Takes ownership of all pointer paramters. | 170 * Takes ownership of all pointer paramters. |
170 */ | 171 */ |
171 SkWbmpScanlineDecoder(SkWbmpCodec* codec) | 172 SkWbmpScanlineDecoder(SkWbmpCodec* codec) |
172 : INHERITED(codec->getInfo()) | 173 : INHERITED(codec, codec->getInfo()) |
173 , fCodec(codec) | 174 , fCodec(codec) |
174 , fColorTable(nullptr) | 175 , fColorTable(nullptr) |
175 , fSwizzler(nullptr) | 176 , fSwizzler(nullptr) |
176 , fSrcBuffer(codec->fSrcRowBytes) | 177 , fSrcBuffer(codec->fSrcRowBytes) |
177 {} | 178 {} |
178 | 179 |
179 SkCodec::Result onGetScanlines(void* dst, int count, size_t dstRowBytes) ove
rride { | 180 uint32_t onGetScanlines(void* dst, int count, size_t dstRowBytes) override { |
180 void* dstRow = dst; | 181 void* dstRow = dst; |
181 for (int y = 0; y < count; ++y) { | 182 for (int y = 0; y < count; ++y) { |
182 SkCodec::Result rowResult = fCodec->readRow(fSrcBuffer.get()); | 183 SkCodec::Result rowResult = fCodec->readRow(fSrcBuffer.get()); |
183 if (SkCodec::kSuccess != rowResult) { | 184 if (SkCodec::kSuccess != rowResult) { |
184 return rowResult; | 185 return y; |
185 } | 186 } |
186 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); | 187 fSwizzler->swizzle(dstRow, fSrcBuffer.get()); |
187 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); | 188 dstRow = SkTAddOffset<void>(dstRow, dstRowBytes); |
188 } | 189 } |
189 return SkCodec::kSuccess; | 190 return count; |
190 } | 191 } |
191 | 192 |
192 SkCodec::Result onStart(const SkImageInfo& dstInfo, | 193 SkCodec::Result onStart(const SkImageInfo& dstInfo, |
193 const SkCodec::Options& options, SkPMColor inputColorTable[], | 194 const SkCodec::Options& options, SkPMColor inputColorTable[], |
194 int* inputColorCount) { | 195 int* inputColorCount) { |
195 if (!fCodec->rewindIfNeeded()) { | 196 if (!fCodec->rewindIfNeeded()) { |
196 return SkCodec::kCouldNotRewind; | 197 return SkCodec::kCouldNotRewind; |
197 } | 198 } |
198 if (options.fSubset) { | 199 if (options.fSubset) { |
199 // Subsets are not supported. | 200 // Subsets are not supported. |
(...skipping 25 matching lines...) Expand all Loading... |
225 } | 226 } |
226 | 227 |
227 return SkCodec::kSuccess; | 228 return SkCodec::kSuccess; |
228 } | 229 } |
229 | 230 |
230 SkEncodedFormat onGetEncodedFormat() const { | 231 SkEncodedFormat onGetEncodedFormat() const { |
231 return kWBMP_SkEncodedFormat; | 232 return kWBMP_SkEncodedFormat; |
232 } | 233 } |
233 | 234 |
234 private: | 235 private: |
235 SkAutoTDelete<SkWbmpCodec> fCodec; | 236 SkWbmpCodec* fCodec; // Owned by parent class |
236 SkAutoTUnref<SkColorTable> fColorTable; | 237 SkAutoTUnref<SkColorTable> fColorTable; |
237 SkAutoTDelete<SkSwizzler> fSwizzler; | 238 SkAutoTDelete<SkSwizzler> fSwizzler; |
238 SkAutoTMalloc<uint8_t> fSrcBuffer; | 239 SkAutoTMalloc<uint8_t> fSrcBuffer; |
239 | 240 |
240 typedef SkScanlineDecoder INHERITED; | 241 typedef SkScanlineDecoder INHERITED; |
241 }; | 242 }; |
242 | 243 |
243 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { | 244 SkScanlineDecoder* SkWbmpCodec::NewSDFromStream(SkStream* stream) { |
244 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( | 245 SkAutoTDelete<SkWbmpCodec> codec(static_cast<SkWbmpCodec*>( |
245 SkWbmpCodec::NewFromStream(stream))); | 246 SkWbmpCodec::NewFromStream(stream))); |
246 if (!codec) { | 247 if (!codec) { |
247 return nullptr; | 248 return nullptr; |
248 } | 249 } |
249 | 250 |
250 // Return the new scanline decoder | 251 // Return the new scanline decoder |
251 return new SkWbmpScanlineDecoder(codec.detach()); | 252 return new SkWbmpScanlineDecoder(codec.detach()); |
252 } | 253 } |
OLD | NEW |