| 49 | } |
| 50 | |
| 51 | ImageSourceFileTinyExr::ImageSourceFileTinyExr( DataSourceRef dataSource, ImageSource::Options /*options*/ ) |
| 52 | : mExrHeader( new EXRHeader, FreeEXRHeader ) // We're using the provided FreeEXRHeader function as a custom deleter |
| 53 | , mExrImage( new EXRImage, FreeEXRImage ) // We're using the provided FreeEXRImage function as a custom deleter |
| 54 | { |
| 55 | InitEXRHeader( mExrHeader.get() ); |
| 56 | InitEXRImage( mExrImage.get() ); |
| 57 | |
| 58 | int status = 0; |
| 59 | |
| 60 | EXRVersion version; |
| 61 | status = ParseEXRVersionFromFile( &version, dataSource->getFilePath().string().c_str() ); |
| 62 | if( status != TINYEXR_SUCCESS ) |
| 63 | throw ImageIoExceptionFailedLoadTinyExr( string( "Failed to parse OpenEXR version" ) ); |
| 64 | |
| 65 | if( version.multipart ) |
| 66 | throw ImageIoExceptionFailedLoadTinyExr( "Multi-part EXR not supported" ); |
| 67 | if( version.non_image ) |
| 68 | throw ImageIoExceptionFailedLoadTinyExr( "Deep image EXR not supported" ); |
| 69 | if( version.tiled ) |
| 70 | throw ImageIoExceptionFailedLoadTinyExr( "Tiled EXR not supported" ); |
| 71 | |
| 72 | if( dataSource->isFilePath() ) { |
| 73 | const string filename = dataSource->getFilePath().string(); |
| 74 | |
| 75 | const char *error = nullptr; |
| 76 | status = ParseEXRHeaderFromFile( mExrHeader.get(), &version, filename.c_str(), &error ); |
| 77 | if( status != TINYEXR_SUCCESS ) { |
| 78 | string errorMsg = error ? string( "Failed to parse OpenEXR header; Error message: " ) + error : "Failed to parse OpenEXR header"; |
| 79 | if( error ) |
| 80 | FreeEXRErrorMessage( error ); |
| 81 | throw ImageIoExceptionFailedLoadTinyExr( errorMsg ); |
| 82 | } |
| 83 | |
| 84 | status = LoadEXRImageFromFile( mExrImage.get(), mExrHeader.get(), filename.c_str(), &error ); |
| 85 | if( status != TINYEXR_SUCCESS ) { |
| 86 | string errorMsg = error ? string( "Failed to parse OpenEXR file; Error message: " ) + error : "Failed to parse OpenEXR file"; |
| 87 | if( error ) |
| 88 | FreeEXRErrorMessage( error ); |
| 89 | throw ImageIoExceptionFailedLoadTinyExr( errorMsg ); |
| 90 | } |
| 91 | } |
| 92 | else { |
| 93 | const auto buffer = dataSource->getBuffer(); |
| 94 | const auto memory = static_cast<const unsigned char *>( buffer->getData() ); |
| 95 | const size_t size = buffer->getSize(); |
| 96 | |
| 97 | const char *error = nullptr; |
| 98 | status = ParseEXRHeaderFromMemory( mExrHeader.get(), &version, memory, size, &error ); |
| 99 | if( status != TINYEXR_SUCCESS ) { |
| 100 | string errorMsg = error ? string( "Failed to parse OpenEXR header; Error message: " ) + error : "Failed to parse OpenEXR header"; |
| 101 | if( error ) |
| 102 | FreeEXRErrorMessage( error ); |
| 103 | throw ImageIoExceptionFailedLoadTinyExr( errorMsg ); |
| 104 | } |
| 105 | |
| 106 | status = LoadEXRImageFromMemory( mExrImage.get(), mExrHeader.get(), memory, size, &error ); |
| 107 | if( status != TINYEXR_SUCCESS ) { |
| 108 | string errorMsg = error ? string( "Failed to parse OpenEXR file; Error message: " ) + error : "Failed to parse OpenEXR file"; |
nothing calls this directly
no test coverage detected