| 265 | } |
| 266 | |
| 267 | ImageTargetFileTinyExr::ImageTargetFileTinyExr( DataTargetRef dataTarget, ImageSourceRef imageSource, ImageTarget::Options options, const std::string & /*extensionData*/ ) |
| 268 | { |
| 269 | if( ! dataTarget->providesFilePath() ) { |
| 270 | throw ImageIoExceptionFailedWrite( "ImageTargetFileTinyExr only supports writing to files." ); |
| 271 | } |
| 272 | |
| 273 | mFilePath = dataTarget->getFilePath(); |
| 274 | |
| 275 | setSize( imageSource->getWidth(), imageSource->getHeight() ); |
| 276 | ImageIo::ColorModel cm = options.isColorModelDefault() ? imageSource->getColorModel() : options.getColorModel(); |
| 277 | |
| 278 | switch( cm ) { |
| 279 | case ImageIo::ColorModel::CM_RGB: |
| 280 | mNumComponents = ( imageSource->hasAlpha() ) ? 4 : 3; |
| 281 | setColorModel( ImageIo::ColorModel::CM_RGB ); |
| 282 | setChannelOrder( ( mNumComponents == 3 ) ? ImageIo::ChannelOrder::BGR : ImageIo::ChannelOrder::ABGR ); |
| 283 | if( mNumComponents == 3 ) |
| 284 | mChannelNames = { "B", "G", "R" }; |
| 285 | else |
| 286 | mChannelNames = { "A", "B", "G", "R" }; |
| 287 | break; |
| 288 | case ImageIo::ColorModel::CM_GRAY: |
| 289 | mNumComponents = ( imageSource->hasAlpha() ) ? 2 : 1; |
| 290 | setColorModel( ImageIo::ColorModel::CM_GRAY ); |
| 291 | setChannelOrder( ( mNumComponents == 2 ) ? ImageIo::ChannelOrder::YA : ImageIo::ChannelOrder::Y ); |
| 292 | if( mNumComponents == 2 ) |
| 293 | mChannelNames = { "Y", "A" }; |
| 294 | else |
| 295 | mChannelNames = { "Y" }; |
| 296 | break; |
| 297 | default: |
| 298 | throw ImageIoExceptionIllegalColorModel(); |
| 299 | } |
| 300 | |
| 301 | // TODO: consider supporting half float and uint types as well |
| 302 | setDataType( ImageIo::DataType::FLOAT32 ); |
| 303 | mData.resize( mHeight * mWidth * mNumComponents ); |
| 304 | } |
| 305 | |
| 306 | void *ImageTargetFileTinyExr::getRowPointer( int32_t row ) |
| 307 | { |
nothing calls this directly
no test coverage detected