Browse code

Fix decoding some 1bpp tiff files, they are palettized.

Fixes ticket #830.

Carl Eugen Hoyos authored on 2011/12/31 10:00:33
Showing 1 changed files
... ...
@@ -107,6 +107,18 @@ static void av_always_inline horizontal_fill(unsigned int bpp, uint8_t* dst,
107 107
                                              uint8_t c, int width, int offset)
108 108
 {
109 109
     switch (bpp) {
110
+    case 1:
111
+        while (--width >= 0) {
112
+            dst[(width+offset)*8+7] = (usePtr ? src[width] : c)      & 0x1;
113
+            dst[(width+offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
114
+            dst[(width+offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
115
+            dst[(width+offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
116
+            dst[(width+offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
117
+            dst[(width+offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
118
+            dst[(width+offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
119
+            dst[(width+offset)*8+0] = (usePtr ? src[width] : c) >> 7;
120
+        }
121
+        break;
110 122
     case 2:
111 123
         while (--width >= 0) {
112 124
             dst[(width+offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
... ...
@@ -149,11 +161,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
149 149
         }
150 150
         src = zbuf;
151 151
         for(line = 0; line < lines; line++){
152
-            if(s->bpp == 4){
153
-                horizontal_fill(s->bpp, dst, 1, src, 0, width, 0);
154
-            }else{
155
-                memcpy(dst, src, width);
156
-            }
152
+            horizontal_fill(s->bpp, dst, 1, src, 0, width, 0);
157 153
             dst += stride;
158 154
             src += width;
159 155
         }
... ...
@@ -194,6 +202,11 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
194 194
             ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, s->compr, s->fax_opts);
195 195
             break;
196 196
         }
197
+        if (s->bpp < 8)
198
+            for (line = 0; line < lines; line++) {
199
+                horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0);
200
+                dst += stride;
201
+            }
197 202
         av_free(src2);
198 203
         return ret;
199 204
     }
... ...
@@ -245,7 +258,7 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
245 245
                 av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n", pixels, width);
246 246
                 return -1;
247 247
             }
248
-            if(s->bpp == 4)
248
+            if (s->bpp < 8)
249 249
                 horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0);
250 250
             break;
251 251
         }
... ...
@@ -261,8 +274,6 @@ static int init_image(TiffContext *s)
261 261
 
262 262
     switch (s->bpp * 10 + s->bppcount) {
263 263
     case 11:
264
-        s->avctx->pix_fmt = PIX_FMT_MONOBLACK;
265
-        break;
266 264
     case 21:
267 265
     case 41:
268 266
     case 81: