Commit 875efafa authored by Roberto Togni's avatar Roberto Togni

Moved to new palette API

Added check to aviod stride change between frames

Originally committed as revision 2466 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 5e29abf8
......@@ -26,7 +26,7 @@
* The MS RLE decoder outputs PAL8 colorspace data.
*
* Note that this decoder expects the palette colors from the end of the
* BITMAPINFO header passed through extradata.
* BITMAPINFO header passed through palctrl.
*/
#include <stdio.h>
......@@ -46,7 +46,6 @@ typedef struct MsrleContext {
unsigned char *buf;
int size;
unsigned int palette[256];
} MsrleContext;
#define FETCH_NEXT_STREAM_BYTE() \
......@@ -130,7 +129,11 @@ static void msrle_decode_pal8(MsrleContext *s)
}
/* make the palette available */
memcpy(s->frame.data[1], s->palette, 256 * 4);
memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
if (s->avctx->palctrl->palette_changed) {
s->frame.palette_has_changed = 1;
s->avctx->palctrl->palette_changed = 0;
}
/* one last sanity check on the way out */
if (stream_ptr < s->size)
......@@ -141,8 +144,6 @@ static void msrle_decode_pal8(MsrleContext *s)
static int msrle_decode_init(AVCodecContext *avctx)
{
MsrleContext *s = (MsrleContext *)avctx->priv_data;
int i, j;
unsigned char *palette;
s->avctx = avctx;
......@@ -150,15 +151,6 @@ static int msrle_decode_init(AVCodecContext *avctx)
avctx->has_b_frames = 0;
s->frame.data[0] = s->prev_frame.data[0] = NULL;
/* convert palette */
palette = (unsigned char *)s->avctx->extradata;
memset (s->palette, 0, 256 * 4);
for (i = 0, j = 0; i < s->avctx->extradata_size / 4; i++, j += 4)
s->palette[i] =
(palette[j + 2] << 16) |
(palette[j + 1] << 8) |
(palette[j + 0] << 0);
return 0;
}
......@@ -177,6 +169,11 @@ static int msrle_decode_frame(AVCodecContext *avctx,
return -1;
}
if (s->prev_frame.data[0] && (s->frame.linesize[0] != s->prev_frame.linesize[0]))
printf (" MS RLE: Buffer linesize changed: current %u, previous %u.\n"
" Expect wrong image and/or crash!\n",
s->frame.linesize[0], s->prev_frame.linesize[0]);
/* grossly inefficient, but...oh well */
if (s->prev_frame.data[0] != NULL)
memcpy(s->frame.data[0], s->prev_frame.data[0],
......
......@@ -25,8 +25,8 @@
* http://www.pcisys.net/~melanson/codecs/
*
* This decoder outputs either PAL8 or RGB555 data, depending on the
* whether a RGB palette was passed through via extradata; if the extradata
* is present, then the data is PAL8; RGB555 otherwise.
* whether a RGB palette was passed through palctrl;
* if it's present, then the data is PAL8; RGB555 otherwise.
*/
#include <stdio.h>
......@@ -66,34 +66,18 @@ typedef struct Msvideo1Context {
int size;
int mode_8bit; /* if it's not 8-bit, it's 16-bit */
unsigned char palette[PALETTE_COUNT * 4];
} Msvideo1Context;
static int msvideo1_decode_init(AVCodecContext *avctx)
{
Msvideo1Context *s = (Msvideo1Context *)avctx->priv_data;
int i;
unsigned char r, g, b;
unsigned char *raw_palette;
unsigned int *palette32;
s->avctx = avctx;
/* figure out the colorspace based on the presence of a palette in
* extradata */
if (s->avctx->extradata_size) {
/* figure out the colorspace based on the presence of a palette */
if (s->avctx->palctrl) {
s->mode_8bit = 1;
/* load up the palette */
palette32 = (unsigned int *)s->palette;
raw_palette = (unsigned char *)s->avctx->extradata;
for (i = 0; i < s->avctx->extradata_size / 4; i++) {
b = *raw_palette++;
g = *raw_palette++;
r = *raw_palette++;
raw_palette++;
palette32[i] = (r << 16) | (g << 8) | (b);
}
avctx->pix_fmt = PIX_FMT_PAL8;
} else {
s->mode_8bit = 0;
......@@ -207,8 +191,13 @@ static void msvideo1_decode_8bit(Msvideo1Context *s)
}
/* make the palette available on the way out */
if (s->avctx->pix_fmt == PIX_FMT_PAL8)
memcpy(s->frame.data[1], s->palette, PALETTE_COUNT * 4);
if (s->avctx->pix_fmt == PIX_FMT_PAL8) {
memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
if (s->avctx->palctrl->palette_changed) {
s->frame.palette_has_changed = 1;
s->avctx->palctrl->palette_changed = 0;
}
}
}
static void msvideo1_decode_16bit(Msvideo1Context *s)
......@@ -337,6 +326,11 @@ static int msvideo1_decode_frame(AVCodecContext *avctx,
return -1;
}
if (s->prev_frame.data[0] &&(s->frame.linesize[0] != s->prev_frame.linesize[0]))
printf (" MS Video-1: Buffer linesize changed: current %u, previous %u.\n"
" Expect wrong image and/or crash!\n",
s->frame.linesize[0], s->prev_frame.linesize[0]);
if (s->mode_8bit)
msvideo1_decode_8bit(s);
else
......
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