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

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: 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 unified diff | Download patch
« no previous file with comments | « src/codec/SkGifCodec.h ('k') | src/codec/SkIcoCodec.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(SkEncodedInfo::kPalette_Color, alpha, 8);
219 *codecOut = new SkGifCodec(imageInfo, streamDeleter.release(), gif.relea se(), transIndex, 217 *codecOut = new SkGifCodec(size.width(), size.height(), info, streamDele ter.release(),
220 frameRect, frameIsSubset); 218 gif.release(), transIndex, 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(int width, int height, const SkEncodedInfo& info, SkStrea m* stream,
243 uint32_t transIndex, const SkIRect& frameRect, bool frameIsSubset) 241 GifFileType* gif, uint32_t transIndex, const SkIRect& frameRect, bool fr ameIsSubset)
244 : INHERITED(srcInfo, stream) 242 : INHERITED(width, height, 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
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 }
OLDNEW
« 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