Ticket #897: patchsunrast4bpp.diff

File patchsunrast4bpp.diff, 3.1 KB (added by Carl Eugen Hoyos, 15 years ago)
  • libavcodec/sunrast.c

    diff --git a/libavcodec/sunrast.c b/libavcodec/sunrast.c
    index c33265d..34ac38a 100644
    a b static int sunrast_decode_frame(AVCodecContext *avctx, void *data,  
    5151    AVFrame *picture = data;
    5252    AVFrame * const p = &s->picture;
    5353    unsigned int w, h, depth, type, maptype, maplength, stride, x, y, len, alen;
    54     uint8_t *ptr;
     54    uint8_t *ptr, *ptr2;
    5555    const uint8_t *bufstart = buf;
    5656
    5757    if (avpkt->size < 32)
    static int sunrast_decode_frame(AVCodecContext *avctx, void *data,  
    9090
    9191    switch (depth) {
    9292        case 1:
    93             avctx->pix_fmt = PIX_FMT_MONOWHITE;
     93            avctx->pix_fmt = maplength ? PIX_FMT_PAL8 : PIX_FMT_MONOWHITE;
     94            break;
     95        case 4:
     96            avctx->pix_fmt = maplength ? PIX_FMT_PAL8 : PIX_FMT_NONE;
    9497            break;
    9598        case 8:
    9699            avctx->pix_fmt = maplength ? PIX_FMT_PAL8 : PIX_FMT_GRAY8;
    static int sunrast_decode_frame(AVCodecContext *avctx, void *data,  
    118121    if (buf_end - buf < maplength)
    119122        return AVERROR_INVALIDDATA;
    120123
    121     if (depth != 8 && maplength) {
     124    if (depth > 8 && maplength) {
    122125        av_log(avctx, AV_LOG_WARNING, "useless colormap found or file is corrupted, trying to recover\n");
    123126
    124127    } else if (maplength) {
    static int sunrast_decode_frame(AVCodecContext *avctx, void *data,  
    140143
    141144    buf += maplength;
    142145
     146    if (maplength && depth < 8) {
     147        ptr = ptr2 = av_malloc((w + 15) * h);
     148        stride = (w + 15 >> 3) * depth;
     149    } else {
    143150    ptr    = p->data[0];
    144151    stride = p->linesize[0];
     152    }
    145153
    146154    /* scanlines are aligned on 16 bit boundaries */
    147155    len  = (depth * w + 7) >> 3;
    static int sunrast_decode_frame(AVCodecContext *avctx, void *data,  
    182190            buf += alen;
    183191        }
    184192    }
     193    if (avctx->pix_fmt == PIX_FMT_PAL8 && depth < 8) {
     194        uint8_t *ptr_free = ptr2;
     195        ptr = p->data[0];
     196        for (y=0; y<h; y++) {
     197            x = (w + 7 >> 3) * depth;
     198            do {
     199                if (depth == 1) {
     200                    ptr[8*x+7] = ptr2[x]      & 1;
     201                    ptr[8*x+6] = ptr2[x] >> 1 & 1;
     202                    ptr[8*x+5] = ptr2[x] >> 2 & 1;
     203                    ptr[8*x+4] = ptr2[x] >> 3 & 1;
     204                    ptr[8*x+3] = ptr2[x] >> 4 & 1;
     205                    ptr[8*x+2] = ptr2[x] >> 5 & 1;
     206                    ptr[8*x+1] = ptr2[x] >> 6 & 1;
     207                    ptr[8*x]   = ptr2[x] >> 7;
     208                } else {
     209                    ptr[2*x+1] = ptr2[x] & 0xF;
     210                    ptr[2*x]   = ptr2[x] >> 4;
     211                }
     212            } while (x--);
     213            ptr  += p->linesize[0];
     214            ptr2 += (w + 15 >> 3) * depth;
     215        }
     216        av_freep(&ptr_free);
     217    }
    185218
    186219    *picture = s->picture;
    187220    *data_size = sizeof(AVFrame);
    AVCodec ff_sunrast_decoder = {  
    206239    .init           = sunrast_init,
    207240    .close          = sunrast_end,
    208241    .decode         = sunrast_decode_frame,
    209     .capabilities   = CODEC_CAP_DR1,
     242//    .capabilities   = CODEC_CAP_DR1,
    210243    .long_name = NULL_IF_CONFIG_SMALL("Sun Rasterfile image"),
    211244};