コード例 #1
0
ファイル: tif_getimage.c プロジェクト: OS2World/DEV-UTIL-MGL
/*
 * Palette images with <= 8 bits/sample are handled
 * with a table to avoid lots of shifts and masks.  The table
 * is setup so that put*cmaptile (below) can retrieve 8/bitspersample
 * pixel values simply by indexing into the table with one
 * number.
 */
static int
makecmap(TIFFRGBAImage* img)
{
    int bitspersample = img->bitspersample;
    int nsamples = 8 / bitspersample;
    uint16* r = img->redcmap;
    uint16* g = img->greencmap;
    uint16* b = img->bluecmap;
    uint32 *p;
    int i;

    img->PALmap = (uint32**) _TIFFmalloc(
    256*sizeof (uint32 *)+(256*nsamples*sizeof(uint32)));
    if (img->PALmap == NULL) {
    TIFFError(TIFFFileName(img->tif), "No space for Palette mapping table");
    return (0);
    }
    p = (uint32*)(img->PALmap + 256);
    for (i = 0; i < 256; i++) {
    TIFFRGBValue c;
    img->PALmap[i] = p;
#define CMAP(x) c = x; *p++ = PACK(r[c]&0xff, g[c]&0xff, b[c]&0xff);
    switch (bitspersample) {
    case 1:
    CMAP(i>>7);
    CMAP((i>>6)&1);
    CMAP((i>>5)&1);
    CMAP((i>>4)&1);
    CMAP((i>>3)&1);
    CMAP((i>>2)&1);
    CMAP((i>>1)&1);
    CMAP(i&1);
    break;
    case 2:
    CMAP(i>>6);
    CMAP((i>>4)&3);
    CMAP((i>>2)&3);
    CMAP(i&3);
    break;
    case 4:
    CMAP(i>>4);
    CMAP(i&0xf);
    break;
    case 8:
    CMAP(i);
    break;
    }
#undef CMAP
    }
    return (1);
}
コード例 #2
0
ファイル: tiff.c プロジェクト: LambdaCalculus379/SLS-1.02
/*
 * Palette images with <= 8 bits/sample are handled
 * with a table to avoid lots of shifts and masks.  The table
 * is setup so that put*cmaptile (below) can retrieve 8/bitspersample_
 * pixel values simply by indexing into the table with one
 * number.
 */
boolean TIFFRasterImpl::makecmap(
    const u_short* rmap, const u_short* gmap, const u_short* bmap
) {
    register int i;
    int nsamples = 8 / bitspersample_;
    register u_long *p;

    PALmap_ = (u_long **)malloc(
	256*sizeof (u_long *)+(256*nsamples*sizeof(u_long))
    );
    if (PALmap_ == nil) {
	TIFFError(TIFFFileName(tif_), "No space for Palette mapping table");
	return (false);
    }
    p = (u_long *)(PALmap_ + 256);
    for (i = 0; i < 256; i++) {
	PALmap_[i] = p;
#define	CMAP(x)	\
c = x; *p++ = PACK(rmap[c]&0xff, gmap[c]&0xff, bmap[c]&0xff);
	switch (bitspersample_) {
	    register RGBvalue c;
	case 1:
	    CMAP(i>>7);
	    CMAP((i>>6)&1);
	    CMAP((i>>5)&1);
	    CMAP((i>>4)&1);
	    CMAP((i>>3)&1);
	    CMAP((i>>2)&1);
	    CMAP((i>>1)&1);
	    CMAP(i&1);
	    break;
	case 2:
	    CMAP(i>>6);
	    CMAP((i>>4)&3);
	    CMAP((i>>2)&3);
	    CMAP(i&3);
	    break;
	case 4:
	    CMAP(i>>4);
	    CMAP(i&0xf);
	    break;
	case 8:
	    CMAP(i);
	    break;
	}
#undef CMAP
    }
    return (true);
}