diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2019-10-01 22:33:22 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marc@jeanmougin.fr> | 2019-10-01 22:33:22 +0000 |
| commit | 8745fed6c1ae9d773750f491b8a8de4806a0e1c0 (patch) | |
| tree | 9cba4a6beb8aab7c2eaac0bdf2610f23e8929611 /src/display/cairo-utils.cpp | |
| parent | Fix issues pointed by Mc (diff) | |
| download | inkscape-8745fed6c1ae9d773750f491b8a8de4806a0e1c0.tar.gz inkscape-8745fed6c1ae9d773750f491b8a8de4806a0e1c0.zip | |
Fixing shifts for sub-byte PNG packing order
In PNG, pixels are stored left to right with msb first, so the shift of the nth color should be 8-size-n and not n
Fixes https://gitlab.com/inkscape/inkscape/issues/444
Diffstat (limited to 'src/display/cairo-utils.cpp')
| -rw-r--r-- | src/display/cairo-utils.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/display/cairo-utils.cpp b/src/display/cairo-utils.cpp index b7ea59109..d3ca85f7e 100644 --- a/src/display/cairo-utils.cpp +++ b/src/display/cairo-utils.cpp @@ -1544,15 +1544,16 @@ const guchar* pixbuf_to_png(guchar const**rows, guchar* px, int num_rows, int nu *((guint64*)ptr) = (guint64)((b<<40)+(b<<32)+(g<<24)+(g<<16)+(r<<8)+r); } } else { //Grayscale + int realpad = 8 - bit_depth - pad; // in PNG numbers are stored left to right, but in most significant bits first, so the first one processed is the ``big'' mask, etc. if(bit_depth==16) *(guint16*)ptr= ((gray & 0xff00)>>8) + ((gray &0x00ff)<<8); - else *((guint16*)ptr) += guint16(((gray >> (16-bit_depth))<<pad) ); //note the "+=" + else *((guint16*)ptr) += guint16(((gray >> (16-bit_depth))<<realpad) ); //note the "+=" if(color_type & 4) { //Alpha channel if (bit_depth == 16) *((guint32*)(ptr+2)) = a + (a<<8); else - *((guint32*)(ptr)) += guint32((a << 8) >> (16 - bit_depth))<<(bit_depth + pad); + *((guint32*)(ptr)) += guint32((a << 8) >> (16 - bit_depth))<<(bit_depth + realpad); } } |
