xp_comm_proj/ReadGeoTiff/libtiff/tif_getimage.c
/*
 * Greyscale images with less than 8 bits/sample are handled
 * with a table to avoid lots of shifts and masks.  The table
 * is setup so that put*bwtile (below) can retrieve 8/bitspersample
 * pixel values simply by indexing into the table with one
 * number.
 */
Greyscale images with less than 8 bits/sample are handled
with a table to avoid lots of shifts and masks.  The table
is setup so that put*bwtile (below) can retrieve 8/bitspersample
pixel values simply by indexing into the table with one
number.
Greyscale images with less than 8 bits / sample are handled with a table to avoid lots of shifts and masks . The table is setup so that put * bwtile ( below ) can retrieve 8 / bitspersample pixel values simply by indexing into the table with one number .
static int
makebwmap(TIFFRGBAImage* img)
{
    TIFFRGBValue* Map = img->Map;
    int bitspersample = img->bitspersample;
    int nsamples = 8 / bitspersample;
    int i;
    uint32* p;
    img->BWmap = (uint32**) _TIFFmalloc(
	256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32)));
    if (img->BWmap == NULL) {
	TIFFError(TIFFFileName(img->tif), "No space for B&W mapping table");
	return (0);
    }
    p = (uint32*)(img->BWmap + 256);
    for (i = 0; i < 256; i++) {
	TIFFRGBValue c;
	img->BWmap[i] = p;
	switch (bitspersample) {
#define	GREY(x)	c = Map[x]; *p++ = PACK(c,c,c);
	case 1:
	    GREY(i>>7);
	    GREY((i>>6)&1);
	    GREY((i>>5)&1);
	    GREY((i>>4)&1);
	    GREY((i>>3)&1);
	    GREY((i>>2)&1);
	    GREY((i>>1)&1);
	    GREY(i&1);
	    break;
	case 2:
	    GREY(i>>6);
	    GREY((i>>4)&3);
	    GREY((i>>2)&3);
	    GREY(i&3);
	    break;
	case 4:
	    GREY(i>>4);
	    GREY(i&0xf);
	    break;
	case 8:
	    GREY(i);
	    break;
	}
#undef	GREY
    }
    return (1);
}
static int makebwmap ( TIFFRGBAImage * img ) { TIFFRGBValue * Map = img -> Map ; int bitspersample = img -> bitspersample ; int nsamples = 8 / bitspersample ; int i ; uint32 * p ; img -> BWmap = ( uint32 * * ) _TIFFmalloc ( 256 * sizeof ( uint32 * ) + ( 256 * nsamples * sizeof ( uint32 ) ) ) ; if ( img -> BWmap == NULL ) { TIFFError ( TIFFFileName ( img -> tif ) , " " ) ; return ( 0 ) ; } p = ( uint32 * ) ( img -> BWmap + 256 ) ; for ( i = 0 ; i < 256 ; i ++ ) { TIFFRGBValue c ; img -> BWmap [ i ] = p ; switch ( bitspersample ) { #define GREY ( x ) 	c = Map[x]; *p++ = PACK(c,c,c); case 1 : GREY ( i >> 7 ) ; GREY ( ( i >> 6 ) & 1 ) ; GREY ( ( i >> 5 ) & 1 ) ; GREY ( ( i >> 4 ) & 1 ) ; GREY ( ( i >> 3 ) & 1 ) ; GREY ( ( i >> 2 ) & 1 ) ; GREY ( ( i >> 1 ) & 1 ) ; GREY ( i & 1 ) ; break ; case 2 : GREY ( i >> 6 ) ; GREY ( ( i >> 4 ) & 3 ) ; GREY ( ( i >> 2 ) & 3 ) ; GREY ( i & 3 ) ; break ; case 4 : GREY ( i >> 4 ) ; GREY ( i & 0xf ) ; break ; case 8 : GREY ( i ) ; break ; } #undef 	GREY } return ( 1 ) ; }
Greyscale images with less than 8 bits/sample are handled
 with a table to avoid lots of shifts and masks.
Greyscale images with less than 8 bits / sample are handled with a table to avoid lots of shifts and masks .