Yeah, there's no operator== because I think metadata comparison is a lot more 
subtle than a simple binary answer for the whole thing.

The way to do it is like this (in C++):

        bool compare (const ImageSpec &A, const ImageSpec &B)
        {
            size_t nfound = 0;
            for (ParamValueLIst::const_iterator a = A.extra_attribs.cbegin(), e 
= A.extra_attribs.cend();
                        a != e; ++a) {
                ParamValueList::const_iterator b = B.extrra_attribs.find  
(a->name());
                if (b == B.extra_attribs.end())
                    return false;  // attrib in A not found in B
                if (a->type() != b->type() || a->nvalues() != b->nvalues())
                    return false;  // matching names, different types or number 
of values
                if (memcmp (a->data(), b->data(), a->datasize()))
                    return false;  // different values!
                ++nfound;   // match
            }
            if (nfound != B.extra_attribs.size())
                return false;   // Some metadata in B that weren't in A
            return true;   // seems to be identical
        }

Some caveats:

1. I just typed that off the top of my head, make the obvious corrections if it 
fails to compile.

2. This is just the name/value metadata in extra_attribs. I omitted check of 
the named fields in the ImageSpec, like if the channels are named the same 
thing or if they have the same "full" size (display window), etc.

3. I completely glossed over what happens if, for example, A has metadata "foo" 
that's an int whose value is 42, and B also has "foo" that is a short with 
value 42. In the code above, that will not be a match. Similarly, string data 
would not be a match if they differed only in capitalization.

4. Maybe any smart comparison of metadata would want to purposely omit some 
attributes from the comparison. Should two images be considered the same if the 
only thing that differs is the version number of the software in the 
Exif:ImageHistory? That's the kind of question that made me not write an 
operator== in the first place. :-)



On Jun 16, 2014, at 9:55 AM, Ramezanali, Morteza <[email protected]> wrote:

> Is there an easy way to compare two ImageSpec against each other? I'm 
> especially interested in comparing extra_attrib. I don’t see any equal 
> operator in ImageIOParameterList / ParamValueList.
>  
> Cheers,
> Morteza
> _______________________________________________
> Oiio-dev mailing list
> [email protected]
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

--
Larry Gritz
[email protected]



_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to