GraphicsMagick: SetImageInfo(): Avoid creating temporary files d...

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.11753.1667328376.1459.graphicsmagick-commit@lists.sourceforge.net>
changeset ed73da6ca2e7 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=ed73da6ca2e7
summary: SetImageInfo(): Avoid creating temporary files due to compressed input when not necessary.

diffstat:

 ChangeLog          |   5 +++++
 magick/image.c     |  27 ++++++++++++++++++++++++++-
 www/Changelog.html |   4 ++++
 3 files changed, 35 insertions(+), 1 deletions(-)

diffs (87 lines):

diff -r 62cbf900c9ca -r ed73da6ca2e7 ChangeLog
--- a/ChangeLog	Tue Nov 01 11:00:10 2022 -0500
+++ b/ChangeLog	Tue Nov 01 13:45:58 2022 -0500
@@ -1,5 +1,10 @@
 2022-11-01  Bob Friesenhahn  <[email protected]>
 
+	* magick/image.c (SetImageInfo): Avoid creating temporary files
+	when reading files with .bz2, .gz, .svgz, and .Z extensions if the
+	format is non-ambiguous based on the file extension, and the
+	reader does not require seeking.
+
 	* magick/magick.c (MagickToMime): Add MIME mappings for apng,
 	avif, bmp, ico, and webp.
 
diff -r 62cbf900c9ca -r ed73da6ca2e7 magick/image.c
--- a/magick/image.c	Tue Nov 01 11:00:10 2022 -0500
+++ b/magick/image.c	Tue Nov 01 13:45:58 2022 -0500
@@ -3134,14 +3134,21 @@
   */
   if (*magic == '\0')
     {
+      MagickBool
+        compressed_extension = MagickFalse;
+
       /* Restore p to end of modified filename */
       p=image_info->filename+Max((long) strlen(image_info->filename)-1,0);
 
       while ((*p != '.') && (p > (image_info->filename+1)))
         p--;
+
       if ((LocaleCompare(p,".gz") == 0) ||
           (LocaleCompare(p,".Z") == 0) ||
           (LocaleCompare(p,".bz2") == 0))
+        compressed_extension = MagickTrue;
+
+      if (compressed_extension)
         do
           {
             p--;
@@ -3197,7 +3204,22 @@
           magick_info=GetMagickInfo(magic,exception);
           if (magick_info != (const MagickInfo *) NULL)
             {
-              if (magick_info->extension_treatment == IgnoreExtensionTreatment)
+              /*
+                For compressed files with expected extensions
+                (e.g. name.ext.gz) we have already deduced the
+                expected format based on the base file extension, and
+                if the extension is considered to be a good hint, and
+                if seekable_stream is false for that format, use
+                "affirm" in order to avoid using a temporary file.
+              */
+              if (LocaleCompare(magick_info->name,"SVGZ") == 0)
+                compressed_extension = MagickTrue;
+
+              if ((magick_info->extension_treatment == HintExtensionTreatment) &&
+                  (magick_info->seekable_stream == MagickFalse) &&
+                  (compressed_extension))
+                image_info->affirm=MagickTrue;
+              else if (magick_info->extension_treatment == IgnoreExtensionTreatment)
                 exclude=MagickTrue;
               else if (magick_info->extension_treatment == ObeyExtensionTreatment)
                 image_info->affirm=MagickTrue;
@@ -3226,6 +3248,9 @@
           DestroyImage(image);
           return(MagickFail);
         }
+      /*
+        FIXME: Avoid creating temporary files unless absolutely necessary!
+      */
       if (!BlobIsSeekable(image))
         {
           /*
diff -r 62cbf900c9ca -r ed73da6ca2e7 www/Changelog.html
--- a/www/Changelog.html	Tue Nov 01 11:00:10 2022 -0500
+++ b/www/Changelog.html	Tue Nov 01 13:45:58 2022 -0500
@@ -40,6 +40,10 @@
 <p>2022-11-01  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
 <blockquote>
 <ul class="simple">
+<li><p>magick/image.c (SetImageInfo): Avoid creating temporary files
+when reading files with .bz2, .gz, .svgz, and .Z extensions if the
+format is non-ambiguous based on the file extension, and the
+reader does not require seeking.</p></li>
 <li><p>magick/magick.c (MagickToMime): Add MIME mappings for apng,
 avif, bmp, ico, and webp.</p></li>
 </ul>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.