Ticket #864: patchsunrast1bpp.diff

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

    diff --git a/libavcodec/sunrast.c b/libavcodec/sunrast.c
    index 3e1cea6..c9d1f98 100644
    a b 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;
    9494            break;
    9595        case 8:
    9696            avctx->pix_fmt = PIX_FMT_PAL8;
    … … static int sunrast_decode_frame(AVCodecContext *avctx, void *data,  
    118118    if (buf_end - buf < maplength)
    119119        return AVERROR_INVALIDDATA;
    120120
    121     if (depth != 8 && maplength) {
     121    if (avctx->pix_fmt != PIX_FMT_PAL8 && maplength) {
    122122        av_log(avctx, AV_LOG_WARNING, "useless colormap found or file is corrupted, trying to recover\n");
    123123
    124     } else if (depth == 8) {
     124    } else if (avctx->pix_fmt == PIX_FMT_PAL8) {
    125125        unsigned int len = maplength / 3;
    126126
    127127        if (!maplength) {
    … … static int sunrast_decode_frame(AVCodecContext *avctx, void *data,  
    182182            buf += alen;
    183183        }
    184184    }
     185    if (avctx->pix_fmt == PIX_FMT_PAL8 && depth == 1) {
     186        ptr = p->data[0];
     187        for (y=0; y<h; y++) {
     188            x = w + 7 >> 3;
     189            do {
     190                ptr[8*x+7] = ptr[x]      & 1;
     191                ptr[8*x+6] = ptr[x] >> 1 & 1;
     192                ptr[8*x+5] = ptr[x] >> 2 & 1;
     193                ptr[8*x+4] = ptr[x] >> 3 & 1;
     194                ptr[8*x+3] = ptr[x] >> 4 & 1;
     195                ptr[8*x+2] = ptr[x] >> 5 & 1;
     196                ptr[8*x+1] = ptr[x] >> 6 & 1;
     197                ptr[8*x]   = ptr[x] >> 7;
     198            } while (x--);
     199            ptr += stride;
     200        }
     201    }
    185202
    186203    *picture = s->picture;
    187204    *data_size = sizeof(AVFrame);
    … … AVCodec ff_sunrast_decoder = {  
    206223    .init           = sunrast_init,
    207224    .close          = sunrast_end,
    208225    .decode         = sunrast_decode_frame,
    209     .capabilities   = CODEC_CAP_DR1,
     226//    .capabilities   = CODEC_CAP_DR1,
    210227    .long_name = NULL_IF_CONFIG_SMALL("Sun Rasterfile image"),
    211228};