| 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_libgif.h" | 8 #include "SkCodec_libgif.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 return kPremul_SkAlphaType == dst.alphaType() || | 227 return kPremul_SkAlphaType == dst.alphaType() || |
| 228 kUnpremul_SkAlphaType == dst.alphaType(); | 228 kUnpremul_SkAlphaType == dst.alphaType(); |
| 229 case kIndex_8_SkColorType: | 229 case kIndex_8_SkColorType: |
| 230 return kPremul_SkAlphaType == dst.alphaType() || | 230 return kPremul_SkAlphaType == dst.alphaType() || |
| 231 kUnpremul_SkAlphaType == dst.alphaType(); | 231 kUnpremul_SkAlphaType == dst.alphaType(); |
| 232 default: | 232 default: |
| 233 return false; | 233 return false; |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 | 236 |
| 237 bool SkGifCodec::onRewind() { |
| 238 GifFileType* gifOut = NULL; |
| 239 if (!ReadHeader(this->stream(), NULL, &gifOut)) { |
| 240 return false; |
| 241 } |
| 242 |
| 243 SkASSERT(NULL != gifOut); |
| 244 fGif.reset(gifOut); |
| 245 return true; |
| 246 } |
| 247 |
| 237 /* | 248 /* |
| 238 * Initiates the gif decode | 249 * Initiates the gif decode |
| 239 */ | 250 */ |
| 240 SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo, | 251 SkCodec::Result SkGifCodec::onGetPixels(const SkImageInfo& dstInfo, |
| 241 void* dst, size_t dstRowBytes, | 252 void* dst, size_t dstRowBytes, |
| 242 const Options& opts, | 253 const Options& opts, |
| 243 SkPMColor* inputColorPtr, | 254 SkPMColor* inputColorPtr, |
| 244 int* inputColorCount) { | 255 int* inputColorCount) { |
| 245 // Rewind if necessary | 256 // Rewind if necessary |
| 246 SkCodec::RewindState rewindState = this->rewindIfNeeded(); | 257 if (!this->rewindIfNeeded()) { |
| 247 if (rewindState == kCouldNotRewind_RewindState) { | |
| 248 return kCouldNotRewind; | 258 return kCouldNotRewind; |
| 249 } else if (rewindState == kRewound_RewindState) { | |
| 250 GifFileType* gifOut = NULL; | |
| 251 if (!ReadHeader(this->stream(), NULL, &gifOut)) { | |
| 252 return kCouldNotRewind; | |
| 253 } else { | |
| 254 SkASSERT(NULL != gifOut); | |
| 255 fGif.reset(gifOut); | |
| 256 } | |
| 257 } | 259 } |
| 258 | 260 |
| 259 // Check for valid input parameters | 261 // Check for valid input parameters |
| 260 if (opts.fSubset) { | 262 if (opts.fSubset) { |
| 261 // Subsets are not supported. | 263 // Subsets are not supported. |
| 262 return kUnimplemented; | 264 return kUnimplemented; |
| 263 } | 265 } |
| 264 if (dstInfo.dimensions() != this->getInfo().dimensions()) { | 266 if (dstInfo.dimensions() != this->getInfo().dimensions()) { |
| 265 return gif_error("Scaling not supported.\n", kInvalidScale); | 267 return gif_error("Scaling not supported.\n", kInvalidScale); |
| 266 } | 268 } |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 // giflib returns an error code if the record type is not known. | 573 // giflib returns an error code if the record type is not known. |
| 572 // We should catch this error immediately. | 574 // We should catch this error immediately. |
| 573 SkASSERT(false); | 575 SkASSERT(false); |
| 574 break; | 576 break; |
| 575 } | 577 } |
| 576 } while (TERMINATE_RECORD_TYPE != recordType); | 578 } while (TERMINATE_RECORD_TYPE != recordType); |
| 577 | 579 |
| 578 return gif_error("Could not find any images to decode in gif file.\n", | 580 return gif_error("Could not find any images to decode in gif file.\n", |
| 579 kInvalidInput); | 581 kInvalidInput); |
| 580 } | 582 } |
| OLD | NEW |