OLD | NEW |
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 /* | 8 /* |
9 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 9 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
10 * | 10 * |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 SkCodecPrintf("Gif Error: %s\n", msg); | 65 SkCodecPrintf("Gif Error: %s\n", msg); |
66 return result; | 66 return result; |
67 } | 67 } |
68 | 68 |
69 /* | 69 /* |
70 * Assumes IsGif was called and returned true | 70 * Assumes IsGif was called and returned true |
71 * Creates a gif decoder | 71 * Creates a gif decoder |
72 * Reads enough of the stream to determine the image format | 72 * Reads enough of the stream to determine the image format |
73 */ | 73 */ |
74 SkCodec* SkGifCodec::NewFromStream(SkStream* stream) { | 74 SkCodec* SkGifCodec::NewFromStream(SkStream* stream) { |
75 std::unique_ptr<GIFImageReader> reader(new GIFImageReader(stream)); | 75 std::unique_ptr<SkGifImageReader> reader(new SkGifImageReader(stream)); |
76 if (!reader->parse(GIFImageReader::GIFSizeQuery)) { | 76 if (!reader->parse(SkGifImageReader::GIFSizeQuery)) { |
77 // Not enough data to determine the size. | 77 // Not enough data to determine the size. |
78 return nullptr; | 78 return nullptr; |
79 } | 79 } |
80 | 80 |
81 if (0 == reader->screenWidth() || 0 == reader->screenHeight()) { | 81 if (0 == reader->screenWidth() || 0 == reader->screenHeight()) { |
82 return nullptr; | 82 return nullptr; |
83 } | 83 } |
84 | 84 |
85 const auto alpha = reader->firstFrameHasAlpha() ? SkEncodedInfo::kBinary_Alp
ha | 85 const auto alpha = reader->firstFrameHasAlpha() ? SkEncodedInfo::kBinary_Alp
ha |
86 : SkEncodedInfo::kOpaque_Alp
ha; | 86 : SkEncodedInfo::kOpaque_Alp
ha; |
(...skipping 16 matching lines...) Expand all Loading... |
103 colorType, alphaType); | 103 colorType, alphaType); |
104 return new SkGifCodec(encodedInfo, imageInfo, reader.release()); | 104 return new SkGifCodec(encodedInfo, imageInfo, reader.release()); |
105 } | 105 } |
106 | 106 |
107 bool SkGifCodec::onRewind() { | 107 bool SkGifCodec::onRewind() { |
108 fReader->clearDecodeState(); | 108 fReader->clearDecodeState(); |
109 return true; | 109 return true; |
110 } | 110 } |
111 | 111 |
112 SkGifCodec::SkGifCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imag
eInfo, | 112 SkGifCodec::SkGifCodec(const SkEncodedInfo& encodedInfo, const SkImageInfo& imag
eInfo, |
113 GIFImageReader* reader) | 113 SkGifImageReader* reader) |
114 : INHERITED(encodedInfo, imageInfo, nullptr) | 114 : INHERITED(encodedInfo, imageInfo, nullptr) |
115 , fReader(reader) | 115 , fReader(reader) |
116 , fTmpBuffer(nullptr) | 116 , fTmpBuffer(nullptr) |
117 , fSwizzler(nullptr) | 117 , fSwizzler(nullptr) |
118 , fCurrColorTable(nullptr) | 118 , fCurrColorTable(nullptr) |
119 , fCurrColorTableIsReal(false) | 119 , fCurrColorTableIsReal(false) |
120 , fFilledBackground(false) | 120 , fFilledBackground(false) |
121 , fFirstCallToIncrementalDecode(false) | 121 , fFirstCallToIncrementalDecode(false) |
122 , fDst(nullptr) | 122 , fDst(nullptr) |
123 , fDstRowBytes(0) | 123 , fDstRowBytes(0) |
124 , fRowsDecoded(0) | 124 , fRowsDecoded(0) |
125 { | 125 { |
126 reader->setClient(this); | 126 reader->setClient(this); |
127 } | 127 } |
128 | 128 |
129 std::vector<SkCodec::FrameInfo> SkGifCodec::onGetFrameInfo() { | 129 std::vector<SkCodec::FrameInfo> SkGifCodec::onGetFrameInfo() { |
130 fReader->parse(GIFImageReader::GIFFrameCountQuery); | 130 fReader->parse(SkGifImageReader::GIFFrameCountQuery); |
131 const size_t size = fReader->imagesCount(); | 131 const size_t size = fReader->imagesCount(); |
132 std::vector<FrameInfo> result(size); | 132 std::vector<FrameInfo> result(size); |
133 for (size_t i = 0; i < size; i++) { | 133 for (size_t i = 0; i < size; i++) { |
134 const GIFFrameContext* frameContext = fReader->frameContext(i); | 134 const GIFFrameContext* frameContext = fReader->frameContext(i); |
135 result[i].fDuration = frameContext->delayTime(); | 135 result[i].fDuration = frameContext->delayTime(); |
136 result[i].fRequiredFrame = frameContext->getRequiredFrame(); | 136 result[i].fRequiredFrame = frameContext->getRequiredFrame(); |
137 } | 137 } |
138 return result; | 138 return result; |
139 } | 139 } |
140 | 140 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // FIXME: It is possible that a later frame can be decoded to index8, if
it does one of the | 177 // FIXME: It is possible that a later frame can be decoded to index8, if
it does one of the |
178 // following: | 178 // following: |
179 // - Covers the entire previous frame | 179 // - Covers the entire previous frame |
180 // - Shares a color table (and transparent index) with any prior frames
that are showing. | 180 // - Shares a color table (and transparent index) with any prior frames
that are showing. |
181 // We must support index8 for the first frame to be backwards compatible
on Android, but | 181 // We must support index8 for the first frame to be backwards compatible
on Android, but |
182 // we do not (currently) need to support later frames as index8. | 182 // we do not (currently) need to support later frames as index8. |
183 return gif_error("Cannot decode multiframe gif (except frame 0) as index
8.\n", | 183 return gif_error("Cannot decode multiframe gif (except frame 0) as index
8.\n", |
184 kInvalidConversion); | 184 kInvalidConversion); |
185 } | 185 } |
186 | 186 |
187 fReader->parse((GIFImageReader::GIFParseQuery) frameIndex); | 187 fReader->parse((SkGifImageReader::GIFParseQuery) frameIndex); |
188 | 188 |
189 if (frameIndex >= fReader->imagesCount()) { | 189 if (frameIndex >= fReader->imagesCount()) { |
190 return gif_error("frame index out of range!\n", kIncompleteInput); | 190 return gif_error("frame index out of range!\n", kIncompleteInput); |
191 } | 191 } |
192 | 192 |
193 fTmpBuffer.reset(new uint8_t[dstInfo.minRowBytes()]); | 193 fTmpBuffer.reset(new uint8_t[dstInfo.minRowBytes()]); |
194 | 194 |
195 // Initialize color table and copy to the client if necessary | 195 // Initialize color table and copy to the client if necessary |
196 this->initializeColorTable(dstInfo, frameIndex, inputColorPtr, inputColorCou
nt); | 196 this->initializeColorTable(dstInfo, frameIndex, inputColorPtr, inputColorCou
nt); |
197 this->initializeSwizzler(dstInfo, frameIndex); | 197 this->initializeSwizzler(dstInfo, frameIndex); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 | 262 |
263 fFirstCallToIncrementalDecode = true; | 263 fFirstCallToIncrementalDecode = true; |
264 | 264 |
265 return kSuccess; | 265 return kSuccess; |
266 } | 266 } |
267 | 267 |
268 SkCodec::Result SkGifCodec::onIncrementalDecode(int* rowsDecoded) { | 268 SkCodec::Result SkGifCodec::onIncrementalDecode(int* rowsDecoded) { |
269 // It is possible the client has appended more data. Parse, if needed. | 269 // It is possible the client has appended more data. Parse, if needed. |
270 const auto& options = this->options(); | 270 const auto& options = this->options(); |
271 const size_t frameIndex = options.fFrameIndex; | 271 const size_t frameIndex = options.fFrameIndex; |
272 fReader->parse((GIFImageReader::GIFParseQuery) frameIndex); | 272 fReader->parse((SkGifImageReader::GIFParseQuery) frameIndex); |
273 | 273 |
274 const bool firstCallToIncrementalDecode = fFirstCallToIncrementalDecode; | 274 const bool firstCallToIncrementalDecode = fFirstCallToIncrementalDecode; |
275 fFirstCallToIncrementalDecode = false; | 275 fFirstCallToIncrementalDecode = false; |
276 return this->decodeFrame(firstCallToIncrementalDecode, options, rowsDecoded)
; | 276 return this->decodeFrame(firstCallToIncrementalDecode, options, rowsDecoded)
; |
277 } | 277 } |
278 | 278 |
279 SkCodec::Result SkGifCodec::decodeFrame(bool firstAttempt, const Options& opts,
int* rowsDecoded) { | 279 SkCodec::Result SkGifCodec::decodeFrame(bool firstAttempt, const Options& opts,
int* rowsDecoded) { |
280 const SkImageInfo& dstInfo = this->dstInfo(); | 280 const SkImageInfo& dstInfo = this->dstInfo(); |
281 const size_t frameIndex = opts.fFrameIndex; | 281 const size_t frameIndex = opts.fFrameIndex; |
282 SkASSERT(frameIndex < fReader->imagesCount()); | 282 SkASSERT(frameIndex < fReader->imagesCount()); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 fFilledBackground = filledBackground; | 350 fFilledBackground = filledBackground; |
351 if (filledBackground) { | 351 if (filledBackground) { |
352 // Report the full (scaled) height, since the client will never need
to fill. | 352 // Report the full (scaled) height, since the client will never need
to fill. |
353 fRowsDecoded = get_scaled_dimension(dstInfo.height(), fSwizzler->sam
pleY()); | 353 fRowsDecoded = get_scaled_dimension(dstInfo.height(), fSwizzler->sam
pleY()); |
354 } else { | 354 } else { |
355 // This will be updated by haveDecodedRow. | 355 // This will be updated by haveDecodedRow. |
356 fRowsDecoded = 0; | 356 fRowsDecoded = 0; |
357 } | 357 } |
358 } | 358 } |
359 | 359 |
360 // Note: there is a difference between the following call to GIFImageReader:
:decode | 360 // Note: there is a difference between the following call to SkGifImageReade
r::decode |
361 // returning false and leaving frameDecoded false: | 361 // returning false and leaving frameDecoded false: |
362 // - If the method returns false, there was an error in the stream. We still
treat this as | 362 // - If the method returns false, there was an error in the stream. We still
treat this as |
363 // incomplete, since we have already decoded some rows. | 363 // incomplete, since we have already decoded some rows. |
364 // - If frameDecoded is false, that just means that we do not have enough da
ta. If more data | 364 // - If frameDecoded is false, that just means that we do not have enough da
ta. If more data |
365 // is supplied, we may be able to continue decoding this frame. We also tr
eat this as | 365 // is supplied, we may be able to continue decoding this frame. We also tr
eat this as |
366 // incomplete. | 366 // incomplete. |
367 // FIXME: Ensure that we do not attempt to continue decoding if the method r
eturns false and | 367 // FIXME: Ensure that we do not attempt to continue decoding if the method r
eturns false and |
368 // more data is supplied. | 368 // more data is supplied. |
369 bool frameDecoded = false; | 369 bool frameDecoded = false; |
370 if (!fReader->decode(frameIndex, &frameDecoded) || !frameDecoded) { | 370 if (!fReader->decode(frameIndex, &frameDecoded) || !frameDecoded) { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 void* copiedLine = SkTAddOffset<void>(dstLine, fSwizzler->swizzleOffsetB
ytes()); | 554 void* copiedLine = SkTAddOffset<void>(dstLine, fSwizzler->swizzleOffsetB
ytes()); |
555 void* dst = copiedLine; | 555 void* dst = copiedLine; |
556 for (unsigned i = 1; i < repeatCount; i++) { | 556 for (unsigned i = 1; i < repeatCount; i++) { |
557 dst = SkTAddOffset<void>(dst, fDstRowBytes); | 557 dst = SkTAddOffset<void>(dst, fDstRowBytes); |
558 memcpy(dst, copiedLine, bytesToCopy); | 558 memcpy(dst, copiedLine, bytesToCopy); |
559 } | 559 } |
560 } | 560 } |
561 | 561 |
562 return true; | 562 return true; |
563 } | 563 } |
OLD | NEW |