GIFImageReader to read from source data directly
authorhclam@chromium.org <hclam@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Feb 2013 21:38:10 +0000 (21:38 +0000)
committerhclam@chromium.org <hclam@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Feb 2013 21:38:10 +0000 (21:38 +0000)
commitb6fa1cf353799e5a4e126890cf38207851a3a1c4
treea5f92448ed11db0e7b234df13b121e9ee3662f11
parent9f13a5be35c43137dd543f479e2b3a8760dac01c
GIFImageReader to read from source data directly
https://bugs.webkit.org/show_bug.cgi?id=109662

Reviewed by Stephen White.

Source/WebCore:

This is the first patch to improve GIF image decoding.

GIFImageReader has an internal 256 bytes buffer to saving incoming
bytes. This mechanism is out-dated because WebKit holds the entire
file in memory and it is not necessary to hold data in an intermediate
buffer.

This is also a blocker for later work to parse and decode GIF
incrementally.

This change removed the imtermediate 'hold' buffer and uses an index
for data position to keep track of parsing of the GIF file. Buffer for
global colormap and local colormap are also removed because they can be
referenced from the data stream.

This change is tested by:

Layout tests
All tests passed under fast/images.

Unit tests
Added GIFImageDecoderTest for Chromium.

Local testing
I tested this implementation against a set of 50k GIF images and
there's no crashes and produces bit-exact results as previous code.

* platform/image-decoders/gif/GIFImageDecoder.cpp:
(WebCore::GIFImageDecoder::setData):
(WebCore::GIFImageDecoder::frameCount):
(WebCore::GIFImageDecoder::haveDecodedRow):
(WebCore::GIFImageDecoder::decode):
* platform/image-decoders/gif/GIFImageReader.cpp:
(GIFImageReader::doLZW):
(GIFImageReader::decode):
(GIFImageReader::decodeInternal):
(GIFImageReader::setRemainingBytes):
* platform/image-decoders/gif/GIFImageReader.h:
(GIFFrameContext):
(GIFFrameContext::GIFFrameContext):
(GIFFrameContext::~GIFFrameContext):
(GIFImageReader::GIFImageReader):
(GIFImageReader::~GIFImageReader):
(GIFImageReader::setData):
(GIFImageReader):
(GIFImageReader::globalColormap):
(GIFImageReader::localColormap):
(GIFImageReader::localColormapSize):
(GIFImageReader::data):
(GIFImageReader::colormap):

Source/WebKit/chromium:

Added the following unit tests to test new logic in GIFImageDecoder:

GIFImageDecoderTest.decodeTwoFrames
Test that it can decode a multi-frame GIF image correctly.

GIFImageDecoderTest.parseAndDecode
First perform a parse operation and then a decode operation. Expect
that parse and decode operates correctly.

GIFImageDecoderTest.parseByteByByte
Test that multi-frame GIF image can be parsed correctly byte by byte.

GIFImageDecoderTest.parseAndDecodeByteByByte
Run a loop to feed decoder byte by byte, perform a parse and then
decode operation and make sure frames are decoded correctly.

GIFImageDecoderTest.brokenSecondFrame
Decode a GIF image with second frame broken. Expect that the first
frame can be decoded correctly.

* WebKit.gypi:
* tests/GIFImageDecoderTest.cpp: Added.
(WebKit):
(WebKit::readFile):
(WebKit::TEST):
* tests/data/broken.gif: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@144100 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp
Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.h
Source/WebCore/platform/image-decoders/gif/GIFImageReader.cpp
Source/WebCore/platform/image-decoders/gif/GIFImageReader.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/WebKit.gypi
Source/WebKit/chromium/tests/GIFImageDecoderTest.cpp [new file with mode: 0644]
Source/WebKit/chromium/tests/data/broken.gif [new file with mode: 0644]