[FFmpeg-devel] [PATCH] IFF: Add the HAM stuff

Stefano Sabatini stefano.sabatini-lala
Sat May 15 23:52:52 CEST 2010


On date Saturday 2010-05-15 23:12:25 +0200, Sebastian Vater encoded:
> Ronald S. Bultje a ?crit :
> > Hi,
> >
> > On Fri, May 14, 2010 at 10:06 PM, Sebastian Vater
> > <cdgs.basty at googlemail.com> wrote:
> >   
> >> +    uint8_t * ham_buf; // Temporary buffer for planar to chunky conversation
> >> +    uint32_t *ham_palbuf; // HAM decode table
> >> +    unsigned  compression; // Delta compression method used
> >> +    unsigned  bpp; // Bits per plane to decode
> >> +    unsigned  ham; // 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
> >> +    unsigned  flags; // 1 for EHB, 0 is no extra half darkening
> >> +    unsigned  masking; // TODO: Masking method used
> >>     
> >
> > Please vertically align, and use doxy-compatible comments here where
> > appropriate (///< bla, not // bla). See "doxygen" output to get an
> > idea of what we're looking for in these kind of docs.
> >   
> 
> Fixed.
> 
> >> +#define DECODE_HAM_PLANE32(x)       \
> >>     
> >
> > You can probably just make this a for(n=0;n<4;n++), gcc should unroll
> > that automatically. Then you don't need the macro.
> >   
> 
> I tried it out, it doesn't unroll the loop but insteads makes the
> function inline instead.
> 
> Anyway, I spent a lots of time to get this function really fast.
> 
> >> +static void decodehamplane32(uint32_t *dst,
> >> +                             const uint8_t  *buf,
> >> +                             const uint32_t *const pal,
> >> +                             unsigned buf_size)
> >>     
> >
> > You can merge the args on 2 lines, no need for 4. Also, please use
> > underscores, yourfunctionnamesaregettingalittlebittoolong.
> >   
> 
> Fixed.
> 
> > Why?
> >   
> 
> Number of planes can change between IFF-ANIM frames, that's whay. On the
> other hand, it's also used by HAM decoder s->bpp contains original
> number of planes (bits per coded sample is always set to 24 when
> encountering HAM).
> 
> >> +#define GET_EXTRA_DATA(x) ((uint8_t *) (x)->data + AV_RB16((x)->data))
> >>     
> > [..]
> >   
> >> +#define GET_EXTRA_SIZE(x) ((x)->size - AV_RB16((x)->data))
> >>     
> >
> > This is only used in libavcodec/iff.c and thus does not belong in iff.h.
> >   
> 
> Fixed.
> 
> Besides this I fixed an error with the HAM palette initializing, it has
> to always initialize 1 << hbits, but it didn't when the CMAP chunk size
> / 3 was smaller than this.
> 
> Also this patch is based upon newest duplicate code merge patch, again.
> 
> -- 
> 
> Best regards,
>                    :-) Basty/CDGS (-:
> 

> diff --git a/libavcodec/iff.c b/libavcodec/iff.c
> index 3cdc964..0ff81be 100644
> --- a/libavcodec/iff.c
> +++ b/libavcodec/iff.c
> @@ -30,10 +30,37 @@
>  #include "get_bits.h"
>  #include "iff.h"
>  
> +// TODO: masking bits
> +#define MASK_NONE                  0
> +#define MASK_HAS_MASK              1
> +#define MASK_HAS_TRANSPARENT_COLOR 2
> +#define MASK_LASSO                 3
> +
> +/**
> + * Gets the actual packet data after video properties which contains
> + * the raw data beyond the IFF extra context.
> + */
> +#define GET_EXTRA_DATA(x) ((uint8_t *) (x)->data + AV_RB16((x)->data))
> +
> +/**
> + * Gets the size of raw data beyond the IFF extra context. Please note
> + * that any value < 2 of either IFF extra context or raw packet data
> + * is considered as an illegal packet.
> + */
> +#define GET_EXTRA_SIZE(x) ((x)->size - AV_RB16((x)->data))
> +
>  typedef struct {
>      AVFrame frame;
>      int planesize;
>      uint8_t * planebuf;
> +    uint8_t * ham_buf;      ///< Temporary buffer for planar to chunky conversation
> +    uint32_t *ham_palbuf;   ///< HAM decode table
> +    unsigned  compression;  ///< Delta compression method used
> +    unsigned  bpp;          ///< Bits per plane to decode
> +    unsigned  ham;          ///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
> +    unsigned  flags;        ///< 1 for EHB, 0 is no extra half darkening
> +    unsigned  masking;      ///< TODO: Masking method used
> +    unsigned  transparency; ///< TODO: Transparency color index in palette
>  } IffContext;
>  
>  #define LUT8_PART(plane, v)                             \
> @@ -219,6 +246,125 @@ static void decodeplane32(uint32_t *dst, const uint8_t *buf, int buf_size, int p
>      } while (--buf_size);
>  }
>  
> +#define DECODE_HAM_PLANE32(x)       \
> +    first       = buf[x] << 1;      \
> +    second      = buf[(x)+1] << 1;  \
> +    delta      &= pal[first++];     \
> +    delta      |= pal[first];       \
> +    dst[x]      = delta;            \
> +    delta      &= pal[second++];    \
> +    delta      |= pal[second];      \
> +    dst[(x)+1]  = delta;
> +
> +/**
> + * Converts one line of HAM6/8-encoded chunky buffer to 24bpp

missing final dot.

> + *
> + * @param dst the destination 24bpp buffer
> + * @param buf the source 8bpp chunky buffer
> + * @param pal the HAM decode table
> + * @param buf_size the plane size in bytes
> + */
> +static void decode_ham_plane32(uint32_t *dst, const uint8_t  *buf,
> +                               const uint32_t *const pal, unsigned buf_size)
> +{
> +    uint32_t delta = 0;
> +    do {
> +        uint32_t first, second;
> +        DECODE_HAM_PLANE32(0)
> +        DECODE_HAM_PLANE32(2)
> +        DECODE_HAM_PLANE32(4)
> +        DECODE_HAM_PLANE32(6)
> +        buf += 8;
> +        dst += 8;
> +    } while (--buf_size);
> +}
> +
> +/**
> + * Extracts the IFF extra context and updates internal
> + * decoder structures.
> + *
> + * @param avctx the AVCodecContext where to extract extra context to
> + * @param avpkt the AVPacket to extract extra context from
> + *

Nit+++: no need for this empty newline

> + * @return returns error status. 0 is OK, error otherwise

@return 0 in case of success, a negative error code otherwise

> + */
> +static int extract_header(AVCodecContext *const avctx,
> +                          const AVPacket *const avpkt) {
> +    IffContext *s = avctx->priv_data;
> +    const uint8_t *buf = avpkt->data;
> +    const unsigned buf_size = bytestream_get_be16(&buf);
> +    if (buf_size <= 1 || (int) GET_EXTRA_SIZE(avpkt) <= 1) {
> +        av_log(avctx, AV_LOG_ERROR,
> +               "Invalid packet size received: %u -> video data offset: %d\n",
> +               (unsigned) buf_size, (int) GET_EXTRA_SIZE(avpkt));
> +        return AVERROR_INVALIDDATA;
> +    }
> +    if (buf_size > 8) {
> +        s->compression  = bytestream_get_byte(&buf);
> +        s->bpp          = bytestream_get_byte(&buf);
> +        s->ham          = bytestream_get_byte(&buf);
> +        s->flags        = bytestream_get_byte(&buf);
> +        s->transparency = bytestream_get_be16(&buf);
> +        s->masking      = bytestream_get_byte(&buf);
> +    }
> +
> +    if (s->masking == MASK_HAS_TRANSPARENT_COLOR) {
> +        av_log(avctx, AV_LOG_ERROR, "Transparency not supported\n");
> +        return AVERROR_PATCHWELCOME;
> +    } else if (s->masking != MASK_NONE) {
> +        av_log(avctx, AV_LOG_ERROR, "Masking not supported\n");
> +        return AVERROR_PATCHWELCOME;
> +    }
> +
> +    av_freep(&s->ham_buf);
> +    av_freep(&s->ham_palbuf);
> +
> +    if (s->ham) {
> +        int i;
> +        int count = FFMIN(avctx->extradata_size / 3, 1 << s->ham);
> +        const unsigned mbits = 8 - s->ham;
> +        s->ham_buf = av_malloc((s->planesize * 8) + FF_INPUT_BUFFER_PADDING_SIZE);
> +        if (!s->ham_buf)
> +            return AVERROR(ENOMEM);
> +
> +        s->ham_palbuf = av_malloc((8 * (1 << s->ham) * sizeof (uint32_t)) + FF_INPUT_BUFFER_PADDING_SIZE);
> +        if (!s->ham_palbuf) {
> +            av_freep(&s->ham_buf);
> +            return AVERROR(ENOMEM);
> +        }
> +
> +        if (count) { // HAM with color palette attached

> +            // prefill with black and palette and set take direct color mask to zero

"set take" sounds weird

> +            memset(s->ham_palbuf, 0, (1 << s->ham) * 2 * sizeof (uint32_t));
> +            for (i=0; i < count; i++) {
> +                s->ham_palbuf[i*2+1] = AV_RL24( avctx->extradata + i*3 );
> +            }
> +            count = 1 << s->ham;
> +        } else { // HAM with grayscale color palette
> +            count = 1 << s->ham;
> +            for (i=0; i < count; i++) {
> +                s->ham_palbuf[i*2]   = 0x000000; // take direct color value from palette
> +                s->ham_palbuf[i*2+1] = le2me_32(gray2rgb((i * 255) >> s->ham));
> +            }
> +        }
> +        for (i=0; i < count; i++) {
> +            uint32_t tmp = i << mbits;
> +            tmp |= tmp >> s->ham;
> +            s->ham_palbuf[(i+count)*2]   = 0x00FFFF; // just modify blue color component
> +            s->ham_palbuf[(i+count*2)*2] = 0xFFFF00; // just modify red color component
> +            s->ham_palbuf[(i+count*3)*2] = 0xFF00FF; // just modify green color component
> +            s->ham_palbuf[(i+count)*2+1]   = tmp << 16;
> +            s->ham_palbuf[(i+count*2)*2+1] = tmp;
> +            s->ham_palbuf[(i+count*3)*2+1] = tmp << 8;
> +        }
> +    } else if (s->flags & 1) { // EHB (ExtraHalfBrite) color palette
> +        av_log(avctx, AV_LOG_ERROR, "ExtraHalfBrite (EHB) mode not supported\n");
> +        return AVERROR_PATCHWELCOME;
> +    }
> +
> +    return 0;
> +}
> +
>  /**
>   * Decodes one complete byterun1 encoded line.
>   *
> @@ -256,31 +402,43 @@ static int decode_frame_ilbm(AVCodecContext *avctx,
>                              AVPacket *avpkt)
>  {
>      IffContext *s = avctx->priv_data;
> -    const uint8_t *buf = avpkt->data;
> -    int buf_size = avpkt->size;
> +    const uint8_t *buf = GET_EXTRA_DATA(avpkt);
> +    int buf_size = GET_EXTRA_SIZE(avpkt);
>      const uint8_t *buf_end = buf+buf_size;
> -    int y, plane;
> +    int y, plane, err;
>  
>      if (avctx->reget_buffer(avctx, &s->frame) < 0){

Nit++: missing space after closing ")"

>          av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
>          return -1;

if ((err = ...) < 0) {
   av_log(...)
   return err;
}

>      }
>  
> +    if ((err = extract_header(avctx, avpkt)))
> +        return err;
>      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);
> -                for (plane = 0; plane < avctx->bits_per_coded_sample && buf < buf_end; plane++) {
> +                for (plane = 0; plane < s->bpp && buf < buf_end; plane++) {
>                      decodeplane8(row, buf, FFMIN(s->planesize, buf_end - buf), plane);
>                      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 < s->bpp && buf < buf_end; plane++) {
> +                    decodeplane8(s->ham_buf, buf, FFMIN(s->planesize, buf_end - buf), plane);
> +                    buf += s->planesize;
> +                }
> +                decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize);
> +            }
>          } else { // PIX_FMT_BGR32
>              for(y = 0; y < avctx->height; y++ ) {
>                  uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
>                  memset(row, 0, avctx->width << 2);
> -                for (plane = 0; plane < avctx->bits_per_coded_sample && buf < buf_end; plane++) {
> +                for (plane = 0; plane < s->bpp && buf < buf_end; plane++) {
>                      decodeplane32((uint32_t *) row, buf, FFMIN(s->planesize, buf_end - buf), plane);
>                      buf += s->planesize;
>                  }
> @@ -292,6 +450,13 @@ static int decode_frame_ilbm(AVCodecContext *avctx,
>              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++ ) {

for_(

> +            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;
> +            decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, avctx->width);
> +        }
>      }
>  
>      *data_size = sizeof(AVFrame);
> @@ -304,41 +469,59 @@ static int decode_frame_byterun1(AVCodecContext *avctx,
>                              AVPacket *avpkt)
>  {
>      IffContext *s = avctx->priv_data;
> -    const uint8_t *buf = avpkt->data;
> -    int buf_size = avpkt->size;
> +    const uint8_t *buf = GET_EXTRA_DATA(avpkt);
> +    const int buf_size = GET_EXTRA_SIZE(avpkt);
>      const uint8_t *buf_end = buf+buf_size;
> -    int y, plane;
> +    int y, plane, err;
>  
>      if (avctx->reget_buffer(avctx, &s->frame) < 0){
>          av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
>          return -1;
>      }

  
> +    if ((err = extract_header(avctx, avpkt)))
> +        return err;
>      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);
> -                for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) {
> +                for (plane = 0; plane < s->bpp; plane++) {
>                      buf = decode_byterun(s->planebuf, buf, buf_end, s->planesize);
>                      decodeplane8(row, s->planebuf, s->planesize, 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 < s->bpp; plane++) {
> +                    buf = decode_byterun(s->planebuf, buf, buf_end, s->planesize);
> +                    decodeplane8(s->ham_buf, s->planebuf, s->planesize, plane);
> +                }
> +                decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize);
> +            }
>          } else { //PIX_FMT_BGR32
>              for(y = 0; y < avctx->height ; y++ ) {
>                  uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
>                  memset(row, 0, avctx->width << 2);
> -                for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) {
> +                for (plane = 0; plane < s->bpp; plane++) {
>                      buf = decode_byterun(s->planebuf, buf, buf_end, s->planesize);
>                      decodeplane32((uint32_t *) row, s->planebuf, s->planesize, plane);
>                  }
>              }
>          }

Note, this can be factorized (but not in this patch of course ;-)

> -    } 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]];
>              buf = decode_byterun(row, buf, buf_end, avctx->width);
>          }
> +    } else { // IFF-PBM: HAM to PIX_FMT_BGR32
> +        for(y = 0; y < avctx->height ; y++ ) {

Nit++: for_(, no space after y++

> +            uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]];
> +            buf = decode_byterun(s->ham_buf, buf, buf_end, avctx->width);
> +            decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, avctx->width);
> +        }
>      }
>  
>      *data_size = sizeof(AVFrame);
> @@ -352,6 +535,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..86477d8 100644
> --- a/libavcodec/iff.h
> +++ b/libavcodec/iff.h
> @@ -25,6 +25,22 @@
>  #include <stdint.h>
>  #include "avcodec.h"
>  
> +/**
> + * IFF extra video context. This data is prepended to actual
> + * video pixel data, always stored in big-endian format.
> + *
> + * If you add new data here, always check check whether the packet you
> + * receive is large enough (offset >= is actually large enough).
> + *
> + * uint16_t offset;       ///< Offset to add to get raw video pixel data
> + * uint8_t  compression;  ///< Delta compression method used
> + * uint8_t  bpp;          ///< Bits per plane to decode
> + * uint8_t  ham;          ///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
> + * uint8_t  flags;        ///< TODO: 1 for EHB, 0 is no extra half darkening
> + * uint16_t transparency; ///< TODO: Transparency color index in palette
> + * uint8_t  masking;      ///< TODO: Masking method used
> + */

This doxy looks misplaced, seems like IffDemuxContext though but I see
the types are different (maybe having uintX_t is preferable than
using always unsigned).

> +
>  int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal);
>  
>  #endif /* AVCODEC_IFF_H */
> diff --git a/libavformat/iff.c b/libavformat/iff.c
> index 4288c3d..2876aec 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,7 +42,8 @@
>  #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_CMAP       MKTAG('C','M','A','P')
> +#define ID_CAMG       MKTAG('C','A','M','G')
> +#define ID_CMAP       MKTAG('C','M','A','p')
>  
>  #define ID_FORM       MKTAG('F','O','R','M')
>  #define ID_ANNO       MKTAG('A','N','N','O')
> @@ -61,6 +63,18 @@
>  
>  #define PACKET_SIZE 1024
>  
> +// screenmode bits
> +#define CAMG_EHB 0x80    // Extra HalfBrite
> +#define CAMG_HAM 0x800   // Hold And Modify
> +
> +/**
> + * This number of bytes if added at the beginning of each AVPacket
> + * which contain additional information about video properties
> + * which has to be shared between demuxer and decoder also changeable
> + * between frames.

"... and decoder. This number may change between frames."

looks more readable.

> + */
> +#define IFF_EXTRA_VIDEO_SIZE 9
> +
>  typedef enum {
>      COMP_NONE,
>      COMP_FIB,
> @@ -77,6 +91,12 @@ typedef struct {
>      uint32_t  body_size;
>      uint32_t  sent_bytes;
>      uint32_t  audio_frame_count;
> +    unsigned  compression;  ///< Delta compression method used
> +    unsigned  bpp;          ///< Bits per plane to decode
> +    unsigned  ham;          ///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
> +    unsigned  flags;        ///< 1 for EHB, 0 is no extra half darkening
> +    unsigned  masking;      ///< Masking method used
> +    unsigned  transparency; ///< Transparency color index in palette

Nit++: no need for capitalization of the field doxies, as they are
non-complete sentences.

>  } IffDemuxContext;
>  
>  
> @@ -129,6 +149,9 @@ static int iff_read_header(AVFormatContext *s,
>      AVStream *st;
>      uint32_t chunk_id, data_size;
>      int compression = -1;
> +    uint32_t screenmode = 0;
> +    unsigned transparency = 0;
> +    unsigned masking = 0; // MASK_NONE

directly use the macro value

>      st = av_new_stream(s, 0);
>      if (!st)
> @@ -172,6 +195,12 @@ 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);
> @@ -189,12 +218,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);
>              }
> @@ -254,6 +286,18 @@ static int iff_read_header(AVFormatContext *s,
>          break;
>  
>      case AVMEDIA_TYPE_VIDEO:
> +        iff->compression  = compression;
> +        iff->bpp          = st->codec->bits_per_coded_sample;
> +        if ((screenmode & CAMG_HAM) &&

> +             st->codec->bits_per_coded_sample <= 8) {
> +            iff->ham          = st->codec->bits_per_coded_sample > 6 ? 6 : 4;

iff->bpp is shorter.

> +            st->codec->bits_per_coded_sample = 24;
> +        }
> +        iff->flags        = (screenmode & CAMG_EHB) &&
> +                            st->codec->bits_per_coded_sample <= 8 ? 1 : 0;

> +        iff->masking      = masking;
> +        iff->transparency = transparency;
> +
>          switch (compression) {
>          case BITMAP_RAW:
>              st->codec->codec_id = CODEC_ID_IFF_ILBM;
> @@ -294,7 +338,21 @@ static int iff_read_packet(AVFormatContext *s,
>          }
>          interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE);
>      } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
> -        ret = av_get_packet(pb, pkt, iff->body_size);
> +        uint8_t *buf;
> +
> +        if(av_new_packet(pkt, iff->body_size + IFF_EXTRA_VIDEO_SIZE) < 0) {

if_(

> +            return AVERROR(ENOMEM);
> +        }
> +
> +        buf = pkt->data;
> +        bytestream_put_be16(&buf, IFF_EXTRA_VIDEO_SIZE);
> +        bytestream_put_byte(&buf, iff->compression);
> +        bytestream_put_byte(&buf, iff->bpp);
> +        bytestream_put_byte(&buf, iff->ham);
> +        bytestream_put_byte(&buf, iff->flags);
> +        bytestream_put_be16(&buf, iff->transparency);
> +        bytestream_put_byte(&buf, iff->masking);
> +        ret = get_buffer(pb, buf, iff->body_size);
>      } else {
>          ret = av_get_packet(pb, pkt, PACKET_SIZE);
>      }

Regards.
-- 
FFmpeg = Foolish & Formidable Multimedia Pitiful Ecstatic Gadget



More information about the ffmpeg-devel mailing list