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 "SkBmpCodec.h" | 8 #include "SkBmpCodec.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 179 |
180 /* | 180 /* |
181 * Creates an instance of the decoder | 181 * Creates an instance of the decoder |
182 * Called only by NewFromStream | 182 * Called only by NewFromStream |
183 */ | 183 */ |
184 SkIcoCodec::SkIcoCodec(int width, int height, const SkEncodedInfo& info, | 184 SkIcoCodec::SkIcoCodec(int width, int height, const SkEncodedInfo& info, |
185 SkTArray<SkAutoTDelete<SkCodec>, true>* codecs) | 185 SkTArray<SkAutoTDelete<SkCodec>, true>* codecs) |
186 : INHERITED(width, height, info, nullptr) | 186 : INHERITED(width, height, info, nullptr) |
187 , fEmbeddedCodecs(codecs) | 187 , fEmbeddedCodecs(codecs) |
188 , fCurrScanlineCodec(nullptr) | 188 , fCurrScanlineCodec(nullptr) |
| 189 , fCurrIncrementalCodec(nullptr) |
189 {} | 190 {} |
190 | 191 |
191 /* | 192 /* |
192 * Chooses the best dimensions given the desired scale | 193 * Chooses the best dimensions given the desired scale |
193 */ | 194 */ |
194 SkISize SkIcoCodec::onGetScaledDimensions(float desiredScale) const { | 195 SkISize SkIcoCodec::onGetScaledDimensions(float desiredScale) const { |
195 // We set the dimensions to the largest candidate image by default. | 196 // We set the dimensions to the largest candidate image by default. |
196 // Regardless of the scale request, this is the largest image that we | 197 // Regardless of the scale request, this is the largest image that we |
197 // will decode. | 198 // will decode. |
198 int origWidth = this->getInfo().width(); | 199 int origWidth = this->getInfo().width(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 while (true) { | 283 while (true) { |
283 index = this->chooseCodec(dstInfo.dimensions(), index); | 284 index = this->chooseCodec(dstInfo.dimensions(), index); |
284 if (index < 0) { | 285 if (index < 0) { |
285 break; | 286 break; |
286 } | 287 } |
287 | 288 |
288 SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index); | 289 SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index); |
289 result = embeddedCodec->startScanlineDecode(dstInfo, &options, colorTabl
e, colorCount); | 290 result = embeddedCodec->startScanlineDecode(dstInfo, &options, colorTabl
e, colorCount); |
290 if (kSuccess == result) { | 291 if (kSuccess == result) { |
291 fCurrScanlineCodec = embeddedCodec; | 292 fCurrScanlineCodec = embeddedCodec; |
| 293 fCurrIncrementalCodec = nullptr; |
292 return result; | 294 return result; |
293 } | 295 } |
294 | 296 |
295 index++; | 297 index++; |
296 } | 298 } |
297 | 299 |
298 SkCodecPrintf("Error: No matching candidate image in ico.\n"); | 300 SkCodecPrintf("Error: No matching candidate image in ico.\n"); |
299 return result; | 301 return result; |
300 } | 302 } |
301 | 303 |
302 int SkIcoCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { | 304 int SkIcoCodec::onGetScanlines(void* dst, int count, size_t rowBytes) { |
303 SkASSERT(fCurrScanlineCodec); | 305 SkASSERT(fCurrScanlineCodec); |
304 return fCurrScanlineCodec->getScanlines(dst, count, rowBytes); | 306 return fCurrScanlineCodec->getScanlines(dst, count, rowBytes); |
305 } | 307 } |
306 | 308 |
307 bool SkIcoCodec::onSkipScanlines(int count) { | 309 bool SkIcoCodec::onSkipScanlines(int count) { |
308 SkASSERT(fCurrScanlineCodec); | 310 SkASSERT(fCurrScanlineCodec); |
309 return fCurrScanlineCodec->skipScanlines(count); | 311 return fCurrScanlineCodec->skipScanlines(count); |
310 } | 312 } |
311 | 313 |
| 314 SkCodec::Result SkIcoCodec::onStartIncrementalDecode(const SkImageInfo& dstInfo, |
| 315 const SkCodec::Options& options, SkPMColor* colorTable, int* colorCount)
{ |
| 316 int index = 0; |
| 317 while (true) { |
| 318 index = this->chooseCodec(dstInfo.dimensions(), index); |
| 319 if (index < 0) { |
| 320 break; |
| 321 } |
| 322 |
| 323 SkCodec* embeddedCodec = fEmbeddedCodecs->operator[](index); |
| 324 if (SkCodec::kSuccess == embeddedCodec->startIncrementalDecode(dstInfo, |
| 325 &options, colorTable, colorCount)) { |
| 326 fCurrIncrementalCodec = embeddedCodec; |
| 327 fCurrScanlineCodec = nullptr; |
| 328 return SkCodec::kSuccess; |
| 329 } |
| 330 |
| 331 index++; |
| 332 } |
| 333 |
| 334 // FIXME: As long as PNG only supports incremental decode and BMP only |
| 335 // supports scanline decoding, which image the client gets depends on |
| 336 // which entry point they use, meaning getScaledDimensions could return |
| 337 // a set of dimensions that is only supported by one or the other. |
| 338 SkCodecPrintf("Error: No matching candidate image in ico.\n"); |
| 339 return kInvalidScale; |
| 340 } |
| 341 |
| 342 SkCodec::Result SkIcoCodec::onIncrementalDecode(std::function<void*(int)> callba
ck, |
| 343 int* rowsDecoded) { |
| 344 SkASSERT(fCurrIncrementalCodec); |
| 345 return fCurrIncrementalCodec->incrementalDecode(callback, rowsDecoded); |
| 346 } |
| 347 |
312 SkCodec::SkScanlineOrder SkIcoCodec::onGetScanlineOrder() const { | 348 SkCodec::SkScanlineOrder SkIcoCodec::onGetScanlineOrder() const { |
313 // FIXME: This function will possibly return the wrong value if it is called | 349 // FIXME: This function will possibly return the wrong value if it is called |
314 // before startScanlineDecode(). | 350 // before startScanlineDecode()/startIncrementalDecode(). |
315 return fCurrScanlineCodec ? fCurrScanlineCodec->getScanlineOrder() : | 351 if (fCurrScanlineCodec) { |
316 INHERITED::onGetScanlineOrder(); | 352 SkASSERT(!fCurrIncrementalCodec); |
| 353 return fCurrScanlineCodec->getScanlineOrder(); |
| 354 } |
| 355 |
| 356 if (fCurrIncrementalCodec) { |
| 357 return fCurrIncrementalCodec->getScanlineOrder(); |
| 358 } |
| 359 |
| 360 return INHERITED::onGetScanlineOrder(); |
317 } | 361 } |
318 | 362 |
319 SkSampler* SkIcoCodec::getSampler(bool createIfNecessary) { | 363 SkSampler* SkIcoCodec::getSampler(bool createIfNecessary) { |
320 return fCurrScanlineCodec ? fCurrScanlineCodec->getSampler(createIfNecessary
) : nullptr; | 364 if (fCurrScanlineCodec) { |
| 365 SkASSERT(!fCurrIncrementalCodec); |
| 366 return fCurrScanlineCodec->getSampler(createIfNecessary); |
| 367 } |
| 368 |
| 369 if (fCurrIncrementalCodec) { |
| 370 return fCurrIncrementalCodec->getSampler(createIfNecessary); |
| 371 } |
| 372 |
| 373 return nullptr; |
321 } | 374 } |
OLD | NEW |