2007.07.24 07:16 "[Tiff] TIFFShiftArrayOfLong", by Oliver Geisen

2007.07.27 07:22 "Re: [Tiff] TIFFShiftArrayOfLong", by Oliver Geisen

Hello Andrey,

i've gave up shifting lines as arrays of long's because i could not find any performance enhancement instead of doing it with char's. So here is my char code:

// used by bitshift using chars
const unsigned char Lmask[8] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8,
0xFC, 0xFE };
const unsigned char Rmask[8] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, 0x07,
0x03, 0x01 };

// Shift all bits in an array of chars *data by the given ammount nbits to the left

void TIFFShiftLeftArrayOfChar (char *data, unsigned long nchars,

unsigned int nbits)

     if (nbits == 0)
     if (nbits > 7) {
         fprintf(stderr, "ERROR: Shifting more than 7 bits does not
make sense!\n");

     while (nchars-- > 0) {

         *data = ( ((*(data+1)) & Lmask[nbits]) >> (8-nbits) )
               + ( ((*data)     & Rmask[nbits]) << nbits );


It performs well, maybe the compilier still optimize this by loading all relevant params into CPU registers...

Oliver Geisen
Kreisboten Verlag Mühlfellner KG
82362 Weilheim i. Ob.
Tel. 0881/686-904
Fax 0881/686-74
Sitz Weilheim, AG München, HRA 64016, p.h.G.:
Kreisboten-Verlag Verwaltungsgesellschaft mbH,
Weilheim, AG München, HRB 119773,
Geschäftsführer: Dr. Dirk Ippen, Dr. Gerd Waldenmaier