Commit 992f71e9 authored by Ronald Bultje's avatar Ronald Bultje Committed by Justin Ruggles

msrle: convert MS RLE decoding function to bytestream2.

Signed-off-by: 's avatarJustin Ruggles <justin.ruggles@gmail.com>
parent 729f90e2
...@@ -34,17 +34,10 @@ ...@@ -34,17 +34,10 @@
typedef struct AascContext { typedef struct AascContext {
AVCodecContext *avctx; AVCodecContext *avctx;
GetByteContext gb;
AVFrame frame; AVFrame frame;
} AascContext; } AascContext;
#define FETCH_NEXT_STREAM_BYTE() \
if (stream_ptr >= buf_size) \
{ \
av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (fetch)\n"); \
break; \
} \
stream_byte = buf[stream_ptr++];
static av_cold int aasc_decode_init(AVCodecContext *avctx) static av_cold int aasc_decode_init(AVCodecContext *avctx)
{ {
AascContext *s = avctx->priv_data; AascContext *s = avctx->priv_data;
...@@ -84,7 +77,8 @@ static int aasc_decode_frame(AVCodecContext *avctx, ...@@ -84,7 +77,8 @@ static int aasc_decode_frame(AVCodecContext *avctx,
} }
break; break;
case 1: case 1:
ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, buf - 4, buf_size + 4); bytestream2_init(&s->gb, buf - 4, buf_size + 4);
ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, &s->gb);
break; break;
default: default:
av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr); av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr);
......
...@@ -52,6 +52,7 @@ static int bmp_decode_frame(AVCodecContext *avctx, ...@@ -52,6 +52,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
uint8_t *ptr; uint8_t *ptr;
int dsize; int dsize;
const uint8_t *buf0 = buf; const uint8_t *buf0 = buf;
GetByteContext gb;
if(buf_size < 14){ if(buf_size < 14){
av_log(avctx, AV_LOG_ERROR, "buf size too small (%d)\n", buf_size); av_log(avctx, AV_LOG_ERROR, "buf size too small (%d)\n", buf_size);
...@@ -265,7 +266,8 @@ static int bmp_decode_frame(AVCodecContext *avctx, ...@@ -265,7 +266,8 @@ static int bmp_decode_frame(AVCodecContext *avctx,
p->data[0] += p->linesize[0] * (avctx->height - 1); p->data[0] += p->linesize[0] * (avctx->height - 1);
p->linesize[0] = -p->linesize[0]; p->linesize[0] = -p->linesize[0];
} }
ff_msrle_decode(avctx, (AVPicture*)p, depth, buf, dsize); bytestream2_init(&gb, buf, dsize);
ff_msrle_decode(avctx, (AVPicture*)p, depth, &gb);
if(height < 0){ if(height < 0){
p->data[0] += p->linesize[0] * (avctx->height - 1); p->data[0] += p->linesize[0] * (avctx->height - 1);
p->linesize[0] = -p->linesize[0]; p->linesize[0] = -p->linesize[0];
......
...@@ -40,6 +40,7 @@ typedef struct MsrleContext { ...@@ -40,6 +40,7 @@ typedef struct MsrleContext {
AVCodecContext *avctx; AVCodecContext *avctx;
AVFrame frame; AVFrame frame;
GetByteContext gb;
const unsigned char *buf; const unsigned char *buf;
int size; int size;
...@@ -123,7 +124,8 @@ static int msrle_decode_frame(AVCodecContext *avctx, ...@@ -123,7 +124,8 @@ static int msrle_decode_frame(AVCodecContext *avctx,
ptr += s->frame.linesize[0]; ptr += s->frame.linesize[0];
} }
} else { } else {
ff_msrle_decode(avctx, (AVPicture*)&s->frame, avctx->bits_per_coded_sample, buf, buf_size); bytestream2_init(&s->gb, buf, buf_size);
ff_msrle_decode(avctx, (AVPicture*)&s->frame, avctx->bits_per_coded_sample, &s->gb);
} }
*data_size = sizeof(AVFrame); *data_size = sizeof(AVFrame);
......
This diff is collapsed.
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#define AVCODEC_MSRLEDEC_H #define AVCODEC_MSRLEDEC_H
#include "avcodec.h" #include "avcodec.h"
#include "bytestream.h"
/** /**
* Decode stream in MS RLE format into frame. * Decode stream in MS RLE format into frame.
...@@ -30,10 +31,9 @@ ...@@ -30,10 +31,9 @@
* @param avctx codec context * @param avctx codec context
* @param pic destination frame * @param pic destination frame
* @param depth bit depth * @param depth bit depth
* @param data input stream * @param gb input bytestream context
* @param data_size input size
*/ */
int ff_msrle_decode(AVCodecContext *avctx, AVPicture *pic, int depth, int ff_msrle_decode(AVCodecContext *avctx, AVPicture *pic,
const uint8_t* data, int data_size); int depth, GetByteContext *gb);
#endif /* AVCODEC_MSRLEDEC_H */ #endif /* AVCODEC_MSRLEDEC_H */
...@@ -58,6 +58,7 @@ typedef struct TsccContext { ...@@ -58,6 +58,7 @@ typedef struct TsccContext {
unsigned int decomp_size; unsigned int decomp_size;
// Decompression buffer // Decompression buffer
unsigned char* decomp_buf; unsigned char* decomp_buf;
GetByteContext gb;
int height; int height;
z_stream zstream; z_stream zstream;
...@@ -105,8 +106,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac ...@@ -105,8 +106,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
} }
if(zret != Z_DATA_ERROR) if (zret != Z_DATA_ERROR) {
ff_msrle_decode(avctx, (AVPicture*)&c->pic, c->bpp, c->decomp_buf, c->decomp_size - c->zstream.avail_out); bytestream2_init(&c->gb, c->decomp_buf,
c->decomp_size - c->zstream.avail_out);
ff_msrle_decode(avctx, (AVPicture*)&c->pic, c->bpp, &c->gb);
}
/* make the palette available on the way out */ /* make the palette available on the way out */
if (c->avctx->pix_fmt == PIX_FMT_PAL8) { if (c->avctx->pix_fmt == PIX_FMT_PAL8) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment