aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2011-04-09 15:49:51 +0200
committerLuca Barbato <lu_zero@gentoo.org>2011-04-15 18:02:05 +0200
commit2d8591c27e2dc582a7020e2580e16278dbfbddff (patch)
tree5e251cc6e974c0b9e2c99b3f6e622b4983e4941a /libavcodec
parent4de339e219908ff44cbb1d823edeeead3b8facda (diff)
downloadffmpeg-2d8591c27e2dc582a7020e2580e16278dbfbddff.tar.gz
make containers pass palette change in AVPacket
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/8bps.c21
-rw-r--r--libavcodec/cinepak.c19
-rw-r--r--libavcodec/idcinvideo.c12
-rw-r--r--libavcodec/interplayvideo.c21
-rw-r--r--libavcodec/kmvc.c16
-rw-r--r--libavcodec/msrle.c17
-rw-r--r--libavcodec/msvideo1.c24
-rw-r--r--libavcodec/qpeg.c12
-rw-r--r--libavcodec/qtrle.c12
-rw-r--r--libavcodec/rawdec.c10
-rw-r--r--libavcodec/smc.c13
-rw-r--r--libavcodec/targa.c7
-rw-r--r--libavcodec/tscc.c10
13 files changed, 101 insertions, 93 deletions
diff --git a/libavcodec/8bps.c b/libavcodec/8bps.c
index 1c6d4068b0..055715fde5 100644
--- a/libavcodec/8bps.c
+++ b/libavcodec/8bps.c
@@ -50,6 +50,8 @@ typedef struct EightBpsContext {
unsigned char planes;
unsigned char planemap[4];
+
+ uint32_t pal[256];
} EightBpsContext;
@@ -129,13 +131,16 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
}
}
- if (avctx->palctrl) {
- memcpy (c->pic.data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
- if (avctx->palctrl->palette_changed) {
+ if (avctx->bits_per_coded_sample <= 8) {
+ const uint8_t *pal = av_packet_get_side_data(avpkt,
+ AV_PKT_DATA_PALETTE,
+ NULL);
+ if (pal) {
c->pic.palette_has_changed = 1;
- avctx->palctrl->palette_changed = 0;
- } else
- c->pic.palette_has_changed = 0;
+ memcpy(c->pal, pal, AVPALETTE_SIZE);
+ }
+
+ memcpy (c->pic.data[1], c->pal, AVPALETTE_SIZE);
}
*data_size = sizeof(AVFrame);
@@ -164,10 +169,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
avctx->pix_fmt = PIX_FMT_PAL8;
c->planes = 1;
c->planemap[0] = 0; // 1st plane is palette indexes
- if (avctx->palctrl == NULL) {
- av_log(avctx, AV_LOG_ERROR, "Error: PAL8 format but no palette from demuxer.\n");
- return -1;
- }
break;
case 24:
avctx->pix_fmt = avctx->get_format(avctx, pixfmt_rgb24);
diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c
index f325bdb0ce..4bda2a74eb 100644
--- a/libavcodec/cinepak.c
+++ b/libavcodec/cinepak.c
@@ -67,6 +67,7 @@ typedef struct CinepakContext {
int sega_film_skip_bytes;
+ uint32_t pal[256];
} CinepakContext;
static void cinepak_decode_codebook (cvid_codebook *codebook,
@@ -395,7 +396,7 @@ static av_cold int cinepak_decode_init(AVCodecContext *avctx)
s->sega_film_skip_bytes = -1; /* uninitialized state */
// check for paletted data
- if ((avctx->palctrl == NULL) || (avctx->bits_per_coded_sample == 40)) {
+ if (avctx->bits_per_coded_sample != 8) {
s->palette_video = 0;
avctx->pix_fmt = PIX_FMT_YUV420P;
} else {
@@ -427,17 +428,19 @@ static int cinepak_decode_frame(AVCodecContext *avctx,
return -1;
}
- cinepak_decode(s);
-
if (s->palette_video) {
- memcpy (s->frame.data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
- if (avctx->palctrl->palette_changed) {
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+ if (pal) {
s->frame.palette_has_changed = 1;
- avctx->palctrl->palette_changed = 0;
- } else
- s->frame.palette_has_changed = 0;
+ memcpy(s->pal, pal, AVPALETTE_SIZE);
+ }
}
+ cinepak_decode(s);
+
+ if (s->palette_video)
+ memcpy (s->frame.data[1], s->pal, AVPALETTE_SIZE);
+
*data_size = sizeof(AVFrame);
*(AVFrame*)data = s->frame;
diff --git a/libavcodec/idcinvideo.c b/libavcodec/idcinvideo.c
index b8d47ad555..ac56e19442 100644
--- a/libavcodec/idcinvideo.c
+++ b/libavcodec/idcinvideo.c
@@ -72,6 +72,7 @@ typedef struct IdcinContext {
hnode huff_nodes[256][HUF_TOKENS*2];
int num_huff_nodes[256];
+ uint32_t pal[256];
} IdcinContext;
/*
@@ -213,7 +214,7 @@ static int idcin_decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
IdcinContext *s = avctx->priv_data;
- AVPaletteControl *palette_control = avctx->palctrl;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
s->buf = buf;
s->size = buf_size;
@@ -228,13 +229,12 @@ static int idcin_decode_frame(AVCodecContext *avctx,
idcin_decode_vlcs(s);
- /* make the palette available on the way out */
- memcpy(s->frame.data[1], palette_control->palette, PALETTE_COUNT * 4);
- /* If palette changed inform application*/
- if (palette_control->palette_changed) {
- palette_control->palette_changed = 0;
+ if (pal) {
s->frame.palette_has_changed = 1;
+ memcpy(s->pal, pal, AVPALETTE_SIZE);
}
+ /* make the palette available on the way out */
+ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE);
*data_size = sizeof(AVFrame);
*(AVFrame*)data = s->frame;
diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c
index 8dbe6f6cbe..c12b241fcb 100644
--- a/libavcodec/interplayvideo.c
+++ b/libavcodec/interplayvideo.c
@@ -77,6 +77,7 @@ typedef struct IpvideoContext {
int stride;
int upper_motion_limit_offset;
+ uint32_t pal[256];
} IpvideoContext;
#define CHECK_STREAM_PTR(stream_ptr, stream_end, n) \
@@ -969,7 +970,7 @@ static void ipvideo_decode_opcodes(IpvideoContext *s)
if (!s->is_16bpp) {
/* this is PAL8, so make the palette available */
- memcpy(s->current_frame.data[1], s->avctx->palctrl->palette, PALETTE_COUNT * 4);
+ memcpy(s->current_frame.data[1], s->pal, AVPALETTE_SIZE);
s->stride = s->current_frame.linesize[0];
s->stream_ptr = s->buf + 14; /* data starts 14 bytes in */
@@ -1023,10 +1024,6 @@ static av_cold int ipvideo_decode_init(AVCodecContext *avctx)
s->is_16bpp = avctx->bits_per_coded_sample == 16;
avctx->pix_fmt = s->is_16bpp ? PIX_FMT_RGB555 : PIX_FMT_PAL8;
- if (!s->is_16bpp && s->avctx->palctrl == NULL) {
- av_log(avctx, AV_LOG_ERROR, " Interplay video: palette expected.\n");
- return -1;
- }
dsputil_init(&s->dsp, avctx);
@@ -1046,7 +1043,6 @@ static int ipvideo_decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
IpvideoContext *s = avctx->priv_data;
- AVPaletteControl *palette_control = avctx->palctrl;
/* compressed buffer needs to be large enough to at least hold an entire
* decoding map */
@@ -1063,13 +1059,16 @@ static int ipvideo_decode_frame(AVCodecContext *avctx,
return -1;
}
- ipvideo_decode_opcodes(s);
-
- if (!s->is_16bpp && palette_control->palette_changed) {
- palette_control->palette_changed = 0;
- s->current_frame.palette_has_changed = 1;
+ if (!s->is_16bpp) {
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+ if (pal) {
+ s->current_frame.palette_has_changed = 1;
+ memcpy(s->pal, pal, AVPALETTE_SIZE);
+ }
}
+ ipvideo_decode_opcodes(s);
+
*data_size = sizeof(AVFrame);
*(AVFrame*)data = s->current_frame;
diff --git a/libavcodec/kmvc.c b/libavcodec/kmvc.c
index 2671cc6b24..c41c8820c2 100644
--- a/libavcodec/kmvc.c
+++ b/libavcodec/kmvc.c
@@ -233,6 +233,7 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPa
int i;
int header;
int blocksize;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
if (ctx->pic.data[0])
avctx->release_buffer(avctx, &ctx->pic);
@@ -264,13 +265,6 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPa
ctx->pic.pict_type = FF_P_TYPE;
}
- /* if palette has been changed, copy it from palctrl */
- if (ctx->avctx->palctrl && ctx->avctx->palctrl->palette_changed) {
- memcpy(ctx->pal, ctx->avctx->palctrl->palette, AVPALETTE_SIZE);
- ctx->setpal = 1;
- ctx->avctx->palctrl->palette_changed = 0;
- }
-
if (header & KMVC_PALETTE) {
ctx->pic.palette_has_changed = 1;
// palette starts from index 1 and has 127 entries
@@ -279,6 +273,11 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPa
}
}
+ if (pal) {
+ ctx->pic.palette_has_changed = 1;
+ memcpy(ctx->pal, pal, AVPALETTE_SIZE);
+ }
+
if (ctx->setpal) {
ctx->setpal = 0;
ctx->pic.palette_has_changed = 1;
@@ -374,9 +373,6 @@ static av_cold int decode_init(AVCodecContext * avctx)
src += 4;
}
c->setpal = 1;
- if (c->avctx->palctrl) {
- c->avctx->palctrl->palette_changed = 0;
- }
}
avctx->pix_fmt = PIX_FMT_PAL8;
diff --git a/libavcodec/msrle.c b/libavcodec/msrle.c
index a400589fde..f426b058bd 100644
--- a/libavcodec/msrle.c
+++ b/libavcodec/msrle.c
@@ -26,9 +26,6 @@
* http://www.pcisys.net/~melanson/codecs/
*
* 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 palctrl.
*/
#include <stdio.h>
@@ -46,6 +43,7 @@ typedef struct MsrleContext {
const unsigned char *buf;
int size;
+ uint32_t pal[256];
} MsrleContext;
static av_cold int msrle_decode_init(AVCodecContext *avctx)
@@ -91,13 +89,16 @@ static int msrle_decode_frame(AVCodecContext *avctx,
return -1;
}
- if (s->avctx->palctrl) {
- /* make the palette available */
- memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
- if (s->avctx->palctrl->palette_changed) {
+ if (avctx->bits_per_coded_sample <= 8) {
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+
+ if (pal) {
s->frame.palette_has_changed = 1;
- s->avctx->palctrl->palette_changed = 0;
+ memcpy(s->pal, pal, AVPALETTE_SIZE);
}
+
+ /* make the palette available */
+ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE);
}
/* FIXME how to correctly detect RLE ??? */
diff --git a/libavcodec/msvideo1.c b/libavcodec/msvideo1.c
index e01ddf5c47..a89ec6ac65 100644
--- a/libavcodec/msvideo1.c
+++ b/libavcodec/msvideo1.c
@@ -25,9 +25,6 @@
* For more information about the MS Video-1 format, visit:
* http://www.pcisys.net/~melanson/codecs/
*
- * This decoder outputs either PAL8 or RGB555 data, depending on the
- * whether a RGB palette was passed through palctrl;
- * if it's present, then the data is PAL8; RGB555 otherwise.
*/
#include <stdio.h>
@@ -55,6 +52,7 @@ typedef struct Msvideo1Context {
int mode_8bit; /* if it's not 8-bit, it's 16-bit */
+ uint32_t pal[256];
} Msvideo1Context;
static av_cold int msvideo1_decode_init(AVCodecContext *avctx)
@@ -64,7 +62,7 @@ static av_cold int msvideo1_decode_init(AVCodecContext *avctx)
s->avctx = avctx;
/* figure out the colorspace based on the presence of a palette */
- if (s->avctx->palctrl) {
+ if (s->avctx->bits_per_coded_sample == 8) {
s->mode_8bit = 1;
avctx->pix_fmt = PIX_FMT_PAL8;
} else {
@@ -173,13 +171,8 @@ 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->avctx->palctrl->palette, AVPALETTE_SIZE);
- if (s->avctx->palctrl->palette_changed) {
- s->frame.palette_has_changed = 1;
- s->avctx->palctrl->palette_changed = 0;
- }
- }
+ if (s->avctx->pix_fmt == PIX_FMT_PAL8)
+ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE);
}
static void msvideo1_decode_16bit(Msvideo1Context *s)
@@ -309,6 +302,15 @@ static int msvideo1_decode_frame(AVCodecContext *avctx,
return -1;
}
+ if (s->mode_8bit) {
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+
+ if (pal) {
+ memcpy(s->pal, pal, AVPALETTE_SIZE);
+ s->frame.palette_has_changed = 1;
+ }
+ }
+
if (s->mode_8bit)
msvideo1_decode_8bit(s);
else
diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c
index ccd634ae80..c96184ff38 100644
--- a/libavcodec/qpeg.c
+++ b/libavcodec/qpeg.c
@@ -30,6 +30,7 @@ typedef struct QpegContext{
AVCodecContext *avctx;
AVFrame pic;
uint8_t *refdata;
+ uint32_t pal[256];
} QpegContext;
static void qpeg_decode_intra(const uint8_t *src, uint8_t *dst, int size,
@@ -256,6 +257,7 @@ static int decode_frame(AVCodecContext *avctx,
AVFrame * const p= (AVFrame*)&a->pic;
uint8_t* outdata;
int delta;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
if(p->data[0])
avctx->release_buffer(avctx, p);
@@ -274,11 +276,11 @@ static int decode_frame(AVCodecContext *avctx,
}
/* make the palette available on the way out */
- memcpy(a->pic.data[1], a->avctx->palctrl->palette, AVPALETTE_SIZE);
- if (a->avctx->palctrl->palette_changed) {
+ if (pal) {
a->pic.palette_has_changed = 1;
- a->avctx->palctrl->palette_changed = 0;
+ memcpy(a->pal, pal, AVPALETTE_SIZE);
}
+ memcpy(a->pic.data[1], a->pal, AVPALETTE_SIZE);
*data_size = sizeof(AVFrame);
*(AVFrame*)data = a->pic;
@@ -289,10 +291,6 @@ static int decode_frame(AVCodecContext *avctx,
static av_cold int decode_init(AVCodecContext *avctx){
QpegContext * const a = avctx->priv_data;
- if (!avctx->palctrl) {
- av_log(avctx, AV_LOG_FATAL, "Missing required palette via palctrl\n");
- return -1;
- }
a->avctx = avctx;
avctx->pix_fmt= PIX_FMT_PAL8;
a->refdata = av_malloc(avctx->width * avctx->height);
diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index a8cc903fcb..e14c306c6b 100644
--- a/libavcodec/qtrle.c
+++ b/libavcodec/qtrle.c
@@ -46,6 +46,7 @@ typedef struct QtrleContext {
const unsigned char *buf;
int size;
+ uint32_t pal[256];
} QtrleContext;
#define CHECK_STREAM_PTR(n) \
@@ -511,12 +512,15 @@ static int qtrle_decode_frame(AVCodecContext *avctx,
}
if(has_palette) {
- /* make the palette available on the way out */
- memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE);
- if (s->avctx->palctrl->palette_changed) {
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+
+ if (pal) {
s->frame.palette_has_changed = 1;
- s->avctx->palctrl->palette_changed = 0;
+ memcpy(s->pal, pal, AVPALETTE_SIZE);
}
+
+ /* make the palette available on the way out */
+ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE);
}
done:
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 3c38829f17..3dbfdfe793 100644
--- a/libavcodec/rawdec.c
+++ b/libavcodec/rawdec.c
@@ -158,9 +158,13 @@ static int raw_decode(AVCodecContext *avctx,
(av_pix_fmt_descriptors[avctx->pix_fmt].flags & PIX_FMT_PAL))){
frame->data[1]= context->palette;
}
- if (avctx->palctrl && avctx->palctrl->palette_changed) {
- memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
- avctx->palctrl->palette_changed = 0;
+ if (avctx->pix_fmt == PIX_FMT_PAL8) {
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+
+ if (pal) {
+ memcpy(frame->data[1], pal, AVPALETTE_SIZE);
+ frame->palette_has_changed = 1;
+ }
}
if(avctx->pix_fmt==PIX_FMT_BGR24 && ((frame->linesize[0]+3)&~3)*avctx->height <= buf_size)
frame->linesize[0] = (frame->linesize[0]+3)&~3;
diff --git a/libavcodec/smc.c b/libavcodec/smc.c
index fe92b43bc6..e75203d7a5 100644
--- a/libavcodec/smc.c
+++ b/libavcodec/smc.c
@@ -54,6 +54,7 @@ typedef struct SmcContext {
unsigned char color_quads[COLORS_PER_TABLE * CQUAD];
unsigned char color_octets[COLORS_PER_TABLE * COCTET];
+ uint32_t pal[256];
} SmcContext;
#define GET_BLOCK_COUNT() \
@@ -110,11 +111,7 @@ static void smc_decode_stream(SmcContext *s)
int color_octet_index = 0;
/* make the palette available */
- 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;
- }
+ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE);
chunk_size = AV_RB32(&s->buf[stream_ptr]) & 0x00FFFFFF;
stream_ptr += 4;
@@ -440,6 +437,7 @@ static int smc_decode_frame(AVCodecContext *avctx,
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
SmcContext *s = avctx->priv_data;
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
s->buf = buf;
s->size = buf_size;
@@ -452,6 +450,11 @@ static int smc_decode_frame(AVCodecContext *avctx,
return -1;
}
+ if (pal) {
+ s->frame.palette_has_changed = 1;
+ memcpy(s->pal, pal, AVPALETTE_SIZE);
+ }
+
smc_decode_stream(s);
*data_size = sizeof(AVFrame);
diff --git a/libavcodec/targa.c b/libavcodec/targa.c
index 06f87e44b2..910cc1ba94 100644
--- a/libavcodec/targa.c
+++ b/libavcodec/targa.c
@@ -171,13 +171,6 @@ static int decode_frame(AVCodecContext *avctx,
stride = -p->linesize[0];
}
- if(avctx->pix_fmt == PIX_FMT_PAL8 && avctx->palctrl){
- memcpy(p->data[1], avctx->palctrl->palette, AVPALETTE_SIZE);
- if(avctx->palctrl->palette_changed){
- p->palette_has_changed = 1;
- avctx->palctrl->palette_changed = 0;
- }
- }
if(colors){
size_t pal_size;
if((colors + first_clr) > 256){
diff --git a/libavcodec/tscc.c b/libavcodec/tscc.c
index f69597369a..bd05f02a61 100644
--- a/libavcodec/tscc.c
+++ b/libavcodec/tscc.c
@@ -60,6 +60,8 @@ typedef struct TsccContext {
unsigned char* decomp_buf;
int height;
z_stream zstream;
+
+ uint32_t pal[256];
} CamtasiaContext;
/*
@@ -111,11 +113,13 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
/* make the palette available on the way out */
if (c->avctx->pix_fmt == PIX_FMT_PAL8) {
- memcpy(c->pic.data[1], c->avctx->palctrl->palette, AVPALETTE_SIZE);
- if (c->avctx->palctrl->palette_changed) {
+ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
+
+ if (pal) {
c->pic.palette_has_changed = 1;
- c->avctx->palctrl->palette_changed = 0;
+ memcpy(c->pal, pal, AVPALETTE_SIZE);
}
+ memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE);
}
*data_size = sizeof(AVFrame);