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.gyp:
* WebKit.gypi:
* tests/GIFImageDecoderTest.cpp: Added.
(WebKit):
(WebKit::readFile):
(WebKit::TEST):
* tests/data/broken.gif: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@143936 268f45cc-cd09-0410-ab3c-d52691b4dbfc