ImfVersion.h 3.1 KB

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