]> Creatis software - gdcm.git/blob - src/jpeg/ljpg/predict.h
*FIX: When copying a Makefile.am to CMakeLists.txt one should remove the '\'
[gdcm.git] / src / jpeg / ljpg / predict.h
1 /*
2  * predict.h --
3  *
4  * Code for predictor calculation. Its function version, predictor.c,
5  * is used in debugging compilation.
6  */
7 /*
8  * $Id: predict.h,v 1.1 2003/10/21 12:08:54 jpr Exp $
9  */
10 #ifndef _PREDICTOR
11 #define _PREDICTOR
12
13 #ifndef DEBUG
14
15 /*
16  *--------------------------------------------------------------
17  *
18  * Predict --
19  *
20  *      Calculate the predictor for pixel[row][col][curComp],
21  *      i.e. curRowBuf[col][curComp]. It handles the all special 
22  *      cases at image edges, such as first row and first column
23  *      of a scan.
24  *
25  * Results:
26  *      predictor is passed out.
27  *
28  * Side effects:
29  *      None.
30  *
31  *--------------------------------------------------------------
32  */
33 #define Predict(row,col,curComp,curRowBuf,prevRowBuf,Pr,Pt,psv,predictor) \
34 {    register int left,upper,diag,leftcol;                                \
35                                                                           \
36     leftcol=col-1;                                                        \
37     if (row==0) {                                                         \
38                                                                           \
39        /*                                                                 \
40         * The predictor of first pixel is (1<<(Pr-Pt-1), and the          \
41         * predictors for rest of first row are left neighbors.            \
42         */                                                                \
43        if (col==0) {                                                      \
44           *predictor = (1<<(Pr-Pt-1));                                    \
45        }                                                                  \
46        else {                                                             \
47           *predictor = curRowBuf[leftcol][curComp];                       \
48        }                                                                  \
49     }                                                                     \
50     else {                                                                \
51                                                                           \
52        /*                                                                 \
53         * The predictors of first column are upper neighbors.             \
54         * All other preditors are calculated according to psv.            \
55         */                                                                \
56        upper=prevRowBuf[col][curComp];                                    \
57        if (col==0)                                                        \
58           *predictor = upper;                                             \
59        else {                                                             \
60           left=curRowBuf[leftcol][curComp];                               \
61           diag=prevRowBuf[leftcol][curComp];                              \
62           switch (psv) {                                                  \
63              case 0:                                                      \
64                      *predictor = 0;                                      \
65                      break;                                               \
66              case 1:                                                      \
67                      *predictor = left;                                   \
68                      break;                                               \
69              case 2:                                                      \
70                      *predictor = upper;                                  \
71                      break;                                               \
72              case 3:                                                      \
73                      *predictor = diag;                                   \
74                      break;                                               \
75              case 4:                                                      \
76                      *predictor = left+upper-diag;                        \
77                      break;                                               \
78              case 5:                                                      \
79                      *predictor = left+((upper-diag)>>1);                 \
80                      break;                                               \
81              case 6:                                                      \
82                      *predictor = upper+((left-diag)>>1);                 \
83                      break;                                               \
84              case 7:                                                      \
85                      *predictor = (left+upper)>>1;                        \
86                      break;                                               \
87              default:                                                     \
88                      fprintf(stderr,"Warning: Undefined PSV\n");          \
89                      *predictor = 0;                                      \
90            }                                                              \
91         }                                                                 \
92       }                                                                   \
93 }
94
95 /*
96  *--------------------------------------------------------------
97  *
98  * QuickPredict --
99  *
100  *      Calculate the predictor for sample curRowBuf[col][curComp].
101  *        It does not handle the special cases at image edges, such 
102  *      as first row and first column of a scan. We put the special 
103  *        case checkings outside so that the computations in main
104  *        loop can be simpler. This has enhenced the performance
105  *        significantly.
106  *
107  * Results:
108  *      predictor is passed out.
109  *
110  * Side effects:
111  *      None.
112  *
113  *--------------------------------------------------------------
114  */
115 #define QuickPredict(col,curComp,curRowBuf,prevRowBuf,psv,predictor){     \
116     register int left,upper,diag,leftcol;                                 \
117                                                                           \
118     /*                                                                    \
119      * All predictor are calculated according to psv.                     \
120      */                                                                   \
121     switch (psv) {                                                        \
122       case 0:                                                             \
123               *predictor = 0;                                             \
124               break;                                                      \
125       case 1:                                                             \
126               *predictor = curRowBuf [col-1] [curComp];                   \
127               break;                                                      \
128       case 2:                                                             \
129               *predictor = prevRowBuf[col][curComp];                      \
130               break;                                                      \
131       case 3:                                                             \
132               *predictor = prevRowBuf [col-1] [curComp];                  \
133               break;                                                      \
134       case 4:                                                             \
135                   leftcol = col-1;                                        \
136                   upper   = prevRowBuf[col][curComp];                     \
137                   left    = curRowBuf[leftcol][curComp];                  \
138                   diag    = prevRowBuf[leftcol][curComp];                 \
139               *predictor = left + upper - diag;                           \
140               break;                                                      \
141       case 5:                                                             \
142                   leftcol = col-1;                                        \
143                   upper   = prevRowBuf[col][curComp];                     \
144                   left    = curRowBuf[leftcol][curComp];                  \
145                   diag    = prevRowBuf[leftcol][curComp];                 \
146               *predictor = left+((upper-diag)>>1);                        \
147               break;                                                      \
148       case 6:                                                             \
149                   leftcol = col-1;                                        \
150                   upper   = prevRowBuf[col][curComp];                     \
151                   left    = curRowBuf[leftcol][curComp];                  \
152                   diag    = prevRowBuf[leftcol][curComp];                 \
153               *predictor = upper+((left-diag)>>1);                        \
154               break;                                                      \
155       case 7:                                                             \
156                   leftcol = col-1;                                        \
157                   upper   = prevRowBuf[col][curComp];                     \
158                   left    = curRowBuf[leftcol][curComp];                  \
159               *predictor = (left+upper)>>1;                               \
160               break;                                                      \
161       default:                                                            \
162               fprintf(stderr,"Warning: Undefined PSV\n");                 \
163               *predictor = 0;                                             \
164      }                                                                    \
165 }
166
167 #endif /* DEBUG */
168 #endif /* _PREDICTOR */