changeset 8491:902c43f89d92 libavcodec

Enable faxcompr.
author michael
date Fri, 26 Dec 2008 18:42:26 +0000
parents b579b143bbd4
children 639169d7fad5
files Makefile tiff.c
diffstat 2 files changed, 36 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Fri Dec 26 18:39:24 2008 +0000
+++ b/Makefile	Fri Dec 26 18:42:26 2008 +0000
@@ -202,7 +202,7 @@
 OBJS-$(CONFIG_THEORA_DECODER)          += vp3.o xiph.o vp3dsp.o
 OBJS-$(CONFIG_THP_DECODER)             += mjpegdec.o mjpeg.o
 OBJS-$(CONFIG_TIERTEXSEQVIDEO_DECODER) += tiertexseqv.o
-OBJS-$(CONFIG_TIFF_DECODER)            += tiff.o lzw.o
+OBJS-$(CONFIG_TIFF_DECODER)            += tiff.o lzw.o faxcompr.o
 OBJS-$(CONFIG_TIFF_ENCODER)            += tiffenc.o rle.o lzwenc.o
 OBJS-$(CONFIG_TRUEMOTION1_DECODER)     += truemotion1.o
 OBJS-$(CONFIG_TRUEMOTION2_DECODER)     += truemotion2.o
--- a/tiff.c	Fri Dec 26 18:39:24 2008 +0000
+++ b/tiff.c	Fri Dec 26 18:42:26 2008 +0000
@@ -30,6 +30,7 @@
 #endif
 #include "lzw.h"
 #include "tiff.h"
+#include "faxcompr.h"
 
 
 typedef struct TiffContext {
@@ -41,6 +42,7 @@
     int le;
     int compr;
     int invert;
+    int fax_opts;
     int predictor;
 
     int strips, rps, sstype;
@@ -103,6 +105,29 @@
             return -1;
         }
     }
+    if(s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3 || s->compr == TIFF_G4){
+        int i, ret = 0;
+        uint8_t *src2 = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+
+        if(!src2 || (unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE < (unsigned)size){
+            av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
+            return -1;
+        }
+        for(i = 0; i < size; i++)
+            src2[i] = ff_reverse[src[i]];
+        memset(src2+size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
+        if(s->compr == TIFF_G3 && !(s->fax_opts & 1))
+            s->compr = TIFF_CCITT_RLE;
+        switch(s->compr){
+        case TIFF_CCITT_RLE:
+        case TIFF_G3:
+        case TIFF_G4:
+            ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, s->compr);
+            break;
+        }
+        av_free(src2);
+        return ret;
+    }
     for(line = 0; line < lines; line++){
         if(src - ssrc > size){
             av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
@@ -265,6 +290,11 @@
         case TIFF_RAW:
         case TIFF_PACKBITS:
         case TIFF_LZW:
+        case TIFF_CCITT_RLE:
+            break;
+        case TIFF_G3:
+        case TIFF_G4:
+            s->fax_opts = 0;
             break;
         case TIFF_DEFLATE:
         case TIFF_ADOBE_DEFLATE:
@@ -274,15 +304,6 @@
             av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
             return -1;
 #endif
-        case TIFF_G3:
-            av_log(s->avctx, AV_LOG_ERROR, "CCITT G3 compression is not supported\n");
-            return -1;
-        case TIFF_G4:
-            av_log(s->avctx, AV_LOG_ERROR, "CCITT G4 compression is not supported\n");
-            return -1;
-        case TIFF_CCITT_RLE:
-            av_log(s->avctx, AV_LOG_ERROR, "CCITT RLE compression is not supported\n");
-            return -1;
         case TIFF_JPEG:
         case TIFF_NEWJPEG:
             av_log(s->avctx, AV_LOG_ERROR, "JPEG compression is not supported\n");
@@ -373,6 +394,10 @@
             return -1;
         }
         break;
+    case TIFF_T4OPTIONS:
+    case TIFF_T6OPTIONS:
+        s->fax_opts = value;
+        break;
     }
     return 0;
 }
@@ -487,6 +512,7 @@
     avctx->coded_frame= (AVFrame*)&s->picture;
     s->picture.data[0] = NULL;
     ff_lzw_decode_open(&s->lzw);
+    ff_ccitt_unpack_init();
 
     return 0;
 }