[FFmpeg-devel] [PATCH 2/2] iff decoder: support RGB8 and RGBN

Paul B Mahol onemda at gmail.com
Thu Dec 6 13:57:59 CET 2012


On 12/6/12, Peter Ross <pross at xvid.org> wrote:
> ---
>  libavcodec/iff.c | 86
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 85 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/iff.c b/libavcodec/iff.c
> index 0e4c172..2075e4f 100644
> --- a/libavcodec/iff.c
> +++ b/libavcodec/iff.c
> @@ -336,8 +336,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
>                           (avctx->extradata_size >= 2 && palette_size) ?
> AV_PIX_FMT_PAL8 : AV_PIX_FMT_GRAY8;
>      } else if (avctx->bits_per_coded_sample <= 32) {
>          if (avctx->codec_tag != MKTAG('D','E','E','P')) {
> -            if (avctx->bits_per_coded_sample == 24) {
> +            if (avctx->bits_per_coded_sample == 13) {
> +                avctx->pix_fmt = AV_PIX_FMT_RGB444;
> +            } else if (avctx->bits_per_coded_sample == 24) {
>                  avctx->pix_fmt = AV_PIX_FMT_RGB0;
> +            } else if (avctx->bits_per_coded_sample == 25) {
> +                avctx->pix_fmt = AV_PIX_FMT_RGB32;

Better to check for right codec_tag and than set pix_fmt.
>              } else if (avctx->bits_per_coded_sample == 32) {
>                  avctx->pix_fmt = AV_PIX_FMT_BGR32;
>              } else {
> @@ -484,6 +488,78 @@ static int decode_byterun(uint8_t *dst, int dst_size,
>      return buf - buf_start;
>  }
>
> +#define DECODE_RGBX_COMMON(pixel_size) \
> +    if (!length) { \
> +        if (src + 1 > src_end) \

This could theoretically overflow.
bytestream2 would make whole iff.c code nicer to read.
> +            return; \
> +        length = *src; \
> +        src++; \
> +        if (!length) { \
> +            if (src + 2 > src_end) \
> +                return; \
> +            length = AV_RB16(src); \
> +            src += 2; \
> +            if (!length) \
> +                return; \
> +        } \
> +    } \
> +    for (i = 0; i < length; i++) { \
> +        *(uint32_t *)(dst + y*linesize + x * pixel_size) = pixel; \
> +        x += 1; \
> +        if (x >= width) { \
> +            y += 1; \
> +            if (y >= height) \
> +                return; \
> +            x = 0; \
> +        } \
> +    }
> +
> +/**
> + * Decode RGB8 buffer
> + * @param[out] dst Destination buffer
> + * @param[in] src Source buffer
> + * @param src_size Source buffer size (bytes)
> + * @param width Width of destination buffer (pixels)
> + * @param height Height of destination buffer (pixels)
> + * @param linesize Line size of destination buffer (bytes)
> + */
> +static void decode_rgb8(uint8_t *dst, const uint8_t *src, int src_size, int
> width, int height, int linesize)
> +{
> +    const uint8_t *src_end = src + src_size;
> +    int x = 0, y = 0, i, length;
> +    while (src + 4 <= src_end) {
> +        uint32_t pixel = 0xFF000000 | AV_RB24(src);
> +        src += 3;
> +        length = *src & 0x7F;
> +        src++;
> +
> +        DECODE_RGBX_COMMON(4)
> +    }
> +}
> +
> +/**
> + * Decode RGBN buffer
> + * @param[out] dst Destination buffer
> + * @param[in] src Source buffer
> + * @param src_size Source buffer size (bytes)
> + * @param width Width of destination buffer (pixels)
> + * @param height Height of destination buffer (pixels)
> + * @param linesize Line size of destination buffer (bytes)
> + */
> +static void decode_rgbn(uint8_t *dst, const uint8_t *src, int src_size, int
> width, int height, int linesize)
> +{
> +    const uint8_t *src_end = src + src_size;
> +    int x = 0, y = 0, i, length;
> +    while (src + 2 <= src_end) {
> +        uint32_t pixel = AV_RB16(src);
> +        src += 2;
> +        length = pixel & 0x7;
> +        pixel >>= 4;
> +
> +        DECODE_RGBX_COMMON(2)
> +    }
> +}
> +
>  /**
>   * Decode DEEP RLE 32-bit buffer
>   * @param[out] dst Destination buffer
> @@ -770,6 +846,14 @@ static int decode_frame(AVCodecContext *avctx,
>                  return unsupported(avctx);
>          }
>          break;
> +    case 4:
> +        if (avctx->codec_tag == MKTAG('R','G','B','8') && avctx->pix_fmt ==
> AV_PIX_FMT_RGB32) {
> +            decode_rgb8(s->frame.data[0], buf, buf_size, avctx->width,
> avctx->height, s->frame.linesize[0]);
> +        } else if (avctx->codec_tag == MKTAG('R','G','B','N') &&
> avctx->pix_fmt == AV_PIX_FMT_RGB444) {
> +            decode_rgbn(s->frame.data[0], buf, buf_size, avctx->width,
> avctx->height, s->frame.linesize[0]);
> +        } else
> +            return unsupported(avctx);
> +        break;
>      case 5:
>          if (avctx->codec_tag == MKTAG('D','E','E','P')) {
>              const AVPixFmtDescriptor *desc =
> av_pix_fmt_desc_get(avctx->pix_fmt);
> --
> 1.8.0
>
> -- Peter
> (A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
>


More information about the ffmpeg-devel mailing list