openexr-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Openexr-devel] Per Tile "Header-like" storage?


From: Florian Kainz
Subject: Re: [Openexr-devel] Per Tile "Header-like" storage?
Date: Mon, 29 Aug 2005 10:07:12 -0700
User-agent: Mozilla Thunderbird 1.0 (X11/20041207)

Hi Axel,

yes, storing a per-tile signature is possible.  Each tile is uniquely
identified by a tuple of 4 integers: level number (lx,ly) and tile
coordinates (dx,dy).  An OpenEXR file header lets you store attributes
of arbitrary types.  You can create a new attribute type whose value
is a map ((lx,ly,dx,dy) --> signature), and add an attribute of this
type to your file's header.

Adding a new attribute type does not affect compatibility with other
programs that read and write OpenEXR files.  To programs that do not
support it, your new attribute type will appear as an OpaqueAttribute
that can be copied and saved in other files, but whose value is
inaccessible.  (Compatibility is affected if correct interpretation
of the pixels depends on the value of an attribute, for example if
the attribute contains a key for decrypting the pixels.  Doing this
is not recommended.)

The sample code below, adapted from IlmImfTest/testCustomAttributes.cpp,
demonstrates defining and using an application-specific attribute type.

Florian


------------


    #include <ImfAttribute.h>
    ...

    namespace Imf
    {
        //
        // Definition of the custom GlorpAttribute type.
        //

        struct Glorp
        {
            int a, b;
            Glorp (int a = 0, int b = 0): a(a), b(b) {}
        };


        typedef TypedAttribute<Glorp> GlorpAttribute;
        template <> const char *GlorpAttribute::staticTypeName ();
template <> void GlorpAttribute::writeValueTo (OStream &, int) const; template <> void GlorpAttribute::readValueFrom (IStream &, int, int);

        template <>
        const char *
        GlorpAttribute::staticTypeName ()
        {
            return "glorp";
        }


        template <>
        void
        GlorpAttribute::writeValueTo (OStream &os, int version) const
        {
            Xdr::write <StreamIO> (os, _value.a);
            Xdr::write <StreamIO> (os, _value.b);
        }


        template <>
        void
        GlorpAttribute::readValueFrom (IStream &is, int size, int version)
        {
            Xdr::read <StreamIO> (is, _value.a);
            Xdr::read <StreamIO> (is, _value.b);
        }
    }

    ...

    using namespace Imf;

    int
    main ()
    {
        //
// Tell the image file library about the custom GlorpAttribute type.
        //

        GlorpAttribute::registerAttributeType();

        //
        // Add a GlorpAttribute to a Header.
        //

        Header hdr (width, height);
        hdr.insert ("myGlorp", GlorpAttribute (Glorp (4, 9)));

        ...
    }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]