| 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; | |
| 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) | |
| 195 correctAlphaWhenFrameBufferSawNoAlpha(frameIndex); | |
| 196 | |
| 197 m_frameBufferCache[frameIndex].setStatus(ImageFrame::FrameComplete); | 190 m_frameBufferCache[frameIndex].setStatus(ImageFrame::FrameComplete); |
| 198 | 191 |
| 199 return true; | 192 return true; |
| 200 } | 193 } |
| 201 | 194 |
| 202 void GIFImageDecoder::clearFrameBuffer(size_t frameIndex) { | 195 void GIFImageDecoder::clearFrameBuffer(size_t frameIndex) { |
| 203 if (m_reader && | 196 if (m_reader && |
| 204 m_frameBufferCache[frameIndex].getStatus() == ImageFrame::FramePartial) { | 197 m_frameBufferCache[frameIndex].getStatus() == ImageFrame::FramePartial) { |
| 205 // Reset the state of the partial frame in the reader so that the frame | 198 // Reset the state of the partial frame in the reader so that the frame |
| 206 // can be decoded again when requested. | 199 // can be decoded again when requested. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 255 |
| 263 if (!m_reader) { | 256 if (!m_reader) { |
| 264 m_reader = WTF::makeUnique<GIFImageReader>(this); | 257 m_reader = WTF::makeUnique<GIFImageReader>(this); |
| 265 m_reader->setData(m_data); | 258 m_reader->setData(m_data); |
| 266 } | 259 } |
| 267 | 260 |
| 268 if (!m_reader->parse(query)) | 261 if (!m_reader->parse(query)) |
| 269 setFailed(); | 262 setFailed(); |
| 270 } | 263 } |
| 271 | 264 |
| 272 void GIFImageDecoder::onInitFrameBuffer(size_t frameIndex) { | |
| 273 m_currentBufferSawAlpha = false; | |
| 274 } | |
| 275 | |
| 276 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { | 265 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { |
| 277 DCHECK(frameIndex < m_frameBufferCache.size()); | 266 DCHECK(frameIndex < m_frameBufferCache.size()); |
| 278 return m_frameBufferCache[frameIndex].getDisposalMethod() != | 267 return m_frameBufferCache[frameIndex].getDisposalMethod() != |
| 279 ImageFrame::DisposeOverwritePrevious; | 268 ImageFrame::DisposeOverwritePrevious; |
| 280 } | 269 } |
| 281 | 270 |
| 282 } // namespace blink | 271 } // namespace blink |
| OLD | NEW |