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

https://bitbucket.org/cabalistic/ogredeps/ · C++ Header · 322 lines · 100 code · 75 blank · 147 comment · 0 complexity · 58fb93b770514522ce0b0eb51abf84ad MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2007, 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_ACES_FILE_H
  35. #define INCLUDED_IMF_ACES_FILE_H
  36. //-----------------------------------------------------------------------------
  37. //
  38. // ACES image file I/O.
  39. //
  40. // This header file declares two classes that directly support
  41. // image file input and output according to the Academy Image
  42. // Interchange Framework.
  43. //
  44. // The Academy Image Interchange file format is a subset of OpenEXR:
  45. //
  46. // - Images are stored as scanlines. Tiles are not allowed.
  47. //
  48. // - Images contain three color channels, either
  49. // R, G, B (red, green, blue) or
  50. // Y, RY, BY (luminance, sub-sampled chroma)
  51. //
  52. // - Images may optionally contain an alpha channel.
  53. //
  54. // - Only three compression types are allowed:
  55. // - NO_COMPRESSION (file is not compressed)
  56. // - PIZ_COMPRESSION (lossless)
  57. // - B44A_COMPRESSION (lossy)
  58. //
  59. // - The "chromaticities" header attribute must specify
  60. // the ACES RGB primaries and white point.
  61. //
  62. // class AcesOutputFile writes an OpenEXR file, enforcing the
  63. // restrictions listed above. Pixel data supplied by application
  64. // software must already be in the ACES RGB space.
  65. //
  66. // class AcesInputFile reads an OpenEXR file. Pixel data delivered
  67. // to application software is guaranteed to be in the ACES RGB space.
  68. // If the RGB space of the file is not the same as the ACES space,
  69. // then the pixels are automatically converted: the pixels are
  70. // converted to CIE XYZ, a color adaptation transform shifts the
  71. // white point, and the result is converted to ACES RGB.
  72. //
  73. //-----------------------------------------------------------------------------
  74. #include <ImfHeader.h>
  75. #include <ImfRgba.h>
  76. #include "ImathVec.h"
  77. #include "ImathBox.h"
  78. #include <ImfThreading.h>
  79. #include <string>
  80. namespace Imf {
  81. class RgbaOutputFile;
  82. class RgbaInputFile;
  83. struct PreviewRgba;
  84. class Chromaticities;
  85. //
  86. // ACES red, green, blue and white-point chromaticities.
  87. //
  88. const Chromaticities & acesChromaticities ();
  89. //
  90. // ACES output file.
  91. //
  92. class AcesOutputFile
  93. {
  94. public:
  95. //---------------------------------------------------
  96. // Constructor -- header is constructed by the caller
  97. //---------------------------------------------------
  98. AcesOutputFile (const std::string &name,
  99. const Header &header,
  100. RgbaChannels rgbaChannels = WRITE_RGBA,
  101. int numThreads = globalThreadCount());
  102. //----------------------------------------------------
  103. // Constructor -- header is constructed by the caller,
  104. // file is opened by the caller, destructor will not
  105. // automatically close the file.
  106. //----------------------------------------------------
  107. AcesOutputFile (OStream &os,
  108. const Header &header,
  109. RgbaChannels rgbaChannels = WRITE_RGBA,
  110. int numThreads = globalThreadCount());
  111. //----------------------------------------------------------------
  112. // Constructor -- header data are explicitly specified as function
  113. // call arguments (empty dataWindow means "same as displayWindow")
  114. //----------------------------------------------------------------
  115. AcesOutputFile (const std::string &name,
  116. const Imath::Box2i &displayWindow,
  117. const Imath::Box2i &dataWindow = Imath::Box2i(),
  118. RgbaChannels rgbaChannels = WRITE_RGBA,
  119. float pixelAspectRatio = 1,
  120. const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),
  121. float screenWindowWidth = 1,
  122. LineOrder lineOrder = INCREASING_Y,
  123. Compression compression = PIZ_COMPRESSION,
  124. int numThreads = globalThreadCount());
  125. //-----------------------------------------------
  126. // Constructor -- like the previous one, but both
  127. // the display window and the data window are
  128. // Box2i (V2i (0, 0), V2i (width - 1, height -1))
  129. //-----------------------------------------------
  130. AcesOutputFile (const std::string &name,
  131. int width,
  132. int height,
  133. RgbaChannels rgbaChannels = WRITE_RGBA,
  134. float pixelAspectRatio = 1,
  135. const Imath::V2f screenWindowCenter = Imath::V2f (0, 0),
  136. float screenWindowWidth = 1,
  137. LineOrder lineOrder = INCREASING_Y,
  138. Compression compression = PIZ_COMPRESSION,
  139. int numThreads = globalThreadCount());
  140. //-----------
  141. // Destructor
  142. //-----------
  143. virtual ~AcesOutputFile ();
  144. //------------------------------------------------
  145. // Define a frame buffer as the pixel data source:
  146. // Pixel (x, y) is at address
  147. //
  148. // base + x * xStride + y * yStride
  149. //
  150. //------------------------------------------------
  151. void setFrameBuffer (const Rgba *base,
  152. size_t xStride,
  153. size_t yStride);
  154. //-------------------------------------------------
  155. // Write pixel data (see class Imf::OutputFile)
  156. // The pixels are assumed to contain ACES RGB data.
  157. //-------------------------------------------------
  158. void writePixels (int numScanLines = 1);
  159. int currentScanLine () const;
  160. //--------------------------
  161. // Access to the file header
  162. //--------------------------
  163. const Header & header () const;
  164. const Imath::Box2i & displayWindow () const;
  165. const Imath::Box2i & dataWindow () const;
  166. float pixelAspectRatio () const;
  167. const Imath::V2f screenWindowCenter () const;
  168. float screenWindowWidth () const;
  169. LineOrder lineOrder () const;
  170. Compression compression () const;
  171. RgbaChannels channels () const;
  172. // --------------------------------------------------------------------
  173. // Update the preview image (see Imf::OutputFile::updatePreviewImage())
  174. // --------------------------------------------------------------------
  175. void updatePreviewImage (const PreviewRgba[]);
  176. private:
  177. AcesOutputFile (const AcesOutputFile &); // not implemented
  178. AcesOutputFile & operator = (const AcesOutputFile &); // not implemented
  179. class Data;
  180. Data * _data;
  181. };
  182. //
  183. // ACES input file
  184. //
  185. class AcesInputFile
  186. {
  187. public:
  188. //-------------------------------------------------------
  189. // Constructor -- opens the file with the specified name,
  190. // destructor will automatically close the file.
  191. //-------------------------------------------------------
  192. AcesInputFile (const std::string &name,
  193. int numThreads = globalThreadCount());
  194. //-----------------------------------------------------------
  195. // Constructor -- attaches the new AcesInputFile object to a
  196. // file that has already been opened by the caller.
  197. // Destroying the AcesInputFile object will not automatically
  198. // close the file.
  199. //-----------------------------------------------------------
  200. AcesInputFile (IStream &is,
  201. int numThreads = globalThreadCount());
  202. //-----------
  203. // Destructor
  204. //-----------
  205. virtual ~AcesInputFile ();
  206. //-----------------------------------------------------
  207. // Define a frame buffer as the pixel data destination:
  208. // Pixel (x, y) is at address
  209. //
  210. // base + x * xStride + y * yStride
  211. //
  212. //-----------------------------------------------------
  213. void setFrameBuffer (Rgba *base,
  214. size_t xStride,
  215. size_t yStride);
  216. //--------------------------------------------
  217. // Read pixel data (see class Imf::InputFile)
  218. // Pixels returned will contain ACES RGB data.
  219. //--------------------------------------------
  220. void readPixels (int scanLine1, int scanLine2);
  221. void readPixels (int scanLine);
  222. //--------------------------
  223. // Access to the file header
  224. //--------------------------
  225. const Header & header () const;
  226. const Imath::Box2i & displayWindow () const;
  227. const Imath::Box2i & dataWindow () const;
  228. float pixelAspectRatio () const;
  229. const Imath::V2f screenWindowCenter () const;
  230. float screenWindowWidth () const;
  231. LineOrder lineOrder () const;
  232. Compression compression () const;
  233. RgbaChannels channels () const;
  234. const char * fileName () const;
  235. bool isComplete () const;
  236. //----------------------------------
  237. // Access to the file format version
  238. //----------------------------------
  239. int version () const;
  240. private:
  241. AcesInputFile (const AcesInputFile &); // not implemented
  242. AcesInputFile & operator = (const AcesInputFile &); // not implemented
  243. class Data;
  244. Data * _data;
  245. };
  246. } // namespace Imf
  247. #endif