]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/dxv.c
Merge commit '4628443ca3534060888dd0015b229337eac13fd2'
[ffmpeg] / libavcodec / dxv.c
index dd6c7314993633a8b93d6b102d5c56876af49b76..4fdfd65404d40f06404e696c9dfcd7ea2fb755ee 100644 (file)
@@ -314,6 +314,15 @@ static int dxv_decompress_lzf(AVCodecContext *avctx)
     return ff_lzf_uncompress(&ctx->gbc, &ctx->tex_data, &ctx->tex_size);
 }
 
+static int dxv_decompress_raw(AVCodecContext *avctx)
+{
+    DXVContext *ctx = avctx->priv_data;
+    GetByteContext *gbc = &ctx->gbc;
+
+    bytestream2_get_buffer(gbc, ctx->tex_data, ctx->tex_size);
+    return 0;
+}
+
 static int dxv_decode(AVCodecContext *avctx, void *data,
                       int *got_frame, AVPacket *avpkt)
 {
@@ -321,6 +330,7 @@ static int dxv_decode(AVCodecContext *avctx, void *data,
     ThreadFrame tframe;
     GetByteContext *gbc = &ctx->gbc;
     int (*decompress_tex)(AVCodecContext *avctx);
+    const char *msgcomp, *msgtext;
     uint32_t tag;
     int version_major, version_minor = 0;
     int size = 0, old_type = 0;
@@ -335,14 +345,16 @@ static int dxv_decode(AVCodecContext *avctx, void *data,
         ctx->tex_funct = ctx->texdsp.dxt1_block;
         ctx->tex_rat   = 8;
         ctx->tex_step  = 8;
-        av_log(avctx, AV_LOG_DEBUG, "DXTR1 compression and DXT1 texture ");
+        msgcomp = "DXTR1";
+        msgtext = "DXT1";
         break;
     case MKBETAG('D', 'X', 'T', '5'):
         decompress_tex = dxv_decompress_dxt5;
         ctx->tex_funct = ctx->texdsp.dxt5_block;
         ctx->tex_rat   = 4;
         ctx->tex_step  = 16;
-        av_log(avctx, AV_LOG_DEBUG, "DXTR5 compression and DXT5 texture ");
+        msgcomp = "DXTR5";
+        msgtext = "DXT5";
         break;
     case MKBETAG('Y', 'C', 'G', '6'):
     case MKBETAG('Y', 'G', '1', '0'):
@@ -354,19 +366,28 @@ static int dxv_decode(AVCodecContext *avctx, void *data,
         old_type = tag >> 24;
         version_major = (old_type & 0x0F) - 1;
 
+        if (old_type & 0x80) {
+            msgcomp = "RAW";
+            decompress_tex = dxv_decompress_raw;
+        } else {
+            msgcomp = "LZF";
+            decompress_tex = dxv_decompress_lzf;
+        }
+
         if (old_type & 0x40) {
-            av_log(avctx, AV_LOG_DEBUG, "LZF compression and DXT5 texture ");
+            msgtext = "DXT5";
+
             ctx->tex_funct = ctx->texdsp.dxt5_block;
             ctx->tex_step  = 16;
         } else if (old_type & 0x20 || version_major == 1) {
-            av_log(avctx, AV_LOG_DEBUG, "LZF compression and DXT1 texture ");
+            msgtext = "DXT1";
+
             ctx->tex_funct = ctx->texdsp.dxt1_block;
             ctx->tex_step  = 8;
         } else {
             av_log(avctx, AV_LOG_ERROR, "Unsupported header (0x%08X)\n.", tag);
             return AVERROR_INVALIDDATA;
         }
-        decompress_tex = dxv_decompress_lzf;
         ctx->tex_rat = 1;
         break;
     }
@@ -376,13 +397,23 @@ static int dxv_decode(AVCodecContext *avctx, void *data,
         version_major = bytestream2_get_byte(gbc) - 1;
         version_minor = bytestream2_get_byte(gbc);
 
-        bytestream2_skip(gbc, 2); // unknown
+        /* Encoder copies texture data when compression is not advantageous. */
+        if (bytestream2_get_byte(gbc)) {
+            msgcomp = "RAW";
+            ctx->tex_rat = 1;
+            decompress_tex = dxv_decompress_raw;
+        }
+
+        bytestream2_skip(gbc, 1); // unknown
         size = bytestream2_get_le32(gbc);
     }
-    av_log(avctx, AV_LOG_DEBUG, "(version %d.%d)\n", version_major, version_minor);
+    av_log(avctx, AV_LOG_DEBUG,
+           "%s compression with %s texture (version %d.%d)\n",
+           msgcomp, msgtext, version_major, version_minor);
 
     if (size != bytestream2_get_bytes_left(gbc)) {
-        av_log(avctx, AV_LOG_ERROR, "Incomplete or invalid file (%u > %u)\n.",
+        av_log(avctx, AV_LOG_ERROR,
+               "Incomplete or invalid file (header %d, left %d).\n",
                size, bytestream2_get_bytes_left(gbc));
         return AVERROR_INVALIDDATA;
     }