How to set a color profile with exiftool?
For exiftool
to add a color profile, you need a profile.file
You can extract this from any JPEG
image by:
exiftool -icc_profile -b somefile.jpg > profile.icc
Then attach this profile by using
exiftool "-icc_profile<=profile.icc" yourfile.jpg
.bat to move files with specific exiftool color profile output
Exiftool can do this without scripting. Try something like:exiftool -if "$ProfileDescription ne 'sRGB IEC61966-2.1'" "-directory=C:\Users\%Username%\Desktop\Color_Check_v1.4.5\Convert" /path/to/target/dir
Add -r
to recurse into subdirectories. Change -directory
to -testname
and add \%F
to the end of your target path if you want to test and see what the results would be without actually moving the files.
By letting exiftool do the testing and moving, it will be much faster as exiftool will only be run once instead of once per file.
JPG - how to read / extract data from ICC profile section APP2
The overall format of an APP2 segment containing an ICC profile is described in Appendix B.4 of the ICC spec:
The JPEG standard (ISO/IEC 10918-1[2]) supports application specific data segments. These segments may
be used for tagging images with ICC profiles. The APP2 marker is used to introduce the ICC profile tag. Given
that there are only 15 supported APP markers, there is a chance of many applications using the same marker.
ICC tags are thus identified by beginning the data with a special null terminated byte sequence,
“ICC_PROFILE”.
The length field of a JPEG marker is only two bytes long; the length of the length field is included in the total.
Hence, the values 0 and 1 are not legal lengths. This would limit the maximum data length to 65 533. The
identification sequence would lower this even further. As it is quite possible for an ICC profile to be longer than
this, a mechanism is required to break the profile into chunks and place each chunk in a separate marker. A
mechanism to identify each chunk in sequence order is therefore necessary.
The identifier sequence is followed by one byte indicating the sequence number of the chunk (counting starts
at 1) and one byte indicating the total number of chunks. All chunks in the sequence should indicate the same
total number of chunks. The 1-byte chunk count limits the size of embeddable profiles to 16 707 345 bytes.
So, to get a usable profile, you need to strip off the leading "ICC_PROFILE", the length field, and the sequence number from each chunk, then put all the chunks together in sequence.
From there, you'll want to look through section 7 of the ICC for details. Some of the data (e.g., the XYZ of the illuminant) are easy to find in the profile header. Others will need to be computed from the data in the profile (which can be quite non-trivial in some cases).
Reference
ICC Spec
How to embed ICC_Profile in TiffOutputSet
I got it to work. The mistake I made was when I got the TiffOutputDirectory, I called getOrCreateExifDirectory, but it should have been getOrCreateRootDirectory.
Here is the correct code:
TiffImageMetadata tmeta = (TiffImageMetadata) metadata;
TiffOutputSet outputSet = tmeta.getOutputSet();
byte iccBytes[] = Util.getAdobe98ProfileBytes();
TagInfoUndefined ICC_INFO = TiffConstants.EXIF_TAG_INTER_COLOR_PROFILE;
TiffOutputField field = new TiffOutputField(ICC_INFO, FieldType.UNDEFINED, iccBytes.length, iccBytes);
TiffOutputDirectory rootDirectory = outputSet.getOrCreateRootDirectory();
rootDirectory.removeField(ICC_INFO);
rootDirectory.add(field);
TiffImageWriterLossless writerLossless = new TiffImageWriterLossless(imageBytes);
writerLossless.write(new FileOutputStream(resultingFilePath), outputSet);
This is how you embed an ICC_Profile in TiffOutputSet.
Read/Write ICC Profile In Images with Go and OpenCV
After more research, I've found libvips and the go bindings.
libvips doesn't strip any embedded profiles. This blog post mentions this:
The file load/save operations (like tiffload, jpegsave etc.) don't do anything with colour. On load they attach any ICC profiles they see to the vips image as metadata and on save they write any attached profile to the file. They aim to give you something very close to what's actually stored in the file and leave colour processing for you to arrange.
Related Topics
What Does "Private_Dirty" Memory Mean in Smaps
Run Any Linux Terminal Command from Typescript
How to Clear Space on My Main System Drive on a Linux Centos System
Cargo Plugin Throws Cargoexception When Deploying on Glassfish - Deployment Has Failed: Null
Linux Kernel Aio, Open System Call
Rtnetlink Answers: No Such File or Directory
Print Stdout/Stderr and Write Them to a File in Bash
How to Package Mono Applications for Debian/Ubuntu
Window Placement: Winsplit Revolution -Like Application for Linux (Kde)
Is Overwriting a Small File Atomic on Ext4
Linux: Move 1 Million Files into Prefix-Based Created Folders
How to Use Sed to Delete Leading Digits
Webdrivererror Error: Chrome Failed to Start: Exited Abnormally
How to Log from a Non-Root Debian Linux Daemon
I Would Like to Store All Command-Line Arguments to a Bash Script into a Single Variable
How to Remove Warning: Link.Res Contains Output Sections; Did You Forget -T
What's The Meaning of 'C' in Result of Command "Ls -L /Dev/Tty'