OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 // The loops below are almost identical. One writes a transparent pixel | 150 // The loops below are almost identical. One writes a transparent pixel |
151 // and one doesn't based on the value of |writeTransparentPixels|. | 151 // and one doesn't based on the value of |writeTransparentPixels|. |
152 // The condition check is taken out of the loop to enhance performance. | 152 // The condition check is taken out of the loop to enhance performance. |
153 // This optimization reduces decoding time by about 15% for a 3MB image. | 153 // This optimization reduces decoding time by about 15% for a 3MB image. |
154 if (writeTransparentPixels) { | 154 if (writeTransparentPixels) { |
155 for (; rowBegin != rowEnd; ++rowBegin, ++currentAddress) { | 155 for (; rowBegin != rowEnd; ++rowBegin, ++currentAddress) { |
156 const size_t sourceValue = *rowBegin; | 156 const size_t sourceValue = *rowBegin; |
157 if ((sourceValue != transparentPixel) && | 157 if ((sourceValue != transparentPixel) && |
158 (sourceValue < colorTable.size())) { | 158 (sourceValue < colorTable.size())) { |
159 *currentAddress = colorTableIter[sourceValue]; | 159 *currentAddress = colorTableIter[sourceValue]; |
160 } else { | 160 } else |
161 *currentAddress = 0; | 161 *currentAddress = 0; |
162 m_currentBufferSawAlpha = true; | |
163 } | |
164 } | 162 } |
165 } else { | 163 } else { |
166 for (; rowBegin != rowEnd; ++rowBegin, ++currentAddress) { | 164 for (; rowBegin != rowEnd; ++rowBegin, ++currentAddress) { |
167 const size_t sourceValue = *rowBegin; | 165 const size_t sourceValue = *rowBegin; |
168 if ((sourceValue != transparentPixel) && | 166 if ((sourceValue != transparentPixel) && |
169 (sourceValue < colorTable.size())) | 167 (sourceValue < colorTable.size())) |
170 *currentAddress = colorTableIter[sourceValue]; | 168 *currentAddress = colorTableIter[sourceValue]; |
171 else | |
172 m_currentBufferSawAlpha = true; | |
cblume
2017/05/05 00:05:20
I confirmed this line is making a difference and i
| |
173 } | 169 } |
174 } | 170 } |
175 | 171 |
176 // Tell the frame to copy the row data if need be. | 172 // Tell the frame to copy the row data if need be. |
177 if (repeatCount > 1) | 173 if (repeatCount > 1) |
178 buffer.copyRowNTimes(xBegin, xEnd, yBegin, yEnd); | 174 buffer.copyRowNTimes(xBegin, xEnd, yBegin, yEnd); |
179 | 175 |
180 buffer.setPixelsChanged(true); | 176 buffer.setPixelsChanged(true); |
181 return true; | 177 return true; |
182 } | 178 } |
183 | 179 |
184 bool GIFImageDecoder::parseCompleted() const { | 180 bool GIFImageDecoder::parseCompleted() const { |
185 return m_reader && m_reader->parseCompleted(); | 181 return m_reader && m_reader->parseCompleted(); |
186 } | 182 } |
187 | 183 |
188 bool GIFImageDecoder::frameComplete(size_t frameIndex) { | 184 bool GIFImageDecoder::frameComplete(size_t frameIndex) { |
189 // Initialize the frame if necessary. Some GIFs insert do-nothing frames, | 185 // Initialize the frame if necessary. Some GIFs insert do-nothing frames, |
190 // in which case we never reach haveDecodedRow() before getting here. | 186 // in which case we never reach haveDecodedRow() before getting here. |
191 if (!initFrameBuffer(frameIndex)) | 187 if (!initFrameBuffer(frameIndex)) |
192 return setFailed(); | 188 return setFailed(); |
193 | 189 |
194 if (!m_currentBufferSawAlpha) | 190 ImageFrame& buffer = m_frameBufferCache[frameIndex]; |
195 correctAlphaWhenFrameBufferSawNoAlpha(frameIndex); | |
196 | 191 |
197 m_frameBufferCache[frameIndex].setStatus(ImageFrame::FrameComplete); | 192 const GIFFrameContext* frameContext = m_reader->frameContext(frameIndex); |
193 const size_t transparentPixel = frameContext->transparentPixel(); | |
194 buffer.setHasAlpha(transparentPixel != kNotFound); | |
195 | |
196 buffer.setStatus(ImageFrame::FrameComplete); | |
198 | 197 |
199 return true; | 198 return true; |
200 } | 199 } |
201 | 200 |
202 void GIFImageDecoder::clearFrameBuffer(size_t frameIndex) { | 201 void GIFImageDecoder::clearFrameBuffer(size_t frameIndex) { |
203 if (m_reader && | 202 if (m_reader && |
204 m_frameBufferCache[frameIndex].getStatus() == ImageFrame::FramePartial) { | 203 m_frameBufferCache[frameIndex].getStatus() == ImageFrame::FramePartial) { |
205 // Reset the state of the partial frame in the reader so that the frame | 204 // Reset the state of the partial frame in the reader so that the frame |
206 // can be decoded again when requested. | 205 // can be decoded again when requested. |
207 m_reader->clearDecodeState(frameIndex); | 206 m_reader->clearDecodeState(frameIndex); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 | 261 |
263 if (!m_reader) { | 262 if (!m_reader) { |
264 m_reader = WTF::makeUnique<GIFImageReader>(this); | 263 m_reader = WTF::makeUnique<GIFImageReader>(this); |
265 m_reader->setData(m_data); | 264 m_reader->setData(m_data); |
266 } | 265 } |
267 | 266 |
268 if (!m_reader->parse(query)) | 267 if (!m_reader->parse(query)) |
269 setFailed(); | 268 setFailed(); |
270 } | 269 } |
271 | 270 |
272 void GIFImageDecoder::onInitFrameBuffer(size_t frameIndex) { | |
273 m_currentBufferSawAlpha = false; | |
274 } | |
275 | |
276 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { | 271 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { |
277 DCHECK(frameIndex < m_frameBufferCache.size()); | 272 DCHECK(frameIndex < m_frameBufferCache.size()); |
278 return m_frameBufferCache[frameIndex].getDisposalMethod() != | 273 return m_frameBufferCache[frameIndex].getDisposalMethod() != |
279 ImageFrame::DisposeOverwritePrevious; | 274 ImageFrame::DisposeOverwritePrevious; |
280 } | 275 } |
281 | 276 |
282 } // namespace blink | 277 } // namespace blink |
OLD | NEW |