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

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: Order of param eval bug Created 4 years, 8 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
« no previous file with comments | « src/codec/SkGifCodec.h ('k') | src/codec/SkIcoCodec.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkGifCodec.cpp
diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp
index 2233c66c19f5ca81ac002f2f46bce377fc7e80d1..cdd9d088f129d2b80055bc5a8e24755ffd1c7f0f 100644
--- a/src/codec/SkGifCodec.cpp
+++ b/src/codec/SkGifCodec.cpp
@@ -199,25 +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,
- frameRect, frameIsSubset);
+ // 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);
} else {
SkASSERT(nullptr != gifOut);
streamDeleter.release();
@@ -239,9 +237,9 @@ SkCodec* SkGifCodec::NewFromStream(SkStream* stream) {
return nullptr;
}
-SkGifCodec::SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType* gif,
- uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset)
- : INHERITED(srcInfo, stream)
+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)
, fGif(gif)
, fSrcBuffer(new uint8_t[this->getInfo().width()])
, fFrameRect(frameRect)
« no previous file with comments | « src/codec/SkGifCodec.h ('k') | src/codec/SkIcoCodec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698