Ticket #190: patchtiff.2.diff

File patchtiff.2.diff, 2.8 KB (added by Carl Eugen Hoyos, 15 years ago)
  • libavcodec/tiff.c

    diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
    index a42b27f..1997e54 100644
    a b static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,  
    102102}
    103103#endif
    104104
     105static void av_always_inline horizontal_fill(unsigned int bpp, uint8_t* dst,
     106                                             int usePtr, const uint8_t *src,
     107                                             uint8_t c, int width, int offset)
     108{
     109    int i;
     110
     111    if (bpp == 2) {
     112        for (i = 0; i < width; i++) {
     113            dst[(i+offset)*4+0] = (usePtr ? src[i] : c) >> 6;
     114            dst[(i+offset)*4+1] = (usePtr ? src[i] : c) >> 4 & 0x3;
     115            dst[(i+offset)*4+2] = (usePtr ? src[i] : c) >> 2 & 0x3;
     116            dst[(i+offset)*4+3] = (usePtr ? src[i] : c) & 0x3;
     117        }
     118    } else if (bpp == 4) {
     119        for (i = 0; i < width; i++) {
     120            dst[(i+offset)*2+0] = (usePtr ? src[i] : c) >> 4;
     121            dst[(i+offset)*2+1] = (usePtr ? src[i] : c) & 0xF;
     122        }
     123    } else {
     124        if (usePtr) {
     125            memcpy(dst + offset, src, width);
     126        } else {
     127            memset(dst + offset, c, width);
     128        }
     129    }
     130}
     131
    105132static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uint8_t *src, int size, int lines){
    106133    int c, line, pixels, code;
    107134    const uint8_t *ssrc = src;
    static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin  
    173200        switch(s->compr){
    174201        case TIFF_RAW:
    175202            if (!s->fill_order) {
    176                 memcpy(dst, src, width);
     203                horizontal_fill(s->bpp, dst, 1, src, 0, width, 0);
    177204            } else {
    178205                int i;
    179206                for (i = 0; i < width; i++)
    static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin  
    190217                        av_log(s->avctx, AV_LOG_ERROR, "Copy went out of bounds\n");
    191218                        return -1;
    192219                    }
    193                     memcpy(dst + pixels, src, code);
     220                    horizontal_fill(s->bpp, dst, 1, src, 0, code, pixels);
    194221                    src += code;
    195222                    pixels += code;
    196223                }else if(code != -128){ // -127..-1
    static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin  
    200227                        return -1;
    201228                    }
    202229                    c = *src++;
    203                     memset(dst + pixels, c, code);
     230                    horizontal_fill(s->bpp, dst, 0, NULL, c, code, pixels);
    204231                    pixels += code;
    205232                }
    206233            }
    static int init_image(TiffContext *s)  
    227254    case 11:
    228255        s->avctx->pix_fmt = PIX_FMT_MONOBLACK;
    229256        break;
     257    case 21:
     258    case 41:
    230259    case 81:
    231260        s->avctx->pix_fmt = PIX_FMT_PAL8;
    232261        break;