]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/wc3movie.c
sha: add missing include
[ffmpeg] / libavformat / wc3movie.c
index 4d2c88a647aa858cfa858a6a3f2ea58bfef7b5a4..502ff525649e577152f7feea172d7572918e2745 100644 (file)
@@ -72,7 +72,18 @@ typedef struct Wc3DemuxContext {
 
 } 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,
@@ -129,10 +140,9 @@ static int wc3_read_header(AVFormatContext *s,
     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;
 
@@ -174,14 +184,14 @@ static int wc3_read_header(AVFormatContext *s,
 
         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:
@@ -213,8 +223,8 @@ static int wc3_read_header(AVFormatContext *s,
 
         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;
         }
@@ -309,8 +319,6 @@ static int wc3_read_packet(AVFormatContext *s,
             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;
 
@@ -338,8 +346,6 @@ static int wc3_read_packet(AVFormatContext *s,
             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++;
@@ -349,8 +355,8 @@ static int wc3_read_packet(AVFormatContext *s,
 
         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;