Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b2feb48

Browse files
committed
fix flush of left-over bits
we were not adjusting for pixel size, thanks MathemanFlo see libvips#1672 (comment)
1 parent 1f8d007 commit b2feb48

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

libvips/foreign/vips2tiff.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,14 @@ eightbit2nbit( Wtiff *wtiff, VipsPel *q, VipsPel *p, int n )
13101310

13111311
/* Any left-over bits? Need to be left-aligned.
13121312
*/
1313-
if( (x & pixel_mask) != 0 )
1314-
*q++ = (bits ^ mask) << (8 - (x & pixel_mask));
1313+
if( (x & pixel_mask) != 0 ) {
1314+
/* The number of bits we've collected in bits and must
1315+
* left-align and flush.
1316+
*/
1317+
int collected_bits = (x & pixel_mask) << (wtiff->bitdepth - 1);
1318+
1319+
*q++ = (bits ^ mask) << (8 - collected_bits);
1320+
}
13151321
}
13161322

13171323
/* Swap the sense of the first channel, if necessary.

0 commit comments

Comments
 (0)