4 * Code for predictor calculation. Its macro version, predictor.h,
5 * is used in non-debugging compilation.
8 * $Id: predict.c,v 1.1 2003/10/21 12:08:54 jpr Exp $
15 *--------------------------------------------------------------
19 * Calculate the predictor for pixel[row][col][curComp],
20 * i.e. curRowBuf[col][curComp]. It handles the all special
21 * cases at image edges, such as first row and first column
25 * predictor is passed out.
30 *--------------------------------------------------------------
33 Predict(int row,int col, /* position of the pixel to be predicted */
34 int curComp, /* the pixel's component that is predicting */
35 MCU *curRowBuf,MCU *prevRowBuf, /* current and previous row of image */
36 int Pr, /* data precision */
37 int Pt, /* point transformation */
38 int psv, /* predictor selection value */
39 int *predictor) /* preditor value (output) */
41 register int left,upper,diag,leftcol;
47 * The predictor of first pixel is (1<<(Pr-Pt-1), and the
48 * predictors for rest of first row are left neighbors.
51 *predictor = (1<<(Pr-Pt-1));
54 *predictor = curRowBuf[leftcol][curComp];
60 * The predictors of first column are upper neighbors.
61 * All other preditors are calculated according to psv.
63 upper=prevRowBuf[col][curComp];
67 left=curRowBuf[leftcol][curComp];
68 diag=prevRowBuf[leftcol][curComp];
83 *predictor = left+upper-diag;
86 *predictor = left+((upper-diag)>>1);
89 *predictor = upper+((left-diag)>>1);
92 *predictor = (left+upper)>>1;
95 fprintf(stderr,"Warning: Undefined PSV\n");
103 *--------------------------------------------------------------
107 * Calculate the predictor for sample curRowBuf[col][curComp].
108 * It does not handle the special cases at image edges, such
109 * as first row and first column of a scan. We put the special
110 * case checkings outside so that the computations in main
111 * loop can be simpler. This has enhenced the performance
115 * predictor is passed out.
120 *--------------------------------------------------------------
123 QuickPredict(int col /* column # of the pixel to be predicted */,
124 int curComp /* the pixel's component that is predicting */,
125 MCU *curRowBuf,MCU *prevRowBuf,/* current and previous row of image */
126 int psv /* predictor selection value */,
127 int predictor /* preditor value (output) */)
129 register int left,upper,diag,leftcol;
132 * All predictor are calculated according to psv.
140 left = curRowBuf[leftcol][curComp];
144 upper = prevRowBuf[col][curComp];
149 diag = prevRowBuf[leftcol][curComp];
154 upper = prevRowBuf[col][curComp];
155 left = curRowBuf[leftcol][curComp];
156 diag = prevRowBuf[leftcol][curComp];
157 *predictor = left + upper - diag;
161 upper = prevRowBuf[col][curComp];
162 left = curRowBuf[leftcol][curComp];
163 diag = prevRowBuf[leftcol][curComp];
164 *predictor = left+((upper-diag)>>1);
168 upper = prevRowBuf[col][curComp];
169 left = curRowBuf[leftcol][curComp];
170 diag = prevRowBuf[leftcol][curComp];
171 *predictor = upper+((left-diag)>>1);
175 upper = prevRowBuf[col][curComp];
176 left = curRowBuf[leftcol][curComp];
177 *predictor = (left+upper)>>1;
180 fprintf(stderr,"Warning: Undefined PSV\n");