1 // 2 // SPDX-License-Identifier: BSD-3-Clause 3 // Copyright (c) Contributors to the OpenEXR Project. 4 // 5 6 #include "ImfGenericInputFile.h" 7 8 #include <ImfIO.h> 9 #include <ImfVersion.h> 10 #include <ImfXdr.h> 11 #include <Iex.h> 12 #include <OpenEXRConfig.h> 13 14 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER 15 ~GenericInputFile()16GenericInputFile::~GenericInputFile () 17 {} 18 GenericInputFile()19GenericInputFile::GenericInputFile () 20 {} 21 readMagicNumberAndVersionField(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream & is,int & version)22void GenericInputFile::readMagicNumberAndVersionField(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is, int& version) 23 { 24 // 25 // Read the magic number and the file format version number. 26 // Then check if we can read the rest of this file. 27 // 28 29 int magic; 30 31 OPENEXR_IMF_INTERNAL_NAMESPACE::Xdr::read <OPENEXR_IMF_INTERNAL_NAMESPACE::StreamIO> (is, magic); 32 OPENEXR_IMF_INTERNAL_NAMESPACE::Xdr::read <OPENEXR_IMF_INTERNAL_NAMESPACE::StreamIO> (is, version); 33 34 if (magic != MAGIC) 35 { 36 throw IEX_NAMESPACE::InputExc ("File is not an image file."); 37 } 38 39 if (getVersion (version) != EXR_VERSION) 40 { 41 THROW (IEX_NAMESPACE::InputExc, "Cannot read " 42 "version " << getVersion (version) << " " 43 "image files. Current file format version " 44 "is " << EXR_VERSION << "."); 45 } 46 47 if (!supportsFlags (getFlags (version))) 48 { 49 THROW (IEX_NAMESPACE::InputExc, "The file format version number's flag field " 50 "contains unrecognized flags."); 51 } 52 } 53 54 OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT 55