openexr-devel
[Top][All Lists]
Advanced

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

Re: [Openexr-devel] wish for memory-to-memory version


From: Florian Kainz
Subject: Re: [Openexr-devel] wish for memory-to-memory version
Date: Mon, 22 Nov 2004 11:03:39 -0800
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030314

gary demos wrote:

Dear OpenExr developers, and the ILM OpenExr team,

The current reference implementation OpenExr1.2 (which I am using on the Mac under OS X.3.5) is for file-to-memory, and memory-to-file. That is, if I have a "half" image in memory, I can write it to a file, and if I have a file, I can read it into a "half" image in memory.

I would like to request your consideration of a memory-to-memory capability, such that if I already have the file in memory, I can decode it into a "half" image in memory,
and visa-versa.



This capability was added in version 1.2.0.

Section 6.2 of "Reading and Writing OpenEXR Image Files with
the IlmImf Library" (at http://www.openexr.com/api.print.html)
describes storing OpenEXR files in arbitrary "file-like" objects.
File IlmImfExamples/lowLevelIoExamples.cpp contains compilable
code that reads and writes OpenEXR files via C-style FILEs.

Images can be written to and read from any object for which you can
supply low-level "read", "write", seek and "tell" operations.  For
example, a class MemOStream, as shown below, might be used to write
to an in-memory buffer supplied by the caller.  (The corresponding
MemIstream class is left as an exercise for the reader.)

    class MemOstream: public OStream
    {
      public:

        MemOstream (std::vector &buf);

        virtual void            write (const char c[/*n*/], int n);
        virtual Int64           tellp ();
        virtual void            seekp (Int64 pos);

      private:

        Int64                   _pos;
        std::vector<char> &     _buf;
    };

    MemOStream::MemOStream (std::vector &buf):
        OStream ("in-memory buffer"), _pos (0), _buf (buf) {}

    void
    MemOstream::write (const char c[/*n*/], int n)
    {
        if (_buf.size() < _pos + n)
            _buf.resize (_pos + n);

        for (int i = 0; i < n; ++n)
            _buf[_pos++] = c[i];
    }

    Int64
    MemOstream::tellp ()
    {
        return _pos;
    }

    void
    MemOstream::seekp (Int64 pos)
    {
        _pos = pos;
    }






reply via email to

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