Added dcraw coder (dcraw:img.cr2) that can be used to force the use of the dcraw...
authorDirk Lemstra <dirk@git.imagemagick.org>
Sun, 12 Aug 2018 19:24:20 +0000 (21:24 +0200)
committerDirk Lemstra <dirk@git.imagemagick.org>
Sun, 12 Aug 2018 19:24:20 +0000 (21:24 +0200)
ChangeLog
coders/dng.c

index cd4523255674e01cdd28e51a25bbac0e3857a290..6767ff7798017df5f298f4bcd4c4acfb5f70ae7d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-09-12  7.0.8-10 Dirk Lemstra <dirk@lem.....org>
+  * Added dcraw coder (dcraw:img.cr2) that can be used to force the use of the
+    dcraw delegate when libraw is the default raw delegate.
+
 2018-08-08  7.0.8-10 Cristy  <quetzlzacatenango@image...>
   * ThumbnailImage function no longer reveals sensitive information (reference
     https://github.com/ImageMagick/ImageMagick/issues/1243).
index 03499cb8f48cd2d5d7db2ab38123c9b51a2c238f..120b84bb91ace7b823470b4dce0e85a83b699367 100644 (file)
@@ -233,6 +233,108 @@ static void SetDNGProperties(Image *image,const libraw_data_t *raw_info,
 }
 #endif
 
+static Image *InvokeDNGDelegate(const ImageInfo *image_info,Image *image,
+  ExceptionInfo *exception)
+{
+  ExceptionInfo
+    *sans_exception;
+
+  ImageInfo
+    *read_info;
+
+  /*
+    Convert DNG to PPM with delegate.
+  */
+  (void) DestroyImageList(image);
+  InitializeDcrawOpenCL(exception);
+  image=AcquireImage(image_info,exception);
+  read_info=CloneImageInfo(image_info);
+  SetImageInfoBlob(read_info,(void *) NULL,0);
+  (void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception);
+  image=DestroyImage(image);
+  (void) FormatLocaleString(read_info->filename,MagickPathExtent,"%s.png",
+    read_info->unique);
+  sans_exception=AcquireExceptionInfo();
+  image=ReadImage(read_info,sans_exception);
+  sans_exception=DestroyExceptionInfo(sans_exception);
+  if (image == (Image *) NULL)
+    {
+      (void) FormatLocaleString(read_info->filename,MagickPathExtent,"%s.ppm",
+        read_info->unique);
+      image=ReadImage(read_info,exception);
+    }
+  (void) RelinquishUniqueFileResource(read_info->filename);
+  if (image != (Image *) NULL)
+    {
+      char
+        filename[MagickPathExtent],
+        *xml;
+
+      ExceptionInfo
+        *sans;
+
+      (void) CopyMagickString(image->magick,read_info->magick,
+        MagickPathExtent);
+      (void) FormatLocaleString(filename,MagickPathExtent,"%s.ufraw",
+        read_info->unique);
+      sans=AcquireExceptionInfo();
+      xml=FileToString(filename,MagickPathExtent,sans);
+      (void) RelinquishUniqueFileResource(filename);
+      if (xml != (char *) NULL)
+        {
+          XMLTreeInfo
+            *ufraw;
+
+          /*
+            Inject.
+          */
+          ufraw=NewXMLTree(xml,sans);
+          if (ufraw != (XMLTreeInfo *) NULL)
+            {
+              char
+                *content,
+                property[MagickPathExtent];
+
+              const char
+                *tag;
+
+              XMLTreeInfo
+                *next;
+
+              if (image->properties == (void *) NULL)
+                ((Image *) image)->properties=NewSplayTree(
+                  CompareSplayTreeString,RelinquishMagickMemory,
+                  RelinquishMagickMemory);
+              next=GetXMLTreeChild(ufraw,(const char *) NULL);
+              while (next != (XMLTreeInfo *) NULL)
+              {
+                tag=GetXMLTreeTag(next);
+                if (tag == (char *) NULL)
+                  tag="unknown";
+                (void) FormatLocaleString(property,MagickPathExtent,"dng:%s",
+                  tag);
+                content=ConstantString(GetXMLTreeContent(next));
+                StripString(content);
+                if ((LocaleCompare(tag,"log") != 0) &&
+                    (LocaleCompare(tag,"InputFilename") != 0) &&
+                    (LocaleCompare(tag,"OutputFilename") != 0) &&
+                    (LocaleCompare(tag,"OutputType") != 0) &&
+                    (strlen(content) != 0))
+                  (void) AddValueToSplayTree((SplayTreeInfo *)
+                    ((Image *) image)->properties,ConstantString(property),
+                    content);
+                next=GetXMLTreeSibling(next);
+              }
+              ufraw=DestroyXMLTree(ufraw);
+            }
+          xml=DestroyString(xml);
+        }
+      sans=DestroyExceptionInfo(sans);
+    }
+  read_info=DestroyImageInfo(read_info);
+  return(image);
+}
+
 static Image *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
 {
   Image
@@ -259,6 +361,8 @@ static Image *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
       return((Image *) NULL);
     }
   (void) CloseBlob(image);
+  if (LocaleCompare(image_info->magick,"DCRAW") == 0)
+    return(InvokeDNGDelegate(image_info,image,exception));
 #if defined(MAGICKCORE_RAW_R_DELEGATE)
   {
     int
@@ -426,105 +530,7 @@ static Image *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
     return(image);
   }
 #else
-  {
-    ExceptionInfo
-      *sans_exception;
-
-    ImageInfo
-      *read_info;
-
-    /*
-      Convert DNG to PPM with delegate.
-    */
-    (void) DestroyImageList(image);
-    InitializeDcrawOpenCL(exception);
-    image=AcquireImage(image_info,exception);
-    read_info=CloneImageInfo(image_info);
-    SetImageInfoBlob(read_info,(void *) NULL,0);
-    (void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception);
-    image=DestroyImage(image);
-    (void) FormatLocaleString(read_info->filename,MagickPathExtent,"%s.png",
-      read_info->unique);
-    sans_exception=AcquireExceptionInfo();
-    image=ReadImage(read_info,sans_exception);
-    sans_exception=DestroyExceptionInfo(sans_exception);
-    if (image == (Image *) NULL)
-      {
-        (void) FormatLocaleString(read_info->filename,MagickPathExtent,"%s.ppm",
-          read_info->unique);
-        image=ReadImage(read_info,exception);
-      }
-    (void) RelinquishUniqueFileResource(read_info->filename);
-    if (image != (Image *) NULL)
-      {
-        char
-          filename[MagickPathExtent],
-          *xml;
-
-        ExceptionInfo
-          *sans;
-
-        (void) CopyMagickString(image->magick,read_info->magick,
-          MagickPathExtent);
-        (void) FormatLocaleString(filename,MagickPathExtent,"%s.ufraw",
-          read_info->unique);
-        sans=AcquireExceptionInfo();
-        xml=FileToString(filename,MagickPathExtent,sans);
-        (void) RelinquishUniqueFileResource(filename);
-        if (xml != (char *) NULL)
-          {
-            XMLTreeInfo
-              *ufraw;
-
-            /*
-              Inject.
-            */
-            ufraw=NewXMLTree(xml,sans);
-            if (ufraw != (XMLTreeInfo *) NULL)
-              {
-                char
-                  *content,
-                  property[MagickPathExtent];
-
-                const char
-                  *tag;
-
-                XMLTreeInfo
-                  *next;
-
-                if (image->properties == (void *) NULL)
-                  ((Image *) image)->properties=NewSplayTree(
-                    CompareSplayTreeString,RelinquishMagickMemory,
-                    RelinquishMagickMemory);
-                next=GetXMLTreeChild(ufraw,(const char *) NULL);
-                while (next != (XMLTreeInfo *) NULL)
-                {
-                  tag=GetXMLTreeTag(next);
-                  if (tag == (char *) NULL)
-                    tag="unknown";
-                  (void) FormatLocaleString(property,MagickPathExtent,"dng:%s",
-                    tag);
-                  content=ConstantString(GetXMLTreeContent(next));
-                  StripString(content);
-                  if ((LocaleCompare(tag,"log") != 0) &&
-                      (LocaleCompare(tag,"InputFilename") != 0) &&
-                      (LocaleCompare(tag,"OutputFilename") != 0) &&
-                      (LocaleCompare(tag,"OutputType") != 0) &&
-                      (strlen(content) != 0))
-                    (void) AddValueToSplayTree((SplayTreeInfo *)
-                      ((Image *) image)->properties,ConstantString(property),
-                      content);
-                  next=GetXMLTreeSibling(next);
-                }
-                ufraw=DestroyXMLTree(ufraw);
-              }
-            xml=DestroyString(xml);
-          }
-        sans=DestroyExceptionInfo(sans);
-      }
-    read_info=DestroyImageInfo(read_info);
-    return(image);
-  }
+  return(InvokeDNGDelegate(image_info,image,exception));
 #endif
 }
 \f
@@ -592,6 +598,12 @@ ModuleExport size_t RegisterDNGImage(void)
   entry->flags^=CoderBlobSupportFlag;
   entry->format_type=ExplicitFormatType;
   (void) RegisterMagickInfo(entry);
+  entry=AcquireMagickInfo("DNG","DCRAW","Raw Photo Decoder (dcraw)");
+  entry->decoder=(DecodeImageHandler *) ReadDNGImage;
+  entry->flags|=CoderDecoderSeekableStreamFlag;
+  entry->flags^=CoderBlobSupportFlag;
+  entry->format_type=ExplicitFormatType;
+  (void) RegisterMagickInfo(entry);
   entry=AcquireMagickInfo("DNG","ERF","Epson RAW Format");
   entry->decoder=(DecodeImageHandler *) ReadDNGImage;
   entry->flags|=CoderDecoderSeekableStreamFlag;