1 ///////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
6 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Industrial Light & Magic nor the names of
18 // its contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ///////////////////////////////////////////////////////////////////////////
36 #ifndef INCLUDED_IMF_TILED_RGBA_FILE_H
37 #define INCLUDED_IMF_TILED_RGBA_FILE_H
39 //-----------------------------------------------------------------------------
41 // Simplified RGBA image I/O for tiled files
43 // class TiledRgbaOutputFile
44 // class TiledRgbaInputFile
46 //-----------------------------------------------------------------------------
48 #include <ImfHeader.h>
49 #include <ImfFrameBuffer.h>
53 #include <ImfTileDescription.h>
55 #include <ImfThreading.h>
59 class TiledOutputFile;
65 // Tiled RGBA output file.
68 class TiledRgbaOutputFile
72 //---------------------------------------------------
73 // Constructor -- rgbaChannels, tileXSize, tileYSize,
74 // levelMode, and levelRoundingMode overwrite the
75 // channel list and tile description attribute in the
76 // header that is passed as an argument to the
78 //---------------------------------------------------
80 TiledRgbaOutputFile (const char name[],
82 RgbaChannels rgbaChannels,
86 LevelRoundingMode rmode = ROUND_DOWN,
87 int numThreads = globalThreadCount ());
90 //---------------------------------------------------
91 // Constructor -- like the previous one, but the new
92 // TiledRgbaOutputFile is attached to a file that has
93 // already been opened by the caller. Destroying
94 // TiledRgbaOutputFileObjects constructed with this
95 // constructor does not automatically close the
96 // corresponding files.
97 //---------------------------------------------------
99 TiledRgbaOutputFile (OStream &os,
100 const Header &header,
101 RgbaChannels rgbaChannels,
105 LevelRoundingMode rmode = ROUND_DOWN,
106 int numThreads = globalThreadCount ());
109 //------------------------------------------------------
110 // Constructor -- header data are explicitly specified
111 // as function call arguments (an empty dataWindow means
112 // "same as displayWindow")
113 //------------------------------------------------------
115 TiledRgbaOutputFile (const char name[],
119 LevelRoundingMode rmode,
120 const Imath::Box2i &displayWindow,
121 const Imath::Box2i &dataWindow = Imath::Box2i(),
122 RgbaChannels rgbaChannels = WRITE_RGBA,
123 float pixelAspectRatio = 1,
124 const Imath::V2f screenWindowCenter =
126 float screenWindowWidth = 1,
127 LineOrder lineOrder = INCREASING_Y,
128 Compression compression = ZIP_COMPRESSION,
129 int numThreads = globalThreadCount ());
132 //-----------------------------------------------
133 // Constructor -- like the previous one, but both
134 // the display window and the data window are
135 // Box2i (V2i (0, 0), V2i (width - 1, height -1))
136 //-----------------------------------------------
138 TiledRgbaOutputFile (const char name[],
144 LevelRoundingMode rmode = ROUND_DOWN,
145 RgbaChannels rgbaChannels = WRITE_RGBA,
146 float pixelAspectRatio = 1,
147 const Imath::V2f screenWindowCenter =
149 float screenWindowWidth = 1,
150 LineOrder lineOrder = INCREASING_Y,
151 Compression compression = ZIP_COMPRESSION,
152 int numThreads = globalThreadCount ());
155 virtual ~TiledRgbaOutputFile ();
158 //------------------------------------------------
159 // Define a frame buffer as the pixel data source:
160 // Pixel (x, y) is at address
162 // base + x * xStride + y * yStride
164 //------------------------------------------------
166 void setFrameBuffer (const Rgba *base,
170 //--------------------------
171 // Access to the file header
172 //--------------------------
174 const Header & header () const;
175 const FrameBuffer & frameBuffer () const;
176 const Imath::Box2i & displayWindow () const;
177 const Imath::Box2i & dataWindow () const;
178 float pixelAspectRatio () const;
179 const Imath::V2f screenWindowCenter () const;
180 float screenWindowWidth () const;
181 LineOrder lineOrder () const;
182 Compression compression () const;
183 RgbaChannels channels () const;
186 //----------------------------------------------------
187 // Utility functions (same as in Imf::TiledOutputFile)
188 //----------------------------------------------------
190 unsigned int tileXSize () const;
191 unsigned int tileYSize () const;
192 LevelMode levelMode () const;
193 LevelRoundingMode levelRoundingMode () const;
195 int numLevels () const;
196 int numXLevels () const;
197 int numYLevels () const;
198 bool isValidLevel (int lx, int ly) const;
200 int levelWidth (int lx) const;
201 int levelHeight (int ly) const;
203 int numXTiles (int lx = 0) const;
204 int numYTiles (int ly = 0) const;
206 Imath::Box2i dataWindowForLevel (int l = 0) const;
207 Imath::Box2i dataWindowForLevel (int lx, int ly) const;
209 Imath::Box2i dataWindowForTile (int dx, int dy,
212 Imath::Box2i dataWindowForTile (int dx, int dy,
213 int lx, int ly) const;
215 //------------------------------------------------------------------
218 // writeTile(dx, dy, lx, ly) writes the tile with tile
219 // coordinates (dx, dy), and level number (lx, ly) to
222 // dx must lie in the interval [0, numXTiles(lx)-1]
223 // dy must lie in the interval [0, numYTiles(ly)-1]
225 // lx must lie in the interval [0, numXLevels()-1]
226 // ly must lie in the inverval [0, numYLevels()-1]
228 // writeTile(dx, dy, level) is a convenience function
229 // used for ONE_LEVEL and MIPMAP_LEVEL files. It calls
230 // writeTile(dx, dy, level, level).
232 // The two writeTiles(dx1, dx2, dy1, dy2, ...) functions allow
233 // writing multiple tiles at once. If multi-threading is used
234 // multiple tiles are written concurrently.
236 // Pixels that are outside the pixel coordinate range for the tile's
237 // level, are never accessed by writeTile().
239 // Each tile in the file must be written exactly once.
241 //------------------------------------------------------------------
243 void writeTile (int dx, int dy, int l = 0);
244 void writeTile (int dx, int dy, int lx, int ly);
246 void writeTiles (int dxMin, int dxMax, int dyMin, int dyMax,
249 void writeTiles (int dxMin, int dxMax, int dyMin, int dyMax,
253 // -------------------------------------------------------------------------
254 // Update the preview image (see Imf::TiledOutputFile::updatePreviewImage())
255 // -------------------------------------------------------------------------
257 void updatePreviewImage (const PreviewRgba[]);
260 //------------------------------------------------
261 // Break a tile -- for testing and debugging only
262 // (see Imf::TiledOutputFile::breakTile())
264 // Warning: Calling this function usually results
265 // in a broken image file. The file or parts of
266 // it may not be readable, or the file may contain
269 //------------------------------------------------
271 void breakTile (int dx, int dy,
279 // Copy constructor and assignment are not implemented
282 TiledRgbaOutputFile (const TiledRgbaOutputFile &);
283 TiledRgbaOutputFile & operator = (const TiledRgbaOutputFile &);
287 TiledOutputFile * _outputFile;
294 // Tiled RGBA input file
297 class TiledRgbaInputFile
301 //--------------------------------------------------------
302 // Constructor -- opens the file with the specified name.
303 // Destroying TiledRgbaInputFile objects constructed with
304 // this constructor automatically closes the corresponding
306 //--------------------------------------------------------
308 TiledRgbaInputFile (const char name[],
309 int numThreads = globalThreadCount ());
312 //-------------------------------------------------------
313 // Constructor -- attaches the new TiledRgbaInputFile
314 // object to a file that has already been opened by the
316 // Destroying TiledRgbaInputFile objects constructed with
317 // this constructor does not automatically close the
318 // corresponding files.
319 //-------------------------------------------------------
321 TiledRgbaInputFile (IStream &is, int numThreads = globalThreadCount ());
328 virtual ~TiledRgbaInputFile ();
331 //-----------------------------------------------------
332 // Define a frame buffer as the pixel data destination:
333 // Pixel (x, y) is at address
335 // base + x * xStride + y * yStride
337 //-----------------------------------------------------
339 void setFrameBuffer (Rgba *base,
343 //--------------------------
344 // Access to the file header
345 //--------------------------
347 const Header & header () const;
348 const FrameBuffer & frameBuffer () const;
349 const Imath::Box2i & displayWindow () const;
350 const Imath::Box2i & dataWindow () const;
351 float pixelAspectRatio () const;
352 const Imath::V2f screenWindowCenter () const;
353 float screenWindowWidth () const;
354 LineOrder lineOrder () const;
355 Compression compression () const;
356 RgbaChannels channels () const;
357 const char * fileName () const;
358 bool isComplete () const;
360 //----------------------------------
361 // Access to the file format version
362 //----------------------------------
364 int version () const;
367 //---------------------------------------------------
368 // Utility functions (same as in Imf::TiledInputFile)
369 //---------------------------------------------------
371 unsigned int tileXSize () const;
372 unsigned int tileYSize () const;
373 LevelMode levelMode () const;
374 LevelRoundingMode levelRoundingMode () const;
376 int numLevels () const;
377 int numXLevels () const;
378 int numYLevels () const;
379 bool isValidLevel (int lx, int ly) const;
381 int levelWidth (int lx) const;
382 int levelHeight (int ly) const;
384 int numXTiles (int lx = 0) const;
385 int numYTiles (int ly = 0) const;
387 Imath::Box2i dataWindowForLevel (int l = 0) const;
388 Imath::Box2i dataWindowForLevel (int lx, int ly) const;
390 Imath::Box2i dataWindowForTile (int dx, int dy,
393 Imath::Box2i dataWindowForTile (int dx, int dy,
394 int lx, int ly) const;
397 //----------------------------------------------------------------
400 // readTile(dx, dy, lx, ly) reads the tile with tile
401 // coordinates (dx, dy), and level number (lx, ly),
402 // and stores it in the current frame buffer.
404 // dx must lie in the interval [0, numXTiles(lx)-1]
405 // dy must lie in the interval [0, numYTiles(ly)-1]
407 // lx must lie in the interval [0, numXLevels()-1]
408 // ly must lie in the inverval [0, numYLevels()-1]
410 // readTile(dx, dy, level) is a convenience function used
411 // for ONE_LEVEL and MIPMAP_LEVELS files. It calls
412 // readTile(dx, dy, level, level).
414 // The two readTiles(dx1, dx2, dy1, dy2, ...) functions allow
415 // reading multiple tiles at once. If multi-threading is used
416 // multiple tiles are read concurrently.
418 // Pixels that are outside the pixel coordinate range for the
419 // tile's level, are never accessed by readTile().
421 // Attempting to access a tile that is not present in the file
422 // throws an InputExc exception.
424 //----------------------------------------------------------------
426 void readTile (int dx, int dy, int l = 0);
427 void readTile (int dx, int dy, int lx, int ly);
429 void readTiles (int dxMin, int dxMax,
430 int dyMin, int dyMax, int lx, int ly);
432 void readTiles (int dxMin, int dxMax,
433 int dyMin, int dyMax, int l = 0);
438 // Copy constructor and assignment are not implemented
441 TiledRgbaInputFile (const TiledRgbaInputFile &);
442 TiledRgbaInputFile & operator = (const TiledRgbaInputFile &);
446 TiledInputFile * _inputFile;