| 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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 if ((buffer.status() == ImageFrame::FrameEmpty) && !initFrameBuffer(frameInd
ex)) | 221 if ((buffer.status() == ImageFrame::FrameEmpty) && !initFrameBuffer(frameInd
ex)) |
| 222 return false; // initFrameBuffer() has already called setFailed(). | 222 return false; // initFrameBuffer() has already called setFailed(). |
| 223 | 223 |
| 224 buffer.setStatus(ImageFrame::FrameComplete); | 224 buffer.setStatus(ImageFrame::FrameComplete); |
| 225 | 225 |
| 226 if (!m_currentBufferSawAlpha) { | 226 if (!m_currentBufferSawAlpha) { |
| 227 // The whole frame was non-transparent, so it's possible that the entire | 227 // The whole frame was non-transparent, so it's possible that the entire |
| 228 // resulting buffer was non-transparent, and we can setHasAlpha(false). | 228 // resulting buffer was non-transparent, and we can setHasAlpha(false). |
| 229 if (buffer.originalFrameRect().contains(IntRect(IntPoint(), size()))) { | 229 if (buffer.originalFrameRect().contains(IntRect(IntPoint(), size()))) { |
| 230 buffer.setHasAlpha(false); | 230 buffer.setHasAlpha(false); |
| 231 buffer.setRequiredPreviousFrameIndex(notFound); | 231 buffer.setRequiredPreviousFrameIndex(kNotFound); |
| 232 } else if (buffer.requiredPreviousFrameIndex() != notFound) { | 232 } else if (buffer.requiredPreviousFrameIndex() != kNotFound) { |
| 233 // Tricky case. This frame does not have alpha only if everywhere | 233 // Tricky case. This frame does not have alpha only if everywhere |
| 234 // outside its rect doesn't have alpha. To know whether this is | 234 // outside its rect doesn't have alpha. To know whether this is |
| 235 // true, we check the start state of the frame -- if it doesn't have | 235 // true, we check the start state of the frame -- if it doesn't have |
| 236 // alpha, we're safe. | 236 // alpha, we're safe. |
| 237 const ImageFrame* prevBuffer = &m_frameBufferCache[buffer.requiredPr
eviousFrameIndex()]; | 237 const ImageFrame* prevBuffer = &m_frameBufferCache[buffer.requiredPr
eviousFrameIndex()]; |
| 238 ASSERT(prevBuffer->disposalMethod() != ImageFrame::DisposeOverwriteP
revious); | 238 ASSERT(prevBuffer->disposalMethod() != ImageFrame::DisposeOverwriteP
revious); |
| 239 | 239 |
| 240 // Now, if we're at a DisposeNotSpecified or DisposeKeep frame, then | 240 // Now, if we're at a DisposeNotSpecified or DisposeKeep frame, then |
| 241 // we can say we have no alpha if that frame had no alpha. But | 241 // we can say we have no alpha if that frame had no alpha. But |
| 242 // since in initFrameBuffer() we already copied that frame's alpha | 242 // since in initFrameBuffer() we already copied that frame's alpha |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 parse(GIFFrameCountQuery); | 320 parse(GIFFrameCountQuery); |
| 321 | 321 |
| 322 if (failed()) | 322 if (failed()) |
| 323 return; | 323 return; |
| 324 | 324 |
| 325 Vector<size_t> framesToDecode; | 325 Vector<size_t> framesToDecode; |
| 326 size_t frameToDecode = frameIndex; | 326 size_t frameToDecode = frameIndex; |
| 327 do { | 327 do { |
| 328 framesToDecode.append(frameToDecode); | 328 framesToDecode.append(frameToDecode); |
| 329 frameToDecode = m_frameBufferCache[frameToDecode].requiredPreviousFrameI
ndex(); | 329 frameToDecode = m_frameBufferCache[frameToDecode].requiredPreviousFrameI
ndex(); |
| 330 } while (frameToDecode != notFound && m_frameBufferCache[frameToDecode].stat
us() != ImageFrame::FrameComplete); | 330 } while (frameToDecode != kNotFound && m_frameBufferCache[frameToDecode].sta
tus() != ImageFrame::FrameComplete); |
| 331 | 331 |
| 332 for (size_t i = framesToDecode.size(); i > 0; --i) { | 332 for (size_t i = framesToDecode.size(); i > 0; --i) { |
| 333 size_t frameIndex = framesToDecode[i - 1]; | 333 size_t frameIndex = framesToDecode[i - 1]; |
| 334 if (!m_reader->decode(frameIndex)) { | 334 if (!m_reader->decode(frameIndex)) { |
| 335 setFailed(); | 335 setFailed(); |
| 336 return; | 336 return; |
| 337 } | 337 } |
| 338 | 338 |
| 339 // We need more data to continue decoding. | 339 // We need more data to continue decoding. |
| 340 if (m_frameBufferCache[frameIndex].status() != ImageFrame::FrameComplete
) | 340 if (m_frameBufferCache[frameIndex].status() != ImageFrame::FrameComplete
) |
| 341 break; | 341 break; |
| 342 } | 342 } |
| 343 | 343 |
| 344 // It is also a fatal error if all data is received and we have decoded all | 344 // It is also a fatal error if all data is received and we have decoded all |
| 345 // frames available but the file is truncated. | 345 // frames available but the file is truncated. |
| 346 if (frameIndex >= m_frameBufferCache.size() - 1 && isAllDataReceived() && m_
reader && !m_reader->parseCompleted()) | 346 if (frameIndex >= m_frameBufferCache.size() - 1 && isAllDataReceived() && m_
reader && !m_reader->parseCompleted()) |
| 347 setFailed(); | 347 setFailed(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 bool GIFImageDecoder::initFrameBuffer(size_t frameIndex) | 350 bool GIFImageDecoder::initFrameBuffer(size_t frameIndex) |
| 351 { | 351 { |
| 352 // Initialize the frame rect in our buffer. | 352 // Initialize the frame rect in our buffer. |
| 353 const GIFFrameContext* frameContext = m_reader->frameContext(frameIndex); | 353 const GIFFrameContext* frameContext = m_reader->frameContext(frameIndex); |
| 354 ImageFrame* const buffer = &m_frameBufferCache[frameIndex]; | 354 ImageFrame* const buffer = &m_frameBufferCache[frameIndex]; |
| 355 | 355 |
| 356 size_t requiredPreviousFrameIndex = buffer->requiredPreviousFrameIndex(); | 356 size_t requiredPreviousFrameIndex = buffer->requiredPreviousFrameIndex(); |
| 357 if (requiredPreviousFrameIndex == notFound) { | 357 if (requiredPreviousFrameIndex == kNotFound) { |
| 358 // This frame doesn't rely on any previous data. | 358 // This frame doesn't rely on any previous data. |
| 359 if (!buffer->setSize(size().width(), size().height())) | 359 if (!buffer->setSize(size().width(), size().height())) |
| 360 return setFailed(); | 360 return setFailed(); |
| 361 } else { | 361 } else { |
| 362 const ImageFrame* prevBuffer = &m_frameBufferCache[requiredPreviousFrame
Index]; | 362 const ImageFrame* prevBuffer = &m_frameBufferCache[requiredPreviousFrame
Index]; |
| 363 ASSERT(prevBuffer->status() == ImageFrame::FrameComplete); | 363 ASSERT(prevBuffer->status() == ImageFrame::FrameComplete); |
| 364 | 364 |
| 365 // Preserve the last frame as the starting state for this frame. | 365 // Preserve the last frame as the starting state for this frame. |
| 366 if (!buffer->copyBitmapData(*prevBuffer)) | 366 if (!buffer->copyBitmapData(*prevBuffer)) |
| 367 return setFailed(); | 367 return setFailed(); |
| 368 | 368 |
| 369 if (prevBuffer->disposalMethod() == ImageFrame::DisposeOverwriteBgcolor)
{ | 369 if (prevBuffer->disposalMethod() == ImageFrame::DisposeOverwriteBgcolor)
{ |
| 370 // We want to clear the previous frame to transparent, without | 370 // We want to clear the previous frame to transparent, without |
| 371 // affecting pixels in the image outside of the frame. | 371 // affecting pixels in the image outside of the frame. |
| 372 const IntRect& prevRect = prevBuffer->originalFrameRect(); | 372 const IntRect& prevRect = prevBuffer->originalFrameRect(); |
| 373 ASSERT(!prevRect.contains(IntRect(IntPoint(), size()))); | 373 ASSERT(!prevRect.contains(IntRect(IntPoint(), size()))); |
| 374 buffer->zeroFillFrameRect(prevRect); | 374 buffer->zeroFillFrameRect(prevRect); |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 | 377 |
| 378 // Update our status to be partially complete. | 378 // Update our status to be partially complete. |
| 379 buffer->setStatus(ImageFrame::FramePartial); | 379 buffer->setStatus(ImageFrame::FramePartial); |
| 380 | 380 |
| 381 // Reset the alpha pixel tracker for this frame. | 381 // Reset the alpha pixel tracker for this frame. |
| 382 m_currentBufferSawAlpha = false; | 382 m_currentBufferSawAlpha = false; |
| 383 return true; | 383 return true; |
| 384 } | 384 } |
| 385 | 385 |
| 386 } // namespace WebCore | 386 } // namespace WebCore |
| OLD | NEW |