You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function ImageEXR::loadFloatEXR assumes that the channels in the EXR
file are in the order R, G, B, A. This does not seem to be generally the
case. I have a file with the channels in the order A, B, G, R.
My fix is below. It pulls out the name of each channel and uses that to
figure out the channel index.
namespace
{
int channelIndexFromName(const char* name)
{
char c = tolower(name[0]);
switch (c)
{
case 'r':
return 0;
case 'g':
return 1;
case 'b':
return 2;
default:
return 3;
}
}
}
FloatImage * nv::ImageIO::loadFloatEXR(const char * fileName, Stream & s)
{
nvCheck(s.isLoading());
nvCheck(!s.isError());
ExrStream stream(fileName, s);
Imf::InputFile inputFile(stream);
Imath::Box2i box = inputFile.header().dataWindow();
int width = box.max.x - box.min.y + 1;
int height = box.max.x - box.min.y + 1;
const Imf::ChannelList & channels = inputFile.header().channels();
// Count channels.
uint channelCount= 0;
for (Imf::ChannelList::ConstIterator it = channels.begin(); it !=
channels.end(); ++it)
{
channelCount++;
}
// Allocate FloatImage.
AutoPtr<FloatImage> fimage(new FloatImage());
fimage->allocate(channelCount, width, height);
// Describe image's layout with a framebuffer.
Imf::FrameBuffer frameBuffer;
for (Imf::ChannelList::ConstIterator it = channels.begin(); it !=
channels.end(); ++it)
{
int channelIndex = channelIndexFromName(it.name());
frameBuffer.insert(it.name(), Imf::Slice(Imf::FLOAT, (char
*)fimage->channel(channelIndex), sizeof(float), sizeof(float) * width));
}
// Read it.
inputFile.setFrameBuffer (frameBuffer);
inputFile.readPixels (box.min.y, box.max.y);
return fimage.release();
}
Original issue reported on code.google.com by alastair...@gmail.com on 19 May 2008 at 7:14
The text was updated successfully, but these errors were encountered:
Original issue reported on code.google.com by
alastair...@gmail.com
on 19 May 2008 at 7:14The text was updated successfully, but these errors were encountered: