Add support for saving exr files. Not tested.
Some cleanups.
This commit is contained in:
@ -659,13 +659,6 @@ Image * nv::ImageIO::loadPNG(Stream & s)
|
|||||||
return img.release();
|
return img.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FloatImage * nv::ImageIO::loadFloatPNG(Stream & s)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif // defined(HAVE_PNG)
|
#endif // defined(HAVE_PNG)
|
||||||
|
|
||||||
#if defined(HAVE_JPEG)
|
#if defined(HAVE_JPEG)
|
||||||
@ -914,11 +907,15 @@ FloatImage * nv::ImageIO::loadFloatTIFF(const char * fileName, Stream & s)
|
|||||||
return fimage.release();
|
return fimage.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nv::ImageIO::saveFloatTIFF(const char * fileName, FloatImage *fimage, uint base_component, uint num_components)
|
bool nv::ImageIO::saveFloatTIFF(const char * fileName, const FloatImage * fimage, uint base_component, uint num_components)
|
||||||
{
|
{
|
||||||
int iW=fimage->width();
|
nvCheck(fileName != NULL);
|
||||||
int iH=fimage->height();
|
nvCheck(fimage != NULL);
|
||||||
int iC=num_components;
|
nvCheck(fimage->componentNum() <= base_component + num_components);
|
||||||
|
|
||||||
|
const int iW = fimage->width();
|
||||||
|
const int iH = fimage->height();
|
||||||
|
const int iC = num_components;
|
||||||
|
|
||||||
TIFF * image = TIFFOpen(fileName, "w");
|
TIFF * image = TIFFOpen(fileName, "w");
|
||||||
|
|
||||||
@ -942,13 +939,13 @@ bool nv::ImageIO::saveFloatTIFF(const char * fileName, FloatImage *fimage, uint
|
|||||||
TIFFSetField(image, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
TIFFSetField(image, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
|
||||||
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
TIFFSetField(image, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
|
||||||
|
|
||||||
float *scanline = new float[iW * iC];
|
float * scanline = new float[iW * iC];
|
||||||
for (int y=0; y<iH; y++)
|
for (int y = 0; y < iH; y++)
|
||||||
{
|
{
|
||||||
for (int c=0; c<iC; c++)
|
for (int c = 0; c < iC; c++)
|
||||||
{
|
{
|
||||||
float *src = fimage->scanline(y, base_component + c);
|
const float * src = fimage->scanline(y, base_component + c);
|
||||||
for (int x=0; x<iW; x++) scanline[x*iC+c]=src[x];
|
for (int x = 0; x < iW; x++) scanline[x * iC + c] = src[x];
|
||||||
}
|
}
|
||||||
if (TIFFWriteScanline(image, scanline, y, 0)==-1)
|
if (TIFFWriteScanline(image, scanline, y, 0)==-1)
|
||||||
{
|
{
|
||||||
@ -1047,7 +1044,7 @@ FloatImage * nv::ImageIO::loadFloatEXR(const char * fileName, Stream & s)
|
|||||||
|
|
||||||
FloatImage * nv::ImageIO::loadFloatEXR(const char * fileName)
|
FloatImage * nv::ImageIO::loadFloatEXR(const char * fileName)
|
||||||
{
|
{
|
||||||
StdInputStream stream(name);
|
StdInputStream stream(fileName);
|
||||||
|
|
||||||
if (stream.isError()) {
|
if (stream.isError()) {
|
||||||
return false;
|
return false;
|
||||||
@ -1056,6 +1053,40 @@ FloatImage * nv::ImageIO::loadFloatEXR(const char * fileName)
|
|||||||
return loadFloatExr(fileName, stream);
|
return loadFloatExr(fileName, stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool nv::ImageIO::saveFloatEXR(const char * fileName, const FloatImage * fimage, uint base_component, uint num_components)
|
||||||
|
{
|
||||||
|
nvCheck(fileName != NULL);
|
||||||
|
nvCheck(fimage != NULL);
|
||||||
|
nvCheck(fimage->componentNum() <= base_component + num_components);
|
||||||
|
nvCheck(num_components > 0 && num_components <= 4);
|
||||||
|
|
||||||
|
const int w = fimage->width();
|
||||||
|
const int h = fimage->height();
|
||||||
|
|
||||||
|
const char * channelNames[] = {"R", "G", "B", "A"};
|
||||||
|
|
||||||
|
Header header (width, height);
|
||||||
|
|
||||||
|
for (uint c = 0; c < num_components; c++)
|
||||||
|
{
|
||||||
|
header.channels().insert(channelNames[c], Channel(FLOAT));
|
||||||
|
}
|
||||||
|
|
||||||
|
OutputFile file(fileName, header);
|
||||||
|
FrameBuffer frameBuffer;
|
||||||
|
|
||||||
|
for (uint c = 0; c < num_components; c++)
|
||||||
|
{
|
||||||
|
const char * channel = (char *) fimage->channel(base_component + c);
|
||||||
|
frameBuffer.insert(channelNames[c], Slice(FLOAT, channel, sizeof(float), sizeof(float) * w));
|
||||||
|
}
|
||||||
|
|
||||||
|
file.setFrameBuffer(frameBuffer);
|
||||||
|
file.writePixels(height);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // defined(HAVE_EXR)
|
#endif // defined(HAVE_EXR)
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@ namespace nv
|
|||||||
|
|
||||||
#if defined(HAVE_PNG)
|
#if defined(HAVE_PNG)
|
||||||
NVIMAGE_API Image * loadPNG(Stream & s);
|
NVIMAGE_API Image * loadPNG(Stream & s);
|
||||||
NVIMAGE_API FloatImage * loadFloatPNG(Stream & s);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_JPEG)
|
#if defined(HAVE_JPEG)
|
||||||
@ -35,11 +34,13 @@ namespace nv
|
|||||||
#if defined(HAVE_TIFF)
|
#if defined(HAVE_TIFF)
|
||||||
NVIMAGE_API FloatImage * loadFloatTIFF(const char * fileName, Stream & s);
|
NVIMAGE_API FloatImage * loadFloatTIFF(const char * fileName, Stream & s);
|
||||||
|
|
||||||
NVIMAGE_API bool saveFloatTIFF(const char * fileName, FloatImage *fimage, uint base_component, uint num_components);
|
NVIMAGE_API bool saveFloatTIFF(const char * fileName, const FloatImage * fimage, uint base_component, uint num_components);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_EXR)
|
#if defined(HAVE_EXR)
|
||||||
NVIMAGE_API FloatImage * loadFloatEXR(const char * fileName, Stream & s);
|
NVIMAGE_API FloatImage * loadFloatEXR(const char * fileName, Stream & s);
|
||||||
|
|
||||||
|
NVIMAGE_API bool saveFloatEXR(const char * fileName, const FloatImage * fimage, uint base_component, uint num_components);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // ImageIO namespace
|
} // ImageIO namespace
|
||||||
|
Reference in New Issue
Block a user