Commit 7ac962af authored by Michael Niedermayer's avatar Michael Niedermayer

avformat/avienc: Store pal8 palette

This can be made more efficient, but first and the main goal of this change is to
store it at all
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 4956dc88
......@@ -646,7 +646,11 @@ static int write_skip_frames(AVFormatContext *s, int stream_index, int64_t dts)
static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
{
unsigned char tag[5];
const int stream_index = pkt->stream_index;
const uint8_t *data = pkt->data;
int size = pkt->size;
AVIOContext *pb = s->pb;
AVCodecContext *enc = s->streams[stream_index]->codec;
int ret;
......@@ -667,6 +671,21 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
if (ret < 0)
return ret;
if (ret) {
if (ret == CONTAINS_PAL) {
int pc_tag, i;
avi_stream2fourcc(tag, stream_index, enc->codec_type);
tag[2] = 'p'; tag[3] = 'c';
pc_tag = ff_start_tag(pb, tag);
avio_w8(pb, 0);
avio_w8(pb, 0);
avio_wl16(pb, 0); // reserved
for (i = 0; i<256; i++) {
uint32_t v = AV_RL32(data + size - 1024 + 4*i);
avio_wb32(pb, v<<8);
}
ff_end_tag(pb, pc_tag);
}
ret = avi_write_packet_internal(s, pkt);
av_packet_free(&pkt);
return ret;
......
......@@ -560,11 +560,16 @@ void ff_format_io_close(AVFormatContext *s, AVIOContext **pb);
*/
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds);
#define CONTAINS_PAL 2
/**
* Reshuffles the lines to use the user specified stride.
*
* @param ppkt input and output packet
* @return negative error code or 0 or 1, 1 indicates that ppkt needs to be freed
* @return negative error code or
* 0 if no new packet was allocated
* non-zero if a new packet was allocated and ppkt has to be freed
* CONTAINS_PAL if in addition to a new packet the old contained a palette
*/
int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *enc, int expected_stride);
......
......@@ -29,7 +29,8 @@ int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *en
int64_t bpc = enc->bits_per_coded_sample != 15 ? enc->bits_per_coded_sample : 16;
int min_stride = (enc->width * bpc + 7) >> 3;
int with_pal_size = min_stride * enc->height + 1024;
int size = bpc == 8 && pkt->size == with_pal_size ? min_stride * enc->height : pkt->size;
int contains_pal = bpc == 8 && pkt->size == with_pal_size;
int size = contains_pal ? min_stride * enc->height : pkt->size;
int stride = size / enc->height;
int padding = expected_stride - FFMIN(expected_stride, stride);
int y;
......@@ -58,7 +59,7 @@ int ff_reshuffle_raw_rgb(AVFormatContext *s, AVPacket **ppkt, AVCodecContext *en
}
*ppkt = new_pkt;
return 1;
return 1 + contains_pal;
fail:
av_packet_free(&new_pkt);
......
......@@ -31,7 +31,7 @@
#define LIBAVFORMAT_VERSION_MAJOR 57
#define LIBAVFORMAT_VERSION_MINOR 25
#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_MICRO 102
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
......
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