| 154 | |
| 155 | template< typename T > |
| 156 | inline void merge( bool firstImage, size_t &pixelCount, |
| 157 | const ImagePrimitive * img, ImagePrimitive * outImg, |
| 158 | const Imath::Box2f &windowing, float intensityMultiplier, |
| 159 | FloatVectorData * outR, FloatVectorData * outG, FloatVectorData * outB, FloatVectorData * outA ) |
| 160 | { |
| 161 | |
| 162 | const TypedData< std::vector< T > > *inR = img->getChannel< T >( "R" ); |
| 163 | const TypedData< std::vector< T > > *inG = img->getChannel< T >( "G" ); |
| 164 | const TypedData< std::vector< T > > *inB = img->getChannel< T >( "B" ); |
| 165 | |
| 166 | if ( firstImage ) |
| 167 | { |
| 168 | pixelCount = inR->readable().size(); |
| 169 | outR->writable().resize( pixelCount, 0 ); |
| 170 | outG->writable().resize( pixelCount, 0 ); |
| 171 | outB->writable().resize( pixelCount, 0 ); |
| 172 | outA->writable().resize( pixelCount, 0 ); |
| 173 | outImg->setDisplayWindow( img->getDisplayWindow() ); |
| 174 | outImg->setDataWindow( img->getDataWindow() ); |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | if ( pixelCount != inR->readable().size() || |
| 179 | pixelCount != inG->readable().size() || |
| 180 | pixelCount != inB->readable().size() ) |
| 181 | { |
| 182 | throw Exception( "Images are not of the same resolution!!" ); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | const T *ptrInR = &(inR->readable()[0]); |
| 187 | const T *ptrInG = &(inG->readable()[0]); |
| 188 | const T *ptrInB = &(inB->readable()[0]); |
| 189 | float *ptrOutR = &(outR->writable()[0]); |
| 190 | float *ptrOutG = &(outG->writable()[0]); |
| 191 | float *ptrOutB = &(outB->writable()[0]); |
| 192 | float *ptrOutA = &(outA->writable()[0]); |
| 193 | |
| 194 | for ( size_t i = 0; i < pixelCount; i++ ) |
| 195 | { |
| 196 | float intensity = (*ptrInR + *ptrInG + *ptrInB) / 3.0; |
| 197 | float weight = smoothstep( windowing.min[0], windowing.min[1], intensity ); |
| 198 | if ( !firstImage ) |
| 199 | { |
| 200 | weight *= 1.0f - smoothstep( windowing.max[0], windowing.max[1], intensity ); |
| 201 | } |
| 202 | float m = weight * intensityMultiplier; |
| 203 | *ptrOutR += *ptrInR * m; |
| 204 | *ptrOutG += *ptrInG * m; |
| 205 | *ptrOutB += *ptrInB * m; |
| 206 | *ptrOutA += weight; |
| 207 | |
| 208 | ptrInR++; ptrInG++; ptrInB++; |
| 209 | ptrOutR++; ptrOutG++; ptrOutB++; ptrOutA++; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | ObjectPtr HdrMergeOp::doOperation( const CompoundObject * operands ) |
nothing calls this directly
no test coverage detected