Fast identify for embedded color profile

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
nator
Posts: 6
Joined: 2013-10-18T11:10:19-07:00
Authentication code: 6789

Fast identify for embedded color 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.

Thanks!

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;
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Fast identify for embedded color profile

Post by dlemstra »

I personally prefer Fred's property names: viewtopic.php?f=1&t=24286#p104075.

identify -format "%[profile:icc]\n" someimage (similarly for icm)
and
identify -format "%[profiles]\n" someimage
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Fast identify for embedded color profile

Post by Bonzo »

From memory adding -ping speeds things like this up?
nator
Posts: 6
Joined: 2013-10-18T11:10:19-07:00
Authentication code: 6789

Re: Fast identify for embedded color profile

Post by nator »

Bonzo wrote:From memory adding -ping speeds things like this up?
Winner!!! Holy smokes, that's fast. I would still prefer eventually to incorporate this into my existing identify call (and prefer Fred's syntax as well), but in the meantime you have saved the day:

Code: Select all

convert -ping [filename] /tmp/test.icc
is lightning fast. Thank you!
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Fast identify for embedded color profile

Post by dlemstra »

Thanks for your idea. It has been implemented and you can use it in the next release of ImageMagick:

Code: Select all

C:\Test>identify -format "%[profile:icc]" test.tif
Coated FOGRA27 (ISO 12647-2:2004)

C:\Test>identify -format "%[profiles]" test.tif
8bim,icc,xmp
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
nator
Posts: 6
Joined: 2013-10-18T11:10:19-07:00
Authentication code: 6789

Re: Fast identify for embedded color profile

Post by nator »

Brilliant! Thanks so much for the quick turnaround. Big IM fan now even bigger. :)
Post Reply