/src/FreeImage/Source/OpenEXR/IlmImf/ImfRgbaFile.h

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 344 lines · 116 code · 83 blank · 145 comment · 0 complexity · d75fae18158bdb7c129ed734d5a1e236 MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
  4. // Digital Ltd. LLC
  5. //
  6. // All rights reserved.
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are
  10. // met:
  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
  16. // distribution.
  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.
  20. //
  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.
  32. //
  33. ///////////////////////////////////////////////////////////////////////////
  34. #ifndef INCLUDED_IMF_RGBA_FILE_H
  35. #define INCLUDED_IMF_RGBA_FILE_H
  36. //-----------------------------------------------------------------------------
  37. //
  38. // Simplified RGBA image I/O
  39. //
  40. // class RgbaOutputFile
  41. // class RgbaInputFile
  42. //
  43. //-----------------------------------------------------------------------------
  44. #include <ImfHeader.h>
  45. #include <ImfFrameBuffer.h>
  46. #include <ImfRgba.h>
  47. #include "ImathVec.h"
  48. #include "ImathBox.h"
  49. #include "half.h"
  50. #include <ImfThreading.h>
  51. #include <string>
  52. namespace Imf {
  53. class OutputFile;
  54. class InputFile;
  55. struct PreviewRgba;
  56. //
  57. // RGBA output file.
  58. //
  59. class RgbaOutputFile
  60. {
  61. public:
  62. //---------------------------------------------------
  63. // Constructor -- header is constructed by the caller
  64. //---------------------------------------------------
  65. RgbaOutputFile (const char name[],
  66. const Header &header,
  67. RgbaChannels rgbaChannels = WRITE_RGBA,
  68. int numThreads = globalThreadCount());
  69. //----------------------------------------------------
  70. // Constructor -- header is constructed by the caller,
  71. // file is opened by the caller, destructor will not
  72. // automatically close the file.
  73. //----------------------------------------------------
  74. RgbaOutputFile (OStream &os,
  75. const Header &header,
  76. RgbaChannels rgbaChannels = WRITE_RGBA,
  77. int numThreads = globalThreadCount());
  78. //----------------------------------------------------------------
  79. // Constructor -- header data are explicitly specified as function
  80. // call arguments (empty dataWindow means "same as displayWindow")
  81. //----------------------------------------------------------------
  82. RgbaOutputFile (const char name[],
  83. const Imath::Box2i &displayWindow,
  84. const Imath::Box2i &dataWindow = Imath::Box2i(),
  85. RgbaChannels rgbaChannels = WRITE_RGBA,
  86. float pixelAspectRatio = 1,
  87. const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),
  88. float screenWindowWidth = 1,
  89. LineOrder lineOrder = INCREASING_Y,
  90. Compression compression = PIZ_COMPRESSION,
  91. int numThreads = globalThreadCount());
  92. //-----------------------------------------------
  93. // Constructor -- like the previous one, but both
  94. // the display window and the data window are
  95. // Box2i (V2i (0, 0), V2i (width - 1, height -1))
  96. //-----------------------------------------------
  97. RgbaOutputFile (const char name[],
  98. int width,
  99. int height,
  100. RgbaChannels rgbaChannels = WRITE_RGBA,
  101. float pixelAspectRatio = 1,
  102. const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),
  103. float screenWindowWidth = 1,
  104. LineOrder lineOrder = INCREASING_Y,
  105. Compression compression = PIZ_COMPRESSION,
  106. int numThreads = globalThreadCount());
  107. //-----------
  108. // Destructor
  109. //-----------
  110. virtual ~RgbaOutputFile ();
  111. //------------------------------------------------
  112. // Define a frame buffer as the pixel data source:
  113. // Pixel (x, y) is at address
  114. //
  115. // base + x * xStride + y * yStride
  116. //
  117. //------------------------------------------------
  118. void setFrameBuffer (const Rgba *base,
  119. size_t xStride,
  120. size_t yStride);
  121. //---------------------------------------------
  122. // Write pixel data (see class Imf::OutputFile)
  123. //---------------------------------------------
  124. void writePixels (int numScanLines = 1);
  125. int currentScanLine () const;
  126. //--------------------------
  127. // Access to the file header
  128. //--------------------------
  129. const Header & header () const;
  130. const FrameBuffer & frameBuffer () const;
  131. const Imath::Box2i & displayWindow () const;
  132. const Imath::Box2i & dataWindow () const;
  133. float pixelAspectRatio () const;
  134. const Imath::V2f screenWindowCenter () const;
  135. float screenWindowWidth () const;
  136. LineOrder lineOrder () const;
  137. Compression compression () const;
  138. RgbaChannels channels () const;
  139. // --------------------------------------------------------------------
  140. // Update the preview image (see Imf::OutputFile::updatePreviewImage())
  141. // --------------------------------------------------------------------
  142. void updatePreviewImage (const PreviewRgba[]);
  143. //-----------------------------------------------------------------------
  144. // Rounding control for luminance/chroma images:
  145. //
  146. // If the output file contains luminance and chroma channels (WRITE_YC
  147. // or WRITE_YCA), then the the significands of the luminance and
  148. // chroma values are rounded to roundY and roundC bits respectively (see
  149. // function half::round()). Rounding improves compression with minimal
  150. // image degradation, usually much less than the degradation caused by
  151. // chroma subsampling. By default, roundY is 7, and roundC is 5.
  152. //
  153. // If the output file contains RGB channels or a luminance channel,
  154. // without chroma, then no rounding is performed.
  155. //-----------------------------------------------------------------------
  156. void setYCRounding (unsigned int roundY,
  157. unsigned int roundC);
  158. //----------------------------------------------------
  159. // Break a scan line -- for testing and debugging only
  160. // (see Imf::OutputFile::updatePreviewImage()
  161. //
  162. // Warning: Calling this function usually results in a
  163. // broken image file. The file or parts of it may not
  164. // be readable, or the file may contain bad data.
  165. //
  166. //----------------------------------------------------
  167. void breakScanLine (int y,
  168. int offset,
  169. int length,
  170. char c);
  171. private:
  172. RgbaOutputFile (const RgbaOutputFile &); // not implemented
  173. RgbaOutputFile & operator = (const RgbaOutputFile &); // not implemented
  174. class ToYca;
  175. OutputFile * _outputFile;
  176. ToYca * _toYca;
  177. };
  178. //
  179. // RGBA input file
  180. //
  181. class RgbaInputFile
  182. {
  183. public:
  184. //-------------------------------------------------------
  185. // Constructor -- opens the file with the specified name,
  186. // destructor will automatically close the file.
  187. //-------------------------------------------------------
  188. RgbaInputFile (const char name[], int numThreads = globalThreadCount());
  189. //-----------------------------------------------------------
  190. // Constructor -- attaches the new RgbaInputFile object to a
  191. // file that has already been opened by the caller.
  192. // Destroying the RgbaInputFile object will not automatically
  193. // close the file.
  194. //-----------------------------------------------------------
  195. RgbaInputFile (IStream &is, int numThreads = globalThreadCount());
  196. //--------------------------------------------------------------
  197. // Constructors -- the same as the previous two, but the names
  198. // of the red, green, blue, alpha, luminance and chroma channels
  199. // are expected to be layerName.R, layerName.G, etc.
  200. //--------------------------------------------------------------
  201. RgbaInputFile (const char name[],
  202. const std::string &layerName,
  203. int numThreads = globalThreadCount());
  204. RgbaInputFile (IStream &is,
  205. const std::string &layerName,
  206. int numThreads = globalThreadCount());
  207. //-----------
  208. // Destructor
  209. //-----------
  210. virtual ~RgbaInputFile ();
  211. //-----------------------------------------------------
  212. // Define a frame buffer as the pixel data destination:
  213. // Pixel (x, y) is at address
  214. //
  215. // base + x * xStride + y * yStride
  216. //
  217. //-----------------------------------------------------
  218. void setFrameBuffer (Rgba *base,
  219. size_t xStride,
  220. size_t yStride);
  221. //----------------------------------------------------------------
  222. // Switch to a different layer -- subsequent calls to readPixels()
  223. // will read channels layerName.R, layerName.G, etc.
  224. // After each call to setLayerName(), setFrameBuffer() must be
  225. // called at least once before the next call to readPixels().
  226. //----------------------------------------------------------------
  227. void setLayerName (const std::string &layerName);
  228. //-------------------------------------------
  229. // Read pixel data (see class Imf::InputFile)
  230. //-------------------------------------------
  231. void readPixels (int scanLine1, int scanLine2);
  232. void readPixels (int scanLine);
  233. //--------------------------
  234. // Access to the file header
  235. //--------------------------
  236. const Header & header () const;
  237. const FrameBuffer & frameBuffer () const;
  238. const Imath::Box2i & displayWindow () const;
  239. const Imath::Box2i & dataWindow () const;
  240. float pixelAspectRatio () const;
  241. const Imath::V2f screenWindowCenter () const;
  242. float screenWindowWidth () const;
  243. LineOrder lineOrder () const;
  244. Compression compression () const;
  245. RgbaChannels channels () const;
  246. const char * fileName () const;
  247. bool isComplete () const;
  248. //----------------------------------
  249. // Access to the file format version
  250. //----------------------------------
  251. int version () const;
  252. private:
  253. RgbaInputFile (const RgbaInputFile &); // not implemented
  254. RgbaInputFile & operator = (const RgbaInputFile &); // not implemented
  255. class FromYca;
  256. InputFile * _inputFile;
  257. FromYca * _fromYca;
  258. std::string _channelNamePrefix;
  259. };
  260. } // namespace Imf
  261. #endif