MCPcopy Create free account
hub / github.com/cinder/Cinder / ImageSourceFileTinyExr

Method ImageSourceFileTinyExr

src/cinder/ImageFileTinyExr.cpp:51–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51ImageSourceFileTinyExr::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";

Callers

nothing calls this directly

Calls 15

InitEXRHeaderFunction · 0.85
InitEXRImageFunction · 0.85
ParseEXRVersionFromFileFunction · 0.85
stringFunction · 0.85
ParseEXRHeaderFromFileFunction · 0.85
FreeEXRErrorMessageFunction · 0.85
LoadEXRImageFromFileFunction · 0.85
ParseEXRHeaderFromMemoryFunction · 0.85
LoadEXRImageFromMemoryFunction · 0.85
setColorModelFunction · 0.85
setChannelOrderFunction · 0.85

Tested by

no test coverage detected