| 52 | } |
| 53 | |
| 54 | ImageTargetFileStbImage::ImageTargetFileStbImage( DataTargetRef dataTarget, ImageSourceRef imageSource, ImageTarget::Options options, const std::string &extensionData ) |
| 55 | : mDataTarget( dataTarget ) |
| 56 | { |
| 57 | if( ! ( mDataTarget->providesFilePath() || mDataTarget->getStream() ) ) { |
| 58 | throw ImageIoExceptionFailedWrite( "No file path or stream provided" ); |
| 59 | } |
| 60 | |
| 61 | setSize( imageSource->getWidth(), imageSource->getHeight() ); |
| 62 | ImageIo::ColorModel cm = options.isColorModelDefault() ? imageSource->getColorModel() : options.getColorModel(); |
| 63 | |
| 64 | switch( cm ) { |
| 65 | case ImageIo::ColorModel::CM_RGB: |
| 66 | mNumComponents = ( imageSource->hasAlpha() ) ? 4 : 3; |
| 67 | setColorModel( ImageIo::ColorModel::CM_RGB ); |
| 68 | setChannelOrder( ( mNumComponents == 4 ) ? ImageIo::ChannelOrder::RGBA : ImageIo::ChannelOrder::RGB ); |
| 69 | break; |
| 70 | case ImageIo::ColorModel::CM_GRAY: |
| 71 | mNumComponents = ( imageSource->hasAlpha() ) ? 2 : 1; |
| 72 | setColorModel( ImageIo::ColorModel::CM_GRAY ); |
| 73 | setChannelOrder( ( mNumComponents == 2 ) ? ImageIo::ChannelOrder::YA : ImageIo::ChannelOrder::Y ); |
| 74 | break; |
| 75 | default: |
| 76 | throw ImageIoExceptionIllegalColorModel(); |
| 77 | } |
| 78 | |
| 79 | mExtension = extensionData; |
| 80 | if( mExtension == "hdr" ) { // Radiance files are always float* |
| 81 | setDataType( ImageIo::DataType::FLOAT32 ); |
| 82 | mRowBytes = mNumComponents * imageSource->getWidth() * sizeof(float); |
| 83 | } |
| 84 | else { |
| 85 | setDataType( ImageIo::DataType::UINT8 ); |
| 86 | mRowBytes = mNumComponents * imageSource->getWidth() * sizeof(uint8_t); |
| 87 | } |
| 88 | |
| 89 | if( mDataTarget->providesFilePath() ) { |
| 90 | mFilePath = dataTarget->getFilePath(); |
| 91 | } |
| 92 | |
| 93 | mData = std::unique_ptr<uint8_t[]>( new uint8_t[mHeight * mRowBytes] ); |
| 94 | } |
| 95 | |
| 96 | void* ImageTargetFileStbImage::getRowPointer( int32_t row ) |
| 97 | { |
nothing calls this directly
no test coverage detected