]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/fraps.c
mlpdec: Validate non-restart bit from the substream header.
[ffmpeg] / libavcodec / fraps.c
index d180ee0a77f8c2f369e1d98b4117342fd62d0a8d..14da1a0b616bdcb0f1524a934e643f19d57fc940 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 /**
- * @file fraps.c
+ * @file libavcodec/fraps.c
  * Lossless Fraps 'FPS1' decoder
  * @author Roine Gustafsson <roine at users sf net>
  * @author Konstantin Shishkov
@@ -55,7 +55,7 @@ typedef struct FrapsContext{
  * @param avctx codec context
  * @return 0 on success or negative if fails
  */
-static int decode_init(AVCodecContext *avctx)
+static av_cold int decode_init(AVCodecContext *avctx)
 {
     FrapsContext * const s = avctx->priv_data;
 
@@ -141,17 +141,17 @@ static int decode_frame(AVCodecContext *avctx,
     const uint32_t *buf32;
     uint32_t *luma1,*luma2,*cb,*cr;
     uint32_t offs[4];
-    int i, is_chroma, planes;
+    int i, j, is_chroma, planes;
 
 
     header = AV_RL32(buf);
     version = header & 0xff;
     header_size = (header & (1<<30))? 8 : 4; /* bit 30 means pad to 8 bytes */
 
-    if (version > 2 && version != 4 && version != 5) {
+    if (version > 5) {
         av_log(avctx, AV_LOG_ERROR,
                "This file is encoded with Fraps version %d. " \
-               "This codec can only decode version 0, 1, 2 and 4.\n", version);
+               "This codec can only decode versions <= 5.\n", version);
         return -1;
     }
 
@@ -288,6 +288,7 @@ static int decode_frame(AVCodecContext *avctx,
             }
         }
         break;
+    case 3:
     case 5:
         /* Virtually the same as version 4, but is for RGB24 */
         avctx->pix_fmt = PIX_FMT_BGR24;
@@ -323,11 +324,18 @@ static int decode_frame(AVCodecContext *avctx,
         for(i = 0; i < planes; i++){
             s->tmpbuf = av_realloc(s->tmpbuf, offs[i + 1] - offs[i] - 1024 + FF_INPUT_BUFFER_PADDING_SIZE);
             if(fraps2_decode_plane(s, f->data[0] + i + (f->linesize[0] * (avctx->height - 1)), -f->linesize[0],
-                    avctx->width, avctx->height, buf + offs[i], offs[i + 1] - offs[i], 1, 3) < 0) {
+                    avctx->width, avctx->height, buf + offs[i], offs[i + 1] - offs[i], 0, 3) < 0) {
                 av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i);
                 return -1;
             }
         }
+        // convert pseudo-YUV into real RGB
+        for(j = 0; j < avctx->height; j++){
+            for(i = 0; i < avctx->width; i++){
+                f->data[0][0 + i*3 + j*f->linesize[0]] += f->data[0][1 + i*3 + j*f->linesize[0]];
+                f->data[0][2 + i*3 + j*f->linesize[0]] += f->data[0][1 + i*3 + j*f->linesize[0]];
+            }
+        }
         break;
     }
 
@@ -343,7 +351,7 @@ static int decode_frame(AVCodecContext *avctx,
  * @param avctx codec context
  * @return 0 on success or negative if fails
  */
-static int decode_end(AVCodecContext *avctx)
+static av_cold int decode_end(AVCodecContext *avctx)
 {
     FrapsContext *s = (FrapsContext*)avctx->priv_data;
 
@@ -365,4 +373,5 @@ AVCodec fraps_decoder = {
     decode_end,
     decode_frame,
     CODEC_CAP_DR1,
+    .long_name = NULL_IF_CONFIG_SMALL("Fraps"),
 };