comparison tiff.c @ 4080:f426c81afc9e libavcodec

LZW decoder as separate module plus TIFF LZW support
author kostya
date Thu, 26 Oct 2006 04:15:48 +0000
parents 00a0b18cfb92
children c70922cdf2ee
comparison
equal deleted inserted replaced
4079:00a0b18cfb92 4080:f426c81afc9e
21 */ 21 */
22 #include "avcodec.h" 22 #include "avcodec.h"
23 #ifdef CONFIG_ZLIB 23 #ifdef CONFIG_ZLIB
24 #include <zlib.h> 24 #include <zlib.h>
25 #endif 25 #endif
26 #include "lzw.h"
26 27
27 /* abridged list of TIFF tags */ 28 /* abridged list of TIFF tags */
28 enum TiffTags{ 29 enum TiffTags{
29 TIFF_WIDTH = 0x100, 30 TIFF_WIDTH = 0x100,
30 TIFF_HEIGHT, 31 TIFF_HEIGHT,
72 int strips, rps; 73 int strips, rps;
73 int sot; 74 int sot;
74 uint8_t* stripdata; 75 uint8_t* stripdata;
75 uint8_t* stripsizes; 76 uint8_t* stripsizes;
76 int stripsize, stripoff; 77 int stripsize, stripoff;
78 LZWState *lzw;
77 } TiffContext; 79 } TiffContext;
78 80
79 static int tget_short(uint8_t **p, int le){ 81 static int tget_short(uint8_t **p, int le){
80 int v = le ? LE_16(*p) : BE_16(*p); 82 int v = le ? LE_16(*p) : BE_16(*p);
81 *p += 2; 83 *p += 2;
124 } 126 }
125 av_free(zbuf); 127 av_free(zbuf);
126 return 0; 128 return 0;
127 } 129 }
128 #endif 130 #endif
131 if(s->compr == TIFF_LZW){
132 if(ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0){
133 av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
134 return -1;
135 }
136 }
129 for(line = 0; line < lines; line++){ 137 for(line = 0; line < lines; line++){
130 if(src - ssrc > size){ 138 if(src - ssrc > size){
131 av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n"); 139 av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
132 return -1; 140 return -1;
133 } 141 }
158 memset(dst + pixels, c, code); 166 memset(dst + pixels, c, code);
159 pixels += code; 167 pixels += code;
160 } 168 }
161 } 169 }
162 break; 170 break;
171 case TIFF_LZW:
172 pixels = ff_lzw_decode(s->lzw, dst, width);
173 if(pixels < width){
174 av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n", pixels, width);
175 return -1;
176 }
177 break;
163 } 178 }
164 dst += stride; 179 dst += stride;
165 } 180 }
166 return 0; 181 return 0;
167 } 182 }
245 case TIFF_COMPR: 260 case TIFF_COMPR:
246 s->compr = value; 261 s->compr = value;
247 switch(s->compr){ 262 switch(s->compr){
248 case TIFF_RAW: 263 case TIFF_RAW:
249 case TIFF_PACKBITS: 264 case TIFF_PACKBITS:
265 case TIFF_LZW:
250 break; 266 break;
251 case TIFF_DEFLATE: 267 case TIFF_DEFLATE:
252 case TIFF_ADOBE_DEFLATE: 268 case TIFF_ADOBE_DEFLATE:
253 #ifdef CONFIG_ZLIB 269 #ifdef CONFIG_ZLIB
254 break; 270 break;
255 #else 271 #else
256 av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n"); 272 av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
257 return -1; 273 return -1;
258 #endif 274 #endif
259 case TIFF_LZW:
260 av_log(s->avctx, AV_LOG_ERROR, "LZW: not implemented yet\n");
261 return -1;
262 case TIFF_G3: 275 case TIFF_G3:
263 av_log(s->avctx, AV_LOG_ERROR, "CCITT G3 compression is not supported\n"); 276 av_log(s->avctx, AV_LOG_ERROR, "CCITT G3 compression is not supported\n");
264 return -1; 277 return -1;
265 case TIFF_G4: 278 case TIFF_G4:
266 av_log(s->avctx, AV_LOG_ERROR, "CCITT G4 compression is not supported\n"); 279 av_log(s->avctx, AV_LOG_ERROR, "CCITT G4 compression is not supported\n");
403 s->height = 0; 416 s->height = 0;
404 s->avctx = avctx; 417 s->avctx = avctx;
405 avcodec_get_frame_defaults((AVFrame*)&s->picture); 418 avcodec_get_frame_defaults((AVFrame*)&s->picture);
406 avctx->coded_frame= (AVFrame*)&s->picture; 419 avctx->coded_frame= (AVFrame*)&s->picture;
407 s->picture.data[0] = NULL; 420 s->picture.data[0] = NULL;
421 ff_lzw_decode_open(&s->lzw);
408 422
409 return 0; 423 return 0;
410 } 424 }
411 425
412 static int tiff_end(AVCodecContext *avctx) 426 static int tiff_end(AVCodecContext *avctx)
413 { 427 {
414 TiffContext * const s = avctx->priv_data; 428 TiffContext * const s = avctx->priv_data;
415 429
430 ff_lzw_decode_close(&s->lzw);
416 if(s->picture.data[0]) 431 if(s->picture.data[0])
417 avctx->release_buffer(avctx, &s->picture); 432 avctx->release_buffer(avctx, &s->picture);
418 return 0; 433 return 0;
419 } 434 }
420 435