| 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 "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkColorTable.h" | 10 #include "SkColorTable.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 192 |
| 193 if (nullptr != codecOut) { | 193 if (nullptr != codecOut) { |
| 194 SkISize size; | 194 SkISize size; |
| 195 SkIRect frameRect; | 195 SkIRect frameRect; |
| 196 if (!GetDimensions(gif, &size, &frameRect)) { | 196 if (!GetDimensions(gif, &size, &frameRect)) { |
| 197 gif_error("Invalid gif size.\n"); | 197 gif_error("Invalid gif size.\n"); |
| 198 return false; | 198 return false; |
| 199 } | 199 } |
| 200 bool frameIsSubset = (size != frameRect.size()); | 200 bool frameIsSubset = (size != frameRect.size()); |
| 201 | 201 |
| 202 // Determine the recommended alpha type. The transIndex might be valid
if it less | 202 // Determine the encoded alpha type. The transIndex might be valid if i
t less |
| 203 // than 256. We are not certain that the index is valid until we proces
s the color | 203 // than 256. We are not certain that the index is valid until we proces
s the color |
| 204 // table, since some gifs have color tables with less than 256 colors.
If | 204 // table, since some gifs have color tables with less than 256 colors.
If |
| 205 // there might be a valid transparent index, we must indicate that the i
mage has | 205 // there might be a valid transparent index, we must indicate that the i
mage has |
| 206 // alpha. | 206 // alpha. |
| 207 // In the case where we must support alpha, we have the option to set th
e | 207 // In the case where we must support alpha, we indicate kBinary, since e
very |
| 208 // suggested alpha type to kPremul or kUnpremul. Both are valid since t
he alpha | 208 // pixel will either be fully opaque or fully transparent. |
| 209 // component will always be 0xFF or the entire 32-bit pixel will be set
to zero. | 209 SkEncodedInfo::Alpha alpha = (transIndex < 256) ? SkEncodedInfo::kBinary
_Alpha : |
| 210 // We prefer kPremul because we support kPremul, and it is more efficien
t to use | 210 SkEncodedInfo::kOpaque_Alpha; |
| 211 // kPremul directly even when kUnpremul is supported. | |
| 212 SkAlphaType alphaType = (transIndex < 256) ? kPremul_SkAlphaType : kOpaq
ue_SkAlphaType; | |
| 213 | 211 |
| 214 // Return the codec | 212 // Return the codec |
| 215 // kIndex is the most natural color type for gifs, so we set this as | 213 // Use kPalette since Gifs are encoded with a color table. |
| 216 // the default. | 214 // Use 8-bits per component, since this is the output we get from giflib
. |
| 217 SkImageInfo imageInfo = SkImageInfo::Make(size.width(), size.height(), k
Index_8_SkColorType, | 215 // FIXME: Gifs can actually be encoded with 4-bits per pixel. Can we su
pport this? |
| 218 alphaType); | 216 SkEncodedInfo info = SkEncodedInfo::Make(size, SkEncodedInfo::kPalette_C
olor, alpha, 8); |
| 219 *codecOut = new SkGifCodec(imageInfo, streamDeleter.release(), gif.relea
se(), transIndex, | 217 *codecOut = new SkGifCodec(info, streamDeleter.release(), gif.release(),
transIndex, |
| 220 frameRect, frameIsSubset); | 218 frameRect, frameIsSubset); |
| 221 } else { | 219 } else { |
| 222 SkASSERT(nullptr != gifOut); | 220 SkASSERT(nullptr != gifOut); |
| 223 streamDeleter.release(); | 221 streamDeleter.release(); |
| 224 *gifOut = gif.release(); | 222 *gifOut = gif.release(); |
| 225 } | 223 } |
| 226 return true; | 224 return true; |
| 227 } | 225 } |
| 228 | 226 |
| 229 /* | 227 /* |
| 230 * Assumes IsGif was called and returned true | 228 * Assumes IsGif was called and returned true |
| 231 * Creates a gif decoder | 229 * Creates a gif decoder |
| 232 * Reads enough of the stream to determine the image format | 230 * Reads enough of the stream to determine the image format |
| 233 */ | 231 */ |
| 234 SkCodec* SkGifCodec::NewFromStream(SkStream* stream) { | 232 SkCodec* SkGifCodec::NewFromStream(SkStream* stream) { |
| 235 SkCodec* codec = nullptr; | 233 SkCodec* codec = nullptr; |
| 236 if (ReadHeader(stream, &codec, nullptr)) { | 234 if (ReadHeader(stream, &codec, nullptr)) { |
| 237 return codec; | 235 return codec; |
| 238 } | 236 } |
| 239 return nullptr; | 237 return nullptr; |
| 240 } | 238 } |
| 241 | 239 |
| 242 SkGifCodec::SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType
* gif, | 240 SkGifCodec::SkGifCodec(const SkEncodedInfo& info, SkStream* stream, GifFileType*
gif, |
| 243 uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset) | 241 uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset) |
| 244 : INHERITED(srcInfo, stream) | 242 : INHERITED(info, stream) |
| 245 , fGif(gif) | 243 , fGif(gif) |
| 246 , fSrcBuffer(new uint8_t[this->getInfo().width()]) | 244 , fSrcBuffer(new uint8_t[this->getInfo().width()]) |
| 247 , fFrameRect(frameRect) | 245 , fFrameRect(frameRect) |
| 248 // If it is valid, fTransIndex will be used to set fFillIndex. We don't kno
w if | 246 // If it is valid, fTransIndex will be used to set fFillIndex. We don't kno
w if |
| 249 // fTransIndex is valid until we process the color table, since fTransIndex
may | 247 // fTransIndex is valid until we process the color table, since fTransIndex
may |
| 250 // be greater than the size of the color table. | 248 // be greater than the size of the color table. |
| 251 , fTransIndex(transIndex) | 249 , fTransIndex(transIndex) |
| 252 // Default fFillIndex is 0. We will overwrite this if fTransIndex is valid,
or if | 250 // Default fFillIndex is 0. We will overwrite this if fTransIndex is valid,
or if |
| 253 // there is a valid background color. | 251 // there is a valid background color. |
| 254 , fFillIndex(0) | 252 , fFillIndex(0) |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 int SkGifCodec::onOutputScanline(int inputScanline) const { | 597 int SkGifCodec::onOutputScanline(int inputScanline) const { |
| 600 if (fGif->Image.Interlace) { | 598 if (fGif->Image.Interlace) { |
| 601 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott
om()) { | 599 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott
om()) { |
| 602 return inputScanline; | 600 return inputScanline; |
| 603 } | 601 } |
| 604 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram
eRect.height()) + | 602 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram
eRect.height()) + |
| 605 fFrameRect.top(); | 603 fFrameRect.top(); |
| 606 } | 604 } |
| 607 return inputScanline; | 605 return inputScanline; |
| 608 } | 606 } |
| OLD | NEW |