openexr-devel
[Top][All Lists]
Advanced

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

[Openexr-devel] tiff to exr problem


From: the nrgy
Subject: [Openexr-devel] tiff to exr problem
Date: Sun, 23 Oct 2005 16:56:14 -0500

I've been messing around with OpenEXR and recently I've been coding a small util to read tiff images and write exr files.  I am having problems when I pass the array which represents the tiff information to the one which I will be passing to the exr calls.  When I extract a channel from my tiff array and pass it to an array exr will use it is all messed up.  One thing I have noticed is when I view what is inside this array exr will be using is that only a small portion is filled with information.   I think I can tell what some of my problems are, these being "my uint to float conversions which I have googled to no end without any results, maybe I'm inproperly setting up my data arrays,  and last but not least I just dont get it :D".  I have included some mangled code which is a sample for my problem and any replys would be welcome.  I should mention I'm developing under Linux x86_64, using libtiff for my tiff functions, and using gcc v4.

Thanks Nathan

#include <iostream>
#include <stdlib.h>
#include <tiffio.h>
#include <ImfOutputFile.h>
#include <ImfInputFile.h>
#include <ImfChannelList.h>
#include <ImfStringAttribute.h>
#include <ImfMatrixAttribute.h>
#include <ImfArray.h>

using namespace std;
using namespace Imath;
using namespace Imf;

int main() {
    TIFF *tif;
    TIFFRGBAImage img;
    char emsg[1024];
   
    int i;
    uint32 *inputTexture;
    float *outputTexture;
    long int npixels;
    long int imageSizeOf;

    tif = TIFFOpen("/home/nrgy/test/test.tif", "rb");
    if (tif != NULL) {
        if (TIFFRGBAImageBegin(&img, tif, 0, emsg)) {
            npixels = img.width * img.height;
            imageSizeOf = npixels * 4;
            inputTexture = new uint32 [imageSizeOf];
            if (inputTexture != NULL) {
                if (TIFFRGBAImageGet(&img, inputTexture, img.width, img.height) == 0 ) {
                    TIFFError("/home/nrgy/test/test.tif", emsg);
                    exit(1);
                }
            }
            TIFFRGBAImageEnd(&img);
        }
    }
   
    outputTexture = new float [npixels];
    for (i = 0; i < npixels; i++) {
        outputTexture[i] = (float)inputTexture[i * 4];
        cout << "hey! " << i;
        printf(" - %f\n", (float)inputTexture[i * 4]);
        if ((float)inputTexture[i * 4] == 0) exit(0);
    }

    Header header(img.width, img.height);
    header.channels().insert("R", Channel (FLOAT));
    header.channels().insert("G", Channel (FLOAT));
    header.channels().insert("B", Channel (FLOAT));
    header.compression() = Compression(1);

    OutputFile file ("/home/nrgy/test/test.exr", header);
    FrameBuffer frameBuffer;
    frameBuffer.insert ("R",
            Slice (FLOAT,
               (char *) outputTexture,
               sizeof (*outputTexture) * 1,
               sizeof (*outputTexture) * img.width));
    frameBuffer.insert ("G",
            Slice (FLOAT,
               (char *) outputTexture,
               sizeof (*outputTexture) * 1,
               sizeof (*outputTexture) * img.width));
    frameBuffer.insert ("B",
            Slice (FLOAT,
               (char *) outputTexture,
               sizeof (*outputTexture) * 1,
               sizeof (*outputTexture) * img.width));
    file.setFrameBuffer(frameBuffer);
    file.writePixels(img.height);

    if (inputTexture) delete[] inputTexture;
    if (outputTexture) delete[] outputTexture;

    return 0;
}

reply via email to

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