📄 tif_predict.c
字号:
_TIFFmemcpy(tmp, cp0, cc); cp = (uint8 *) cp0; for (count = 0; count < wc; count++) { uint32 byte; for (byte = 0; byte < bps; byte++) {#if WORDS_BIGENDIAN cp[bps * count + byte] = tmp[byte * wc + count];#else cp[bps * count + byte] = tmp[(bps - byte - 1) * wc + count];#endif } } _TIFFfree(tmp);}/* * Decode a scanline and apply the predictor routine. */static intPredictorDecodeRow(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s){ TIFFPredictorState *sp = PredictorState(tif); assert(sp != NULL); assert(sp->coderow != NULL); assert(sp->pfunc != NULL); if ((*sp->coderow)(tif, op0, occ0, s)) { (*sp->pfunc)(tif, op0, occ0); return 1; } else return 0;}/* * Decode a tile/strip and apply the predictor routine. * Note that horizontal differencing must be done on a * row-by-row basis. The width of a "row" has already * been calculated at pre-decode time according to the * strip/tile dimensions. */static intPredictorDecodeTile(TIFF* tif, tidata_t op0, tsize_t occ0, tsample_t s){ TIFFPredictorState *sp = PredictorState(tif); assert(sp != NULL); assert(sp->codetile != NULL); if ((*sp->codetile)(tif, op0, occ0, s)) { tsize_t rowsize = sp->rowsize; assert(rowsize > 0); assert(sp->pfunc != NULL); while ((long)occ0 > 0) { (*sp->pfunc)(tif, op0, (tsize_t) rowsize); occ0 -= rowsize; op0 += rowsize; } return 1; } else return 0;}static voidhorDiff8(TIFF* tif, tidata_t cp0, tsize_t cc){ TIFFPredictorState* sp = PredictorState(tif); tsize_t stride = sp->stride; char* cp = (char*) cp0; if (cc > stride) { cc -= stride; /* * Pipeline the most common cases. */ if (stride == 3) { int r1, g1, b1; int r2 = cp[0]; int g2 = cp[1]; int b2 = cp[2]; do { r1 = cp[3]; cp[3] = r1-r2; r2 = r1; g1 = cp[4]; cp[4] = g1-g2; g2 = g1; b1 = cp[5]; cp[5] = b1-b2; b2 = b1; cp += 3; } while ((int32)(cc -= 3) > 0); } else if (stride == 4) { int r1, g1, b1, a1; int r2 = cp[0]; int g2 = cp[1]; int b2 = cp[2]; int a2 = cp[3]; do { r1 = cp[4]; cp[4] = r1-r2; r2 = r1; g1 = cp[5]; cp[5] = g1-g2; g2 = g1; b1 = cp[6]; cp[6] = b1-b2; b2 = b1; a1 = cp[7]; cp[7] = a1-a2; a2 = a1; cp += 4; } while ((int32)(cc -= 4) > 0); } else { cp += cc - 1; do { REPEAT4(stride, cp[stride] -= cp[0]; cp--) } while ((int32)(cc -= stride) > 0); } }}static voidhorDiff16(TIFF* tif, tidata_t cp0, tsize_t cc){ TIFFPredictorState* sp = PredictorState(tif); tsize_t stride = sp->stride; int16 *wp = (int16*) cp0; tsize_t wc = cc/2; if (wc > stride) { wc -= stride; wp += wc - 1; do { REPEAT4(stride, wp[stride] -= wp[0]; wp--) wc -= stride; } while ((int32) wc > 0); }}/* * Floating point predictor differencing routine. */static voidfpDiff(TIFF* tif, tidata_t cp0, tsize_t cc){ tsize_t stride = PredictorState(tif)->stride; uint32 bps = tif->tif_dir.td_bitspersample / 8; tsize_t wc = cc / bps; tsize_t count; uint8 *cp = (uint8 *) cp0; uint8 *tmp = (uint8 *)_TIFFmalloc(cc); if (!tmp) return; _TIFFmemcpy(tmp, cp0, cc); for (count = 0; count < wc; count++) { uint32 byte; for (byte = 0; byte < bps; byte++) {#if WORDS_BIGENDIAN cp[byte * wc + count] = tmp[bps * count + byte];#else cp[(bps - byte - 1) * wc + count] = tmp[bps * count + byte];#endif } } _TIFFfree(tmp); cp = (uint8 *) cp0; cp += cc - stride - 1; for (count = cc; count > stride; count -= stride) REPEAT4(stride, cp[stride] -= cp[0]; cp--)}static intPredictorEncodeRow(TIFF* tif, tidata_t bp, tsize_t cc, tsample_t s){ TIFFPredictorState *sp = PredictorState(tif); assert(sp != NULL); assert(sp->pfunc != NULL); assert(sp->coderow != NULL); /* XXX horizontal differencing alters user's data XXX */ (*sp->pfunc)(tif, bp, cc); return (*sp->coderow)(tif, bp, cc, s);}static intPredictorEncodeTile(TIFF* tif, tidata_t bp0, tsize_t cc0, tsample_t s){ TIFFPredictorState *sp = PredictorState(tif); tsize_t cc = cc0, rowsize; unsigned char* bp = bp0; assert(sp != NULL); assert(sp->pfunc != NULL); assert(sp->codetile != NULL); rowsize = sp->rowsize; assert(rowsize > 0); while ((long)cc > 0) { (*sp->pfunc)(tif, bp, (tsize_t) rowsize); cc -= rowsize; bp += rowsize; } return (*sp->codetile)(tif, bp0, cc0, s);}#define FIELD_PREDICTOR (FIELD_CODEC+0) /* XXX */static const TIFFFieldInfo predictFieldInfo[] = { { TIFFTAG_PREDICTOR, 1, 1, TIFF_SHORT, FIELD_PREDICTOR, FALSE, FALSE, "Predictor" },};#define N(a) (sizeof (a) / sizeof (a[0]))static intPredictorVSetField(TIFF* tif, ttag_t tag, va_list ap){ TIFFPredictorState *sp = PredictorState(tif); assert(sp != NULL); assert(sp->vsetparent != NULL); switch (tag) { case TIFFTAG_PREDICTOR: sp->predictor = (uint16) va_arg(ap, int); TIFFSetFieldBit(tif, FIELD_PREDICTOR); break; default: return (*sp->vsetparent)(tif, tag, ap); } tif->tif_flags |= TIFF_DIRTYDIRECT; return 1;}static intPredictorVGetField(TIFF* tif, ttag_t tag, va_list ap){ TIFFPredictorState *sp = PredictorState(tif); assert(sp != NULL); assert(sp->vgetparent != NULL); switch (tag) { case TIFFTAG_PREDICTOR: *va_arg(ap, uint16*) = sp->predictor; break; default: return (*sp->vgetparent)(tif, tag, ap); } return 1;}static voidPredictorPrintDir(TIFF* tif, FILE* fd, long flags){ TIFFPredictorState* sp = PredictorState(tif); (void) flags; if (TIFFFieldSet(tif,FIELD_PREDICTOR)) { fprintf(fd, " Predictor: "); switch (sp->predictor) { case 1: fprintf(fd, "none "); break; case 2: fprintf(fd, "horizontal differencing "); break; case 3: fprintf(fd, "floating point predictor "); break; } fprintf(fd, "%u (0x%x)\n", sp->predictor, sp->predictor); } if (sp->printdir) (*sp->printdir)(tif, fd, flags);}intTIFFPredictorInit(TIFF* tif){ TIFFPredictorState* sp = PredictorState(tif); assert(sp != 0); /* * Merge codec-specific tag information and * override parent get/set field methods. */ _TIFFMergeFieldInfo(tif, predictFieldInfo, N(predictFieldInfo)); sp->vgetparent = tif->tif_tagmethods.vgetfield; tif->tif_tagmethods.vgetfield = PredictorVGetField;/* hook for predictor tag */ sp->vsetparent = tif->tif_tagmethods.vsetfield; tif->tif_tagmethods.vsetfield = PredictorVSetField;/* hook for predictor tag */ sp->printdir = tif->tif_tagmethods.printdir; tif->tif_tagmethods.printdir = PredictorPrintDir; /* hook for predictor tag */ sp->setupdecode = tif->tif_setupdecode; tif->tif_setupdecode = PredictorSetupDecode; sp->setupencode = tif->tif_setupencode; tif->tif_setupencode = PredictorSetupEncode; sp->predictor = 1; /* default value */ sp->pfunc = NULL; /* no predictor routine */ return 1;}intTIFFPredictorCleanup(TIFF* tif){ TIFFPredictorState* sp = PredictorState(tif); assert(sp != 0); tif->tif_tagmethods.vgetfield = sp->vgetparent; tif->tif_tagmethods.vsetfield = sp->vsetparent; tif->tif_tagmethods.printdir = sp->printdir; tif->tif_setupdecode = sp->setupdecode; tif->tif_setupencode = sp->setupencode; return 1;}/* vim: set ts=8 sts=8 sw=8 noet: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -