diff options
author | Andreas Kling <andreas.kling@nokia.com> | 2010-06-16 03:00:47 (GMT) |
---|---|---|
committer | Andreas Kling <andreas.kling@nokia.com> | 2010-06-16 12:43:15 (GMT) |
commit | 3d03e0a1fdd04e1ab97ba0f95a3a934c879d047e (patch) | |
tree | 3b0d1dc25d1cc55d5c1843b1d1b7cca2ca2c2306 | |
parent | 47d3d5569e25d0e88259e1f0448d87325da0ab6a (diff) | |
download | Qt-3d03e0a1fdd04e1ab97ba0f95a3a934c879d047e.zip Qt-3d03e0a1fdd04e1ab97ba0f95a3a934c879d047e.tar.gz Qt-3d03e0a1fdd04e1ab97ba0f95a3a934c879d047e.tar.bz2 |
Defer allocation of GIF decoding tables/stack.
WebKit creates many image readers but will only retrieve the dimensions
until the image itself is actually needed (i.e appears in the viewport.)
This avoids allocating 16kB per GIF image until it's time to actually
decode it.
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
-rw-r--r-- | src/plugins/imageformats/gif/qgifhandler.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/plugins/imageformats/gif/qgifhandler.cpp b/src/plugins/imageformats/gif/qgifhandler.cpp index 5e2157e..58093aa 100644 --- a/src/plugins/imageformats/gif/qgifhandler.cpp +++ b/src/plugins/imageformats/gif/qgifhandler.cpp @@ -132,8 +132,8 @@ private: int code_size, clear_code, end_code, max_code_size, max_code; int firstcode, oldcode, incode; - short table[2][1<< max_lzw_bits]; - short stack[(1<<(max_lzw_bits))*2]; + short* table[2]; + short* stack; short *sp; bool needfirst; int x, y; @@ -162,6 +162,9 @@ QGIFFormat::QGIFFormat() lcmap = false; newFrame = false; partialNewFrame = false; + table[0] = 0; + table[1] = 0; + stack = 0; } /*! @@ -171,6 +174,7 @@ QGIFFormat::~QGIFFormat() { if (globalcmap) delete[] globalcmap; if (localcmap) delete[] localcmap; + delete [] stack; } void QGIFFormat::disposePrevious(QImage *image) @@ -237,6 +241,12 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length, // CompuServe Incorporated. GIF(sm) is a Service Mark property of // CompuServe Incorporated." + if (!stack) { + stack = new short[(1 << max_lzw_bits) * 4]; + table[0] = &stack[(1 << max_lzw_bits) * 2]; + table[1] = &stack[(1 << max_lzw_bits) * 3]; + } + image->detach(); int bpl = image->bytesPerLine(); unsigned char *bits = image->bits(); |