ImfAcesFile.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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 "ImfNamespace.h"
  80. #include "ImfExport.h"
  81. #include "ImfForward.h"
  82. #include <string>
  83. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  84. //
  85. // ACES red, green, blue and white-point chromaticities.
  86. //
  87. const Chromaticities & acesChromaticities ();
  88. //
  89. // ACES output file.
  90. //
  91. class AcesOutputFile
  92. {
  93. public:
  94. //---------------------------------------------------
  95. // Constructor -- header is constructed by the caller
  96. //---------------------------------------------------
  97. IMF_EXPORT
  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. IMF_EXPORT
  108. AcesOutputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os,
  109. const Header &header,
  110. RgbaChannels rgbaChannels = WRITE_RGBA,
  111. int numThreads = globalThreadCount());
  112. //----------------------------------------------------------------
  113. // Constructor -- header data are explicitly specified as function
  114. // call arguments (empty dataWindow means "same as displayWindow")
  115. //----------------------------------------------------------------
  116. IMF_EXPORT
  117. AcesOutputFile (const std::string &name,
  118. const IMATH_NAMESPACE::Box2i &displayWindow,
  119. const IMATH_NAMESPACE::Box2i &dataWindow = IMATH_NAMESPACE::Box2i(),
  120. RgbaChannels rgbaChannels = WRITE_RGBA,
  121. float pixelAspectRatio = 1,
  122. const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
  123. float screenWindowWidth = 1,
  124. LineOrder lineOrder = INCREASING_Y,
  125. Compression compression = PIZ_COMPRESSION,
  126. int numThreads = globalThreadCount());
  127. //-----------------------------------------------
  128. // Constructor -- like the previous one, but both
  129. // the display window and the data window are
  130. // Box2i (V2i (0, 0), V2i (width - 1, height -1))
  131. //-----------------------------------------------
  132. IMF_EXPORT
  133. AcesOutputFile (const std::string &name,
  134. int width,
  135. int height,
  136. RgbaChannels rgbaChannels = WRITE_RGBA,
  137. float pixelAspectRatio = 1,
  138. const IMATH_NAMESPACE::V2f screenWindowCenter = IMATH_NAMESPACE::V2f (0, 0),
  139. float screenWindowWidth = 1,
  140. LineOrder lineOrder = INCREASING_Y,
  141. Compression compression = PIZ_COMPRESSION,
  142. int numThreads = globalThreadCount());
  143. //-----------
  144. // Destructor
  145. //-----------
  146. IMF_EXPORT
  147. virtual ~AcesOutputFile ();
  148. //------------------------------------------------
  149. // Define a frame buffer as the pixel data source:
  150. // Pixel (x, y) is at address
  151. //
  152. // base + x * xStride + y * yStride
  153. //
  154. //------------------------------------------------
  155. IMF_EXPORT
  156. void setFrameBuffer (const Rgba *base,
  157. size_t xStride,
  158. size_t yStride);
  159. //-------------------------------------------------
  160. // Write pixel data (see class Imf::OutputFile)
  161. // The pixels are assumed to contain ACES RGB data.
  162. //-------------------------------------------------
  163. void writePixels (int numScanLines = 1);
  164. int currentScanLine () const;
  165. //--------------------------
  166. // Access to the file header
  167. //--------------------------
  168. IMF_EXPORT
  169. const Header & header () const;
  170. IMF_EXPORT
  171. const IMATH_NAMESPACE::Box2i & displayWindow () const;
  172. IMF_EXPORT
  173. const IMATH_NAMESPACE::Box2i & dataWindow () const;
  174. IMF_EXPORT
  175. float pixelAspectRatio () const;
  176. IMF_EXPORT
  177. const IMATH_NAMESPACE::V2f screenWindowCenter () const;
  178. IMF_EXPORT
  179. float screenWindowWidth () const;
  180. IMF_EXPORT
  181. LineOrder lineOrder () const;
  182. IMF_EXPORT
  183. Compression compression () const;
  184. IMF_EXPORT
  185. RgbaChannels channels () const;
  186. // --------------------------------------------------------------------
  187. // Update the preview image (see Imf::OutputFile::updatePreviewImage())
  188. // --------------------------------------------------------------------
  189. IMF_EXPORT
  190. void updatePreviewImage (const PreviewRgba[]);
  191. private:
  192. AcesOutputFile (const AcesOutputFile &); // not implemented
  193. AcesOutputFile & operator = (const AcesOutputFile &); // not implemented
  194. class Data;
  195. Data * _data;
  196. };
  197. //
  198. // ACES input file
  199. //
  200. class AcesInputFile
  201. {
  202. public:
  203. //-------------------------------------------------------
  204. // Constructor -- opens the file with the specified name,
  205. // destructor will automatically close the file.
  206. //-------------------------------------------------------
  207. IMF_EXPORT
  208. AcesInputFile (const std::string &name,
  209. int numThreads = globalThreadCount());
  210. //-----------------------------------------------------------
  211. // Constructor -- attaches the new AcesInputFile object to a
  212. // file that has already been opened by the caller.
  213. // Destroying the AcesInputFile object will not automatically
  214. // close the file.
  215. //-----------------------------------------------------------
  216. IMF_EXPORT
  217. AcesInputFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is,
  218. int numThreads = globalThreadCount());
  219. //-----------
  220. // Destructor
  221. //-----------
  222. IMF_EXPORT
  223. virtual ~AcesInputFile ();
  224. //-----------------------------------------------------
  225. // Define a frame buffer as the pixel data destination:
  226. // Pixel (x, y) is at address
  227. //
  228. // base + x * xStride + y * yStride
  229. //
  230. //-----------------------------------------------------
  231. IMF_EXPORT
  232. void setFrameBuffer (Rgba *base,
  233. size_t xStride,
  234. size_t yStride);
  235. //--------------------------------------------
  236. // Read pixel data (see class Imf::InputFile)
  237. // Pixels returned will contain ACES RGB data.
  238. //--------------------------------------------
  239. IMF_EXPORT
  240. void readPixels (int scanLine1, int scanLine2);
  241. IMF_EXPORT
  242. void readPixels (int scanLine);
  243. //--------------------------
  244. // Access to the file header
  245. //--------------------------
  246. IMF_EXPORT
  247. const Header & header () const;
  248. IMF_EXPORT
  249. const IMATH_NAMESPACE::Box2i & displayWindow () const;
  250. IMF_EXPORT
  251. const IMATH_NAMESPACE::Box2i & dataWindow () const;
  252. IMF_EXPORT
  253. float pixelAspectRatio () const;
  254. IMF_EXPORT
  255. const IMATH_NAMESPACE::V2f screenWindowCenter () const;
  256. IMF_EXPORT
  257. float screenWindowWidth () const;
  258. IMF_EXPORT
  259. LineOrder lineOrder () const;
  260. IMF_EXPORT
  261. Compression compression () const;
  262. IMF_EXPORT
  263. RgbaChannels channels () const;
  264. IMF_EXPORT
  265. const char * fileName () const;
  266. IMF_EXPORT
  267. bool isComplete () const;
  268. //----------------------------------
  269. // Access to the file format version
  270. //----------------------------------
  271. IMF_EXPORT
  272. int version () const;
  273. private:
  274. AcesInputFile (const AcesInputFile &); // not implemented
  275. AcesInputFile & operator = (const AcesInputFile &); // not implemented
  276. class Data;
  277. Data * _data;
  278. };
  279. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  280. #endif