From d91c1422a9d0b96172fb13da5a179688b590d125 Mon Sep 17 00:00:00 2001 From: aavit Date: Wed, 7 Nov 2012 15:19:20 +0100 Subject: [PATCH] Fix GIF image decoding: do not zero transparent pixels For the special transparent color index, the decoder would skip writing anything out (thus leaving the pixels at 0 rgba value). Although correct for later frames, for the initial frame this would loose the color information for such pixels (which one otherwise could have made visible e.g. by converting then image to an alpha-less image format). Change-Id: I316cefce8f21797feedebfbf98296ad84eaa4b99 Reviewed-by: Eskil Abrahamsen Blomfeldt (cherry picked from qt/c309d424f45dc0e7b62fbbbabf20dbfe355f48a7) Reviewed-by: aavit --- src/gui/image/qgifhandler.cpp | 15 ++++++--------- tests/auto/gui/image/qimagereader/images/trans.gif | Bin 0 -> 3234 bytes tests/auto/gui/image/qimagereader/tst_qimagereader.cpp | 9 +++++++++ 3 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 tests/auto/gui/image/qimagereader/images/trans.gif diff --git a/src/gui/image/qgifhandler.cpp b/src/gui/image/qgifhandler.cpp index cedb27c..b60d1a1 100644 --- a/src/gui/image/qgifhandler.cpp +++ b/src/gui/image/qgifhandler.cpp @@ -488,7 +488,7 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length, } else { if (needfirst) { firstcode=oldcode=code; - if (!out_of_bounds && image->height() > y && firstcode!=trans_index) + if (!out_of_bounds && image->height() > y && ((frame == 0) || (firstcode != trans_index))) ((QRgb*)FAST_SCAN_LINE(bits, bpl, y))[x] = color(firstcode); x++; if (x>=swidth) out_of_bounds = true; @@ -540,17 +540,13 @@ int QGIFFormat::decode(QImage *image, const uchar *buffer, int length, } oldcode=incode; const int h = image->height(); - const QRgb *map = lcmap ? localcmap : globalcmap; QRgb *line = 0; if (!out_of_bounds && h > y) line = (QRgb*)FAST_SCAN_LINE(bits, bpl, y); while (sp>stack) { const uchar index = *(--sp); - if (!out_of_bounds && h > y && index!=trans_index) { - if (index > ncols) - line[x] = Q_TRANSPARENT; - else - line[x] = map ? map[index] : 0; + if (!out_of_bounds && h > y && ((frame == 0) || (index != trans_index))) { + line[x] = color(index); } x++; if (x>=swidth) out_of_bounds = true; @@ -1031,11 +1027,12 @@ void QGIFFormat::nextY(unsigned char *bits, int bpl) inline QRgb QGIFFormat::color(uchar index) const { - if (index == trans_index || index > ncols) + if (index > ncols) return Q_TRANSPARENT; QRgb *map = lcmap ? localcmap : globalcmap; - return map ? map[index] : 0; + QRgb col = map ? map[index] : 0; + return index == trans_index ? col & Q_TRANSPARENT : col; } //------------------------------------------------------------------------- diff --git a/tests/auto/gui/image/qimagereader/images/trans.gif b/tests/auto/gui/image/qimagereader/images/trans.gif new file mode 100644 index 0000000000000000000000000000000000000000..e26398af5354d04432ae7c4235f3b6b0194eb1c8 GIT binary patch literal 3234 zcmW+&2{@E%8`i16{YbV{D3U};DTh?wkrs@lC?R=UWhssn6?w-}MB>=@&z7C+`*@WQ z%7`o#eYUKTC40^HzjL1Jn(Li;=DF|tx$pOz>zdP=r<7H${9N{P*<3IWF6MtP=6?qh ze_}E#adlQE)lUF|fCNDj1R@BEAZUUh009620YL%+0fGVq4Y)%95)cw3BoHJhNYIcA z10(@Sf+Pt<5)?_$B$o&v0wRJ$1VRLb2pSQX8c+nJ2$CWYMNkw$Qv?xQ7b@KmvdOpa7up6y&xb1SA9q0tx~e0=zUHf+QeGfJi`* zfF=R9fng8<5&?t&g#e8JHin5H1xN}Y3Q!cFDS)kFYDfc;28ad}4QLt=1jJ&HYZM}` z2}l!=01$A+A;~3%6c+^X6z<_7Aw&>T5YiY&LcAhwkt9SUq)14U5Qm7D#zQ262tf)# z8bKT@wt-h@>H+Aw@%)h6F)ktC*VP#!OP&2uT8v0C2@fu2GWW znji`8f?Ro$D}{+M4F=&6+~5`>Ns1(C%!EiB8D0^$5F#l=(ul;DibKRp;~_+m6h+b$ ziLV*Qifv#RqDhJ-X__PmgoDP$FcIQjGNK7Y00aQnDyBxaVjbdBa z1YQ|0$dyN2DNKxMFbI#}2Dd1LXoLs~0SZBiyCR|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