comparison faxcompr.c @ 8481:f456c3aebe1c libavcodec

Get rid of pix_left in the 2d code, it is simpler that way.
author michael
date Fri, 26 Dec 2008 16:57:35 +0000
parents 2f7c09bb6bfb
children ff23c1a249b2
comparison
equal deleted inserted replaced
8480:c0f1e9a9402c 8481:f456c3aebe1c
154 *runs++ = 0; 154 *runs++ = 0;
155 return 0; 155 return 0;
156 } 156 }
157 157
158 static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb, 158 static int decode_group3_2d_line(AVCodecContext *avctx, GetBitContext *gb,
159 int pix_left, int *runs, const int *runend, const int *ref) 159 int width, int *runs, const int *runend, const int *ref)
160 { 160 {
161 int mode = 0, offs = 0, run = 0, saved_run = 0, t; 161 int mode = 0, offs = 0, run = 0, saved_run = 0, t;
162 int run_off = *ref++; 162 int run_off = *ref++;
163 int *run_start = runs; 163 int *run_start = runs;
164 164
165 runend--; // for the last written 0 165 runend--; // for the last written 0
166 166
167 while(pix_left > 0){ 167 while(offs < width){
168 int cmode = get_vlc2(gb, ccitt_group3_2d_vlc.table, 9, 1); 168 int cmode = get_vlc2(gb, ccitt_group3_2d_vlc.table, 9, 1);
169 if(cmode == -1){ 169 if(cmode == -1){
170 av_log(avctx, AV_LOG_ERROR, "Incorrect mode VLC\n"); 170 av_log(avctx, AV_LOG_ERROR, "Incorrect mode VLC\n");
171 return -1; 171 return -1;
172 } 172 }
177 } 177 }
178 if(!cmode){//pass mode 178 if(!cmode){//pass mode
179 run_off += *ref++; 179 run_off += *ref++;
180 run = run_off - offs; 180 run = run_off - offs;
181 run_off += *ref++; 181 run_off += *ref++;
182 pix_left -= run; 182 offs += run;
183 if(pix_left < 0){ 183 if(offs > width){
184 av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); 184 av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n");
185 return -1; 185 return -1;
186 } 186 }
187 offs += run;
188 saved_run += run; 187 saved_run += run;
189 }else if(cmode == 1){//horizontal mode 188 }else if(cmode == 1){//horizontal mode
190 int k; 189 int k;
191 for(k = 0; k < 2; k++){ 190 for(k = 0; k < 2; k++){
192 run = 0; 191 run = 0;
204 if(runs >= runend){ 203 if(runs >= runend){
205 av_log(avctx, AV_LOG_ERROR, "Run overrun\n"); 204 av_log(avctx, AV_LOG_ERROR, "Run overrun\n");
206 return -1; 205 return -1;
207 } 206 }
208 saved_run = 0; 207 saved_run = 0;
209 pix_left -= run; 208 offs += run;
210 if(pix_left < 0){ 209 if(offs > width){
211 av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); 210 av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n");
212 return -1; 211 return -1;
213 } 212 }
214 offs += run;
215 mode = !mode; 213 mode = !mode;
216 } 214 }
217 }else if(cmode == 9 || cmode == 10){ 215 }else if(cmode == 9 || cmode == 10){
218 av_log(avctx, AV_LOG_ERROR, "Special modes are not supported (yet)\n"); 216 av_log(avctx, AV_LOG_ERROR, "Special modes are not supported (yet)\n");
219 return -1; 217 return -1;
221 run = run_off - offs + (cmode - 5); 219 run = run_off - offs + (cmode - 5);
222 if(cmode >= 5) 220 if(cmode >= 5)
223 run_off += *ref++; 221 run_off += *ref++;
224 else 222 else
225 run_off -= *--ref; 223 run_off -= *--ref;
226 pix_left -= run; 224 offs += run;
227 if(pix_left < 0){ 225 if(offs > width){
228 av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n"); 226 av_log(avctx, AV_LOG_ERROR, "Run went out of bounds\n");
229 return -1; 227 return -1;
230 } 228 }
231 offs += run;
232 *runs++ = run + saved_run; 229 *runs++ = run + saved_run;
233 if(runs >= runend){ 230 if(runs >= runend){
234 av_log(avctx, AV_LOG_ERROR, "Run overrun\n"); 231 av_log(avctx, AV_LOG_ERROR, "Run overrun\n");
235 return -1; 232 return -1;
236 } 233 }