On Thu, 19 Jan 2012 21:22:12 +0000, Paul B Mahol <[email protected]> wrote:
> ---
>  Changelog              |    1 +
>  doc/general.texi       |    2 +
>  libavcodec/Makefile    |    2 +
>  libavcodec/allcodecs.c |    1 +
>  libavcodec/avcodec.h   |    1 +
>  libavcodec/version.h   |    2 +-
>  libavcodec/xwddec.c    |  220 ++++++++++++++++++++++++++++++++++++++++
>  libavcodec/xwdenc.c    |  260 
> ++++++++++++++++++++++++++++++++++++++++++++++++
>  libavformat/img2.c     |    3 +-
>  9 files changed, 490 insertions(+), 2 deletions(-)
>  create mode 100644 libavcodec/xwddec.c
>  create mode 100644 libavcodec/xwdenc.c
> 
> diff --git a/Changelog b/Changelog
> index 3515ba5..559fad3 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -15,6 +15,7 @@ version 0.8_beta2:
>    enable it but it may be removed in a later Libav release.
>  - rv34: frame-level multi-threading
>  - optimized iMDCT transform on x86 using SSE for for mpegaudiodec
> +- XWD decoder and encoder
>  
>  
>  version 0.8_beta1:
> diff --git a/doc/general.texi b/doc/general.texi
> index 79af887..cda79c0 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -379,6 +379,8 @@ following image formats are supported:
>      @tab YUV, JPEG and some extension is not supported yet.
>  @item Truevision Targa  @tab X @tab X
>      @tab Targa (.TGA) image format
> +@item XWD  @tab X @tab X
> +    @tab X Window Dump image format
>  @end multitable
>  
>  @code{X} means that encoding (resp. decoding) is supported.
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index 1e8d09b..3468f66 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -435,6 +435,8 @@ OBJS-$(CONFIG_XAN_WC4_DECODER)         += xxan.o
>  OBJS-$(CONFIG_XL_DECODER)              += xl.o
>  OBJS-$(CONFIG_XSUB_DECODER)            += xsubdec.o
>  OBJS-$(CONFIG_XSUB_ENCODER)            += xsubenc.o
> +OBJS-$(CONFIG_XWD_DECODER)             += xwddec.o
> +OBJS-$(CONFIG_XWD_ENCODER)             += xwdenc.o
>  OBJS-$(CONFIG_YOP_DECODER)             += yop.o
>  OBJS-$(CONFIG_ZLIB_DECODER)            += lcldec.o
>  OBJS-$(CONFIG_ZLIB_ENCODER)            += lclenc.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index 5289692..d00bd0b 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -230,6 +230,7 @@ void avcodec_register_all(void)
>      REGISTER_DECODER (XAN_WC3, xan_wc3);
>      REGISTER_DECODER (XAN_WC4, xan_wc4);
>      REGISTER_DECODER (XL, xl);
> +    REGISTER_ENCDEC  (XWD, xwd);
>      REGISTER_DECODER (YOP, yop);
>      REGISTER_ENCDEC  (ZLIB, zlib);
>      REGISTER_ENCDEC  (ZMBV, zmbv);
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index be1b202..967a134 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -254,6 +254,7 @@ enum CodecID {
>      CODEC_ID_VBLE,
>      CODEC_ID_DXTORY,
>      CODEC_ID_V410,
> +    CODEC_ID_XWD,
>  
>      /* various PCM "codecs" */
>      CODEC_ID_FIRST_AUDIO = 0x10000,     ///< A dummy id pointing at the 
> start of audio codecs
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index c7b4c15..77e1682 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -21,7 +21,7 @@
>  #define AVCODEC_VERSION_H
>  
>  #define LIBAVCODEC_VERSION_MAJOR 53
> -#define LIBAVCODEC_VERSION_MINOR 34
> +#define LIBAVCODEC_VERSION_MINOR 35
>  #define LIBAVCODEC_VERSION_MICRO  0
>  
>  #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
> diff --git a/libavcodec/xwddec.c b/libavcodec/xwddec.c
> new file mode 100644
> index 0000000..9615959
> --- /dev/null
> +++ b/libavcodec/xwddec.c
> @@ -0,0 +1,220 @@
> +/*
> + * XWD image format
> + *
> + * Copyright (c) 2012 Paul B Mahol
> + *
> + * 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
> + */
> +
> +#include "libavutil/imgutils.h"
> +#include "avcodec.h"
> +#include "bytestream.h"
> +
> +static av_cold int xwd_decode_init(AVCodecContext *avctx)
> +{
> +    avctx->coded_frame = avcodec_alloc_frame();
> +    if (!avctx->coded_frame)
> +        return AVERROR(ENOMEM);
> +
> +    return 0;
> +}
> +
> +static int xwd_decode_frame(AVCodecContext *avctx, void *data,
> +                            int *data_size, AVPacket *avpkt)
> +{
> +    AVFrame *p = avctx->coded_frame;
> +    const uint8_t *buf = avpkt->data;
> +    int i, ret, buf_size = avpkt->size;
> +    uint32_t version, header_size, vclass, cmap;
> +    uint32_t xoffset, be, bpp, lsize;
> +    uint32_t pixformat, pixdepth, bunit, bitorder, bpad;
> +    uint32_t rgb[3];
> +    uint8_t *ptr;
> +
> +    if (buf_size < 100)
> +        return AVERROR_INVALIDDATA;
> +
> +    header_size = bytestream_get_be32(&buf);
> +    if (buf_size < header_size)
> +        return AVERROR_INVALIDDATA;
> +
> +    version = bytestream_get_be32(&buf);
> +    if (version != 7) {
> +        av_log(avctx, AV_LOG_ERROR, "unsupported version\n");
> +        return AVERROR_INVALIDDATA;
> +    }
> +
> +    if (header_size < 100 || header_size > buf_size) {
> +        av_log(avctx, AV_LOG_ERROR, "invalid header size\n");
> +        return AVERROR_INVALIDDATA;
> +    }

This check is redundant, it's equivalent to the two above.

> +
> +    pixformat = bytestream_get_be32(&buf);
> +    pixdepth  = bytestream_get_be32(&buf);
> +    avctx->width = bytestream_get_be32(&buf);
> +    avctx->height = bytestream_get_be32(&buf);
> +    xoffset   = bytestream_get_be32(&buf);
> +    be        = bytestream_get_be32(&buf);
> +    bunit     = bytestream_get_be32(&buf);
> +    bitorder  = bytestream_get_be32(&buf);
> +    bpad      = bytestream_get_be32(&buf);
> +    bpp       = bytestream_get_be32(&buf);
> +    lsize     = bytestream_get_be32(&buf);
> +    vclass    = bytestream_get_be32(&buf);
> +    rgb[0]    = bytestream_get_be32(&buf);
> +    rgb[1]    = bytestream_get_be32(&buf);
> +    rgb[2]    = bytestream_get_be32(&buf);
> +    buf      += 8;
> +    cmap      = bytestream_get_be32(&buf);
> +    buf      += header_size - 80;
> +
> +    av_log(avctx, AV_LOG_DEBUG, "pixformat %d, pixdepth %d, bunit %d, 
> bitorder %d, bpad %d\n",
> +           pixformat, pixdepth, bunit, bitorder, bpad);
> +    av_log(avctx, AV_LOG_DEBUG, "vclass %d, cmap %d, bpp %d, be %d, lsize 
> %d, xoffset %d\n",
> +           vclass, cmap, bpp, be, lsize, xoffset);
> +    av_log(avctx, AV_LOG_DEBUG, "red %0x, green %0x, blue %0x\n", rgb[0], 
> rgb[1], rgb[2]);
> +
> +    if (pixformat != 2) {
> +        av_log_missing_feature(avctx, "pixformat <2", 0);

You didn't test that it's actually less than 2.
And printing what value it actually is would be nice.

Also the amount of magic number throughout the code is annoying, can't
you do something about them?


-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to