📄 tif_getimage.c
字号:
*/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, w/ Map => RGB */DECLAREContigPutFunc(putRGBcontig8bitMaptile){ TIFFRGBValue* Map = img->Map; int samplesperpixel = img->samplesperpixel; (void) y; fromskew *= samplesperpixel; while (h-- > 0) { for (x = w; x-- > 0;) { *cp++ = PACK(Map[pp[0]], Map[pp[1]], Map[pp[2]]); pp += samplesperpixel; } pp += fromskew; cp += toskew; }}/* * 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; for (x = w; x-- > 0;) { a = pp[3]; r = (pp[0] * a) / 255; g = (pp[1] * a) / 255; b = (pp[2] * a) / 255; *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++ = PACKW(wp[0], wp[1], 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++ = PACKW4(wp[0], wp[1], wp[2], 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; /* * We shift alpha down four bits just in case unsigned * arithmetic doesn't handle the full range. * We still have plenty of accuracy, since the output is 8 bits. * So we have (r * 0xffff) * (a * 0xfff)) = r*a * (0xffff*0xfff) * Since we want r*a * 0xff for eight bit output, * we divide by (0xffff * 0xfff) / 0xff == 0x10eff. */ for (x = w; x-- > 0;) { a = wp[3] >> 4; r = (wp[0] * a) / 0x10eff; g = (wp[1] * a) / 0x10eff; b = (wp[2] * a) / 0x10eff; *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,\ u_char* r, u_char* g, u_char* b, u_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 => RGB */DECLARESepPutFunc(putRGBseparate8bitMaptile){ TIFFRGBValue* Map = img->Map; (void) y; (void) a; while (h-- > 0) { for (x = w; x > 0; x--) *cp++ = PACK(Map[*r++], Map[*g++], Map[*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; for (x = w; x-- > 0;) { av = *a++; rv = (*r++ * av) / 255; gv = (*g++ * av) / 255; bv = (*b++ * av) / 255; *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++ = PACKW(*wr++, *wg++, *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++ = PACKW4(*wr++, *wg++, *wb++, *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; /* * We shift alpha down four bits just in case unsigned * arithmetic doesn't handle the full range. * We still have plenty of accuracy, since the output is 8 bits. * So we have (r * 0xffff) * (a * 0xfff)) = r*a * (0xffff*0xfff) * Since we want r*a * 0xff for eight bit output, * we divide by (0xffff * 0xfff) / 0xff == 0x10eff. */ for (x = w; x-- > 0;) { a = *wa++ >> 4; r = (*wr++ * a) / 0x10eff; g = (*wg++ * a) / 0x10eff; b = (*wb++ * a) / 0x10eff; *cp++ = PACK4(r,g,b,a); } SKEW4(wr, wg, wb, wa, fromskew); cp += toskew; }}/* * YCbCr -> RGB conversion and packing routines. The colorspace * conversion algorithm comes from the IJG v5a code; see below * for more information on how it works. */#define YCbCrtoRGB(dst, yc) { \ int Y = (yc); \ dst = PACK( \ clamptab[Y+Crrtab[Cr]], \ clamptab[Y + (int)((Cbgtab[Cb]+Crgtab[Cr])>>16)], \ clamptab[Y+Cbbtab[Cb]]); \}#define YCbCrSetup \ TIFFYCbCrToRGB* ycbcr = img->ycbcr; \ int* Crrtab = ycbcr->Cr_r_tab; \ int* Cbbtab = ycbcr->Cb_b_tab; \ int32* Crgtab = ycbcr->Cr_g_tab; \ int32* Cbgtab = ycbcr->Cb_g_tab; \ TIFFRGBValue* clamptab = ycbcr->clamptab/* * 8-bit packed YCbCr samples => RGB * This function is generic for different sampling sizes, * and can handle blocks sizes that aren't multiples of the * sampling size. However, it is substantially less optimized * than the specific sampling cases. It is used as a fallback * for difficult blocks. */#ifdef notdefstatic void putcontig8bitYCbCrGenericTile( TIFFRGBAImage* img, uint32* cp, uint32 x, uint32 y, uint32 w, uint32 h, int32 fromskew, int32 toskew, u_char* pp, int h_group, int v_group ){ YCbCrSetup; uint32* cp1 = cp+w+toskew; uint32* cp2 = cp1+w+toskew; uint32* cp3 = cp2+w+toskew; int32 incr = 3*w+4*toskew; int Cb, Cr; int group_size = v_group * h_group + 2; (void) y; fromskew = (fromskew * group_size) / h_group; for( yy = 0; yy < h; yy++ ) { u_char *pp_line; int y_line_group = yy / v_group; int y_remainder = yy - y_line_group * v_group; pp_line = pp + v_line_group * for( xx = 0; xx < w; xx++ ) { Cb = pp } } for (; h >= 4; h -= 4) { x = w>>2; do { Cb = pp[16]; Cr = pp[17]; YCbCrtoRGB(cp [0], pp[ 0]); YCbCrtoRGB(cp [1], pp[ 1]); YCbCrtoRGB(cp [2], pp[ 2]); YCbCrtoRGB(cp [3], pp[ 3]); YCbCrtoRGB(cp1[0], pp[ 4]); YCbCrtoRGB(cp1[1], pp[ 5]); YCbCrtoRGB(cp1[2], pp[ 6]); YCbCrtoRGB(cp1[3], pp[ 7]); YCbCrtoRGB(cp2[0], pp[ 8]); YCbCrtoRGB(cp2[1], pp[ 9]); YCbCrtoRGB(cp2[2], pp[10]); YCbCrtoRGB(cp2[3], pp[11]); YCbCrtoRGB(cp3[0], pp[12]); YCbCrtoRGB(cp3[1], pp[13]); YCbCrtoRGB(cp3[2], pp[14]); YCbCrtoRGB(cp3[3], pp[15]); cp += 4, cp1 += 4, cp2 += 4, cp3 += 4; pp += 18; } while (--x); cp += incr, cp1 += incr, cp2 += incr, cp3 += incr; pp += fromskew; }}#endif/* * 8-bit packed YCbCr samples w/ 4,4 subsampling => RGB */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -