commit 2d8591c27e2dc582a7020e2580e16278dbfbddff
Author: Kostya Shishkov <kostya.shishkov@gmail.com>
Date: Sat Apr 9 15:49:51 2011 +0200
make containers pass palette change in AVPacket
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
diff --git a/libavcodec/8bps.c b/libavcodec/8bps.c
index 1c6d406..055715f 100644
|
a
|
b
|
typedef struct EightBpsContext {
|
| 50 | 50 | |
| 51 | 51 | unsigned char planes; |
| 52 | 52 | unsigned char planemap[4]; |
| | 53 | |
| | 54 | uint32_t pal[256]; |
| 53 | 55 | } EightBpsContext; |
| 54 | 56 | |
| 55 | 57 | |
| … |
… |
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
|
| 129 | 131 | } |
| 130 | 132 | } |
| 131 | 133 | |
| 132 | | if (avctx->palctrl) { |
| 133 | | memcpy (c->pic.data[1], avctx->palctrl->palette, AVPALETTE_SIZE); |
| 134 | | if (avctx->palctrl->palette_changed) { |
| | 134 | if (avctx->bits_per_coded_sample <= 8) { |
| | 135 | const uint8_t *pal = av_packet_get_side_data(avpkt, |
| | 136 | AV_PKT_DATA_PALETTE, |
| | 137 | NULL); |
| | 138 | if (pal) { |
| 135 | 139 | c->pic.palette_has_changed = 1; |
| 136 | | avctx->palctrl->palette_changed = 0; |
| 137 | | } else |
| 138 | | c->pic.palette_has_changed = 0; |
| | 140 | memcpy(c->pal, pal, AVPALETTE_SIZE); |
| | 141 | } |
| | 142 | |
| | 143 | memcpy (c->pic.data[1], c->pal, AVPALETTE_SIZE); |
| 139 | 144 | } |
| 140 | 145 | |
| 141 | 146 | *data_size = sizeof(AVFrame); |
| … |
… |
static av_cold int decode_init(AVCodecContext *avctx)
|
| 164 | 169 | avctx->pix_fmt = PIX_FMT_PAL8; |
| 165 | 170 | c->planes = 1; |
| 166 | 171 | c->planemap[0] = 0; // 1st plane is palette indexes |
| 167 | | if (avctx->palctrl == NULL) { |
| 168 | | av_log(avctx, AV_LOG_ERROR, "Error: PAL8 format but no palette from demuxer.\n"); |
| 169 | | return -1; |
| 170 | | } |
| 171 | 172 | break; |
| 172 | 173 | case 24: |
| 173 | 174 | avctx->pix_fmt = avctx->get_format(avctx, pixfmt_rgb24); |
diff --git a/libavcodec/cinepak.c b/libavcodec/cinepak.c
index f325bdb..4bda2a7 100644
|
a
|
b
|
typedef struct CinepakContext {
|
| 67 | 67 | |
| 68 | 68 | int sega_film_skip_bytes; |
| 69 | 69 | |
| | 70 | uint32_t pal[256]; |
| 70 | 71 | } CinepakContext; |
| 71 | 72 | |
| 72 | 73 | static void cinepak_decode_codebook (cvid_codebook *codebook, |
| … |
… |
static av_cold int cinepak_decode_init(AVCodecContext *avctx)
|
| 395 | 396 | s->sega_film_skip_bytes = -1; /* uninitialized state */ |
| 396 | 397 | |
| 397 | 398 | // check for paletted data |
| 398 | | if ((avctx->palctrl == NULL) || (avctx->bits_per_coded_sample == 40)) { |
| | 399 | if (avctx->bits_per_coded_sample != 8) { |
| 399 | 400 | s->palette_video = 0; |
| 400 | 401 | avctx->pix_fmt = PIX_FMT_YUV420P; |
| 401 | 402 | } else { |
| … |
… |
static int cinepak_decode_frame(AVCodecContext *avctx,
|
| 427 | 428 | return -1; |
| 428 | 429 | } |
| 429 | 430 | |
| 430 | | cinepak_decode(s); |
| 431 | | |
| 432 | 431 | if (s->palette_video) { |
| 433 | | memcpy (s->frame.data[1], avctx->palctrl->palette, AVPALETTE_SIZE); |
| 434 | | if (avctx->palctrl->palette_changed) { |
| | 432 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| | 433 | if (pal) { |
| 435 | 434 | s->frame.palette_has_changed = 1; |
| 436 | | avctx->palctrl->palette_changed = 0; |
| 437 | | } else |
| 438 | | s->frame.palette_has_changed = 0; |
| | 435 | memcpy(s->pal, pal, AVPALETTE_SIZE); |
| | 436 | } |
| 439 | 437 | } |
| 440 | 438 | |
| | 439 | cinepak_decode(s); |
| | 440 | |
| | 441 | if (s->palette_video) |
| | 442 | memcpy (s->frame.data[1], s->pal, AVPALETTE_SIZE); |
| | 443 | |
| 441 | 444 | *data_size = sizeof(AVFrame); |
| 442 | 445 | *(AVFrame*)data = s->frame; |
| 443 | 446 | |
diff --git a/libavcodec/idcinvideo.c b/libavcodec/idcinvideo.c
index b8d47ad..ac56e19 100644
|
a
|
b
|
typedef struct IdcinContext {
|
| 72 | 72 | hnode huff_nodes[256][HUF_TOKENS*2]; |
| 73 | 73 | int num_huff_nodes[256]; |
| 74 | 74 | |
| | 75 | uint32_t pal[256]; |
| 75 | 76 | } IdcinContext; |
| 76 | 77 | |
| 77 | 78 | /* |
| … |
… |
static int idcin_decode_frame(AVCodecContext *avctx,
|
| 213 | 214 | const uint8_t *buf = avpkt->data; |
| 214 | 215 | int buf_size = avpkt->size; |
| 215 | 216 | IdcinContext *s = avctx->priv_data; |
| 216 | | AVPaletteControl *palette_control = avctx->palctrl; |
| | 217 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| 217 | 218 | |
| 218 | 219 | s->buf = buf; |
| 219 | 220 | s->size = buf_size; |
| … |
… |
static int idcin_decode_frame(AVCodecContext *avctx,
|
| 228 | 229 | |
| 229 | 230 | idcin_decode_vlcs(s); |
| 230 | 231 | |
| 231 | | /* make the palette available on the way out */ |
| 232 | | memcpy(s->frame.data[1], palette_control->palette, PALETTE_COUNT * 4); |
| 233 | | /* If palette changed inform application*/ |
| 234 | | if (palette_control->palette_changed) { |
| 235 | | palette_control->palette_changed = 0; |
| | 232 | if (pal) { |
| 236 | 233 | s->frame.palette_has_changed = 1; |
| | 234 | memcpy(s->pal, pal, AVPALETTE_SIZE); |
| 237 | 235 | } |
| | 236 | /* make the palette available on the way out */ |
| | 237 | memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); |
| 238 | 238 | |
| 239 | 239 | *data_size = sizeof(AVFrame); |
| 240 | 240 | *(AVFrame*)data = s->frame; |
diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c
index 8dbe6f6..c12b241 100644
|
a
|
b
|
typedef struct IpvideoContext {
|
| 77 | 77 | int stride; |
| 78 | 78 | int upper_motion_limit_offset; |
| 79 | 79 | |
| | 80 | uint32_t pal[256]; |
| 80 | 81 | } IpvideoContext; |
| 81 | 82 | |
| 82 | 83 | #define CHECK_STREAM_PTR(stream_ptr, stream_end, n) \ |
| … |
… |
static void ipvideo_decode_opcodes(IpvideoContext *s)
|
| 969 | 970 | |
| 970 | 971 | if (!s->is_16bpp) { |
| 971 | 972 | /* this is PAL8, so make the palette available */ |
| 972 | | memcpy(s->current_frame.data[1], s->avctx->palctrl->palette, PALETTE_COUNT * 4); |
| | 973 | memcpy(s->current_frame.data[1], s->pal, AVPALETTE_SIZE); |
| 973 | 974 | |
| 974 | 975 | s->stride = s->current_frame.linesize[0]; |
| 975 | 976 | s->stream_ptr = s->buf + 14; /* data starts 14 bytes in */ |
| … |
… |
static av_cold int ipvideo_decode_init(AVCodecContext *avctx)
|
| 1023 | 1024 | |
| 1024 | 1025 | s->is_16bpp = avctx->bits_per_coded_sample == 16; |
| 1025 | 1026 | avctx->pix_fmt = s->is_16bpp ? PIX_FMT_RGB555 : PIX_FMT_PAL8; |
| 1026 | | if (!s->is_16bpp && s->avctx->palctrl == NULL) { |
| 1027 | | av_log(avctx, AV_LOG_ERROR, " Interplay video: palette expected.\n"); |
| 1028 | | return -1; |
| 1029 | | } |
| 1030 | 1027 | |
| 1031 | 1028 | dsputil_init(&s->dsp, avctx); |
| 1032 | 1029 | |
| … |
… |
static int ipvideo_decode_frame(AVCodecContext *avctx,
|
| 1046 | 1043 | const uint8_t *buf = avpkt->data; |
| 1047 | 1044 | int buf_size = avpkt->size; |
| 1048 | 1045 | IpvideoContext *s = avctx->priv_data; |
| 1049 | | AVPaletteControl *palette_control = avctx->palctrl; |
| 1050 | 1046 | |
| 1051 | 1047 | /* compressed buffer needs to be large enough to at least hold an entire |
| 1052 | 1048 | * decoding map */ |
| … |
… |
static int ipvideo_decode_frame(AVCodecContext *avctx,
|
| 1063 | 1059 | return -1; |
| 1064 | 1060 | } |
| 1065 | 1061 | |
| 1066 | | ipvideo_decode_opcodes(s); |
| 1067 | | |
| 1068 | | if (!s->is_16bpp && palette_control->palette_changed) { |
| 1069 | | palette_control->palette_changed = 0; |
| 1070 | | s->current_frame.palette_has_changed = 1; |
| | 1062 | if (!s->is_16bpp) { |
| | 1063 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| | 1064 | if (pal) { |
| | 1065 | s->current_frame.palette_has_changed = 1; |
| | 1066 | memcpy(s->pal, pal, AVPALETTE_SIZE); |
| | 1067 | } |
| 1071 | 1068 | } |
| 1072 | 1069 | |
| | 1070 | ipvideo_decode_opcodes(s); |
| | 1071 | |
| 1073 | 1072 | *data_size = sizeof(AVFrame); |
| 1074 | 1073 | *(AVFrame*)data = s->current_frame; |
| 1075 | 1074 | |
diff --git a/libavcodec/kmvc.c b/libavcodec/kmvc.c
index 2671cc6..c41c882 100644
|
a
|
b
|
static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPa
|
| 233 | 233 | int i; |
| 234 | 234 | int header; |
| 235 | 235 | int blocksize; |
| | 236 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| 236 | 237 | |
| 237 | 238 | if (ctx->pic.data[0]) |
| 238 | 239 | avctx->release_buffer(avctx, &ctx->pic); |
| … |
… |
static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPa
|
| 264 | 265 | ctx->pic.pict_type = FF_P_TYPE; |
| 265 | 266 | } |
| 266 | 267 | |
| 267 | | /* if palette has been changed, copy it from palctrl */ |
| 268 | | if (ctx->avctx->palctrl && ctx->avctx->palctrl->palette_changed) { |
| 269 | | memcpy(ctx->pal, ctx->avctx->palctrl->palette, AVPALETTE_SIZE); |
| 270 | | ctx->setpal = 1; |
| 271 | | ctx->avctx->palctrl->palette_changed = 0; |
| 272 | | } |
| 273 | | |
| 274 | 268 | if (header & KMVC_PALETTE) { |
| 275 | 269 | ctx->pic.palette_has_changed = 1; |
| 276 | 270 | // palette starts from index 1 and has 127 entries |
| … |
… |
static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPa
|
| 279 | 273 | } |
| 280 | 274 | } |
| 281 | 275 | |
| | 276 | if (pal) { |
| | 277 | ctx->pic.palette_has_changed = 1; |
| | 278 | memcpy(ctx->pal, pal, AVPALETTE_SIZE); |
| | 279 | } |
| | 280 | |
| 282 | 281 | if (ctx->setpal) { |
| 283 | 282 | ctx->setpal = 0; |
| 284 | 283 | ctx->pic.palette_has_changed = 1; |
| … |
… |
static av_cold int decode_init(AVCodecContext * avctx)
|
| 374 | 373 | src += 4; |
| 375 | 374 | } |
| 376 | 375 | c->setpal = 1; |
| 377 | | if (c->avctx->palctrl) { |
| 378 | | c->avctx->palctrl->palette_changed = 0; |
| 379 | | } |
| 380 | 376 | } |
| 381 | 377 | |
| 382 | 378 | avctx->pix_fmt = PIX_FMT_PAL8; |
diff --git a/libavcodec/msrle.c b/libavcodec/msrle.c
index a400589..f426b05 100644
|
a
|
b
|
|
| 26 | 26 | * http://www.pcisys.net/~melanson/codecs/ |
| 27 | 27 | * |
| 28 | 28 | * The MS RLE decoder outputs PAL8 colorspace data. |
| 29 | | * |
| 30 | | * Note that this decoder expects the palette colors from the end of the |
| 31 | | * BITMAPINFO header passed through palctrl. |
| 32 | 29 | */ |
| 33 | 30 | |
| 34 | 31 | #include <stdio.h> |
| … |
… |
typedef struct MsrleContext {
|
| 46 | 43 | const unsigned char *buf; |
| 47 | 44 | int size; |
| 48 | 45 | |
| | 46 | uint32_t pal[256]; |
| 49 | 47 | } MsrleContext; |
| 50 | 48 | |
| 51 | 49 | static av_cold int msrle_decode_init(AVCodecContext *avctx) |
| … |
… |
static int msrle_decode_frame(AVCodecContext *avctx,
|
| 91 | 89 | return -1; |
| 92 | 90 | } |
| 93 | 91 | |
| 94 | | if (s->avctx->palctrl) { |
| 95 | | /* make the palette available */ |
| 96 | | memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); |
| 97 | | if (s->avctx->palctrl->palette_changed) { |
| | 92 | if (avctx->bits_per_coded_sample <= 8) { |
| | 93 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| | 94 | |
| | 95 | if (pal) { |
| 98 | 96 | s->frame.palette_has_changed = 1; |
| 99 | | s->avctx->palctrl->palette_changed = 0; |
| | 97 | memcpy(s->pal, pal, AVPALETTE_SIZE); |
| 100 | 98 | } |
| | 99 | |
| | 100 | /* make the palette available */ |
| | 101 | memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); |
| 101 | 102 | } |
| 102 | 103 | |
| 103 | 104 | /* FIXME how to correctly detect RLE ??? */ |
diff --git a/libavcodec/msvideo1.c b/libavcodec/msvideo1.c
index e01ddf5..a89ec6a 100644
|
a
|
b
|
|
| 25 | 25 | * For more information about the MS Video-1 format, visit: |
| 26 | 26 | * http://www.pcisys.net/~melanson/codecs/ |
| 27 | 27 | * |
| 28 | | * This decoder outputs either PAL8 or RGB555 data, depending on the |
| 29 | | * whether a RGB palette was passed through palctrl; |
| 30 | | * if it's present, then the data is PAL8; RGB555 otherwise. |
| 31 | 28 | */ |
| 32 | 29 | |
| 33 | 30 | #include <stdio.h> |
| … |
… |
typedef struct Msvideo1Context {
|
| 55 | 52 | |
| 56 | 53 | int mode_8bit; /* if it's not 8-bit, it's 16-bit */ |
| 57 | 54 | |
| | 55 | uint32_t pal[256]; |
| 58 | 56 | } Msvideo1Context; |
| 59 | 57 | |
| 60 | 58 | static av_cold int msvideo1_decode_init(AVCodecContext *avctx) |
| … |
… |
static av_cold int msvideo1_decode_init(AVCodecContext *avctx)
|
| 64 | 62 | s->avctx = avctx; |
| 65 | 63 | |
| 66 | 64 | /* figure out the colorspace based on the presence of a palette */ |
| 67 | | if (s->avctx->palctrl) { |
| | 65 | if (s->avctx->bits_per_coded_sample == 8) { |
| 68 | 66 | s->mode_8bit = 1; |
| 69 | 67 | avctx->pix_fmt = PIX_FMT_PAL8; |
| 70 | 68 | } else { |
| … |
… |
static void msvideo1_decode_8bit(Msvideo1Context *s)
|
| 173 | 171 | } |
| 174 | 172 | |
| 175 | 173 | /* make the palette available on the way out */ |
| 176 | | if (s->avctx->pix_fmt == PIX_FMT_PAL8) { |
| 177 | | memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); |
| 178 | | if (s->avctx->palctrl->palette_changed) { |
| 179 | | s->frame.palette_has_changed = 1; |
| 180 | | s->avctx->palctrl->palette_changed = 0; |
| 181 | | } |
| 182 | | } |
| | 174 | if (s->avctx->pix_fmt == PIX_FMT_PAL8) |
| | 175 | memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); |
| 183 | 176 | } |
| 184 | 177 | |
| 185 | 178 | static void msvideo1_decode_16bit(Msvideo1Context *s) |
| … |
… |
static int msvideo1_decode_frame(AVCodecContext *avctx,
|
| 309 | 302 | return -1; |
| 310 | 303 | } |
| 311 | 304 | |
| | 305 | if (s->mode_8bit) { |
| | 306 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| | 307 | |
| | 308 | if (pal) { |
| | 309 | memcpy(s->pal, pal, AVPALETTE_SIZE); |
| | 310 | s->frame.palette_has_changed = 1; |
| | 311 | } |
| | 312 | } |
| | 313 | |
| 312 | 314 | if (s->mode_8bit) |
| 313 | 315 | msvideo1_decode_8bit(s); |
| 314 | 316 | else |
diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c
index ccd634a..c96184f 100644
|
a
|
b
|
typedef struct QpegContext{
|
| 30 | 30 | AVCodecContext *avctx; |
| 31 | 31 | AVFrame pic; |
| 32 | 32 | uint8_t *refdata; |
| | 33 | uint32_t pal[256]; |
| 33 | 34 | } QpegContext; |
| 34 | 35 | |
| 35 | 36 | static void qpeg_decode_intra(const uint8_t *src, uint8_t *dst, int size, |
| … |
… |
static int decode_frame(AVCodecContext *avctx,
|
| 256 | 257 | AVFrame * const p= (AVFrame*)&a->pic; |
| 257 | 258 | uint8_t* outdata; |
| 258 | 259 | int delta; |
| | 260 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| 259 | 261 | |
| 260 | 262 | if(p->data[0]) |
| 261 | 263 | avctx->release_buffer(avctx, p); |
| … |
… |
static int decode_frame(AVCodecContext *avctx,
|
| 274 | 276 | } |
| 275 | 277 | |
| 276 | 278 | /* make the palette available on the way out */ |
| 277 | | memcpy(a->pic.data[1], a->avctx->palctrl->palette, AVPALETTE_SIZE); |
| 278 | | if (a->avctx->palctrl->palette_changed) { |
| | 279 | if (pal) { |
| 279 | 280 | a->pic.palette_has_changed = 1; |
| 280 | | a->avctx->palctrl->palette_changed = 0; |
| | 281 | memcpy(a->pal, pal, AVPALETTE_SIZE); |
| 281 | 282 | } |
| | 283 | memcpy(a->pic.data[1], a->pal, AVPALETTE_SIZE); |
| 282 | 284 | |
| 283 | 285 | *data_size = sizeof(AVFrame); |
| 284 | 286 | *(AVFrame*)data = a->pic; |
| … |
… |
static int decode_frame(AVCodecContext *avctx,
|
| 289 | 291 | static av_cold int decode_init(AVCodecContext *avctx){ |
| 290 | 292 | QpegContext * const a = avctx->priv_data; |
| 291 | 293 | |
| 292 | | if (!avctx->palctrl) { |
| 293 | | av_log(avctx, AV_LOG_FATAL, "Missing required palette via palctrl\n"); |
| 294 | | return -1; |
| 295 | | } |
| 296 | 294 | a->avctx = avctx; |
| 297 | 295 | avctx->pix_fmt= PIX_FMT_PAL8; |
| 298 | 296 | a->refdata = av_malloc(avctx->width * avctx->height); |
diff --git a/libavcodec/qtrle.c b/libavcodec/qtrle.c
index a8cc903..e14c306 100644
|
a
|
b
|
typedef struct QtrleContext {
|
| 46 | 46 | const unsigned char *buf; |
| 47 | 47 | int size; |
| 48 | 48 | |
| | 49 | uint32_t pal[256]; |
| 49 | 50 | } QtrleContext; |
| 50 | 51 | |
| 51 | 52 | #define CHECK_STREAM_PTR(n) \ |
| … |
… |
static int qtrle_decode_frame(AVCodecContext *avctx,
|
| 511 | 512 | } |
| 512 | 513 | |
| 513 | 514 | if(has_palette) { |
| 514 | | /* make the palette available on the way out */ |
| 515 | | memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); |
| 516 | | if (s->avctx->palctrl->palette_changed) { |
| | 515 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| | 516 | |
| | 517 | if (pal) { |
| 517 | 518 | s->frame.palette_has_changed = 1; |
| 518 | | s->avctx->palctrl->palette_changed = 0; |
| | 519 | memcpy(s->pal, pal, AVPALETTE_SIZE); |
| 519 | 520 | } |
| | 521 | |
| | 522 | /* make the palette available on the way out */ |
| | 523 | memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); |
| 520 | 524 | } |
| 521 | 525 | |
| 522 | 526 | done: |
diff --git a/libavcodec/rawdec.c b/libavcodec/rawdec.c
index 3c38829..3dbfdfe 100644
|
a
|
b
|
static int raw_decode(AVCodecContext *avctx,
|
| 158 | 158 | (av_pix_fmt_descriptors[avctx->pix_fmt].flags & PIX_FMT_PAL))){ |
| 159 | 159 | frame->data[1]= context->palette; |
| 160 | 160 | } |
| 161 | | if (avctx->palctrl && avctx->palctrl->palette_changed) { |
| 162 | | memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); |
| 163 | | avctx->palctrl->palette_changed = 0; |
| | 161 | if (avctx->pix_fmt == PIX_FMT_PAL8) { |
| | 162 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| | 163 | |
| | 164 | if (pal) { |
| | 165 | memcpy(frame->data[1], pal, AVPALETTE_SIZE); |
| | 166 | frame->palette_has_changed = 1; |
| | 167 | } |
| 164 | 168 | } |
| 165 | 169 | if(avctx->pix_fmt==PIX_FMT_BGR24 && ((frame->linesize[0]+3)&~3)*avctx->height <= buf_size) |
| 166 | 170 | frame->linesize[0] = (frame->linesize[0]+3)&~3; |
diff --git a/libavcodec/smc.c b/libavcodec/smc.c
index fe92b43..e75203d 100644
|
a
|
b
|
typedef struct SmcContext {
|
| 54 | 54 | unsigned char color_quads[COLORS_PER_TABLE * CQUAD]; |
| 55 | 55 | unsigned char color_octets[COLORS_PER_TABLE * COCTET]; |
| 56 | 56 | |
| | 57 | uint32_t pal[256]; |
| 57 | 58 | } SmcContext; |
| 58 | 59 | |
| 59 | 60 | #define GET_BLOCK_COUNT() \ |
| … |
… |
static void smc_decode_stream(SmcContext *s)
|
| 110 | 111 | int color_octet_index = 0; |
| 111 | 112 | |
| 112 | 113 | /* make the palette available */ |
| 113 | | memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); |
| 114 | | if (s->avctx->palctrl->palette_changed) { |
| 115 | | s->frame.palette_has_changed = 1; |
| 116 | | s->avctx->palctrl->palette_changed = 0; |
| 117 | | } |
| | 114 | memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); |
| 118 | 115 | |
| 119 | 116 | chunk_size = AV_RB32(&s->buf[stream_ptr]) & 0x00FFFFFF; |
| 120 | 117 | stream_ptr += 4; |
| … |
… |
static int smc_decode_frame(AVCodecContext *avctx,
|
| 440 | 437 | const uint8_t *buf = avpkt->data; |
| 441 | 438 | int buf_size = avpkt->size; |
| 442 | 439 | SmcContext *s = avctx->priv_data; |
| | 440 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| 443 | 441 | |
| 444 | 442 | s->buf = buf; |
| 445 | 443 | s->size = buf_size; |
| … |
… |
static int smc_decode_frame(AVCodecContext *avctx,
|
| 452 | 450 | return -1; |
| 453 | 451 | } |
| 454 | 452 | |
| | 453 | if (pal) { |
| | 454 | s->frame.palette_has_changed = 1; |
| | 455 | memcpy(s->pal, pal, AVPALETTE_SIZE); |
| | 456 | } |
| | 457 | |
| 455 | 458 | smc_decode_stream(s); |
| 456 | 459 | |
| 457 | 460 | *data_size = sizeof(AVFrame); |
diff --git a/libavcodec/targa.c b/libavcodec/targa.c
index 06f87e4..910cc1b 100644
|
a
|
b
|
static int decode_frame(AVCodecContext *avctx,
|
| 171 | 171 | stride = -p->linesize[0]; |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | | if(avctx->pix_fmt == PIX_FMT_PAL8 && avctx->palctrl){ |
| 175 | | memcpy(p->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); |
| 176 | | if(avctx->palctrl->palette_changed){ |
| 177 | | p->palette_has_changed = 1; |
| 178 | | avctx->palctrl->palette_changed = 0; |
| 179 | | } |
| 180 | | } |
| 181 | 174 | if(colors){ |
| 182 | 175 | size_t pal_size; |
| 183 | 176 | if((colors + first_clr) > 256){ |
diff --git a/libavcodec/tscc.c b/libavcodec/tscc.c
index f695973..bd05f02 100644
|
a
|
b
|
typedef struct TsccContext {
|
| 60 | 60 | unsigned char* decomp_buf; |
| 61 | 61 | int height; |
| 62 | 62 | z_stream zstream; |
| | 63 | |
| | 64 | uint32_t pal[256]; |
| 63 | 65 | } CamtasiaContext; |
| 64 | 66 | |
| 65 | 67 | /* |
| … |
… |
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
|
| 111 | 113 | |
| 112 | 114 | /* make the palette available on the way out */ |
| 113 | 115 | if (c->avctx->pix_fmt == PIX_FMT_PAL8) { |
| 114 | | memcpy(c->pic.data[1], c->avctx->palctrl->palette, AVPALETTE_SIZE); |
| 115 | | if (c->avctx->palctrl->palette_changed) { |
| | 116 | const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); |
| | 117 | |
| | 118 | if (pal) { |
| 116 | 119 | c->pic.palette_has_changed = 1; |
| 117 | | c->avctx->palctrl->palette_changed = 0; |
| | 120 | memcpy(c->pal, pal, AVPALETTE_SIZE); |
| 118 | 121 | } |
| | 122 | memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE); |
| 119 | 123 | } |
| 120 | 124 | |
| 121 | 125 | *data_size = sizeof(AVFrame); |
diff --git a/libavformat/asf.h b/libavformat/asf.h
index b563459..b72445d 100644
|
a
|
b
|
typedef struct {
|
| 44 | 44 | |
| 45 | 45 | uint16_t stream_language_index; |
| 46 | 46 | |
| | 47 | int palette_changed; |
| | 48 | uint32_t palette[256]; |
| 47 | 49 | } ASFStream; |
| 48 | 50 | |
| 49 | 51 | typedef uint8_t ff_asf_guid[16]; |
diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index 30828ad..36e9efa 100644
|
a
|
b
|
static int asf_read_stream_properties(AVFormatContext *s, int64_t size)
|
| 365 | 365 | /* This is true for all paletted codecs implemented in ffmpeg */ |
| 366 | 366 | if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) { |
| 367 | 367 | int av_unused i; |
| 368 | | st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl)); |
| 369 | 368 | #if HAVE_BIGENDIAN |
| 370 | 369 | for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++) |
| 371 | | st->codec->palctrl->palette[i] = av_bswap32(((uint32_t*)st->codec->extradata)[i]); |
| | 370 | asf_st->palette[i] = av_bswap32(((uint32_t*)st->codec->extradata)[i]); |
| 372 | 371 | #else |
| 373 | | memcpy(st->codec->palctrl->palette, st->codec->extradata, |
| 374 | | FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)); |
| | 372 | memcpy(asf_st->palette, st->codec->extradata, |
| | 373 | FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)); |
| 375 | 374 | #endif |
| 376 | | st->codec->palctrl->palette_changed = 1; |
| | 375 | asf_st->palette_changed = 1; |
| 377 | 376 | } |
| 378 | 377 | |
| 379 | 378 | st->codec->codec_tag = tag1; |
| … |
… |
static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
| 966 | 965 | asf_st->pkt.stream_index = asf->stream_index; |
| 967 | 966 | asf_st->pkt.pos = |
| 968 | 967 | asf_st->packet_pos= asf->packet_pos; |
| | 968 | if (asf_st->pkt.data && asf_st->palette_changed) { |
| | 969 | uint8_t *pal; |
| | 970 | pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, |
| | 971 | AVPALETTE_SIZE); |
| | 972 | if (!pal) { |
| | 973 | av_log(s, AV_LOG_ERROR, "Cannot append palette to packet\n"); |
| | 974 | } else { |
| | 975 | memcpy(pal, asf_st->palette, AVPALETTE_SIZE); |
| | 976 | asf_st->palette_changed = 0; |
| | 977 | } |
| | 978 | } |
| 969 | 979 | //printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n", |
| 970 | 980 | //asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & AV_PKT_FLAG_KEY, |
| 971 | 981 | //s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO, asf->packet_obj_size); |
| … |
… |
static int asf_read_close(AVFormatContext *s)
|
| 1127 | 1137 | asf_reset_header(s); |
| 1128 | 1138 | for(i=0;i<s->nb_streams;i++) { |
| 1129 | 1139 | AVStream *st = s->streams[i]; |
| 1130 | | av_free(st->codec->palctrl); |
| 1131 | 1140 | } |
| 1132 | 1141 | return 0; |
| 1133 | 1142 | } |
diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index ec3aa93..c7bbf42 100644
|
a
|
b
|
static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
|
| 590 | 590 | /* This code assumes that extradata contains only palette. */ |
| 591 | 591 | /* This is true for all paletted codecs implemented in FFmpeg. */ |
| 592 | 592 | if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) { |
| 593 | | st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl)); |
| 594 | 593 | #if HAVE_BIGENDIAN |
| 595 | 594 | for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++) |
| 596 | | st->codec->palctrl->palette[i] = av_bswap32(((uint32_t*)st->codec->extradata)[i]); |
| | 595 | ast->pal[i] = av_bswap32(((uint32_t*)st->codec->extradata)[i]); |
| 597 | 596 | #else |
| 598 | | memcpy(st->codec->palctrl->palette, st->codec->extradata, |
| | 597 | memcpy(ast->pal, st->codec->extradata, |
| 599 | 598 | FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)); |
| 600 | 599 | #endif |
| 601 | | st->codec->palctrl->palette_changed = 1; |
| | 600 | ast->has_pal = 1; |
| 602 | 601 | } |
| 603 | 602 | |
| 604 | 603 | print_tag("video", tag1, 0); |
| … |
… |
resync:
|
| 932 | 931 | return err; |
| 933 | 932 | |
| 934 | 933 | if(ast->has_pal && pkt->data && pkt->size<(unsigned)INT_MAX/2){ |
| 935 | | void *ptr= av_realloc(pkt->data, pkt->size + 4*256 + FF_INPUT_BUFFER_PADDING_SIZE); |
| 936 | | if(ptr){ |
| 937 | | ast->has_pal=0; |
| 938 | | pkt->size += 4*256; |
| 939 | | pkt->data= ptr; |
| 940 | | memcpy(pkt->data + pkt->size - 4*256, ast->pal, 4*256); |
| 941 | | }else |
| 942 | | av_log(s, AV_LOG_ERROR, "Failed to append palette\n"); |
| | 934 | uint8_t *pal; |
| | 935 | pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); |
| | 936 | if(!pal){ |
| | 937 | av_log(s, AV_LOG_ERROR, "Failed to allocate data for palette\n"); |
| | 938 | }else{ |
| | 939 | memcpy(pal, ast->pal, AVPALETTE_SIZE); |
| | 940 | ast->has_pal = 0; |
| | 941 | } |
| 943 | 942 | } |
| 944 | 943 | |
| 945 | 944 | if (CONFIG_DV_DEMUXER && avi->dv_demux) { |
| … |
… |
static int avi_read_close(AVFormatContext *s)
|
| 1340 | 1339 | for(i=0;i<s->nb_streams;i++) { |
| 1341 | 1340 | AVStream *st = s->streams[i]; |
| 1342 | 1341 | AVIStream *ast = st->priv_data; |
| 1343 | | av_free(st->codec->palctrl); |
| 1344 | 1342 | if (ast) { |
| 1345 | 1343 | if (ast->sub_ctx) { |
| 1346 | 1344 | av_freep(&ast->sub_ctx->pb); |
diff --git a/libavformat/idcin.c b/libavformat/idcin.c
index e6883c7..04ae687 100644
|
a
|
b
|
typedef struct IdcinDemuxContext {
|
| 86 | 86 | int audio_present; |
| 87 | 87 | |
| 88 | 88 | int64_t pts; |
| 89 | | |
| 90 | | AVPaletteControl palctrl; |
| 91 | 89 | } IdcinDemuxContext; |
| 92 | 90 | |
| 93 | 91 | static int idcin_probe(AVProbeData *p) |
| … |
… |
static int idcin_read_header(AVFormatContext *s,
|
| 172 | 170 | if (avio_read(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE) != |
| 173 | 171 | HUFFMAN_TABLE_SIZE) |
| 174 | 172 | return AVERROR(EIO); |
| 175 | | /* save a reference in order to transport the palette */ |
| 176 | | st->codec->palctrl = &idcin->palctrl; |
| 177 | 173 | |
| 178 | 174 | /* if sample rate is 0, assume no audio */ |
| 179 | 175 | if (sample_rate) { |
| … |
… |
static int idcin_read_packet(AVFormatContext *s,
|
| 226 | 222 | int palette_scale; |
| 227 | 223 | unsigned char r, g, b; |
| 228 | 224 | unsigned char palette_buffer[768]; |
| | 225 | uint32_t palette[256]; |
| 229 | 226 | |
| 230 | 227 | if (s->pb->eof_reached) |
| 231 | 228 | return AVERROR(EIO); |
| … |
… |
static int idcin_read_packet(AVFormatContext *s,
|
| 236 | 233 | return AVERROR(EIO); |
| 237 | 234 | } else if (command == 1) { |
| 238 | 235 | /* trigger a palette change */ |
| 239 | | idcin->palctrl.palette_changed = 1; |
| 240 | 236 | if (avio_read(pb, palette_buffer, 768) != 768) |
| 241 | 237 | return AVERROR(EIO); |
| 242 | 238 | /* scale the palette as necessary */ |
| … |
… |
static int idcin_read_packet(AVFormatContext *s,
|
| 251 | 247 | r = palette_buffer[i * 3 ] << palette_scale; |
| 252 | 248 | g = palette_buffer[i * 3 + 1] << palette_scale; |
| 253 | 249 | b = palette_buffer[i * 3 + 2] << palette_scale; |
| 254 | | idcin->palctrl.palette[i] = (r << 16) | (g << 8) | (b); |
| | 250 | palette[i] = (r << 16) | (g << 8) | (b); |
| 255 | 251 | } |
| 256 | 252 | } |
| 257 | 253 | |
| … |
… |
static int idcin_read_packet(AVFormatContext *s,
|
| 262 | 258 | ret= av_get_packet(pb, pkt, chunk_size); |
| 263 | 259 | if (ret < 0) |
| 264 | 260 | return ret; |
| | 261 | if (command == 1) { |
| | 262 | uint8_t *pal; |
| | 263 | |
| | 264 | pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, |
| | 265 | AVPALETTE_SIZE); |
| | 266 | if (ret < 0) |
| | 267 | return ret; |
| | 268 | memcpy(pal, palette, AVPALETTE_SIZE); |
| | 269 | } |
| 265 | 270 | pkt->stream_index = idcin->video_stream_index; |
| 266 | 271 | pkt->pts = idcin->pts; |
| 267 | 272 | } else { |
diff --git a/libavformat/ipmovie.c b/libavformat/ipmovie.c
index e1d08df..e3215d3 100644
|
a
|
b
|
typedef struct IPMVEContext {
|
| 97 | 97 | unsigned int video_width; |
| 98 | 98 | unsigned int video_height; |
| 99 | 99 | int64_t video_pts; |
| | 100 | uint32_t palette[256]; |
| | 101 | int has_palette; |
| 100 | 102 | |
| 101 | 103 | unsigned int audio_bits; |
| 102 | 104 | unsigned int audio_channels; |
| … |
… |
typedef struct IPMVEContext {
|
| 116 | 118 | |
| 117 | 119 | int64_t next_chunk_offset; |
| 118 | 120 | |
| 119 | | AVPaletteControl palette_control; |
| 120 | | |
| 121 | 121 | } IPMVEContext; |
| 122 | 122 | |
| 123 | 123 | static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb, |
| … |
… |
static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb,
|
| 162 | 162 | if (av_new_packet(pkt, s->decode_map_chunk_size + s->video_chunk_size)) |
| 163 | 163 | return CHUNK_NOMEM; |
| 164 | 164 | |
| | 165 | if (s->has_palette) { |
| | 166 | uint8_t *pal; |
| | 167 | |
| | 168 | pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, |
| | 169 | AVPALETTE_SIZE); |
| | 170 | if (pal) { |
| | 171 | memcpy(pal, s->palette, AVPALETTE_SIZE); |
| | 172 | s->has_palette = 0; |
| | 173 | } |
| | 174 | } |
| | 175 | |
| 165 | 176 | pkt->pos= s->decode_map_chunk_offset; |
| 166 | 177 | avio_seek(pb, s->decode_map_chunk_offset, SEEK_SET); |
| 167 | 178 | s->decode_map_chunk_offset = 0; |
| … |
… |
static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb,
|
| 456 | 467 | r = scratch[j++] * 4; |
| 457 | 468 | g = scratch[j++] * 4; |
| 458 | 469 | b = scratch[j++] * 4; |
| 459 | | s->palette_control.palette[i] = (r << 16) | (g << 8) | (b); |
| | 470 | s->palette[i] = (r << 16) | (g << 8) | (b); |
| 460 | 471 | } |
| 461 | | /* indicate a palette change */ |
| 462 | | s->palette_control.palette_changed = 1; |
| | 472 | s->has_palette = 1; |
| 463 | 473 | break; |
| 464 | 474 | |
| 465 | 475 | case OPCODE_SET_PALETTE_COMPRESSED: |
| … |
… |
static int ipmovie_read_header(AVFormatContext *s,
|
| 573 | 583 | st->codec->height = ipmovie->video_height; |
| 574 | 584 | st->codec->bits_per_coded_sample = ipmovie->video_bpp; |
| 575 | 585 | |
| 576 | | /* palette considerations */ |
| 577 | | st->codec->palctrl = &ipmovie->palette_control; |
| 578 | | |
| 579 | 586 | if (ipmovie->audio_type) { |
| 580 | 587 | st = av_new_stream(s, 0); |
| 581 | 588 | if (!st) |
diff --git a/libavformat/isom.h b/libavformat/isom.h
index fba4963..48e0bcf 100644
|
a
|
b
|
typedef struct MOVStreamContext {
|
| 123 | 123 | int width; ///< tkhd width |
| 124 | 124 | int height; ///< tkhd height |
| 125 | 125 | int dts_shift; ///< dts shift when ctts is negative |
| | 126 | uint32_t palette[256]; |
| | 127 | int has_palette; |
| 126 | 128 | } MOVStreamContext; |
| 127 | 129 | |
| 128 | 130 | typedef struct MOVContext { |
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 61ceaac..bd8cf03 100644
|
a
|
b
|
int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
|
| 1027 | 1027 | unsigned int color_start, color_count, color_end; |
| 1028 | 1028 | unsigned char r, g, b; |
| 1029 | 1029 | |
| 1030 | | st->codec->palctrl = av_malloc(sizeof(*st->codec->palctrl)); |
| 1031 | 1030 | if (color_greyscale) { |
| 1032 | 1031 | int color_index, color_dec; |
| 1033 | 1032 | /* compute the greyscale palette */ |
| … |
… |
int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
|
| 1037 | 1036 | color_dec = 256 / (color_count - 1); |
| 1038 | 1037 | for (j = 0; j < color_count; j++) { |
| 1039 | 1038 | r = g = b = color_index; |
| 1040 | | st->codec->palctrl->palette[j] = |
| | 1039 | sc->palette[j] = |
| 1041 | 1040 | (r << 16) | (g << 8) | (b); |
| 1042 | 1041 | color_index -= color_dec; |
| 1043 | 1042 | if (color_index < 0) |
| … |
… |
int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
|
| 1058 | 1057 | r = color_table[j * 3 + 0]; |
| 1059 | 1058 | g = color_table[j * 3 + 1]; |
| 1060 | 1059 | b = color_table[j * 3 + 2]; |
| 1061 | | st->codec->palctrl->palette[j] = |
| | 1060 | sc->palette[j] = |
| 1062 | 1061 | (r << 16) | (g << 8) | (b); |
| 1063 | 1062 | } |
| 1064 | 1063 | } else { |
| … |
… |
int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
|
| 1080 | 1079 | avio_r8(pb); |
| 1081 | 1080 | b = avio_r8(pb); |
| 1082 | 1081 | avio_r8(pb); |
| 1083 | | st->codec->palctrl->palette[j] = |
| | 1082 | sc->palette[j] = |
| 1084 | 1083 | (r << 16) | (g << 8) | (b); |
| 1085 | 1084 | } |
| 1086 | 1085 | } |
| 1087 | 1086 | } |
| 1088 | | st->codec->palctrl->palette_changed = 1; |
| | 1087 | sc->has_palette = 1; |
| 1089 | 1088 | } |
| 1090 | 1089 | } else if(st->codec->codec_type==AVMEDIA_TYPE_AUDIO) { |
| 1091 | 1090 | int bits_per_sample, flags; |
| … |
… |
static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
|
| 2433 | 2432 | ret = av_get_packet(sc->pb, pkt, sample->size); |
| 2434 | 2433 | if (ret < 0) |
| 2435 | 2434 | return ret; |
| | 2435 | if (sc->has_palette) { |
| | 2436 | uint8_t *pal; |
| | 2437 | |
| | 2438 | pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); |
| | 2439 | if (!pal) { |
| | 2440 | av_log(mov->fc, AV_LOG_ERROR, "Cannot append palette to packet\n"); |
| | 2441 | } else { |
| | 2442 | memcpy(pal, sc->palette, AVPALETTE_SIZE); |
| | 2443 | sc->has_palette = 0; |
| | 2444 | } |
| | 2445 | } |
| 2436 | 2446 | #if CONFIG_DV_DEMUXER |
| 2437 | 2447 | if (mov->dv_demux && sc->dv_audio_container) { |
| 2438 | 2448 | dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size); |