1111#include < ImfArray.h>
1212#include < half.h>
1313#include < ImfRgbaFile.h>
14+ #include < ImfTiledOutputFile.h>
1415
1516namespace EXR = OPENEXR_IMF_NAMESPACE;
1617using namespace IMATH_NAMESPACE ;
@@ -120,6 +121,67 @@ void writeExr(const char fileName[], const float *rPixels, const float *gPixels,
120121 file.writePixels (height);
121122}
122123
124+ void writeTiledExr (const char fileName[], const float *rPixels, const float *gPixels ,
125+ const float *bPixels, const float *aPixels, int width, int height)
126+ {
127+ // Define the tile size
128+ const int tileWidth = 64 ;
129+ const int tileHeight = 64 ;
130+
131+ // Create the header and specify tiled storage
132+ EXR::Header header (width, height);
133+ header.compression () = EXR::PIZ_COMPRESSION;
134+ header.channels ().insert (" R" , EXR::Channel (EXR::FLOAT));
135+ header.channels ().insert (" G" , EXR::Channel (EXR::FLOAT));
136+ header.channels ().insert (" B" , EXR::Channel (EXR::FLOAT));
137+ header.channels ().insert (" A" , EXR::Channel (EXR::FLOAT));
138+ header.setTileDescription (EXR::TileDescription (
139+ tileWidth, tileHeight, // Tile dimensions
140+ EXR::MIPMAP_LEVELS // Tiling mode: EXR::ONE_LEVEL or EXR::MIPMAP_LEVELS
141+ ));
142+
143+ // Use TiledOutputFile
144+ EXR::TiledOutputFile file (fileName, header);
145+
146+ // Create and populate the frame buffer
147+ EXR::FrameBuffer frameBuffer;
148+
149+ frameBuffer.insert (" R" , // name
150+ EXR::Slice (EXR::FLOAT, // type
151+ (char *)rPixels, // base
152+ sizeof (*rPixels) * 1 , // xStride
153+ sizeof (*rPixels) * width)); // yStride
154+
155+ frameBuffer.insert (" G" , // name
156+ EXR::Slice (EXR::FLOAT, // type
157+ (char *)gPixels , // base
158+ sizeof (*gPixels ) * 1 , // xStride
159+ sizeof (*gPixels ) * width)); // yStride
160+
161+ frameBuffer.insert (" B" , // name
162+ EXR::Slice (EXR::FLOAT, // type
163+ (char *)bPixels, // base
164+ sizeof (*bPixels) * 1 , // xStride
165+ sizeof (*bPixels) * width)); // yStride
166+
167+ frameBuffer.insert (" A" , // name
168+ EXR::Slice (EXR::FLOAT, // type
169+ (char *)aPixels, // base
170+ sizeof (*aPixels) * 1 , // xStride
171+ sizeof (*aPixels) * width)); // yStride
172+
173+ file.setFrameBuffer (frameBuffer);
174+
175+ // Write tiles
176+ for (int y = 0 ; y < file.numYTiles (); ++y)
177+ {
178+ for (int x = 0 ; x < file.numXTiles (); ++x)
179+ {
180+ file.writeTile (x, y);
181+ }
182+ }
183+ }
184+
123185// writes floating single channel data point data to disk
124186void writeSingleChannelExr (const char fileName[], const float *rPixels, int width, int height)
125187{
@@ -131,7 +193,7 @@ void writeSingleChannelExr(const char fileName[], const float *rPixels, int widt
131193
132194 EXR::FrameBuffer frameBuffer;
133195
134- frameBuffer.insert (" R" , // name
196+ frameBuffer.insert (" R" , // name
135197 EXR::Slice (EXR::FLOAT, // type
136198 (char *)rPixels, // base
137199 sizeof (*rPixels) * 1 , // xStride
@@ -185,7 +247,7 @@ void oceanDataToEXR(aaOcean *&pOcean, const char *outputFolder, const char *post
185247 }
186248
187249 genFullFilePath (&outputFileName[0 ], &outputFolder[0 ], &postfix[0 ], frame);
188- writeExr (&outputFileName[0 ], &rPixels[0 ][0 ], &gPixels [0 ][0 ], &bPixels[0 ][0 ], &aPixels[0 ][0 ], dimension, dimension);
250+ writeTiledExr (&outputFileName[0 ], &rPixels[0 ][0 ], &gPixels [0 ][0 ], &bPixels[0 ][0 ], &aPixels[0 ][0 ], dimension, dimension);
189251
190252 free (green);
191253 if (red)
0 commit comments