/src/FreeImage/Source/OpenEXR/IlmImf/ImfCRgbaFile.cpp

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