Fast way to detect embedded profile

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
nator
Posts: 6
Joined: 2013-10-18T11:10:19-07:00
Authentication code: 6789

Fast way to detect embedded profile

Post by nator »

I would like to propose adding an option to identify -format "[format string]" to enable rapid detection of embedded icc/icm profiles.

Both currently available methods are too slow for my needs: identify -verbose [filename] | grep -A1 'Profile-ic' and convert [filename] test.icc.

The problem is I don't need the full details of verbose, and I certainly don't need to convert the whole file to test for an icc. I just need to know (quickly!) if it exists so I don't double-apply profiles.

Thoughts? Am I missing a faster way to do this? The sips program on OS X is in the speed range I'm after, but since I need to run identify -format anyway I'd prefer to consolidate the call.

Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fast way to detect embedded profile

Post by fmw42 »

I would suggest you repost this on the Developers forum
nator
Posts: 6
Joined: 2013-10-18T11:10:19-07:00
Authentication code: 6789

Re: Fast way to detect embedded profile

Post by nator »

Something like this meets my needs perfectly, but I'm dealing with situations where I can't build from source. Thanks for reviewing and incorporating!

Code: Select all

--- magick/property.c.bak	2013-10-18 13:51:10.000000000 -0500
+++ magick/property.c	2013-10-18 13:51:16.000000000 -0500
@@ -2372,6 +2372,22 @@
         image->page.height);
       break;
     }
+    case 'I': /* presence of icc profile */
+    {
+      ResetImageProfileIterator(image);
+      const char *name=GetNextImageProfile(image);
+      while (name != (char *) NULL)
+      {
+        if ((LocaleCompare(name,"icc") == 0) ||
+                  (LocaleCompare(name,"icm") == 0))
+        {
+          (void) FormatLocaleString(value,MaxTextExtent,"%s",name);
+          break;
+        }
+        name = GetNextImageProfile(image);
+      }
+      break;
+    }
     case 'M': /* Magick filename - filename given incl. coder & read mods */
     {
       string=image->magick_filename;
nator
Posts: 6
Joined: 2013-10-18T11:10:19-07:00
Authentication code: 6789

Re: Fast way to detect embedded profile

Post by nator »

fmw42 wrote:I would suggest you repost this on the Developers forum
I must be blind. Will do. Still, hoping for users to chime in support of this feature...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Fast way to detect embedded profile

Post by fmw42 »

It seems like a reasonable thing. I do not know how hard it would be. Perhaps a string format something like

identify -format "%[profile:icc]\n" someimage (similarly for icm)

or

identify -format "%[profile-icc]\n" someimage


which would list the name (Description from the verbose info) of the icc profile


or

identify -format "%[profiles]\n" someimage

which would list all types of profiles that exist for the image.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Fast way to detect embedded profile

Post by snibgo »

I don't think there is a faster way, and this seems a useful enhancement.

However, in my tests I have noticed that "-profile sRGB.icc" takes no time if the input has no profile or already has sRGB embedded. It takes time only if it has a different profile embedded. (About 2 seconds for a 5000x7500 image on my oldish laptop.)
snibgo's IM pages: im.snibgo.com
Post Reply