comparison tiff.c @ 8491:902c43f89d92 libavcodec

Enable faxcompr.
author michael
date Fri, 26 Dec 2008 18:42:26 +0000
parents b3ecaba81501
children 7a463923ecd1
comparison
equal deleted inserted replaced
8490:b579b143bbd4 8491:902c43f89d92
28 #ifdef CONFIG_ZLIB 28 #ifdef CONFIG_ZLIB
29 #include <zlib.h> 29 #include <zlib.h>
30 #endif 30 #endif
31 #include "lzw.h" 31 #include "lzw.h"
32 #include "tiff.h" 32 #include "tiff.h"
33 #include "faxcompr.h"
33 34
34 35
35 typedef struct TiffContext { 36 typedef struct TiffContext {
36 AVCodecContext *avctx; 37 AVCodecContext *avctx;
37 AVFrame picture; 38 AVFrame picture;
39 int width, height; 40 int width, height;
40 unsigned int bpp; 41 unsigned int bpp;
41 int le; 42 int le;
42 int compr; 43 int compr;
43 int invert; 44 int invert;
45 int fax_opts;
44 int predictor; 46 int predictor;
45 47
46 int strips, rps, sstype; 48 int strips, rps, sstype;
47 int sot; 49 int sot;
48 const uint8_t* stripdata; 50 const uint8_t* stripdata;
100 if(s->compr == TIFF_LZW){ 102 if(s->compr == TIFF_LZW){
101 if(ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0){ 103 if(ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0){
102 av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n"); 104 av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
103 return -1; 105 return -1;
104 } 106 }
107 }
108 if(s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3 || s->compr == TIFF_G4){
109 int i, ret = 0;
110 uint8_t *src2 = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
111
112 if(!src2 || (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE < (unsigned)size){
113 av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
114 return -1;
115 }
116 for(i = 0; i < size; i++)
117 src2[i] = ff_reverse[src[i]];
118 memset(src2+size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
119 if(s->compr == TIFF_G3 && !(s->fax_opts & 1))
120 s->compr = TIFF_CCITT_RLE;
121 switch(s->compr){
122 case TIFF_CCITT_RLE:
123 case TIFF_G3:
124 case TIFF_G4:
125 ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, s->compr);
126 break;
127 }
128 av_free(src2);
129 return ret;
105 } 130 }
106 for(line = 0; line < lines; line++){ 131 for(line = 0; line < lines; line++){
107 if(src - ssrc > size){ 132 if(src - ssrc > size){
108 av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n"); 133 av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
109 return -1; 134 return -1;
263 s->predictor = 0; 288 s->predictor = 0;
264 switch(s->compr){ 289 switch(s->compr){
265 case TIFF_RAW: 290 case TIFF_RAW:
266 case TIFF_PACKBITS: 291 case TIFF_PACKBITS:
267 case TIFF_LZW: 292 case TIFF_LZW:
293 case TIFF_CCITT_RLE:
294 break;
295 case TIFF_G3:
296 case TIFF_G4:
297 s->fax_opts = 0;
268 break; 298 break;
269 case TIFF_DEFLATE: 299 case TIFF_DEFLATE:
270 case TIFF_ADOBE_DEFLATE: 300 case TIFF_ADOBE_DEFLATE:
271 #ifdef CONFIG_ZLIB 301 #ifdef CONFIG_ZLIB
272 break; 302 break;
273 #else 303 #else
274 av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n"); 304 av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
275 return -1; 305 return -1;
276 #endif 306 #endif
277 case TIFF_G3:
278 av_log(s->avctx, AV_LOG_ERROR, "CCITT G3 compression is not supported\n");
279 return -1;
280 case TIFF_G4:
281 av_log(s->avctx, AV_LOG_ERROR, "CCITT G4 compression is not supported\n");
282 return -1;
283 case TIFF_CCITT_RLE:
284 av_log(s->avctx, AV_LOG_ERROR, "CCITT RLE compression is not supported\n");
285 return -1;
286 case TIFF_JPEG: 307 case TIFF_JPEG:
287 case TIFF_NEWJPEG: 308 case TIFF_NEWJPEG:
288 av_log(s->avctx, AV_LOG_ERROR, "JPEG compression is not supported\n"); 309 av_log(s->avctx, AV_LOG_ERROR, "JPEG compression is not supported\n");
289 return -1; 310 return -1;
290 default: 311 default:
370 case TIFF_PLANAR: 391 case TIFF_PLANAR:
371 if(value == 2){ 392 if(value == 2){
372 av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n"); 393 av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n");
373 return -1; 394 return -1;
374 } 395 }
396 break;
397 case TIFF_T4OPTIONS:
398 case TIFF_T6OPTIONS:
399 s->fax_opts = value;
375 break; 400 break;
376 } 401 }
377 return 0; 402 return 0;
378 } 403 }
379 404
485 s->avctx = avctx; 510 s->avctx = avctx;
486 avcodec_get_frame_defaults((AVFrame*)&s->picture); 511 avcodec_get_frame_defaults((AVFrame*)&s->picture);
487 avctx->coded_frame= (AVFrame*)&s->picture; 512 avctx->coded_frame= (AVFrame*)&s->picture;
488 s->picture.data[0] = NULL; 513 s->picture.data[0] = NULL;
489 ff_lzw_decode_open(&s->lzw); 514 ff_lzw_decode_open(&s->lzw);
515 ff_ccitt_unpack_init();
490 516
491 return 0; 517 return 0;
492 } 518 }
493 519
494 static av_cold int tiff_end(AVCodecContext *avctx) 520 static av_cold int tiff_end(AVCodecContext *avctx)