Ticket #190: patchtiff.diff

File patchtiff.diff, 3.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..2ac8355 100644
    a b static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin  
    166166        return ret;
    167167    }
    168168    for(line = 0; line < lines; line++){
     169        int i;
    169170        if(src - ssrc > size){
    170171            av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
    171172            return -1;
    static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin  
    173174        switch(s->compr){
    174175        case TIFF_RAW:
    175176            if (!s->fill_order) {
    176                 memcpy(dst, src, width);
     177                if (s->bpp == 2) {
     178                    for(i = 0; i < width; i++) {
     179                        dst[i*4+0] = src[i] >> 6;
     180                        dst[i*4+1] = src[i] >> 4 & 0x3;
     181                        dst[i*4+2] = src[i] >> 2 & 0x3;
     182                        dst[i*4+3] = src[i] & 0x3;
     183                    }
     184                } else if (s->bpp == 4) {
     185                    for(i = 0; i < width; i++) {
     186                        dst[i*2+0] = src[i] >> 4;
     187                        dst[i*2+1] = src[i] & 0xF;
     188                    }
     189                } else {
     190                    memcpy(dst, src, width);
     191                }
    177192            } else {
    178                 int i;
    179193                for (i = 0; i < width; i++)
    180194                    dst[i] = av_reverse[src[i]];
    181195            }
    static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin  
    190204                        av_log(s->avctx, AV_LOG_ERROR, "Copy went out of bounds\n");
    191205                        return -1;
    192206                    }
    193                     memcpy(dst + pixels, src, code);
     207                    if (s->bpp == 2) {
     208                        for (i = 0; i < code; i++) {
     209                            dst[(pixels+i)*4+0] = src[i] >> 6;
     210                            dst[(pixels+i)*4+1] = src[i] >> 4 & 0x3;
     211                            dst[(pixels+i)*4+2] = src[i] >> 2 & 0x3;
     212                            dst[(pixels+i)*4+3] = src[i] & 0x3;
     213                        }
     214                    } else if (s->bpp == 4) {
     215                        for(i = 0; i < code; i++) {
     216                            dst[(pixels+i)*2+0] = src[i] >> 4;
     217                            dst[(pixels+i)*2+1] = src[i] & 0xF;
     218                        }
     219                    } else {
     220                        memcpy(dst + pixels, src, code);
     221                    }
    194222                    src += code;
    195223                    pixels += code;
    196224                }else if(code != -128){ // -127..-1
    static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin  
    200228                        return -1;
    201229                    }
    202230                    c = *src++;
    203                     memset(dst + pixels, c, code);
     231                    if (s->bpp == 2) {
     232                        for (i = 0; i < code; i++) {
     233                            dst[(pixels+i)*4+0] = c >> 6;
     234                            dst[(pixels+i)*4+1] = c >> 4 & 0x3;
     235                            dst[(pixels+i)*4+2] = c >> 2 & 0x3;
     236                            dst[(pixels+i)*4+3] = c & 0x3;
     237                        }
     238                    } else if (s->bpp == 4) {
     239                        for(i = 0; i < code; i++) {
     240                            dst[(pixels+i)*2+0] = c >> 4;
     241                            dst[(pixels+i)*2+1] = c & 0xF;
     242                        }
     243                    } else {
     244                        memset(dst + pixels, c, code);
     245                    }
    204246                    pixels += code;
    205247                }
    206248            }
    static int init_image(TiffContext *s)  
    227269    case 11:
    228270        s->avctx->pix_fmt = PIX_FMT_MONOBLACK;
    229271        break;
     272    case 21:
     273    case 41:
    230274    case 81:
    231275        s->avctx->pix_fmt = PIX_FMT_PAL8;
    232276        break;