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

Side by Side 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 unified diff | Download patch
OLDNEW
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
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.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!
219 *codecOut = new SkGifCodec(imageInfo, streamDeleter.release(), gif.relea se(), transIndex, 217 SkEncodedInfo::kPalette_Color, alpha, 8);
218 *codecOut = new SkGifCodec(info, streamDeleter.release(), gif.release(), transIndex,
220 frameRect, frameIsSubset); 219 frameRect, frameIsSubset);
221 } else { 220 } else {
222 SkASSERT(nullptr != gifOut); 221 SkASSERT(nullptr != gifOut);
223 streamDeleter.release(); 222 streamDeleter.release();
224 *gifOut = gif.release(); 223 *gifOut = gif.release();
225 } 224 }
226 return true; 225 return true;
227 } 226 }
228 227
229 /* 228 /*
230 * Assumes IsGif was called and returned true 229 * Assumes IsGif was called and returned true
231 * Creates a gif decoder 230 * Creates a gif decoder
232 * Reads enough of the stream to determine the image format 231 * Reads enough of the stream to determine the image format
233 */ 232 */
234 SkCodec* SkGifCodec::NewFromStream(SkStream* stream) { 233 SkCodec* SkGifCodec::NewFromStream(SkStream* stream) {
235 SkCodec* codec = nullptr; 234 SkCodec* codec = nullptr;
236 if (ReadHeader(stream, &codec, nullptr)) { 235 if (ReadHeader(stream, &codec, nullptr)) {
237 return codec; 236 return codec;
238 } 237 }
239 return nullptr; 238 return nullptr;
240 } 239 }
241 240
242 SkGifCodec::SkGifCodec(const SkImageInfo& srcInfo, SkStream* stream, GifFileType * gif, 241 SkGifCodec::SkGifCodec(const SkEncodedInfo& info, SkStream* stream, GifFileType* gif,
243 uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset) 242 uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset)
244 : INHERITED(srcInfo, stream) 243 : INHERITED(info, stream)
245 , fGif(gif) 244 , fGif(gif)
246 , fSrcBuffer(new uint8_t[this->getInfo().width()]) 245 , fSrcBuffer(new uint8_t[this->getInfo().width()])
247 , fFrameRect(frameRect) 246 , fFrameRect(frameRect)
248 // If it is valid, fTransIndex will be used to set fFillIndex. We don't kno w if 247 // 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 248 // fTransIndex is valid until we process the color table, since fTransIndex may
250 // be greater than the size of the color table. 249 // be greater than the size of the color table.
251 , fTransIndex(transIndex) 250 , fTransIndex(transIndex)
252 // Default fFillIndex is 0. We will overwrite this if fTransIndex is valid, or if 251 // Default fFillIndex is 0. We will overwrite this if fTransIndex is valid, or if
253 // there is a valid background color. 252 // there is a valid background color.
254 , fFillIndex(0) 253 , fFillIndex(0)
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 int SkGifCodec::onOutputScanline(int inputScanline) const { 598 int SkGifCodec::onOutputScanline(int inputScanline) const {
600 if (fGif->Image.Interlace) { 599 if (fGif->Image.Interlace) {
601 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott om()) { 600 if (inputScanline < fFrameRect.top() || inputScanline >= fFrameRect.bott om()) {
602 return inputScanline; 601 return inputScanline;
603 } 602 }
604 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram eRect.height()) + 603 return get_output_row_interlaced(inputScanline - fFrameRect.top(), fFram eRect.height()) +
605 fFrameRect.top(); 604 fFrameRect.top();
606 } 605 }
607 return inputScanline; 606 return inputScanline;
608 } 607 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698