Mercurial > libavcodec.hg
diff 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 |
line wrap: on
line diff
--- a/tiff.c Thu Oct 26 04:06:08 2006 +0000 +++ b/tiff.c Thu Oct 26 04:15:48 2006 +0000 @@ -23,6 +23,7 @@ #ifdef CONFIG_ZLIB #include <zlib.h> #endif +#include "lzw.h" /* abridged list of TIFF tags */ enum TiffTags{ @@ -74,6 +75,7 @@ uint8_t* stripdata; uint8_t* stripsizes; int stripsize, stripoff; + LZWState *lzw; } TiffContext; static int tget_short(uint8_t **p, int le){ @@ -126,6 +128,12 @@ return 0; } #endif + if(s->compr == TIFF_LZW){ + if(ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0){ + av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n"); + return -1; + } + } for(line = 0; line < lines; line++){ if(src - ssrc > size){ av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n"); @@ -160,6 +168,13 @@ } } break; + case TIFF_LZW: + pixels = ff_lzw_decode(s->lzw, dst, width); + if(pixels < width){ + av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n", pixels, width); + return -1; + } + break; } dst += stride; } @@ -247,6 +262,7 @@ switch(s->compr){ case TIFF_RAW: case TIFF_PACKBITS: + case TIFF_LZW: break; case TIFF_DEFLATE: case TIFF_ADOBE_DEFLATE: @@ -256,9 +272,6 @@ av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n"); return -1; #endif - case TIFF_LZW: - av_log(s->avctx, AV_LOG_ERROR, "LZW: not implemented yet\n"); - return -1; case TIFF_G3: av_log(s->avctx, AV_LOG_ERROR, "CCITT G3 compression is not supported\n"); return -1; @@ -405,6 +418,7 @@ avcodec_get_frame_defaults((AVFrame*)&s->picture); avctx->coded_frame= (AVFrame*)&s->picture; s->picture.data[0] = NULL; + ff_lzw_decode_open(&s->lzw); return 0; } @@ -413,6 +427,7 @@ { TiffContext * const s = avctx->priv_data; + ff_lzw_decode_close(&s->lzw); if(s->picture.data[0]) avctx->release_buffer(avctx, &s->picture); return 0;