From 3d03e0a1fdd04e1ab97ba0f95a3a934c879d047e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 16 Jun 2010 05:00:47 +0200 Subject: Defer allocation of GIF decoding tables/stack. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/plugins/imageformats/gif/qgifhandler.cpp | 14 ++++++++++++-- 1 file 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(); -- cgit v0.12