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