openexr-devel
[Top][All Lists]
Advanced

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

Re: [Openexr-devel] Memory usage in Imf libraries


From: Florian Kainz
Subject: Re: [Openexr-devel] Memory usage in Imf libraries
Date: Mon, 19 Apr 2004 11:51:17 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030314

Hi,

when you write an image file, it is not necessary to allocate a buffer
for the entire image.  If you want, you can write a single scan line or
a few scan lines at a time.
Function OutputFile::writePixels() has a "number of scan lines" argument;
and if necessary, you can call OutputFile::setFrameBuffer() before each
writePixels() call.
Below is a modified version of one of the examples from the documentation
on the OpenEXR web site (http://www.openexr.com/api.html#sec_2_1); in this
version, only a single scan line is buffered.  Each scan line is written
to the file as soon as possible. (The example assumes that the call to
renderPixels(y,...) generates the pixels for scan line y, and stores
them in gPixels and zPixels.)

Florian


---

void
writeImage (const char fileName[], int width, int height)
{
    Header header (width, height);
    header.channels().insert ("G", Channel (HALF));
    header.channels().insert ("Z", Channel (FLOAT));

    OutputFile file (fileName, header);

    Array<half>  gPixels(width);
    Array<float> zPixels(width);

    FrameBuffer frameBuffer;

    frameBuffer.insert ("G",                            // name
                        Slice (HALF,                    // type
                               (char *) &gPixels[0],    // base
                               sizeof (gPixels[0]),     // xStride
                               0));                     // yStride

    frameBuffer.insert ("Z",                            // name
                        Slice (FLOAT,                   // type
                               (char *) &zPixels[0],    // base
                               sizeof (zPixels[0]),     // xStride
                               0));                     // yStride

    file.setFrameBuffer (frameBuffer);

    for (int y = 0; y < height; ++y)
    {
        renderPixels (y, gPixels, zPixels);
        file.writePixels (height);
    }
}


John Cooper wrote:
Hello,
I have been using the 1.0.6 library for a while now and am curious about its memory usage. From what I can tell, one must allocate an entire image buffer for any particular channel in order for OutputFile::writePixels() to do its thing. A quick back-of-the-napkin calculation suggests that if one is writing, say, 10 channels of HALF data for a 2k frame, we're talking 60MB of RAM consumed. Why can't the data be written row by row instead of an entire image buffer at once? There is such a thing as fseek() after all. Could this at least be implemented as an optional writing method? I realize that it would take longer to write to disk, but sometimes its worth it to save on the RAM footprint required during rendering. Cheers,
- John


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

_______________________________________________
Openexr-devel mailing list
address@hidden
http://mail.nongnu.org/mailman/listinfo/openexr-devel







reply via email to

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