4 Replies Latest reply: Oct 15, 2009 1:00 PM by G_Soucy RSS

    How to deal with metadata?

    G_Soucy Community Member

      Hello,

       

      I am writing a new format plugin and I would like to preserve the metadata as much as possible.My plugin works fine as is in terms of managing the image data but I can't figure out how to deal with metadata in a general way. I am new to the world of metadata so please forgive me if my question sounds trivial.

       

      From the SDK doc, it is not clear to me how to push the metadata to Photoshop when I read a file (and in which format, through which interface) and how to get it back when the plugin needs to save a file. Could someone give me some pointer on how to do that?

       

      Is Photoshop using the XMP standard (http://www.adobe.com/products/xmp/) ? If so, does it mean that I also need to get the SDK for XMP and use it to feed photoshop with metadata formatted with the XMP standard ?

       

      Ideally, I would like to be able to manage metadata in a way that files loaded with my plugin can export their metadata to other formats once loaded in photoshop.

       

      Thank you!

       

      Gilbert

        • 1. Re: How to deal with metadata?
          Chris Cox Adobe Employee

          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 Community Member

            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 Adobe Employee

              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 Community Member

                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.