-
1. Re: How to deal with metadata?
Chris Cox Oct 2, 2009 12:25 PM (in response to G_Soucy)Yes, Photoshop uses XMP.
Yes, there are APIs to set and get XMP metadata when reading or writing a file.
-
2. Re: How to deal with metadata?
G_Soucy Oct 2, 2009 3:29 PM (in response to Chris Cox)Thanks for the info.
I have a few more questions just to make sure that I am on the right track:
1- So, is it right to say that the data that I get from Photoshop (when saving a file in my plugin) from the handle
gFormatRecord->imageRsrcData
is raw binary XMP data ? If not, what is the data that I get from there and how do I get the XMP data?
2- Does the Photshop SDK api provide ways, by itself, to decode/encode XMP data or should I download and install the SDK for XMP( http://www.adobe.com/devnet/xmp/ ) and deal with the binary data myself thougth the XMP api provided from the SDK?
Thanks again!
Gilbert
-
3. Re: How to deal with metadata?
Chris Cox Oct 3, 2009 4:54 PM (in response to G_Soucy)No, as explained in the SDK - the image resource data is the Photoshop data, and contains many different things (mostly in binary form).
The Photoshop SDK does not include ways to compose or parse XMP data. XMP is just an XML format, not binary. Please read up on it.
-
4. Re: How to deal with metadata?
G_Soucy Oct 15, 2009 1:00 PM (in response to Chris Cox)Since that posting, I found a few answers to my questions, so here is some info regarding metadata loaded and saved from a format plugin. I am not sure about everything I say below (or whether this is the right way to do things) but it worked for me.
Photoshop raw binary metadata is all stored in the gFormatRecord->imageRsrcData handle passed to the pluginMain callback routine. In write mode, the size of the metadata is given by gFormatRecord->imageRsrcSize .
You can acces the raw binary data via a 'lock' of the handle:
Ptr p = NULL;
sPSHandle->SetLock(gFormatRecord->imageRsrcData,
true, &p, NULL);
which you must unlock (after you are done) with
sPSHandle->SetLock(gFormatRecord->imageRsrcData,
false, &p, NULL);
During the "lock", the "p" pointer (in this example) contains the raw binary metadata of length gFormatRecord->imageRsrcSize (you can parse the data via p[i] for example). You can interpret the binary metadata contained in p[] with the info given in html doc page found in the CS4 SDK :
<rootDir>\Adobe Photoshop CS4 SDK\documentation\html\imageresourcessection.html
This page tells you how to decode the binary metadata and make sense from it. For example, you can extract the exif raw binary data (if any) by looking for a block with resource id of 1058 (that magic number is given in that html doc page). There are many ids for specific usage. XMP metadata is only one of the possible resource id. XMP is not very much used because it is not supported by many application or file formats.
You can store you own metadata that only your plugin can understand by using a resource id in the range from 4000 to 4999. Only your plugin can decode or use that but it can be very handy to carry arbitrary data over.
When loading an image, your plugin must create the resource handle and copy your metadata to it:
<load the metadata somwhow then...>
int size = metaDataSize;
gFormatRecord->imageRsrcData = sPSHandle->New(size);
if (gFormatRecord->imageRsrcData == NULL){*gResult = memFullErr;
return;}
Ptr resourcePtr = NULL;
sPSHandle->SetLock(gFormatRecord->imageRsrcData,
true, &resourcePtr, NULL);
if (resourcePtr != NULL){memcpy(resourcePtr, data, size);
sPSHandle->SetLock(gFormatRecord->imageRsrcData,
false, &resourcePtr, NULL);
if (*gResult != noErr)
return;gFormatRecord->imageRsrcSize = size;
}
That's it. With that recipe, I was able to load exif data with my own image format and get photoshop to display the data correctly (exif data is supported only for 7.0 and above). Hope it can help a bit other people.



