From 8745fed6c1ae9d773750f491b8a8de4806a0e1c0 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Wed, 2 Oct 2019 00:33:22 +0200 Subject: 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 --- src/display/cairo-utils.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/display/cairo-utils.cpp') 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))<