} Wc3DemuxContext;
-/* bizarre palette lookup table */
+/**
+ * palette lookup table that does gamma correction
+ *
+ * can be calculated by this formula:
+ * for i between 0 and 251 inclusive:
+ * wc3_pal_lookup[i] = round(pow(i / 256.0, 0.8) * 256);
+ * values 252, 253, 254 and 255 are all 0xFD
+ * calculating this at runtime should not cause any
+ * rounding issues, the maximum difference between
+ * the table values and the calculated doubles is
+ * about 0.497527
+ */
static const unsigned char wc3_pal_lookup[] = {
0x00, 0x03, 0x05, 0x07, 0x09, 0x0B, 0x0D, 0x0E,
0x10, 0x12, 0x13, 0x15, 0x16, 0x18, 0x19, 0x1A,
unsigned int fourcc_tag;
unsigned int size;
AVStream *st;
- char buffer[513];
int ret = 0;
int current_palette = 0;
- int bytes_to_read;
+ char *buffer;
int i;
unsigned char rotate;
case BNAM_TAG:
/* load up the name */
- if ((unsigned)size < 512)
- bytes_to_read = size;
- else
- bytes_to_read = 512;
- if ((ret = get_buffer(pb, buffer, bytes_to_read)) != bytes_to_read)
+ buffer = av_malloc(size+1);
+ if (!buffer)
+ return AVERROR_NOMEM;
+ if ((ret = get_buffer(pb, buffer, size)) != size)
return AVERROR(EIO);
- buffer[bytes_to_read] = 0;
- av_metadata_set(&s->metadata, "title", buffer);
+ buffer[size] = 0;
+ av_metadata_set2(&s->metadata, "title", buffer,
+ AV_METADATA_DONT_STRDUP_VAL);
break;
case SIZE_TAG:
default:
av_log(s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
- (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24),
- (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24));
+ (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24),
+ (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24));
return AVERROR_INVALIDDATA;
break;
}
ret= av_get_packet(pb, pkt, size);
pkt->stream_index = wc3->video_stream_index;
pkt->pts = wc3->pts;
- if (ret != size)
- ret = AVERROR(EIO);
packet_read = 1;
break;
ret= av_get_packet(pb, pkt, size);
pkt->stream_index = wc3->audio_stream_index;
pkt->pts = wc3->pts;
- if (ret != size)
- ret = AVERROR(EIO);
/* time to advance pts */
wc3->pts++;
default:
av_log (s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
- (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24),
- (char)fourcc_tag, (char)(fourcc_tag >> 8), (char)(fourcc_tag >> 16), (char)(fourcc_tag >> 24));
+ (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24),
+ (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24));
ret = AVERROR_INVALIDDATA;
packet_read = 1;
break;