On Mon, Mar 10, 2014 at 10:33:27PM +0100, Vittorio Giovara wrote:
> From: Peter Ross <[email protected]>
> 
> Signed-off-by: Vittorio Giovara <[email protected]>
> ---
>  Changelog               |   1 +
>  doc/general.texi        |   2 +
>  libavcodec/Makefile     |   2 +
>  libavcodec/allcodecs.c  |   2 +
>  libavcodec/avcodec.h    |   2 +
>  libavcodec/codec_desc.c |  14 +++
>  libavcodec/mvcdec.c     | 287 
> ++++++++++++++++++++++++++++++++++++++++++++++++
>  libavcodec/version.h    |   4 +-
>  8 files changed, 312 insertions(+), 2 deletions(-)
>  create mode 100644 libavcodec/mvcdec.c
> 
> diff --git a/Changelog b/Changelog
> index 279c0d8..f975648 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
>  version <next>:
>  - compand audio filter
>  - shuffleplanes filter
> +- Silicon Graphics Motion Video Compressor 1 & 2 decoder
>  
>  
>  version 10:
> diff --git a/doc/general.texi b/doc/general.texi
> index 6bc7fda..14ea1cd 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -638,6 +638,8 @@ following image formats are supported:
>      @tab used in some games by Entertainment Software Partners
>  @item Sierra VMD video       @tab     @tab  X
>      @tab Used in Sierra VMD files.
> +@item Silicon Graphics Motion Video Compressor 1 (MVC1)  @tab     @tab  X
> +@item Silicon Graphics Motion Video Compressor 2 (MVC2)  @tab     @tab  X
>  @item Smacker video          @tab     @tab  X
>      @tab Video encoding used in Smacker.
>  @item SMPTE VC-1             @tab     @tab  X
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index bd93a6f..da9524a 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -265,6 +265,8 @@ OBJS-$(CONFIG_MSS2_DECODER)            += mss2.o mss12.o 
> mss2dsp.o
>  OBJS-$(CONFIG_MSVIDEO1_DECODER)        += msvideo1.o
>  OBJS-$(CONFIG_MSZH_DECODER)            += lcldec.o
>  OBJS-$(CONFIG_MTS2_DECODER)            += mss4.o mss34dsp.o
> +OBJS-$(CONFIG_MVC1_DECODER)            += mvcdec.o
> +OBJS-$(CONFIG_MVC2_DECODER)            += mvcdec.o
>  OBJS-$(CONFIG_MXPEG_DECODER)           += mxpegdec.o
>  OBJS-$(CONFIG_NELLYMOSER_DECODER)      += nellymoserdec.o nellymoser.o
>  OBJS-$(CONFIG_NELLYMOSER_ENCODER)      += nellymoserenc.o nellymoser.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index ed6d7ff..b379830 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -196,6 +196,8 @@ void avcodec_register_all(void)
>      REGISTER_DECODER(MSVIDEO1,          msvideo1);
>      REGISTER_DECODER(MSZH,              mszh);
>      REGISTER_DECODER(MTS2,              mts2);
> +    REGISTER_DECODER(MVC1,              mvc1);
> +    REGISTER_DECODER(MVC2,              mvc2);
>      REGISTER_DECODER(MXPEG,             mxpeg);
>      REGISTER_DECODER(NUV,               nuv);
>      REGISTER_ENCDEC (PAM,               pam);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 244f47b..80fdfaa 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -284,6 +284,8 @@ enum AVCodecID {
>      AV_CODEC_ID_HNM4_VIDEO,
>      AV_CODEC_ID_HEVC,
>      AV_CODEC_ID_FIC,
> +    AV_CODEC_ID_MVC1,
> +    AV_CODEC_ID_MVC2,
>  
>      /* various PCM "codecs" */
>      AV_CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the 
> start of audio codecs
> diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
> index 1270323..d310231 100644
> --- a/libavcodec/codec_desc.c
> +++ b/libavcodec/codec_desc.c
> @@ -1057,6 +1057,20 @@ static const AVCodecDescriptor codec_descriptors[] = {
>          .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
>      },
>      {
> +        .id        = AV_CODEC_ID_MVC1,
> +        .type      = AVMEDIA_TYPE_VIDEO,
> +        .name      = "mvc1",
> +        .long_name = NULL_IF_CONFIG_SMALL("Silicon Graphics Motion Video 
> Compressor 1"),
> +        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
> +    },
> +    {
> +        .id        = AV_CODEC_ID_MVC2,
> +        .type      = AVMEDIA_TYPE_VIDEO,
> +        .name      = "mvc2",
> +        .long_name = NULL_IF_CONFIG_SMALL("Silicon Graphics Motion Video 
> Compressor 2"),
> +        .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSY,
> +    },
> +    {
>          .id        = AV_CODEC_ID_MXPEG,
>          .type      = AVMEDIA_TYPE_VIDEO,
>          .name      = "mxpeg",
> diff --git a/libavcodec/mvcdec.c b/libavcodec/mvcdec.c
> new file mode 100644
> index 0000000..be46584
> --- /dev/null
> +++ b/libavcodec/mvcdec.c
> @@ -0,0 +1,287 @@
> +/*
> + * Silicon Graphics Motion Video Compressor 1 & 2 decoder
> + * Copyright (c) 2012 Peter Ross
> + *
> + * This file is part of Libav.
> + *
> + * Libav is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * Libav is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with Libav; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +/**
> + * @file
> + * Silicon Graphics Motion Video Compressor 1 & 2 decoder
> + */
> +
> +#include "libavutil/intreadwrite.h"
> +#include "avcodec.h"
> +#include "bytestream.h"
> +#include "internal.h"
> +
> +typedef struct MvcContext {
> +    AVFrame *frame;
> +    int vflip;
> +} MvcContext;
> +
> +static av_cold int mvc_decode_init(AVCodecContext *avctx)
> +{
> +    MvcContext *s = avctx->priv_data;
> +    int width     = avctx->width;
> +    int height    = avctx->height;
> +    int ret;
> +
> +    if (avctx->codec_id == AV_CODEC_ID_MVC1) {
> +        width  += 3;
> +        height += 3;
> +    }
> +    width  &= ~3;
> +    height &= ~3;
> +    if ((ret = ff_set_dimensions(avctx, width, height)) < 0)
> +        return ret;
> +
> +    avctx->pix_fmt = (avctx->codec_id == AV_CODEC_ID_MVC1) ? 
> AV_PIX_FMT_RGB555 : AV_PIX_FMT_BGRA;
> +    s->frame       = av_frame_alloc();
> +    if (!s->frame)
> +        return AVERROR(ENOMEM);
> +
> +    s->vflip = avctx->extradata_size >= 9 && !memcmp(avctx->extradata + 
> avctx->extradata_size - 9, "BottomUp", 9);

please break very long lines

> +    return 0;
> +}
> +
> +static int decode_mvc1(AVCodecContext *avctx, GetByteContext *gb, uint8_t 
> *dst_start, int width, int height, int linesize)
> +{
> +    uint8_t *dst;
> +    uint16_t v[8];
> +    int mask, x, y, i;
> +
> +    x = y = 0;
> +    while (bytestream2_get_bytes_left(gb) >= 6) {
> +        mask = bytestream2_get_be16u(gb);
> +        v[0] = bytestream2_get_be16u(gb);
> +        v[1] = bytestream2_get_be16u(gb);
> +        if ((v[0] & 0x8000)) {
> +            if (bytestream2_get_bytes_left(gb) < 12) {
> +                av_log(avctx, AV_LOG_WARNING, "buffer overflow\n");
> +                return AVERROR_INVALIDDATA;
> +            }
> +            for (i = 2; i < 8; i++)
> +                v[i] = bytestream2_get_be16u(gb);
> +        } else {
> +            v[2] = v[4] = v[6] = v[0];
> +            v[3] = v[5] = v[7] = v[1];
> +        }
> +
> +#define PIX16(target, true, false) \
> +    i = (mask & target) ? true : false; \
> +    AV_WN16A(dst, (v[i] & 0x7C00) | (v[i] & 0x3E0) | (v[i] & 0x1F)); \

AV_WN16A(dst, v[i] & 0x7FFF) ?

> +    dst += 2;
> +
> +#define ROW16(row, a1, a0, b1, b0) \
> +    dst = dst_start + (y + row) * linesize + x * 2; \
> +    PIX16(1 << (row * 4), a1, a0) \
> +    PIX16(1 << (row * 4 + 1), a1, a0) \
> +    PIX16(1 << (row * 4 + 2), b1, b0) \
> +    PIX16(1 << (row * 4 + 3), b1, b0)
> +
> +        ROW16(0, 0, 1, 2, 3);
> +        ROW16(1, 0, 1, 2, 3);
> +        ROW16(2, 4, 5, 6, 7);
> +        ROW16(3, 4, 5, 6, 7);
> +
> +        x += 4;
> +        if (x >= width) {
> +            y += 4;
> +            if (y >= height) {
> +                break;
> +            }
> +            x = 0;
> +        }

nit: looks like this can be rewritten as
 for (y = 0; y < height; y += 4) {
     for (x = 0; x < width; x += 4) {
         if (bytestream_get_bytes_left() < 6)
             return 0;
         do decoding
     }
 }

> +    }
> +    return 0;
> +}
> +
> +static void set_4x4_block(uint8_t *dst, int linesize, uint32_t pixel)
> +{
> +    int i, j;
> +    for (j = 0; j < 4; j++)
> +        for (i = 0; i < 4; i++)
> +            AV_WN32A(dst + j * linesize + i * 4, pixel);
> +}
> +
> +#define PIX32(target, true, false) \
> +    AV_WN32A(dst, (mask & target) ? v[true] : v[false]); \
> +    dst += 4;
> +
> +#define ROW32(row, a1, a0, b1, b0) \
> +    dst = dst_start + (y + row) * linesize + x * 4; \
> +    PIX32(1 << (row * 4), a1, a0) \

valign a bit?

> +    PIX32(1 << (row * 4 + 1), a1, a0) \
> +    PIX32(1 << (row * 4 + 2), b1, b0) \
> +    PIX32(1 << (row * 4 + 3), b1, b0)
> +
> +#define MVC2_BLOCK \
> +    ROW32(0, 1, 0, 3, 2); \
> +    ROW32(1, 1, 0, 3, 2); \
> +    ROW32(2, 5, 4, 7, 6); \
> +    ROW32(3, 5, 4, 7, 6);

[...]

in general LGTM
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to