Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Unified Diff: src/codec/SkGifCodec.cpp

Issue 1820073002: Add SkEncodedInfo to report properties of encoded image data (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/codec/SkGifCodec.cpp
diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp
index 2233c66c19f5ca81ac002f2f46bce377fc7e80d1..c239c6b07305a03736d4cde7a22738b3a22e72e0 100644
--- a/src/codec/SkGifCodec.cpp
+++ b/src/codec/SkGifCodec.cpp
@@ -199,24 +199,23 @@ bool SkGifCodec::ReadHeader(SkStream* stream, SkCodec** codecOut, GifFileType**
}
bool frameIsSubset = (size != frameRect.size());
- // Determine the recommended alpha type. The transIndex might be valid if it less
+ // Determine the encoded 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 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;
+ // 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;
// Return the codec
- // 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,
+ // 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(size.width(), size.height(),
scroggo 2016/03/23 14:48:50 Should Make have an option to take an SkISize?
msarett 2016/03/24 16:20:44 Yes, why not!
+ SkEncodedInfo::kPalette_Color, alpha, 8);
+ *codecOut = new SkGifCodec(info, streamDeleter.release(), gif.release(), transIndex,
frameRect, frameIsSubset);
} else {
SkASSERT(nullptr != gifOut);
@@ -239,9 +238,9 @@ SkCodec* SkGifCodec::NewFromStream(SkStream* stream) {
return nullptr;
}
-SkGifCodec::SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType* gif,
+SkGifCodec::SkGifCodec(const SkEncodedInfo& info, SkStream* stream, GifFileType* gif,
uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset)
- : INHERITED(srcInfo, stream)
+ : INHERITED(info, stream)
, fGif(gif)
, fSrcBuffer(new uint8_t[this->getInfo().width()])
, fFrameRect(frameRect)

Powered by Google App Engine
This is Rietveld 408576698