ImfAcesFile.h 9.3 KB

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