| Index: src/codec/SkGifCodec.cpp
|
| diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp
|
| index cdd9d088f129d2b80055bc5a8e24755ffd1c7f0f..2233c66c19f5ca81ac002f2f46bce377fc7e80d1 100644
|
| --- a/src/codec/SkGifCodec.cpp
|
| +++ b/src/codec/SkGifCodec.cpp
|
| @@ -199,23 +199,25 @@
|
| }
|
| bool frameIsSubset = (size != frameRect.size());
|
|
|
| - // Determine the encoded alpha type. The transIndex might be valid if it less
|
| + // Determine the recommended alpha type. The transIndex might be valid if it less
|
| // than 256. We are not certain that the index is valid until we process the color
|
| // table, since some gifs have color tables with less than 256 colors. If
|
| // there might be a valid transparent index, we must indicate that the image has
|
| // alpha.
|
| - // In the case where we must support alpha, we indicate kBinary, since every
|
| - // pixel will either be fully opaque or fully transparent.
|
| - SkEncodedInfo::Alpha alpha = (transIndex < 256) ? SkEncodedInfo::kBinary_Alpha :
|
| - SkEncodedInfo::kOpaque_Alpha;
|
| + // In the case where we must support alpha, we have the option to set the
|
| + // suggested alpha type to kPremul or kUnpremul. Both are valid since the alpha
|
| + // component will always be 0xFF or the entire 32-bit pixel will be set to zero.
|
| + // We prefer kPremul because we support kPremul, and it is more efficient to use
|
| + // kPremul directly even when kUnpremul is supported.
|
| + SkAlphaType alphaType = (transIndex < 256) ? kPremul_SkAlphaType : kOpaque_SkAlphaType;
|
|
|
| // Return the codec
|
| - // Use kPalette since Gifs are encoded with a color table.
|
| - // Use 8-bits per component, since this is the output we get from giflib.
|
| - // FIXME: Gifs can actually be encoded with 4-bits per pixel. Can we support this?
|
| - SkEncodedInfo info = SkEncodedInfo::Make(SkEncodedInfo::kPalette_Color, alpha, 8);
|
| - *codecOut = new SkGifCodec(size.width(), size.height(), info, streamDeleter.release(),
|
| - gif.release(), transIndex, frameRect, frameIsSubset);
|
| + // kIndex is the most natural color type for gifs, so we set this as
|
| + // the default.
|
| + SkImageInfo imageInfo = SkImageInfo::Make(size.width(), size.height(), kIndex_8_SkColorType,
|
| + alphaType);
|
| + *codecOut = new SkGifCodec(imageInfo, streamDeleter.release(), gif.release(), transIndex,
|
| + frameRect, frameIsSubset);
|
| } else {
|
| SkASSERT(nullptr != gifOut);
|
| streamDeleter.release();
|
| @@ -237,9 +239,9 @@
|
| return nullptr;
|
| }
|
|
|
| -SkGifCodec::SkGifCodec(int width, int height, const SkEncodedInfo& info, SkStream* stream,
|
| - GifFileType* gif, uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset)
|
| - : INHERITED(width, height, info, stream)
|
| +SkGifCodec::SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType* gif,
|
| + uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset)
|
| + : INHERITED(srcInfo, stream)
|
| , fGif(gif)
|
| , fSrcBuffer(new uint8_t[this->getInfo().width()])
|
| , fFrameRect(frameRect)
|
|
|