[FFmpeg-devel] [PATCH] HAM6/HAM8 support for IFF demuxer/decoder

Stefano Sabatini stefano.sabatini-lala
Sun May 9 17:35:12 CEST 2010


On date Thursday 2010-05-06 23:23:20 +0200, Sebastian Vater encoded:
> Sebastian Vater a ?crit :
> > So, here's a new patch, which removes the call of ff_cmap_read_palette
> > from libavformat/iff.c completely and also removed prototype declaration
> > it from libavcodec/iff.h and made it static with the ff_ prefix removed
> > in libavcodec/iff.c
> >
> > There's no CODEC_ID_RAWVIDEO anymore and decoding the chunky PBM file is
> > done within decode_frame_ilbm now.
> >
> > I should notice, however, I investigated the ASH.LBM file (which is a
> > PBM, but byterun1 compressed).
> >
> > Looking at the demuxer shows me that it normally uses the ILBM code line
> > except that decode_frame_byterun1 handles this special case which showed
> > me that it's the same as decodeplane8 stuff just without calling
> > decodeplane8 at all (so I assume that it's just chunky pixel data).
> >
> > I implemented the same behaviour in decode_frame_ilbm by just memcpy'ing
> > each line into the output buffer.
> >
> > Please review that carefully!
> >   
> 
> Damn, I just forgot to add HAM decoding for PBM files, too...again, I
> have no files to test, but it should do much the same as the
> decodeplane8 and HAM decoding afterwards...the PBM HAM decoders just
> take the chunky data and interpret it as HAM encoding.
> 
> So here's an updated patch, just forget the previous one.
> 
> Big sorry @ all!
> 
> -- 
> 
> Best regards,
>                    :-) Basty/CDGS (-:
> 

> diff --git a/libavcodec/iff.c b/libavcodec/iff.c
> index 7189ac3..f49f35a 100644
> --- a/libavcodec/iff.c
> +++ b/libavcodec/iff.c
> @@ -34,28 +34,78 @@ typedef struct {
>      AVFrame frame;
>      int planesize;
>      uint8_t * planebuf;
> +    uint8_t * ham_buf;
> +    uint32_t *ham_palbuf;
> +    uint8_t   compression;
> +    uint8_t   ham;
> +    uint8_t   ehb;
> +    uint8_t   masking;
> +    uint16_t  transparency;
>  } IffContext;
>  
>  /**
>   * Convert CMAP buffer (stored in extradata) to lavc palette format
>   */
> -int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)
> +static int cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)

This looks fine, but this change deserves a separate patch.

>  {
>      int count, i;
> +    IffContext *s = avctx->priv_data;
>  
>      if (avctx->bits_per_coded_sample > 8) {
>          av_log(avctx, AV_LOG_ERROR, "bit_per_coded_sample > 8 not supported\n");
>          return AVERROR_INVALIDDATA;

> +    } else if (s->masking != MASK_NONE) {
> +        av_log(avctx, AV_LOG_ERROR, "Masking not supported\n");
> +        return AVERROR_INVALIDDATA;
> +    } else if ((s->masking == MASK_HAS_TRANSPARENT_COLOR) && (s->transparency != 0)) {
> +        av_log(avctx, AV_LOG_ERROR, "Transparency not supported\n");
> +        return AVERROR_INVALIDDATA;
>      }

return AVERROR_PATCHWELCOME.

> -    count = 1 << avctx->bits_per_coded_sample;
> -    if (avctx->extradata_size < count * 3) {
> -        av_log(avctx, AV_LOG_ERROR, "palette data underflow\n");
> +    if (s->ham) { // adjust HAM color palette
> +        count = 1 << (avctx->bits_per_coded_sample > 6 ? 6 : 4); // adjust HAM5/HAM7 to HAM6/HAM8
> +    } else if (s->ehb) { // EHB (ExtraHalfBrite) color palette
> +        av_log(avctx, AV_LOG_ERROR, "ExtraHalfBrite (EHB) mode not supported\n");
>          return AVERROR_INVALIDDATA;

AVERROR_PATCHWELCOME

> +    } else {
> +        count = 1 << avctx->bits_per_coded_sample;
>      }
> +    count = FFMIN((avctx->extradata_size - IFF_EXTRA_CONTEXT_SIZE), count);
> +    if (pal) { // PIX_FMT_PAL8 or PIX_FMT_GRAY8
> +        if (avctx->pix_fmt == PIX_FMT_PAL8) {
>      for (i=0; i < count; i++) {
>          pal[i] = 0xFF000000 | AV_RB24( avctx->extradata + i*3 );
>      }
> +        } else { // PIX_FMT_GRAY8 has no color palette, create one
> +            uint8_t *gray_pal = (uint8_t *) pal;
> +            count = 1 << avctx->bits_per_coded_sample;
> +
> +            for (i=0; i < count; i++) {
> +                gray_pal[i] = (i * 255) >> avctx->bits_per_coded_sample;
> +            }
> +        }
> +    } else { // PIX_FMT_BGR32 for HAM requires color palette
> +        s->ham_buf = av_malloc((s->planesize * 8) + FF_INPUT_BUFFER_PADDING_SIZE);
> +        if (!s->ham_buf)
> +            return AVERROR(ENOMEM);
> +
> +        if (count != 0) { // HAM with normal color palette
> +            s->ham_palbuf = av_malloc((count * sizeof (uint32_t)) + FF_INPUT_BUFFER_PADDING_SIZE);
> +            if (!s->ham_palbuf)
> +                return AVERROR(ENOMEM);
> +            for (i=0; i < count; i++) {
> +                s->ham_palbuf[i] = AV_RL24( avctx->extradata + i*3 );
> +            }
> +        } else { // HAM with grayscale color palette
> +            count = 1 << (avctx->bits_per_coded_sample > 6 ? 6 : 4);
> +            s->ham_palbuf = av_malloc((count * sizeof (uint32_t)) + FF_INPUT_BUFFER_PADDING_SIZE);
> +            if (!s->ham_palbuf)
> +                return AVERROR(ENOMEM);

Isn't this leaking? If this fails s->ham_buf is not freed.

> +            for (i=0; i < count; i++) {
> +                s->ham_palbuf[i] = le2me_32(GRAY2RGB((i * 255) >> (avctx->bits_per_coded_sample > 6 ? 6 : 4)));
> +            }
> +        }
> +    }
>      return 0;
>  }
>  
> @@ -63,9 +113,19 @@ static av_cold int decode_init(AVCodecContext *avctx)
>  {
>      IffContext *s = avctx->priv_data;
>      int err;
> +    const uint8_t *ex = GET_EXTRA_CONTEXT(avctx);
>  
> -    if (avctx->bits_per_coded_sample <= 8) {
> -        avctx->pix_fmt = PIX_FMT_PAL8;
> +    if (ex) {
> +        s->compression  = bytestream_get_byte(&ex);
> +        s->ham          = bytestream_get_byte(&ex);
> +        s->ehb          = bytestream_get_byte(&ex);
> +        s->masking      = bytestream_get_byte(&ex);
> +        s->transparency = bytestream_get_be16(&ex);
> +    }
> +    if ((avctx->bits_per_coded_sample <= 8) && !s->ham) {
> +        avctx->pix_fmt = ((avctx->extradata_size == IFF_EXTRA_CONTEXT_SIZE) ||
> +                          (avctx->extradata_size == 0)) ? PIX_FMT_GRAY8
> +                                                        : PIX_FMT_PAL8;
>      } else if (avctx->bits_per_coded_sample <= 32) {
>          avctx->pix_fmt = PIX_FMT_BGR32;
>      } else {
> @@ -84,7 +144,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
>      }
>  
>      return avctx->bits_per_coded_sample <= 8 ?
> -       ff_cmap_read_palette(avctx, (uint32_t*)s->frame.data[1]) : 0;
> +       cmap_read_palette(avctx, (uint32_t*)s->frame.data[1]) : 0;
>  }
>  
>  /**
> @@ -125,6 +185,57 @@ static void decodeplane32(uint32_t *dst, const uint8_t *const buf, int buf_size,
>      }
>  }
>  
> +/**
> + * Convert one line of HAM6/8-encoded chunky buffer to 24bpp

third person -> Converts -> for bikeshed sake

> + * @param dst Destination 24bpp buffer

the destination

> + * @param buf Source 8bpp chunky buffer

the source

> + * @param pal lavc palette with alpha channel always at 0
> + * @param buf_size
> + * @param bps 5-6 for HAM6, 7-8 for HAM8
> + */
> +

Ugly empty newline.

> +static void decodehamplane32(uint32_t *dst,
> +                             const uint8_t  *buf,
> +                             const uint32_t *const pal,
> +                             const unsigned buf_size,
> +                             const unsigned bps)
> +{
> +    uint32_t prev = 0;
> +    const uint32_t *end  = dst + (buf_size * 8);
> +    const unsigned hbits = bps > 6 ? 6 : 4;
> +    const unsigned mbits = 8 - hbits;
> +    const uint32_t mask  = (1 << hbits) - 1;
> +
> +    for(; dst < end; dst++) {
> +        uint32_t tmp;
> +        const uint32_t v = *buf++;
> +        switch (v >> hbits) {
> +        case 0: // take direct color value from palette
> +            prev = pal[v & mask];
> +            break;
> +
> +        case 1: // just modify blue color component
> +            tmp = (v & mask) << mbits;
> +            tmp |= tmp >> hbits;
> +            prev = (prev & 0x00FFFF) | (tmp << 16);
> +            break;
> +
> +        case 2: // just modify red color component
> +            tmp = (v & mask) << mbits;
> +            tmp |= tmp >> hbits;
> +            prev = (prev & 0xFFFF00) | tmp;
> +            break;
> +
> +        case 3: // just modify green color component
> +            tmp = (v & mask) << mbits;
> +            tmp |= tmp >> hbits;
> +            prev = (prev & 0xFF00FF) | (tmp << 8);
> +            break;
> +        }
> +        *dst = prev;
> +    }
> +}
> +
>  static int decode_frame_ilbm(AVCodecContext *avctx,
>                              void *data, int *data_size,
>                              AVPacket *avpkt)
> @@ -140,7 +251,8 @@ static int decode_frame_ilbm(AVCodecContext *avctx,
>          return -1;
>      }
>  
> -    if (avctx->pix_fmt == PIX_FMT_PAL8) {
> +    if (avctx->codec_tag == MKTAG('I','L','B','M')) { //interleaved
> +    if ((avctx->pix_fmt == PIX_FMT_PAL8) || (avctx->pix_fmt == PIX_FMT_GRAY8)) {
>          for(y = 0; y < avctx->height; y++ ) {
>              uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
>              memset(row, 0, avctx->width);
> @@ -149,6 +261,16 @@ static int decode_frame_ilbm(AVCodecContext *avctx,
>                  buf += s->planesize;
>              }
>          }
> +    } else if (s->ham) { // HAM to PIX_FMT_BGR32
> +        for(y = 0; y < avctx->height; y++ ) {
> +            uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
> +            memset(s->ham_buf, 0, avctx->width);
> +            for (plane = 0; plane < avctx->bits_per_coded_sample && buf < buf_end; plane++) {
> +                decodeplane8(s->ham_buf, buf, FFMIN(s->planesize, buf_end - buf), avctx->bits_per_coded_sample, plane);
> +                buf += s->planesize;
> +            }
> +            decodehamplane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize, avctx->bits_per_coded_sample);
> +        }
>      } else { // PIX_FMT_BGR32
>          for(y = 0; y < avctx->height; y++ ) {
>              uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
> @@ -159,6 +281,20 @@ static int decode_frame_ilbm(AVCodecContext *avctx,
>              }
>          }
>      }
> +    } else if ((avctx->pix_fmt == PIX_FMT_PAL8) || (avctx->pix_fmt == PIX_FMT_GRAY8)) { // IFF PBM
> +        for(y = 0; y < avctx->height; y++ ) {
> +            uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
> +            memcpy(row, buf, FFMIN(avctx->width, buf_end - buf));
> +            buf += avctx->width;
> +        }
> +    } else { // IFF-PBM: HAM to PIX_FMT_BGR32
> +        for(y = 0; y < avctx->height; y++ ) {
> +            uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
> +            memcpy(s->ham_buf, buf, FFMIN(avctx->width, buf_end - buf));
> +            buf += avctx->width;
> +            decodehamplane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize, avctx->bits_per_coded_sample);
> +        }
> +    }
>  
>      *data_size = sizeof(AVFrame);
>      *(AVFrame*)data = s->frame;
> @@ -181,7 +317,7 @@ static int decode_frame_byterun1(AVCodecContext *avctx,
>      }
>  
>      if (avctx->codec_tag == MKTAG('I','L','B','M')) { //interleaved
> -        if (avctx->pix_fmt == PIX_FMT_PAL8) {
> +        if ((avctx->pix_fmt == PIX_FMT_PAL8) || (avctx->pix_fmt == PIX_FMT_GRAY8)) {
>              for(y = 0; y < avctx->height ; y++ ) {
>                  uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ];
>                  memset(row, 0, avctx->width);
> @@ -204,6 +340,30 @@ static int decode_frame_byterun1(AVCodecContext *avctx,
>                      decodeplane8(row, s->planebuf, s->planesize, avctx->bits_per_coded_sample, plane);
>                  }
>              }
> +        } else if (s->ham) { // HAM to PIX_FMT_BGR32
> +            for(y = 0; y < avctx->height ; y++ ) {
> +                uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
> +                memset(s->ham_buf, 0, avctx->width);
> +                for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) {
> +                    for(x = 0; x < s->planesize && buf < buf_end; ) {
> +                        const int8_t value = *buf++;
> +                        unsigned length;
> +                        if (value >= 0) {
> +                            length = value + 1;
> +                            memcpy(s->planebuf + x, buf, FFMIN3(length, s->planesize - x, buf_end - buf));
> +                            buf += length;
> +                        } else if (value > -128) {
> +                            length = -value + 1;
> +                            memset(s->planebuf + x, *buf++, FFMIN(length, s->planesize - x));
> +                        } else { // noop
> +                            continue;
> +                        }
> +                        x += length;
> +                    }
> +                    decodeplane8(s->ham_buf, s->planebuf, s->planesize, avctx->bits_per_coded_sample, plane);
> +                }
> +                decodehamplane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize, avctx->bits_per_coded_sample);
> +            }
>          } else { //PIX_FMT_BGR32
>              for(y = 0; y < avctx->height ; y++ ) {
>                  uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
> @@ -228,7 +388,7 @@ static int decode_frame_byterun1(AVCodecContext *avctx,
>                  }
>              }
>          }
> -    } else {
> +    } else if ((avctx->pix_fmt == PIX_FMT_PAL8) || (avctx->pix_fmt == PIX_FMT_GRAY8)) { // IFF-PBM
>          for(y = 0; y < avctx->height ; y++ ) {
>              uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
>              for(x = 0; x < avctx->width && buf < buf_end; ) {
> @@ -247,6 +407,26 @@ static int decode_frame_byterun1(AVCodecContext *avctx,
>                  x += length;
>              }
>          }
> +    } else { // IFF-PBM: HAM to PIX_FMT_BGR32
> +        for(y = 0; y < avctx->height ; y++ ) {
> +            uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];

> +            for(x = 0; x < avctx->width && buf < buf_end; ) {
> +                const int8_t value = *buf++;
> +                unsigned length;
> +                if (value >= 0) {
> +                    length = value + 1;
> +                    memcpy(s->ham_buf + x, buf, FFMIN3(length, buf_end - buf, avctx->width - x));
> +                    buf += length;
> +                } else if (value > -128) {
> +                    length = -value + 1;
> +                    memset(s->ham_buf + x, *buf++, FFMIN(length, avctx->width - x));
> +                } else { // noop
> +                    continue;
> +                }
> +                x += length;
> +            }

Looks similar to "HAM to PIX_FMT_BGR32", maybe it can be factorized.

> +            decodehamplane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize, avctx->bits_per_coded_sample);
> +        }
>      }
>  
>      *data_size = sizeof(AVFrame);
> @@ -260,6 +440,8 @@ static av_cold int decode_end(AVCodecContext *avctx)
>      if (s->frame.data[0])
>          avctx->release_buffer(avctx, &s->frame);
>      av_freep(&s->planebuf);
> +    av_freep(&s->ham_buf);
> +    av_freep(&s->ham_palbuf);
>      return 0;
>  }
>  
> diff --git a/libavcodec/iff.h b/libavcodec/iff.h
> index 76db10b..94761eb 100644
> --- a/libavcodec/iff.h
> +++ b/libavcodec/iff.h
> @@ -25,6 +25,52 @@
>  #include <stdint.h>
>  #include "avcodec.h"
>  
> -int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal);
> +// Gray to RGB, required for HAM palette table
> +#define GRAY2RGB(x) (((x) << 16) | ((x) <<  8) | (x))
> +
> +// screenmode bits
> +#define CAMG_EHB 0x80    // Extra HalfBrite
> +#define CAMG_HAM 0x800   // Hold And Modify
> +
> +// TODO: masking bits
> +#define MASK_NONE                  0
> +#define MASK_HAS_MASK              1
> +#define MASK_HAS_TRANSPARENT_COLOR 2
> +#define MASK_LASSO                 3
> +
> +/**
> + * IFF extra context size has to be larger than maximum palette data
> + * size of previous IFF demuxer and decoder in order to retain
> + * backward compatibility between an old version of IFF decoder and
> + * current version of IFF demuxer.
> + *
> + * Since 256 palette entries with 3 bytes each color yields in
> + * 768 bytes, we simply round up to nearest 512 byte block, which
> + * is exactly 1 KB.
> + */
> +#define IFF_EXTRA_CONTEXT_SIZE      1024
> +
> +/**
> + * Gets the extradata context appended to palette dataq (if any) or
> + * NULL if there it's an old version of IFF demuxer which doesn't
> + * support the new extradata fields.
> + */
> +#define GET_EXTRA_CONTEXT(x)        (uint8_t *) (((x)->extradata_size >= IFF_EXTRA_CONTEXT_SIZE)    ?  \
> +                                    (x)->extradata + ((x)->extradata_size - IFF_EXTRA_CONTEXT_SIZE) :  \
> +                                    NULL)
> +
> +/**
> + * IFF extra context. This data is appended to actual
> + * palette data, always stored in big-endian format.
> + *
> + * If you add new data here, please add a new identifier tag != 0 before it
> + * and check for the existence of identifier before accessing the new data.
> + *
> + * uint8_t  compression  : Compression method used
> + * uint8_t  ham          : 1 if HAM mode used, 0 otherwise
> + * uint8_t  ehb          : TODO: 1 if EHB mode used, 0 otherwise
> + * uint8_t  masking      : TODO: Masking method used
> + * uint16_t transparency : TODO: Transparency
> + */
>  
>  #endif /* AVCODEC_IFF_H */
> diff --git a/libavformat/iff.c b/libavformat/iff.c
> index 7e3f3ad..a1af659 100644
> --- a/libavformat/iff.c
> +++ b/libavformat/iff.c
> @@ -30,6 +30,7 @@
>   */
>  
>  #include "libavutil/intreadwrite.h"
> +#include "libavcodec/bytestream.h"
>  #include "libavcodec/iff.h"
>  #include "avformat.h"
>  
> @@ -41,6 +42,7 @@
>  #define ID_PBM        MKTAG('P','B','M',' ')
>  #define ID_ILBM       MKTAG('I','L','B','M')
>  #define ID_BMHD       MKTAG('B','M','H','D')
> +#define ID_CAMG       MKTAG('C','A','M','G')
>  #define ID_CMAP       MKTAG('C','M','A','P')
>  
>  #define ID_FORM       MKTAG('F','O','R','M')
> @@ -127,8 +129,12 @@ static int iff_read_header(AVFormatContext *s,
>      IffDemuxContext *iff = s->priv_data;
>      ByteIOContext *pb = s->pb;
>      AVStream *st;
> +    uint8_t *ex;
>      uint32_t chunk_id, data_size;
> -    int compression = -1;
> +    uint32_t screenmode = 0;
> +    uint16_t transparency = 0;
> +    uint8_t masking = MASK_NONE;
> +    int8_t compression = -1;
>  
>      st = av_new_stream(s, 0);
>      if (!st)
> @@ -172,9 +178,15 @@ static int iff_read_header(AVFormatContext *s,
>              st->codec->channels = (get_be32(pb) < 6) ? 1 : 2;
>              break;
>  
> +        case ID_CAMG:
> +            if (data_size < 4)
> +                return AVERROR_INVALIDDATA;
> +            screenmode                = get_be32(pb);
> +            break;
> +
>          case ID_CMAP:
> -            st->codec->extradata_size = data_size;
> -            st->codec->extradata      = av_malloc(data_size);
> +            st->codec->extradata_size = data_size + IFF_EXTRA_CONTEXT_SIZE;
> +            st->codec->extradata      = av_malloc(data_size + IFF_EXTRA_CONTEXT_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
>              if (!st->codec->extradata)
>                  return AVERROR(ENOMEM);
>              if (get_buffer(pb, st->codec->extradata, data_size) < 0)
> @@ -189,12 +201,15 @@ static int iff_read_header(AVFormatContext *s,
>              st->codec->height                = get_be16(pb);
>              url_fskip(pb, 4); // x, y offset
>              st->codec->bits_per_coded_sample = get_byte(pb);
> -            if (data_size >= 11) {
> -                url_fskip(pb, 1); // masking
> +            if (data_size >= 10)
> +                masking                      = get_byte(pb);
> +            if (data_size >= 11)
>                  compression                  = get_byte(pb);
> +            if (data_size >= 14) {
> +                url_fskip(pb, 1); // padding
> +                transparency                 = get_be16(pb);
>              }
>              if (data_size >= 16) {
> -                url_fskip(pb, 3); // paddding, transparent
>                  st->sample_aspect_ratio.num  = get_byte(pb);
>                  st->sample_aspect_ratio.den  = get_byte(pb);
>              }
> @@ -229,6 +244,20 @@ static int iff_read_header(AVFormatContext *s,
>  
>      url_fseek(pb, iff->body_pos, SEEK_SET);
>  
> +    if (!st->codec->extradata) {
> +        st->codec->extradata_size = IFF_EXTRA_CONTEXT_SIZE;
> +        st->codec->extradata = av_malloc(IFF_EXTRA_CONTEXT_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
> +        if (!st->codec->extradata)
> +            return AVERROR(ENOMEM);
> +    }
> +    ex = GET_EXTRA_CONTEXT(st->codec);
> +    memset(ex, 0, IFF_EXTRA_CONTEXT_SIZE);
> +    bytestream_put_byte(&ex, compression);
> +    bytestream_put_byte(&ex, (screenmode & CAMG_HAM) != 0);
> +    bytestream_put_byte(&ex, (screenmode & CAMG_EHB) != 0);
> +    bytestream_put_byte(&ex, masking);
> +    bytestream_put_be16(&ex, transparency);
> +
>      switch(st->codec->codec_type) {
>      case AVMEDIA_TYPE_AUDIO:
>          av_set_pts_info(st, 32, 1, st->codec->sample_rate);
> @@ -256,13 +285,7 @@ static int iff_read_header(AVFormatContext *s,
>      case AVMEDIA_TYPE_VIDEO:
>          switch (compression) {
>          case BITMAP_RAW:
> -            if (st->codec->codec_tag == ID_ILBM) {
>                  st->codec->codec_id = CODEC_ID_IFF_ILBM;
> -            } else {
> -                st->codec->codec_id = CODEC_ID_RAWVIDEO;
> -                st->codec->pix_fmt  = PIX_FMT_PAL8;
> -                st->codec->codec_tag = 0;
> -            }
>              break;
>          case BITMAP_BYTERUN1:
>              st->codec->codec_id = CODEC_ID_IFF_BYTERUN1;
> @@ -290,7 +313,7 @@ static int iff_read_packet(AVFormatContext *s,
>      if(iff->sent_bytes >= iff->body_size)
>          return AVERROR(EIO);
>  
> -    if(s->streams[0]->codec->channels == 2) {

cosmetics -> separate patch

> +    if(st->codec->channels == 2) {
>          uint8_t sample_buffer[PACKET_SIZE];
>  
>          ret = get_buffer(pb, sample_buffer, PACKET_SIZE);
> @@ -299,19 +322,7 @@ static int iff_read_packet(AVFormatContext *s,
>              return AVERROR(ENOMEM);
>          }
>          interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE);
> -    } else if (s->streams[0]->codec->codec_id == CODEC_ID_RAWVIDEO) {
> -        if(av_new_packet(pkt, iff->body_size + AVPALETTE_SIZE) < 0) {
> -            return AVERROR(ENOMEM);
> -        }
> -
> -        ret = ff_cmap_read_palette(st->codec, (uint32_t*)(pkt->data + iff->body_size));
> -        if (ret < 0)
> -            return ret;
> -        av_freep(&st->codec->extradata);
> -        st->codec->extradata_size = 0;
> -
> -        ret = get_buffer(pb, pkt->data, iff->body_size);
> -    } else if (s->streams[0]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
> +    } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {

ditto

>          ret = av_get_packet(pb, pkt, iff->body_size);
>      } else {
>          ret = av_get_packet(pb, pkt, PACKET_SIZE);
> @@ -320,13 +331,13 @@ static int iff_read_packet(AVFormatContext *s,
>      if(iff->sent_bytes == 0)
>          pkt->flags |= AV_PKT_FLAG_KEY;
>  
> -    if(s->streams[0]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
> +    if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {

ditto

>          iff->sent_bytes += PACKET_SIZE;
>      } else {
>          iff->sent_bytes = iff->body_size;
>      }
>      pkt->stream_index = 0;
> -    if(s->streams[0]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
> +    if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {

ditto

>          pkt->pts = iff->audio_frame_count;
>          iff->audio_frame_count += ret / s->streams[0]->codec->channels;
>      }

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel


-- 
FFmpeg = Fascinating & Friendly Mastering Purposeless Extroverse Ghost



More information about the ffmpeg-devel mailing list