openexr-devel
[Top][All Lists]
Advanced

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

Re: [Openexr-devel] writing an exr


From: Drew Hess
Subject: Re: [Openexr-devel] writing an exr
Date: Thu, 23 Jan 2003 17:24:25 -0800 (PST)

I'll work on releasing some simple EXR manipulation tools, which include
the ability to write files.  But for now, here's a snippet that takes an
RGBA Half image in memory and writes it out (cut and pasted from some
other code, there may be a few small issues with it since it's out of
context and I didn't bother compiling it):


    // pixels is the array of RGBA Half pixels, width and height are
    // its dimensions
    

    try
    {
        Imf::Compression compression;
        compression = Imf::PIZ_COMPRESSION;

        Imf::RgbaChannels rgbaChannels;
        rgbaChannels = Imf::WRITE_RGBA;

        Imf::Header header(width, height, 1, Imath::V2f (0, 0), 1,
                           Imf::INCREASING_Y, compression);

        Imf::ChannelList channels;
        if (rgbaChannels & Imf::WRITE_R)
            channels.insert("R", Imf::Channel(Imf::HALF, 1, 1));
        if (rgbaChannels & Imf::WRITE_G)
            channels.insert("G", Imf::Channel(Imf::HALF, 1, 1));
        if (rgbaChannels & Imf::WRITE_B)
            channels.insert("B", Imf::Channel(Imf::HALF, 1, 1));
        if (rgbaChannels & Imf::WRITE_A)
            channels.insert("A", Imf::Channel(Imf::HALF, 1, 1));

        header.channels() = channels;

        Imf::OutputFile imfFile(filename, header);

        int bpc = sizeof(half);    // channel stride
        int bpp = 4*sizeof(half);  // pixel stride      
        int bpr = width*bpp;       // row stride

        Imf::FrameBuffer fb;
        if (rgbaChannels & Imf::WRITE_R)
            fb.insert("R", Imf::Slice(Imf::HALF, (char *)pixels + 
                      0*bpc, bpp, bpr));
        if (rgbaChannels & Imf::WRITE_G)
            fb.insert("G", Imf::Slice(Imf::HALF, (char *)pixels + 
                      1*bpc, bpp, bpr));
        if (rgbaChannels & Imf::WRITE_B)
            fb.insert("B", Imf::Slice(Imf::HALF, (char *)pixels + 
                      2*bpc, bpp, bpr));
        if (rgbaChannels & Imf::WRITE_A)
            fb.insert("A", Imf::Slice(Imf::HALF, (char *)pixels + 
                      3*bpc, bpp, bpr));

        imfFile.setFrameBuffer(fb);
        imfFile.writePixels(height);
    }
    catch (Iex::BaseExc &e)
    {
        ERROR(e);
        success = false;
    }



It's actually slightly easier with the RgbaOutputFile class, but the code
above can be adapted to add additional channels.


-dwh-



On Thu, 23 Jan 2003, Kevin Smith wrote:

> 
>    Can anyone share some boilerplater code for writing an exr image? Something
> as simple as writing out a 512x512, middle grey (0.18) .exr would be great.
> 
> 
> 
> _______________________________________________
> 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]