ImfTestFile.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. // Utility routines to test quickly if a given
  37. // file is an OpenEXR file, and whether the
  38. // file is scanline-based or tiled.
  39. //
  40. //-----------------------------------------------------------------------------
  41. #include <ImfTestFile.h>
  42. #include <ImfStdIO.h>
  43. #include <ImfXdr.h>
  44. #include <ImfVersion.h>
  45. #include "ImfNamespace.h"
  46. OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER
  47. bool
  48. isOpenExrFile
  49. (const char fileName[],
  50. bool &tiled,
  51. bool &deep,
  52. bool &multiPart)
  53. {
  54. try
  55. {
  56. StdIFStream is (fileName);
  57. int magic, version;
  58. Xdr::read <StreamIO> (is, magic);
  59. Xdr::read <StreamIO> (is, version);
  60. tiled = isTiled (version);
  61. deep = isNonImage (version);
  62. multiPart = isMultiPart (version);
  63. return magic == MAGIC;
  64. }
  65. catch (...)
  66. {
  67. tiled = false;
  68. return false;
  69. }
  70. }
  71. bool
  72. isOpenExrFile (const char fileName[], bool &tiled, bool &deep)
  73. {
  74. bool multiPart;
  75. return isOpenExrFile (fileName, tiled, deep, multiPart);
  76. }
  77. bool
  78. isOpenExrFile (const char fileName[], bool &tiled)
  79. {
  80. bool deep, multiPart;
  81. return isOpenExrFile (fileName, tiled, deep, multiPart);
  82. }
  83. bool
  84. isOpenExrFile (const char fileName[])
  85. {
  86. bool tiled, deep, multiPart;
  87. return isOpenExrFile (fileName, tiled, deep, multiPart);
  88. }
  89. bool
  90. isTiledOpenExrFile (const char fileName[])
  91. {
  92. bool exr, tiled, deep, multiPart;
  93. exr = isOpenExrFile (fileName, tiled, deep, multiPart);
  94. return exr && tiled;
  95. }
  96. bool
  97. isDeepOpenExrFile (const char fileName[])
  98. {
  99. bool exr, tiled, deep, multiPart;
  100. exr = isOpenExrFile (fileName, tiled, deep, multiPart);
  101. return exr && deep;
  102. }
  103. bool
  104. isMultiPartOpenExrFile (const char fileName[])
  105. {
  106. bool exr, tiled, deep, multiPart;
  107. exr = isOpenExrFile (fileName, tiled, deep, multiPart);
  108. return exr && multiPart;
  109. }
  110. bool
  111. isOpenExrFile
  112. (IStream &is,
  113. bool &tiled,
  114. bool &deep,
  115. bool &multiPart)
  116. {
  117. try
  118. {
  119. Int64 pos = is.tellg();
  120. if (pos != 0)
  121. is.seekg (0);
  122. int magic, version;
  123. Xdr::read <StreamIO> (is, magic);
  124. Xdr::read <StreamIO> (is, version);
  125. is.seekg (pos);
  126. tiled = isTiled (version);
  127. deep = isNonImage (version);
  128. multiPart = isMultiPart (version);
  129. return magic == MAGIC;
  130. }
  131. catch (...)
  132. {
  133. is.clear();
  134. tiled = false;
  135. return false;
  136. }
  137. }
  138. bool
  139. isOpenExrFile (IStream &is, bool &tiled, bool &deep)
  140. {
  141. bool multiPart;
  142. return isOpenExrFile (is, tiled, deep, multiPart);
  143. }
  144. bool
  145. isOpenExrFile (IStream &is, bool &tiled)
  146. {
  147. bool deep, multiPart;
  148. return isOpenExrFile (is, tiled, deep, multiPart);
  149. }
  150. bool
  151. isOpenExrFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is)
  152. {
  153. bool tiled, deep, multiPart;
  154. return isOpenExrFile (is, tiled, deep, multiPart);
  155. }
  156. bool
  157. isTiledOpenExrFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is)
  158. {
  159. bool exr, tiled, deep, multiPart;
  160. exr = isOpenExrFile (is, tiled, deep, multiPart);
  161. return exr && tiled;
  162. }
  163. bool
  164. isDeepOpenExrFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is)
  165. {
  166. bool exr, tiled, deep, multiPart;
  167. exr = isOpenExrFile (is, tiled, deep, multiPart);
  168. return exr && deep;
  169. }
  170. bool
  171. isMultiPartOpenExrFile (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is)
  172. {
  173. bool exr, tiled, deep, multiPart;
  174. exr = isOpenExrFile (is, tiled, deep, multiPart);
  175. return exr && multiPart;
  176. }
  177. OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT