1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 #ifndef INCLUDED_IMF_VERSION_H
7 #define INCLUDED_IMF_VERSION_H
8 
9 //-----------------------------------------------------------------------------
10 //
11 //	Magic and version number.
12 //
13 //-----------------------------------------------------------------------------
14 
15 #include "ImfExport.h"
16 #include "ImfNamespace.h"
17 
18 OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
19 
20 //
21 // The MAGIC number is stored in the first four bytes of every
22 // OpenEXR image file.  This can be used to quickly test whether
23 // a given file is an OpenEXR image file (see isImfMagic(), below).
24 //
25 
26 static const int MAGIC = 20000630;
27 
28 
29 //
30 // The second item in each OpenEXR image file, right after the
31 // magic number, is a four-byte file version identifier.  Depending
32 // on a file's version identifier, a file reader can enable various
33 // backwards-compatibility switches, or it can quickly reject files
34 // that it cannot read.
35 //
36 // The version identifier is split into an 8-bit version number,
37 // and a 24-bit flags field.
38 //
39 
40 static const int VERSION_NUMBER_FIELD	= 0x000000ff;
41 static const int VERSION_FLAGS_FIELD	= 0xffffff00;
42 
43 
44 //
45 // Value that goes into VERSION_NUMBER_FIELD.
46 //
47 
48 static const int EXR_VERSION		= 2;
49 
50 
51 //
52 // Flags that can go into VERSION_FLAGS_FIELD.
53 // Flags can only occupy the 1 bits in VERSION_FLAGS_FIELD.
54 //
55 
56 static const int TILED_FLAG		= 0x00000200;   // File is tiled
57 static
58 const int LONG_NAMES_FLAG       = 0x00000400;   // File contains long
59                                                 // attribute or channel
60                                                 // names
61 static
62 const int NON_IMAGE_FLAG        = 0x00000800;   // File has at least one part
63                                                 // which is not a regular
64                                                 // scanline image or regular tiled image
65                                                 // (that is, it is a deep format)
66 static
67 const int MULTI_PART_FILE_FLAG  = 0x00001000;   // File has multiple parts
68 
69 //
70 // Bitwise OR of all known flags.
71 //
72 static
73 const int ALL_FLAGS		= TILED_FLAG | LONG_NAMES_FLAG |
74                                   NON_IMAGE_FLAG | MULTI_PART_FILE_FLAG;
75 
76 
77 //
78 // Utility functions
79 //
80 
isTiled(int version)81 inline bool  isTiled (int version)	{return !!(version & TILED_FLAG);}
isMultiPart(int version)82 inline bool  isMultiPart (int version)  {return !!(version & MULTI_PART_FILE_FLAG); }
isNonImage(int version)83 inline bool  isNonImage(int version)    {return !!(version & NON_IMAGE_FLAG); }
makeTiled(int version)84 inline int   makeTiled (int version)	{return version | TILED_FLAG;}
makeNotTiled(int version)85 inline int   makeNotTiled (int version) {return version & ~TILED_FLAG;}
getVersion(int version)86 inline int   getVersion (int version)	{return version & VERSION_NUMBER_FIELD;}
getFlags(int version)87 inline int   getFlags (int version)	{return version & VERSION_FLAGS_FIELD;}
supportsFlags(int flags)88 inline bool  supportsFlags (int flags)	{return !(flags & ~ALL_FLAGS);}
89 
90 
91 //
92 // Given the first four bytes of a file, returns true if the
93 // file is probably an OpenEXR image file, false if not.
94 //
95 
96 IMF_EXPORT
97 bool	     isImfMagic (const char bytes[4]);
98 
99 
100 OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
101 
102 
103 
104 
105 
106 #endif
107