ImfCRgbaFile.cpp 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  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. //-----------------------------------------------------------------------------
  35. //
  36. // C interface to C++ classes Imf::RgbaOutputFile and Imf::RgbaInputFile
  37. //
  38. //-----------------------------------------------------------------------------
  39. #include <ImfCRgbaFile.h>
  40. #include <ImfRgbaFile.h>
  41. #include <ImfTiledRgbaFile.h>
  42. #include <ImfIntAttribute.h>
  43. #include <ImfFloatAttribute.h>
  44. #include <ImfDoubleAttribute.h>
  45. #include <ImfStringAttribute.h>
  46. #include <ImfBoxAttribute.h>
  47. #include <ImfVecAttribute.h>
  48. #include <ImfMatrixAttribute.h>
  49. #include <ImfChannelList.h>
  50. #include <ImfLut.h>
  51. #include "half.h"
  52. #include "ImfNamespace.h"
  53. #include "ImathForward.h"
  54. #include <string.h>
  55. using IMATH_NAMESPACE::Box2i;
  56. using IMATH_NAMESPACE::Box2f;
  57. using IMATH_NAMESPACE::V2i;
  58. using IMATH_NAMESPACE::V2f;
  59. using IMATH_NAMESPACE::V3i;
  60. using IMATH_NAMESPACE::V3f;
  61. using IMATH_NAMESPACE::M33f;
  62. using IMATH_NAMESPACE::M44f;
  63. namespace {
  64. const int MAX_ERR_LENGTH = 1024;
  65. char errorMessage[MAX_ERR_LENGTH];
  66. void
  67. setErrorMessage (const std::exception &e)
  68. {
  69. strncpy (errorMessage, e.what(), MAX_ERR_LENGTH - 1);
  70. errorMessage[MAX_ERR_LENGTH - 1] = 0;
  71. }
  72. inline OPENEXR_IMF_INTERNAL_NAMESPACE::Header *
  73. header (ImfHeader *hdr)
  74. {
  75. return (OPENEXR_IMF_INTERNAL_NAMESPACE::Header *)(hdr);
  76. }
  77. inline const OPENEXR_IMF_INTERNAL_NAMESPACE::Header *
  78. header (const ImfHeader *hdr)
  79. {
  80. return (const OPENEXR_IMF_INTERNAL_NAMESPACE::Header *)(hdr);
  81. }
  82. inline OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaOutputFile *
  83. outfile (ImfOutputFile *out)
  84. {
  85. return (OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaOutputFile *) out;
  86. }
  87. inline const OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaOutputFile *
  88. outfile (const ImfOutputFile *out)
  89. {
  90. return (const OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaOutputFile *) out;
  91. }
  92. inline OPENEXR_IMF_INTERNAL_NAMESPACE::TiledRgbaOutputFile *
  93. outfile (ImfTiledOutputFile *out)
  94. {
  95. return (OPENEXR_IMF_INTERNAL_NAMESPACE::TiledRgbaOutputFile *) out;
  96. }
  97. inline const OPENEXR_IMF_INTERNAL_NAMESPACE::TiledRgbaOutputFile *
  98. outfile (const ImfTiledOutputFile *out)
  99. {
  100. return (const OPENEXR_IMF_INTERNAL_NAMESPACE::TiledRgbaOutputFile *) out;
  101. }
  102. inline OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaInputFile *
  103. infile (ImfInputFile *in)
  104. {
  105. return (OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaInputFile *) in;
  106. }
  107. inline const OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaInputFile *
  108. infile (const ImfInputFile *in)
  109. {
  110. return (const OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaInputFile *) in;
  111. }
  112. inline OPENEXR_IMF_INTERNAL_NAMESPACE::TiledRgbaInputFile *
  113. infile (ImfTiledInputFile *in)
  114. {
  115. return (OPENEXR_IMF_INTERNAL_NAMESPACE::TiledRgbaInputFile *) in;
  116. }
  117. inline const OPENEXR_IMF_INTERNAL_NAMESPACE::TiledRgbaInputFile *
  118. infile (const ImfTiledInputFile *in)
  119. {
  120. return (const OPENEXR_IMF_INTERNAL_NAMESPACE::TiledRgbaInputFile *) in;
  121. }
  122. } // namespace
  123. void
  124. ImfFloatToHalf (float f, ImfHalf *h)
  125. {
  126. *h = half(f).bits();
  127. }
  128. void
  129. ImfFloatToHalfArray (int n, const float f[/*n*/], ImfHalf h[/*n*/])
  130. {
  131. for (int i = 0; i < n; ++i)
  132. h[i] = half(f[i]).bits();
  133. }
  134. float
  135. ImfHalfToFloat (ImfHalf h)
  136. {
  137. return float (*((half *)&h));
  138. }
  139. void
  140. ImfHalfToFloatArray (int n, const ImfHalf h[/*n*/], float f[/*n*/])
  141. {
  142. for (int i = 0; i < n; ++i)
  143. f[i] = float (*((half *)(h + i)));
  144. }
  145. ImfHeader *
  146. ImfNewHeader (void)
  147. {
  148. try
  149. {
  150. return (ImfHeader *) new OPENEXR_IMF_INTERNAL_NAMESPACE::Header;
  151. }
  152. catch (const std::exception &e)
  153. {
  154. setErrorMessage (e);
  155. return 0;
  156. }
  157. }
  158. void
  159. ImfDeleteHeader (ImfHeader *hdr)
  160. {
  161. delete header (hdr);
  162. }
  163. ImfHeader *
  164. ImfCopyHeader (const ImfHeader *hdr)
  165. {
  166. try
  167. {
  168. return (ImfHeader *) new OPENEXR_IMF_INTERNAL_NAMESPACE::Header (*header (hdr));
  169. }
  170. catch (const std::exception &e)
  171. {
  172. setErrorMessage (e);
  173. return 0;
  174. }
  175. }
  176. void
  177. ImfHeaderSetDisplayWindow (ImfHeader *hdr,
  178. int xMin, int yMin,
  179. int xMax, int yMax)
  180. {
  181. header(hdr)->displayWindow() = Box2i (V2i (xMin, yMin), V2i (xMax, yMax));
  182. }
  183. void
  184. ImfHeaderDisplayWindow (const ImfHeader *hdr,
  185. int *xMin, int *yMin,
  186. int *xMax, int *yMax)
  187. {
  188. const Box2i dw = header(hdr)->displayWindow();
  189. *xMin = dw.min.x;
  190. *yMin = dw.min.y;
  191. *xMax = dw.max.x;
  192. *yMax = dw.max.y;
  193. }
  194. void
  195. ImfHeaderSetDataWindow (ImfHeader *hdr,
  196. int xMin, int yMin,
  197. int xMax, int yMax)
  198. {
  199. header(hdr)->dataWindow() = Box2i (V2i (xMin, yMin), V2i (xMax, yMax));
  200. }
  201. void
  202. ImfHeaderDataWindow (const ImfHeader *hdr,
  203. int *xMin, int *yMin,
  204. int *xMax, int *yMax)
  205. {
  206. const Box2i dw = header(hdr)->dataWindow();
  207. *xMin = dw.min.x;
  208. *yMin = dw.min.y;
  209. *xMax = dw.max.x;
  210. *yMax = dw.max.y;
  211. }
  212. void
  213. ImfHeaderSetPixelAspectRatio (ImfHeader *hdr, float pixelAspectRatio)
  214. {
  215. header(hdr)->pixelAspectRatio() = pixelAspectRatio;
  216. }
  217. float
  218. ImfHeaderPixelAspectRatio (const ImfHeader *hdr)
  219. {
  220. return header(hdr)->pixelAspectRatio();
  221. }
  222. void
  223. ImfHeaderSetScreenWindowCenter (ImfHeader *hdr, float x, float y)
  224. {
  225. header(hdr)->screenWindowCenter() = V2f (x, y);
  226. }
  227. void
  228. ImfHeaderScreenWindowCenter (const ImfHeader *hdr, float *x, float *y)
  229. {
  230. const V2i &swc = header(hdr)->screenWindowCenter();
  231. *x = (float) swc.x;
  232. *y = (float) swc.y;
  233. }
  234. void
  235. ImfHeaderSetScreenWindowWidth (ImfHeader *hdr, float width)
  236. {
  237. header(hdr)->screenWindowWidth() = width;
  238. }
  239. float
  240. ImfHeaderScreenWindowWidth (const ImfHeader *hdr)
  241. {
  242. return header(hdr)->screenWindowWidth();
  243. }
  244. void
  245. ImfHeaderSetLineOrder (ImfHeader *hdr, int lineOrder)
  246. {
  247. header(hdr)->lineOrder() = OPENEXR_IMF_INTERNAL_NAMESPACE::LineOrder (lineOrder);
  248. }
  249. int
  250. ImfHeaderLineOrder (const ImfHeader *hdr)
  251. {
  252. return header(hdr)->lineOrder();
  253. }
  254. void
  255. ImfHeaderSetCompression (ImfHeader *hdr, int compression)
  256. {
  257. header(hdr)->compression() = OPENEXR_IMF_INTERNAL_NAMESPACE::Compression (compression);
  258. }
  259. int
  260. ImfHeaderCompression (const ImfHeader *hdr)
  261. {
  262. return header(hdr)->compression();
  263. }
  264. int
  265. ImfHeaderSetIntAttribute (ImfHeader *hdr, const char name[], int value)
  266. {
  267. try
  268. {
  269. if (header(hdr)->find(name) == header(hdr)->end())
  270. {
  271. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::IntAttribute (value));
  272. }
  273. else
  274. {
  275. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::IntAttribute>(name).value() =
  276. value;
  277. }
  278. return 1;
  279. }
  280. catch (const std::exception &e)
  281. {
  282. setErrorMessage (e);
  283. return 0;
  284. }
  285. }
  286. int
  287. ImfHeaderIntAttribute (const ImfHeader *hdr, const char name[], int *value)
  288. {
  289. try
  290. {
  291. *value = header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::IntAttribute>(name).value();
  292. return 1;
  293. }
  294. catch (const std::exception &e)
  295. {
  296. setErrorMessage (e);
  297. return 0;
  298. }
  299. }
  300. int
  301. ImfHeaderSetFloatAttribute (ImfHeader *hdr, const char name[], float value)
  302. {
  303. try
  304. {
  305. if (header(hdr)->find(name) == header(hdr)->end())
  306. {
  307. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::FloatAttribute (value));
  308. }
  309. else
  310. {
  311. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::FloatAttribute>(name).value() =
  312. value;
  313. }
  314. return 1;
  315. }
  316. catch (const std::exception &e)
  317. {
  318. setErrorMessage (e);
  319. return 0;
  320. }
  321. }
  322. int
  323. ImfHeaderSetDoubleAttribute (ImfHeader *hdr, const char name[], double value)
  324. {
  325. try
  326. {
  327. if (header(hdr)->find(name) == header(hdr)->end())
  328. {
  329. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::DoubleAttribute (value));
  330. }
  331. else
  332. {
  333. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::DoubleAttribute>(name).value() =
  334. value;
  335. }
  336. return 1;
  337. }
  338. catch (const std::exception &e)
  339. {
  340. setErrorMessage (e);
  341. return 0;
  342. }
  343. }
  344. int
  345. ImfHeaderFloatAttribute (const ImfHeader *hdr, const char name[], float *value)
  346. {
  347. try
  348. {
  349. *value = header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::FloatAttribute>(name).value();
  350. return 1;
  351. }
  352. catch (const std::exception &e)
  353. {
  354. setErrorMessage (e);
  355. return 0;
  356. }
  357. }
  358. int
  359. ImfHeaderDoubleAttribute (const ImfHeader *hdr,
  360. const char name[],
  361. double *value)
  362. {
  363. try
  364. {
  365. *value = header(hdr)->
  366. typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::DoubleAttribute>(name).value();
  367. return 1;
  368. }
  369. catch (const std::exception &e)
  370. {
  371. setErrorMessage (e);
  372. return 0;
  373. }
  374. }
  375. int
  376. ImfHeaderSetStringAttribute (ImfHeader *hdr,
  377. const char name[],
  378. const char value[])
  379. {
  380. try
  381. {
  382. if (header(hdr)->find(name) == header(hdr)->end())
  383. {
  384. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::StringAttribute (value));
  385. }
  386. else
  387. {
  388. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::StringAttribute>(name).value() =
  389. value;
  390. }
  391. return 1;
  392. }
  393. catch (const std::exception &e)
  394. {
  395. setErrorMessage (e);
  396. return 0;
  397. }
  398. }
  399. int
  400. ImfHeaderStringAttribute (const ImfHeader *hdr,
  401. const char name[],
  402. const char **value)
  403. {
  404. try
  405. {
  406. *value = header(hdr)->
  407. typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::StringAttribute>(name).value().c_str();
  408. return 1;
  409. }
  410. catch (const std::exception &e)
  411. {
  412. setErrorMessage (e);
  413. return 0;
  414. }
  415. }
  416. int
  417. ImfHeaderSetBox2iAttribute (ImfHeader *hdr,
  418. const char name[],
  419. int xMin, int yMin,
  420. int xMax, int yMax)
  421. {
  422. try
  423. {
  424. Box2i box (V2i (xMin, yMin), V2i (xMax, yMax));
  425. if (header(hdr)->find(name) == header(hdr)->end())
  426. {
  427. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::Box2iAttribute (box));
  428. }
  429. else
  430. {
  431. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::Box2iAttribute>(name).value() =
  432. box;
  433. }
  434. return 1;
  435. }
  436. catch (const std::exception &e)
  437. {
  438. setErrorMessage (e);
  439. return 0;
  440. }
  441. }
  442. int
  443. ImfHeaderBox2iAttribute (const ImfHeader *hdr,
  444. const char name[],
  445. int *xMin, int *yMin,
  446. int *xMax, int *yMax)
  447. {
  448. try
  449. {
  450. const Box2i &box =
  451. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::Box2iAttribute>(name).value();
  452. *xMin = box.min.x;
  453. *yMin = box.min.y;
  454. *xMax = box.max.x;
  455. *yMax = box.max.y;
  456. return 1;
  457. }
  458. catch (const std::exception &e)
  459. {
  460. setErrorMessage (e);
  461. return 0;
  462. }
  463. }
  464. int
  465. ImfHeaderSetBox2fAttribute (ImfHeader *hdr,
  466. const char name[],
  467. float xMin, float yMin,
  468. float xMax, float yMax)
  469. {
  470. try
  471. {
  472. Box2f box (V2f (xMin, yMin), V2f (xMax, yMax));
  473. if (header(hdr)->find(name) == header(hdr)->end())
  474. {
  475. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::Box2fAttribute (box));
  476. }
  477. else
  478. {
  479. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::Box2fAttribute>(name).value() =
  480. box;
  481. }
  482. return 1;
  483. }
  484. catch (const std::exception &e)
  485. {
  486. setErrorMessage (e);
  487. return 0;
  488. }
  489. }
  490. int
  491. ImfHeaderBox2fAttribute (const ImfHeader *hdr,
  492. const char name[],
  493. float *xMin, float *yMin,
  494. float *xMax, float *yMax)
  495. {
  496. try
  497. {
  498. const Box2f &box =
  499. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::Box2fAttribute>(name).value();
  500. *xMin = box.min.x;
  501. *yMin = box.min.y;
  502. *xMax = box.max.x;
  503. *yMax = box.max.y;
  504. return 1;
  505. }
  506. catch (const std::exception &e)
  507. {
  508. setErrorMessage (e);
  509. return 0;
  510. }
  511. }
  512. int
  513. ImfHeaderSetV2iAttribute (ImfHeader *hdr,
  514. const char name[],
  515. int x, int y)
  516. {
  517. try
  518. {
  519. V2i v (x, y);
  520. if (header(hdr)->find(name) == header(hdr)->end())
  521. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::V2iAttribute (v));
  522. else
  523. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::V2iAttribute>(name).value() = v;
  524. return 1;
  525. }
  526. catch (const std::exception &e)
  527. {
  528. setErrorMessage (e);
  529. return 0;
  530. }
  531. }
  532. int
  533. ImfHeaderV2iAttribute (const ImfHeader *hdr,
  534. const char name[],
  535. int *x, int *y)
  536. {
  537. try
  538. {
  539. const V2i &v =
  540. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::V2iAttribute>(name).value();
  541. *x = v.x;
  542. *y = v.y;
  543. return 1;
  544. }
  545. catch (const std::exception &e)
  546. {
  547. setErrorMessage (e);
  548. return 0;
  549. }
  550. }
  551. int
  552. ImfHeaderSetV2fAttribute (ImfHeader *hdr,
  553. const char name[],
  554. float x, float y)
  555. {
  556. try
  557. {
  558. V2f v (x, y);
  559. if (header(hdr)->find(name) == header(hdr)->end())
  560. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::V2fAttribute (v));
  561. else
  562. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::V2fAttribute>(name).value() = v;
  563. return 1;
  564. }
  565. catch (const std::exception &e)
  566. {
  567. setErrorMessage (e);
  568. return 0;
  569. }
  570. }
  571. int
  572. ImfHeaderV2fAttribute (const ImfHeader *hdr,
  573. const char name[],
  574. float *x, float *y)
  575. {
  576. try
  577. {
  578. const V2f &v =
  579. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::V2fAttribute>(name).value();
  580. *x = v.x;
  581. *y = v.y;
  582. return 1;
  583. }
  584. catch (const std::exception &e)
  585. {
  586. setErrorMessage (e);
  587. return 0;
  588. }
  589. }
  590. int
  591. ImfHeaderSetV3iAttribute (ImfHeader *hdr,
  592. const char name[],
  593. int x, int y, int z)
  594. {
  595. try
  596. {
  597. V3i v (x, y, z);
  598. if (header(hdr)->find(name) == header(hdr)->end())
  599. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::V3iAttribute (v));
  600. else
  601. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::V3iAttribute>(name).value() = v;
  602. return 1;
  603. }
  604. catch (const std::exception &e)
  605. {
  606. setErrorMessage (e);
  607. return 0;
  608. }
  609. }
  610. int
  611. ImfHeaderV3iAttribute (const ImfHeader *hdr,
  612. const char name[],
  613. int *x, int *y, int *z)
  614. {
  615. try
  616. {
  617. const V3i &v =
  618. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::V3iAttribute>(name).value();
  619. *x = v.x;
  620. *y = v.y;
  621. *z = v.z;
  622. return 1;
  623. }
  624. catch (const std::exception &e)
  625. {
  626. setErrorMessage (e);
  627. return 0;
  628. }
  629. }
  630. int
  631. ImfHeaderSetV3fAttribute (ImfHeader *hdr,
  632. const char name[],
  633. float x, float y, float z)
  634. {
  635. try
  636. {
  637. V3f v (x, y, z);
  638. if (header(hdr)->find(name) == header(hdr)->end())
  639. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::V3fAttribute (v));
  640. else
  641. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::V3fAttribute>(name).value() = v;
  642. return 1;
  643. }
  644. catch (const std::exception &e)
  645. {
  646. setErrorMessage (e);
  647. return 0;
  648. }
  649. }
  650. int
  651. ImfHeaderV3fAttribute (const ImfHeader *hdr,
  652. const char name[],
  653. float *x, float *y, float *z)
  654. {
  655. try
  656. {
  657. const V3f &v =
  658. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::V3fAttribute>(name).value();
  659. *x = v.x;
  660. *y = v.y;
  661. *z = v.z;
  662. return 1;
  663. }
  664. catch (const std::exception &e)
  665. {
  666. setErrorMessage (e);
  667. return 0;
  668. }
  669. }
  670. int
  671. ImfHeaderSetM33fAttribute (ImfHeader *hdr,
  672. const char name[],
  673. const float m[3][3])
  674. {
  675. try
  676. {
  677. M33f m3 (m);
  678. if (header(hdr)->find(name) == header(hdr)->end())
  679. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::M33fAttribute (m3));
  680. else
  681. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::M33fAttribute>(name).value() = m3;
  682. return 1;
  683. }
  684. catch (const std::exception &e)
  685. {
  686. setErrorMessage (e);
  687. return 0;
  688. }
  689. }
  690. int
  691. ImfHeaderM33fAttribute (const ImfHeader *hdr,
  692. const char name[],
  693. float m[3][3])
  694. {
  695. try
  696. {
  697. const M33f &m3 =
  698. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::M33fAttribute>(name).value();
  699. m[0][0] = m3[0][0];
  700. m[0][1] = m3[0][1];
  701. m[0][2] = m3[0][2];
  702. m[1][0] = m3[1][0];
  703. m[1][1] = m3[1][1];
  704. m[1][2] = m3[1][2];
  705. m[2][0] = m3[2][0];
  706. m[2][1] = m3[2][1];
  707. m[2][2] = m3[2][2];
  708. return 1;
  709. }
  710. catch (const std::exception &e)
  711. {
  712. setErrorMessage (e);
  713. return 0;
  714. }
  715. }
  716. int
  717. ImfHeaderSetM44fAttribute (ImfHeader *hdr,
  718. const char name[],
  719. const float m[4][4])
  720. {
  721. try
  722. {
  723. M44f m4 (m);
  724. if (header(hdr)->find(name) == header(hdr)->end())
  725. header(hdr)->insert (name, OPENEXR_IMF_INTERNAL_NAMESPACE::M44fAttribute (m4));
  726. else
  727. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::M44fAttribute>(name).value() = m4;
  728. return 1;
  729. }
  730. catch (const std::exception &e)
  731. {
  732. setErrorMessage (e);
  733. return 0;
  734. }
  735. }
  736. int
  737. ImfHeaderM44fAttribute (const ImfHeader *hdr,
  738. const char name[],
  739. float m[4][4])
  740. {
  741. try
  742. {
  743. const M44f &m4 =
  744. header(hdr)->typedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::M44fAttribute>(name).value();
  745. m[0][0] = m4[0][0];
  746. m[0][1] = m4[0][1];
  747. m[0][2] = m4[0][2];
  748. m[0][3] = m4[0][3];
  749. m[1][0] = m4[1][0];
  750. m[1][1] = m4[1][1];
  751. m[1][2] = m4[1][2];
  752. m[1][3] = m4[1][3];
  753. m[2][0] = m4[2][0];
  754. m[2][1] = m4[2][1];
  755. m[2][2] = m4[2][2];
  756. m[2][3] = m4[2][3];
  757. m[3][0] = m4[3][0];
  758. m[3][1] = m4[3][1];
  759. m[3][2] = m4[3][2];
  760. m[3][3] = m4[3][3];
  761. return 1;
  762. }
  763. catch (const std::exception &e)
  764. {
  765. setErrorMessage (e);
  766. return 0;
  767. }
  768. }
  769. ImfOutputFile *
  770. ImfOpenOutputFile (const char name[], const ImfHeader *hdr, int channels)
  771. {
  772. try
  773. {
  774. return (ImfOutputFile *) new OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaOutputFile
  775. (name, *header(hdr), OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaChannels (channels));
  776. }
  777. catch (const std::exception &e)
  778. {
  779. setErrorMessage (e);
  780. return 0;
  781. }
  782. }
  783. int
  784. ImfCloseOutputFile (ImfOutputFile *out)
  785. {
  786. try
  787. {
  788. delete outfile (out);
  789. return 1;
  790. }
  791. catch (const std::exception &e)
  792. {
  793. setErrorMessage (e);
  794. return 0;
  795. }
  796. }
  797. int
  798. ImfOutputSetFrameBuffer (ImfOutputFile *out,
  799. const ImfRgba *base,
  800. size_t xStride,
  801. size_t yStride)
  802. {
  803. try
  804. {
  805. outfile(out)->setFrameBuffer ((OPENEXR_IMF_INTERNAL_NAMESPACE::Rgba *)base, xStride, yStride);
  806. return 1;
  807. }
  808. catch (const std::exception &e)
  809. {
  810. setErrorMessage (e);
  811. return 0;
  812. }
  813. }
  814. int
  815. ImfOutputWritePixels (ImfOutputFile *out, int numScanLines)
  816. {
  817. try
  818. {
  819. outfile(out)->writePixels (numScanLines);
  820. return 1;
  821. }
  822. catch (const std::exception &e)
  823. {
  824. setErrorMessage (e);
  825. return 0;
  826. }
  827. }
  828. int
  829. ImfOutputCurrentScanLine (const ImfOutputFile *out)
  830. {
  831. return outfile(out)->currentScanLine();
  832. }
  833. const ImfHeader *
  834. ImfOutputHeader (const ImfOutputFile *out)
  835. {
  836. return (const ImfHeader *) &outfile(out)->header();
  837. }
  838. int
  839. ImfOutputChannels (const ImfOutputFile *out)
  840. {
  841. return outfile(out)->channels();
  842. }
  843. ImfTiledOutputFile *
  844. ImfOpenTiledOutputFile (const char name[],
  845. const ImfHeader *hdr,
  846. int channels,
  847. int xSize, int ySize,
  848. int mode, int rmode)
  849. {
  850. try
  851. {
  852. return (ImfTiledOutputFile *) new OPENEXR_IMF_INTERNAL_NAMESPACE::TiledRgbaOutputFile
  853. (name, *header(hdr),
  854. OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaChannels (channels),
  855. xSize, ySize,
  856. OPENEXR_IMF_INTERNAL_NAMESPACE::LevelMode (mode),
  857. OPENEXR_IMF_INTERNAL_NAMESPACE::LevelRoundingMode (rmode));
  858. }
  859. catch (const std::exception &e)
  860. {
  861. setErrorMessage (e);
  862. return 0;
  863. }
  864. }
  865. int
  866. ImfCloseTiledOutputFile (ImfTiledOutputFile *out)
  867. {
  868. try
  869. {
  870. delete outfile (out);
  871. return 1;
  872. }
  873. catch (const std::exception &e)
  874. {
  875. setErrorMessage (e);
  876. return 0;
  877. }
  878. }
  879. int
  880. ImfTiledOutputSetFrameBuffer (ImfTiledOutputFile *out,
  881. const ImfRgba *base,
  882. size_t xStride,
  883. size_t yStride)
  884. {
  885. try
  886. {
  887. outfile(out)->setFrameBuffer ((OPENEXR_IMF_INTERNAL_NAMESPACE::Rgba *)base, xStride, yStride);
  888. return 1;
  889. }
  890. catch (const std::exception &e)
  891. {
  892. setErrorMessage (e);
  893. return 0;
  894. }
  895. }
  896. int
  897. ImfTiledOutputWriteTile (ImfTiledOutputFile *out,
  898. int dx, int dy,
  899. int lx, int ly)
  900. {
  901. try
  902. {
  903. outfile(out)->writeTile (dx, dy, lx, ly);
  904. return 1;
  905. }
  906. catch (const std::exception &e)
  907. {
  908. setErrorMessage (e);
  909. return 0;
  910. }
  911. }
  912. int
  913. ImfTiledOutputWriteTiles (ImfTiledOutputFile *out,
  914. int dxMin, int dxMax,
  915. int dyMin, int dyMax,
  916. int lx, int ly)
  917. {
  918. try
  919. {
  920. outfile(out)->writeTiles (dxMin, dxMax, dyMin, dyMax, lx, ly);
  921. return 1;
  922. }
  923. catch (const std::exception &e)
  924. {
  925. setErrorMessage (e);
  926. return 0;
  927. }
  928. }
  929. const ImfHeader *
  930. ImfTiledOutputHeader (const ImfTiledOutputFile *out)
  931. {
  932. return (const ImfHeader *) &outfile(out)->header();
  933. }
  934. int
  935. ImfTiledOutputChannels (const ImfTiledOutputFile *out)
  936. {
  937. return outfile(out)->channels();
  938. }
  939. int
  940. ImfTiledOutputTileXSize (const ImfTiledOutputFile *out)
  941. {
  942. return outfile(out)->tileXSize();
  943. }
  944. int
  945. ImfTiledOutputTileYSize (const ImfTiledOutputFile *out)
  946. {
  947. return outfile(out)->tileYSize();
  948. }
  949. int
  950. ImfTiledOutputLevelMode (const ImfTiledOutputFile *out)
  951. {
  952. return outfile(out)->levelMode();
  953. }
  954. int
  955. ImfTiledOutputLevelRoundingMode (const ImfTiledOutputFile *out)
  956. {
  957. return outfile(out)->levelRoundingMode();
  958. }
  959. ImfInputFile *
  960. ImfOpenInputFile (const char name[])
  961. {
  962. try
  963. {
  964. return (ImfInputFile *) new OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaInputFile (name);
  965. }
  966. catch (const std::exception &e)
  967. {
  968. setErrorMessage (e);
  969. return 0;
  970. }
  971. }
  972. int
  973. ImfCloseInputFile (ImfInputFile *in)
  974. {
  975. try
  976. {
  977. delete infile (in);
  978. return 1;
  979. }
  980. catch (const std::exception &e)
  981. {
  982. setErrorMessage (e);
  983. return 0;
  984. }
  985. }
  986. int
  987. ImfInputSetFrameBuffer (ImfInputFile *in,
  988. ImfRgba *base,
  989. size_t xStride,
  990. size_t yStride)
  991. {
  992. try
  993. {
  994. infile(in)->setFrameBuffer ((OPENEXR_IMF_INTERNAL_NAMESPACE::Rgba *) base, xStride, yStride);
  995. return 1;
  996. }
  997. catch (const std::exception &e)
  998. {
  999. setErrorMessage (e);
  1000. return 0;
  1001. }
  1002. }
  1003. int
  1004. ImfInputReadPixels (ImfInputFile *in, int scanLine1, int scanLine2)
  1005. {
  1006. try
  1007. {
  1008. infile(in)->readPixels (scanLine1, scanLine2);
  1009. return 1;
  1010. }
  1011. catch (const std::exception &e)
  1012. {
  1013. setErrorMessage (e);
  1014. return 0;
  1015. }
  1016. }
  1017. const ImfHeader *
  1018. ImfInputHeader (const ImfInputFile *in)
  1019. {
  1020. return (const ImfHeader *) &infile(in)->header();
  1021. }
  1022. int
  1023. ImfInputChannels (const ImfInputFile *in)
  1024. {
  1025. return infile(in)->channels();
  1026. }
  1027. const char *
  1028. ImfInputFileName (const ImfInputFile *in)
  1029. {
  1030. return infile(in)->fileName();
  1031. }
  1032. ImfTiledInputFile *
  1033. ImfOpenTiledInputFile (const char name[])
  1034. {
  1035. try
  1036. {
  1037. return (ImfTiledInputFile *) new OPENEXR_IMF_INTERNAL_NAMESPACE::TiledRgbaInputFile (name);
  1038. }
  1039. catch (const std::exception &e)
  1040. {
  1041. setErrorMessage (e);
  1042. return 0;
  1043. }
  1044. }
  1045. int
  1046. ImfCloseTiledInputFile (ImfTiledInputFile *in)
  1047. {
  1048. try
  1049. {
  1050. delete infile (in);
  1051. return 1;
  1052. }
  1053. catch (const std::exception &e)
  1054. {
  1055. setErrorMessage (e);
  1056. return 0;
  1057. }
  1058. }
  1059. int
  1060. ImfTiledInputSetFrameBuffer (ImfTiledInputFile *in,
  1061. ImfRgba *base,
  1062. size_t xStride,
  1063. size_t yStride)
  1064. {
  1065. try
  1066. {
  1067. infile(in)->setFrameBuffer ((OPENEXR_IMF_INTERNAL_NAMESPACE::Rgba *) base, xStride, yStride);
  1068. return 1;
  1069. }
  1070. catch (const std::exception &e)
  1071. {
  1072. setErrorMessage (e);
  1073. return 0;
  1074. }
  1075. }
  1076. int
  1077. ImfTiledInputReadTile (ImfTiledInputFile *in,
  1078. int dx, int dy,
  1079. int lx, int ly)
  1080. {
  1081. try
  1082. {
  1083. infile(in)->readTile (dx, dy, lx, ly);
  1084. return 1;
  1085. }
  1086. catch (const std::exception &e)
  1087. {
  1088. setErrorMessage (e);
  1089. return 0;
  1090. }
  1091. }
  1092. int
  1093. ImfTiledInputReadTiles (ImfTiledInputFile *in,
  1094. int dxMin, int dxMax,
  1095. int dyMin, int dyMax,
  1096. int lx, int ly)
  1097. {
  1098. try
  1099. {
  1100. infile(in)->readTiles (dxMin, dxMax, dyMin, dyMax, lx, ly);
  1101. return 1;
  1102. }
  1103. catch (const std::exception &e)
  1104. {
  1105. setErrorMessage (e);
  1106. return 0;
  1107. }
  1108. }
  1109. const ImfHeader *
  1110. ImfTiledInputHeader (const ImfTiledInputFile *in)
  1111. {
  1112. return (const ImfHeader *) &infile(in)->header();
  1113. }
  1114. int
  1115. ImfTiledInputChannels (const ImfTiledInputFile *in)
  1116. {
  1117. return infile(in)->channels();
  1118. }
  1119. const char *
  1120. ImfTiledInputFileName (const ImfTiledInputFile *in)
  1121. {
  1122. return infile(in)->fileName();
  1123. }
  1124. int
  1125. ImfTiledInputTileXSize (const ImfTiledInputFile *in)
  1126. {
  1127. return infile(in)->tileXSize();
  1128. }
  1129. int
  1130. ImfTiledInputTileYSize (const ImfTiledInputFile *in)
  1131. {
  1132. return infile(in)->tileYSize();
  1133. }
  1134. int
  1135. ImfTiledInputLevelMode (const ImfTiledInputFile *in)
  1136. {
  1137. return infile(in)->levelMode();
  1138. }
  1139. int
  1140. ImfTiledInputLevelRoundingMode (const ImfTiledInputFile *in)
  1141. {
  1142. return infile(in)->levelRoundingMode();
  1143. }
  1144. ImfLut *
  1145. ImfNewRound12logLut (int channels)
  1146. {
  1147. try
  1148. {
  1149. return (ImfLut *) new OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaLut
  1150. (OPENEXR_IMF_INTERNAL_NAMESPACE::round12log, OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaChannels (channels));
  1151. }
  1152. catch (const std::exception &e)
  1153. {
  1154. setErrorMessage (e);
  1155. return 0;
  1156. }
  1157. }
  1158. ImfLut *
  1159. ImfNewRoundNBitLut (unsigned int n, int channels)
  1160. {
  1161. try
  1162. {
  1163. return (ImfLut *) new OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaLut
  1164. (OPENEXR_IMF_INTERNAL_NAMESPACE::roundNBit (n), OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaChannels (channels));
  1165. }
  1166. catch (const std::exception &e)
  1167. {
  1168. setErrorMessage (e);
  1169. return 0;
  1170. }
  1171. }
  1172. void
  1173. ImfDeleteLut (ImfLut *lut)
  1174. {
  1175. delete (OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaLut *) lut;
  1176. }
  1177. void
  1178. ImfApplyLut (ImfLut *lut, ImfRgba *data, int nData, int stride)
  1179. {
  1180. ((OPENEXR_IMF_INTERNAL_NAMESPACE::RgbaLut *)lut)->apply ((OPENEXR_IMF_INTERNAL_NAMESPACE::Rgba *)data, nData, stride);
  1181. }
  1182. const char *
  1183. ImfErrorMessage ()
  1184. {
  1185. return errorMessage;
  1186. }