On 01/16/2012 01:56 AM, Laurentiu Ion wrote:
> ---
> libavcodec/dxa.c | 44 ++++++++++++++++++++++++++------------------
> 1 files changed, 26 insertions(+), 18 deletions(-)
>
> diff --git a/libavcodec/dxa.c b/libavcodec/dxa.c
> index 97b912a..baeb067 100644
> --- a/libavcodec/dxa.c
> +++ b/libavcodec/dxa.c
> @@ -29,6 +29,7 @@
>
> #include "libavutil/intreadwrite.h"
> #include "avcodec.h"
> +#include "bytestream.h"
>
> #include <zlib.h>
>
> @@ -42,12 +43,14 @@ typedef struct DxaDecContext {
> int dsize;
> uint8_t *decomp_buf;
> uint32_t pal[256];
> + GetByteContext g;
> } DxaDecContext;
>
> static const int shift1[6] = { 0, 8, 8, 8, 4, 4 };
> static const int shift2[6] = { 0, 0, 8, 4, 0, 4 };
>
> -static int decode_13(AVCodecContext *avctx, DxaDecContext *c, uint8_t* dst,
> uint8_t *src, uint8_t *ref)
> +static int decode_13(AVCodecContext *avctx, DxaDecContext *c,
> + uint8_t* dst, uint8_t *src, uint8_t *ref)
> {
> uint8_t *code, *data, *mv, *msk, *tmp, *tmp2;
> int i, j, k;
> @@ -188,31 +191,30 @@ static int decode_13(AVCodecContext *avctx,
> DxaDecContext *c, uint8_t* dst, uint
> return 0;
> }
>
> -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
> AVPacket *avpkt)
> +static int decode_frame(AVCodecContext *avctx,
> + void *data, int *data_size, AVPacket *avpkt)
> {
> - const uint8_t *buf = avpkt->data;
> - int buf_size = avpkt->size;
> DxaDecContext * const c = avctx->priv_data;
> uint8_t *outptr, *srcptr, *tmpptr;
> unsigned long dsize;
> int i, j, compr;
> int stride;
> - int orig_buf_size = buf_size;
> int pc = 0;
>
> + bytestream2_init(&c->g, avpkt->data, avpkt->size);
> +
> /* make the palette available on the way out */
> - if(buf[0]=='C' && buf[1]=='M' && buf[2]=='A' && buf[3]=='P'){
> + if(bytestream2_peek_be32(&c->g) == MKTAG('C','M','A','P')) {
> int r, g, b;
>
> - buf += 4;
> + bytestream2_skip(&c->g, 4);
> for(i = 0; i < 256; i++){
> - r = *buf++;
> - g = *buf++;
> - b = *buf++;
> + r = bytestream2_get_byte(&c->g);
> + g = bytestream2_get_byte(&c->g);
> + b = bytestream2_get_byte(&c->g);
> c->pal[i] = (r << 16) | (g << 8) | b;
you should be able to use bytestream2_get_le24() to get the whole
palette entry.
> }
> pc = 1;
> - buf_size -= 768+4;
> }
>
> if(avctx->get_buffer(avctx, &c->pic) < 0){
> @@ -227,13 +229,15 @@ static int decode_frame(AVCodecContext *avctx, void
> *data, int *data_size, AVPac
> tmpptr = c->prev.data[0];
> stride = c->pic.linesize[0];
>
> - if(buf[0]=='N' && buf[1]=='U' && buf[2]=='L' && buf[3]=='L')
> + if(bytestream2_get_be32(&c->g) == MKTAG('N','U','L','L'))
> compr = -1;
> - else
> - compr = buf[4];
> + else {
> + compr = bytestream2_get_byte(&c->g);
> + }
>
> dsize = c->dsize;
> - if((compr != 4 && compr != -1) && uncompress(c->decomp_buf, &dsize, buf
> + 9, buf_size - 9) != Z_OK){
> + if((compr != 4 && compr != -1) &&
> + uncompress(c->decomp_buf, &dsize, avpkt->data +
> bytestream2_tell(&c->g) + 9, avpkt->size - 9) != Z_OK) {
This does not look like it's equivalent to the current code.
I would recommend skipping 5 in the "if" branch and skipping 4 in the
"else" branch. Then pass avpkt->data + bytestream2_tell(&c->g),
bytestream2_get_bytes_left().
> av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n");
> return -1;
> }
> @@ -242,7 +246,9 @@ static int decode_frame(AVCodecContext *avctx, void
> *data, int *data_size, AVPac
> c->pic.key_frame = 0;
> c->pic.pict_type = AV_PICTURE_TYPE_P;
> if(c->prev.data[0])
> - memcpy(c->pic.data[0], c->prev.data[0], c->pic.linesize[0] *
> avctx->height);
> + memcpy(c->pic.data[0],
> + c->prev.data[0],
> + c->pic.linesize[0] * avctx->height);
stray unrelated change?
> else{ // Should happen only when first frame is 'NULL'
> memset(c->pic.data[0], 0, c->pic.linesize[0] * avctx->height);
> c->pic.key_frame = 1;
> @@ -273,7 +279,9 @@ static int decode_frame(AVCodecContext *avctx, void
> *data, int *data_size, AVPac
> decode_13(avctx, c, c->pic.data[0], srcptr, c->prev.data[0]);
> break;
> default:
> - av_log(avctx, AV_LOG_ERROR, "Unknown/unsupported compression type
> %d\n", buf[4]);
> + av_log(avctx, AV_LOG_ERROR,
> + "Unknown/unsupported compression type %d\n",
> + compr);
why the strange line wrapping?
> return -1;
> }
>
> @@ -285,7 +293,7 @@ static int decode_frame(AVCodecContext *avctx, void
> *data, int *data_size, AVPac
> *(AVFrame*)data = c->prev;
>
> /* always report that the buffer was completely consumed */
> - return orig_buf_size;
> + return avpkt->size;
> }
>
> static av_cold int decode_init(AVCodecContext *avctx)
The patch seems to be missing a lot of the file. It looks to me like
bytestream2 functions could also be used in the compr==2-5 case and in
decode_13().
-Justin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel