Fix loading of targa image files (#1478). v2.13.123
authorCarl Hetherington <cth@carlh.net>
Fri, 1 Mar 2019 23:45:12 +0000 (23:45 +0000)
committerCarl Hetherington <cth@carlh.net>
Fri, 1 Mar 2019 23:45:12 +0000 (23:45 +0000)
ChangeLog
src/lib/ffmpeg_image_proxy.cc

index f03f82d959d2b07e18a52e99f94fb193bcd998ad..15987ce9ef0d630e23de711f1536a152b78e317a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2019-03-01  Carl Hetherington  <cth@carlh.net>
+
+       * Fix loading of targa files (#1478).
+
 2019-02-28  Carl Hetherington  <cth@carlh.net>
 
        * Updated cs_CZ translation from Tomáš Begeni.
index 46c9836e060d781b1a5083184f052b053812ae08..87925dabc9360f660115f00d7d668dac0cd3b086 100644 (file)
@@ -135,7 +135,20 @@ FFmpegImageProxy::image (optional<dcp::Size>) const
 
        int e = avformat_open_input (&format_context, 0, 0, &options);
        if (e < 0) {
-               throw OpenFileError (_path->string(), e, true);
+               if (e == AVERROR_INVALIDDATA) {
+                       /* Hack to fix loading of .tga files through AVIOContexts (rather then
+                          directly from the file).  This code just does enough to allow the
+                          probe code to take a hint from "foo.tga" and so try targa format.
+                       */
+                       AVInputFormat* f = av_find_input_format ("image2");
+                       format_context = avformat_alloc_context ();
+                       format_context->pb = avio_context;
+                       format_context->iformat = f;
+                       e = avformat_open_input (&format_context, "foo.tga", f, &options);
+               }
+               if (e < 0) {
+                       throw OpenFileError (_path->string(), e, true);
+               }
        }
 
        if (avformat_find_stream_info(format_context, 0) < 0) {