?? tif_getimage.c
字號:
#define SKEW4(r,g,b,a,skew) { r += skew; g += skew; b += skew; a+= skew; }#define A1 (((uint32)0xffL)<<24)#define PACK(r,g,b) \ ((uint32)(r)|((uint32)(g)<<8)|((uint32)(b)<<16)|A1)#define PACK4(r,g,b,a) \ ((uint32)(r)|((uint32)(g)<<8)|((uint32)(b)<<16)|((uint32)(a)<<24))#define W2B(v) (((v)>>8)&0xff)/* TODO: PACKW should have be made redundant in favor of Bitdepth16To8 LUT */#define PACKW(r,g,b) \ ((uint32)W2B(r)|((uint32)W2B(g)<<8)|((uint32)W2B(b)<<16)|A1)#define PACKW4(r,g,b,a) \ ((uint32)W2B(r)|((uint32)W2B(g)<<8)|((uint32)W2B(b)<<16)|((uint32)W2B(a)<<24))#define DECLAREContigPutFunc(name) \static void name(\ TIFFRGBAImage* img, \ uint32* cp, \ uint32 x, uint32 y, \ uint32 w, uint32 h, \ int32 fromskew, int32 toskew, \ unsigned char* pp \)/* * 8-bit palette => colormap/RGB */DECLAREContigPutFunc(put8bitcmaptile){ uint32** PALmap = img->PALmap; int samplesperpixel = img->samplesperpixel; (void) y; while (h-- > 0) { for (x = w; x-- > 0;) { *cp++ = PALmap[*pp][0]; pp += samplesperpixel; } cp += toskew; pp += fromskew; }}/* * 4-bit palette => colormap/RGB */DECLAREContigPutFunc(put4bitcmaptile){ uint32** PALmap = img->PALmap; (void) x; (void) y; fromskew /= 2; while (h-- > 0) { uint32* bw; UNROLL2(w, bw = PALmap[*pp++], *cp++ = *bw++); cp += toskew; pp += fromskew; }}/* * 2-bit palette => colormap/RGB */DECLAREContigPutFunc(put2bitcmaptile){ uint32** PALmap = img->PALmap; (void) x; (void) y; fromskew /= 4; while (h-- > 0) { uint32* bw; UNROLL4(w, bw = PALmap[*pp++], *cp++ = *bw++); cp += toskew; pp += fromskew; }}/* * 1-bit palette => colormap/RGB */DECLAREContigPutFunc(put1bitcmaptile){ uint32** PALmap = img->PALmap; (void) x; (void) y; fromskew /= 8; while (h-- > 0) { uint32* bw; UNROLL8(w, bw = PALmap[*pp++], *cp++ = *bw++); cp += toskew; pp += fromskew; }}/* * 8-bit greyscale => colormap/RGB */DECLAREContigPutFunc(putgreytile){ int samplesperpixel = img->samplesperpixel; uint32** BWmap = img->BWmap; (void) y; while (h-- > 0) { for (x = w; x-- > 0;) { *cp++ = BWmap[*pp][0]; pp += samplesperpixel; } cp += toskew; pp += fromskew; }}/* * 16-bit greyscale => colormap/RGB */DECLAREContigPutFunc(put16bitbwtile){ int samplesperpixel = img->samplesperpixel; uint32** BWmap = img->BWmap; (void) y; while (h-- > 0) { uint16 *wp = (uint16 *) pp; for (x = w; x-- > 0;) { /* use high order byte of 16bit value */ *cp++ = BWmap[*wp >> 8][0]; pp += 2 * samplesperpixel; wp += samplesperpixel; } cp += toskew; pp += fromskew; }}/* * 1-bit bilevel => colormap/RGB */DECLAREContigPutFunc(put1bitbwtile){ uint32** BWmap = img->BWmap; (void) x; (void) y; fromskew /= 8; while (h-- > 0) { uint32* bw; UNROLL8(w, bw = BWmap[*pp++], *cp++ = *bw++); cp += toskew; pp += fromskew; }}/* * 2-bit greyscale => colormap/RGB */DECLAREContigPutFunc(put2bitbwtile){ uint32** BWmap = img->BWmap; (void) x; (void) y; fromskew /= 4; while (h-- > 0) { uint32* bw; UNROLL4(w, bw = BWmap[*pp++], *cp++ = *bw++); cp += toskew; pp += fromskew; }}/* * 4-bit greyscale => colormap/RGB */DECLAREContigPutFunc(put4bitbwtile){ uint32** BWmap = img->BWmap; (void) x; (void) y; fromskew /= 2; while (h-- > 0) { uint32* bw; UNROLL2(w, bw = BWmap[*pp++], *cp++ = *bw++); cp += toskew; pp += fromskew; }}/* * 8-bit packed samples, no Map => RGB */DECLAREContigPutFunc(putRGBcontig8bittile){ int samplesperpixel = img->samplesperpixel; (void) x; (void) y; fromskew *= samplesperpixel; while (h-- > 0) { UNROLL8(w, NOP, *cp++ = PACK(pp[0], pp[1], pp[2]); pp += samplesperpixel); cp += toskew; pp += fromskew; }}/* * 8-bit packed samples => RGBA w/ associated alpha * (known to have Map == NULL) */DECLAREContigPutFunc(putRGBAAcontig8bittile){ int samplesperpixel = img->samplesperpixel; (void) x; (void) y; fromskew *= samplesperpixel; while (h-- > 0) { UNROLL8(w, NOP, *cp++ = PACK4(pp[0], pp[1], pp[2], pp[3]); pp += samplesperpixel); cp += toskew; pp += fromskew; }}/* * 8-bit packed samples => RGBA w/ unassociated alpha * (known to have Map == NULL) */DECLAREContigPutFunc(putRGBUAcontig8bittile){ int samplesperpixel = img->samplesperpixel; (void) y; fromskew *= samplesperpixel; while (h-- > 0) { uint32 r, g, b, a; uint8* m; for (x = w; x-- > 0;) { a = pp[3]; m = img->UaToAa+(a<<8); r = m[pp[0]]; g = m[pp[1]]; b = m[pp[2]]; *cp++ = PACK4(r,g,b,a); pp += samplesperpixel; } cp += toskew; pp += fromskew; }}/* * 16-bit packed samples => RGB */DECLAREContigPutFunc(putRGBcontig16bittile){ int samplesperpixel = img->samplesperpixel; uint16 *wp = (uint16 *)pp; (void) y; fromskew *= samplesperpixel; while (h-- > 0) { for (x = w; x-- > 0;) { *cp++ = PACK(img->Bitdepth16To8[wp[0]], img->Bitdepth16To8[wp[1]], img->Bitdepth16To8[wp[2]]); wp += samplesperpixel; } cp += toskew; wp += fromskew; }}/* * 16-bit packed samples => RGBA w/ associated alpha * (known to have Map == NULL) */DECLAREContigPutFunc(putRGBAAcontig16bittile){ int samplesperpixel = img->samplesperpixel; uint16 *wp = (uint16 *)pp; (void) y; fromskew *= samplesperpixel; while (h-- > 0) { for (x = w; x-- > 0;) { *cp++ = PACK4(img->Bitdepth16To8[wp[0]], img->Bitdepth16To8[wp[1]], img->Bitdepth16To8[wp[2]], img->Bitdepth16To8[wp[3]]); wp += samplesperpixel; } cp += toskew; wp += fromskew; }}/* * 16-bit packed samples => RGBA w/ unassociated alpha * (known to have Map == NULL) */DECLAREContigPutFunc(putRGBUAcontig16bittile){ int samplesperpixel = img->samplesperpixel; uint16 *wp = (uint16 *)pp; (void) y; fromskew *= samplesperpixel; while (h-- > 0) { uint32 r,g,b,a; uint8* m; for (x = w; x-- > 0;) { a = img->Bitdepth16To8[wp[3]]; m = img->UaToAa+(a<<8); r = m[img->Bitdepth16To8[wp[0]]]; g = m[img->Bitdepth16To8[wp[1]]]; b = m[img->Bitdepth16To8[wp[2]]]; *cp++ = PACK4(r,g,b,a); wp += samplesperpixel; } cp += toskew; wp += fromskew; }}/* * 8-bit packed CMYK samples w/o Map => RGB * * NB: The conversion of CMYK->RGB is *very* crude. */DECLAREContigPutFunc(putRGBcontig8bitCMYKtile){ int samplesperpixel = img->samplesperpixel; uint16 r, g, b, k; (void) x; (void) y; fromskew *= samplesperpixel; while (h-- > 0) { UNROLL8(w, NOP, k = 255 - pp[3]; r = (k*(255-pp[0]))/255; g = (k*(255-pp[1]))/255; b = (k*(255-pp[2]))/255; *cp++ = PACK(r, g, b); pp += samplesperpixel); cp += toskew; pp += fromskew; }}/* * 8-bit packed CMYK samples w/Map => RGB * * NB: The conversion of CMYK->RGB is *very* crude. */DECLAREContigPutFunc(putRGBcontig8bitCMYKMaptile){ int samplesperpixel = img->samplesperpixel; TIFFRGBValue* Map = img->Map; uint16 r, g, b, k; (void) y; fromskew *= samplesperpixel; while (h-- > 0) { for (x = w; x-- > 0;) { k = 255 - pp[3]; r = (k*(255-pp[0]))/255; g = (k*(255-pp[1]))/255; b = (k*(255-pp[2]))/255; *cp++ = PACK(Map[r], Map[g], Map[b]); pp += samplesperpixel; } pp += fromskew; cp += toskew; }}#define DECLARESepPutFunc(name) \static void name(\ TIFFRGBAImage* img,\ uint32* cp,\ uint32 x, uint32 y, \ uint32 w, uint32 h,\ int32 fromskew, int32 toskew,\ unsigned char* r, unsigned char* g, unsigned char* b, unsigned char* a\)/* * 8-bit unpacked samples => RGB */DECLARESepPutFunc(putRGBseparate8bittile){ (void) img; (void) x; (void) y; (void) a; while (h-- > 0) { UNROLL8(w, NOP, *cp++ = PACK(*r++, *g++, *b++)); SKEW(r, g, b, fromskew); cp += toskew; }}/* * 8-bit unpacked samples => RGBA w/ associated alpha */DECLARESepPutFunc(putRGBAAseparate8bittile){ (void) img; (void) x; (void) y; while (h-- > 0) { UNROLL8(w, NOP, *cp++ = PACK4(*r++, *g++, *b++, *a++)); SKEW4(r, g, b, a, fromskew); cp += toskew; }}/* * 8-bit unpacked samples => RGBA w/ unassociated alpha */DECLARESepPutFunc(putRGBUAseparate8bittile){ (void) img; (void) y; while (h-- > 0) { uint32 rv, gv, bv, av; uint8* m; for (x = w; x-- > 0;) { av = *a++; m = img->UaToAa+(av<<8); rv = m[*r++]; gv = m[*g++]; bv = m[*b++]; *cp++ = PACK4(rv,gv,bv,av); } SKEW4(r, g, b, a, fromskew); cp += toskew; }}/* * 16-bit unpacked samples => RGB */DECLARESepPutFunc(putRGBseparate16bittile){ uint16 *wr = (uint16*) r; uint16 *wg = (uint16*) g; uint16 *wb = (uint16*) b; (void) img; (void) y; (void) a; while (h-- > 0) { for (x = 0; x < w; x++) *cp++ = PACK(img->Bitdepth16To8[*wr++], img->Bitdepth16To8[*wg++], img->Bitdepth16To8[*wb++]); SKEW(wr, wg, wb, fromskew); cp += toskew; }}/* * 16-bit unpacked samples => RGBA w/ associated alpha */DECLARESepPutFunc(putRGBAAseparate16bittile){ uint16 *wr = (uint16*) r; uint16 *wg = (uint16*) g; uint16 *wb = (uint16*) b; uint16 *wa = (uint16*) a; (void) img; (void) y; while (h-- > 0) { for (x = 0; x < w; x++) *cp++ = PACK4(img->Bitdepth16To8[*wr++], img->Bitdepth16To8[*wg++], img->Bitdepth16To8[*wb++], img->Bitdepth16To8[*wa++]); SKEW4(wr, wg, wb, wa, fromskew); cp += toskew; }}/* * 16-bit unpacked samples => RGBA w/ unassociated alpha */DECLARESepPutFunc(putRGBUAseparate16bittile){ uint16 *wr = (uint16*) r; uint16 *wg = (uint16*) g; uint16 *wb = (uint16*) b; uint16 *wa = (uint16*) a; (void) img; (void) y; while (h-- > 0) { uint32 r,g,b,a; uint8* m; for (x = w; x-- > 0;) { a = img->Bitdepth16To8[*wa++]; m = img->UaToAa+(a<<8); r = m[img->Bitdepth16To8[*wr++]]; g = m[img->Bitdepth16To8[*wg++]]; b = m[img->Bitdepth16To8[*wb++]]; *cp++ = PACK4(r,g,b,a); } SKEW4(wr, wg, wb, wa, fromskew); cp += toskew; }}/* * 8-bit packed CIE L*a*b 1976 samples => RGB */DECLAREContigPutFunc(putcontig8bitCIELab){ float X, Y, Z; uint32 r, g, b; (void) y; fromskew *= 3; while (h-- > 0) { for (x = w; x-- > 0;) { TIFFCIELabToXYZ(img->cielab, (unsigned char)pp[0], (signed char)pp[1], (signed char)pp[2], &X, &Y, &Z); TIFFXYZToRGB(img->cielab, X, Y, Z, &r, &g, &b);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -