Changeset 13041 for OpenSceneGraph/trunk/src/osg/ImageUtils.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osg/ImageUtils.cpp (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osg/ImageUtils.cpp
r12895 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 34 34 _amin(FLT_MAX), 35 35 _amax(-FLT_MAX) {} 36 36 37 37 float _rmin, _rmax, _gmin, _gmax, _bmin, _bmax, _amin, _amax; 38 38 39 inline void luminance(float l) { rgba(l,l,l,l); } 40 inline void alpha(float a) { rgba(1.0f,1.0f,1.0f,a); } 41 inline void luminance_alpha(float l,float a) { rgba(l,l,l,a); } 39 inline void luminance(float l) { rgba(l,l,l,l); } 40 inline void alpha(float a) { rgba(1.0f,1.0f,1.0f,a); } 41 inline void luminance_alpha(float l,float a) { rgba(l,l,l,a); } 42 42 inline void rgb(float r,float g,float b) { rgba(r,g,b,1.0f); } 43 43 inline void rgba(float r,float g,float b,float a) 44 44 { 45 _rmin = osg::minimum(r,_rmin); 46 _rmax = osg::maximum(r,_rmax); 47 _gmin = osg::minimum(g,_gmin); 48 _gmax = osg::maximum(g,_gmax); 49 _bmin = osg::minimum(b,_bmin); 50 _bmax = osg::maximum(b,_bmax); 51 _amin = osg::minimum(a,_amin); 45 _rmin = osg::minimum(r,_rmin); 46 _rmax = osg::maximum(r,_rmax); 47 _gmin = osg::minimum(g,_gmin); 48 _gmax = osg::maximum(g,_gmax); 49 _bmin = osg::minimum(b,_bmin); 50 _bmax = osg::maximum(b,_bmax); 51 _amin = osg::minimum(a,_amin); 52 52 _amax = osg::maximum(a,_amax); 53 53 } … … 60 60 { 61 61 OffsetAndScaleOperator(const osg::Vec4& offset, const osg::Vec4& scale): 62 _offset(offset), 62 _offset(offset), 63 63 _scale(scale) {} 64 64 … … 66 66 osg::Vec4 _scale; 67 67 68 inline void luminance(float& l) const { l= _offset.r() + l*_scale.r(); } 69 inline void alpha(float& a) const { a = _offset.a() + a*_scale.a(); } 68 inline void luminance(float& l) const { l= _offset.r() + l*_scale.r(); } 69 inline void alpha(float& a) const { a = _offset.a() + a*_scale.a(); } 70 70 inline void luminance_alpha(float& l,float& a) const 71 71 { 72 l= _offset.r() + l*_scale.r(); 72 l= _offset.r() + l*_scale.r(); 73 73 a = _offset.a() + a*_scale.a(); 74 } 74 } 75 75 inline void rgb(float& r,float& g,float& b) const 76 76 { 77 r = _offset.r() + r*_scale.r(); 78 g = _offset.g() + g*_scale.g(); 77 r = _offset.r() + r*_scale.r(); 78 g = _offset.g() + g*_scale.g(); 79 79 b = _offset.b() + b*_scale.b(); 80 80 } 81 81 inline void rgba(float& r,float& g,float& b,float& a) const 82 82 { 83 r = _offset.r() + r*_scale.r(); 84 g = _offset.g() + g*_scale.g(); 83 r = _offset.r() + r*_scale.r(); 84 g = _offset.g() + g*_scale.g(); 85 85 b = _offset.b() + b*_scale.b(); 86 86 a = _offset.a() + a*_scale.a(); … … 92 92 if (!image) return false; 93 93 94 osg::FindRangeOperator rangeOp; 94 osg::FindRangeOperator rangeOp; 95 95 readImage(image, rangeOp); 96 96 minValue.r() = rangeOp._rmin; … … 103 103 maxValue.b() = rangeOp._bmax; 104 104 maxValue.a() = rangeOp._amax; 105 106 return minValue.r()<=maxValue.r() && 105 106 return minValue.r()<=maxValue.r() && 107 107 minValue.g()<=maxValue.g() && 108 108 minValue.b()<=maxValue.b() && … … 115 115 116 116 modifyImage(image,OffsetAndScaleOperator(offset, scale)); 117 117 118 118 return true; 119 119 } … … 175 175 mutable std::vector<osg::Vec4> _colours; 176 176 mutable unsigned int _pos; 177 178 inline void luminance(float l) const { rgba(l,l,l,1.0f); } 179 inline void alpha(float a) const { rgba(1.0f,1.0f,1.0f,a); } 180 inline void luminance_alpha(float l,float a) const { rgba(l,l,l,a); } 177 178 inline void luminance(float l) const { rgba(l,l,l,1.0f); } 179 inline void alpha(float a) const { rgba(1.0f,1.0f,1.0f,a); } 180 inline void luminance_alpha(float l,float a) const { rgba(l,l,l,a); } 181 181 inline void rgb(float r,float g,float b) const { rgba(r,g,b,1.0f); } 182 182 inline void rgba(float r,float g,float b,float a) const { _colours[_pos++].set(r,g,b,a); } … … 190 190 std::vector<osg::Vec4> _colours; 191 191 mutable unsigned int _pos; 192 193 inline void luminance(float& l) const { l = _colours[_pos++].r(); } 194 inline void alpha(float& a) const { a = _colours[_pos++].a(); } 195 inline void luminance_alpha(float& l,float& a) const { l = _colours[_pos].r(); a = _colours[_pos++].a(); } 192 193 inline void luminance(float& l) const { l = _colours[_pos++].r(); } 194 inline void alpha(float& a) const { a = _colours[_pos++].a(); } 195 inline void luminance_alpha(float& l,float& a) const { l = _colours[_pos].r(); a = _colours[_pos++].a(); } 196 196 inline void rgb(float& r,float& g,float& b) const { r = _colours[_pos].r(); g = _colours[_pos].g(); b = _colours[_pos].b(); } 197 197 inline void rgba(float& r,float& g,float& b,float& a) const { r = _colours[_pos].r(); g = _colours[_pos].g(); b = _colours[_pos].b(); a = _colours[_pos++].a(); } … … 279 279 unsigned char* destData = destImage->data(dest_s, dest_t+row, dest_r+slice); 280 280 unsigned int numComponents = osg::Image::computeNumComponents(destImage->getPixelFormat()); 281 281 282 282 _copyRowAndScale(srcData, srcImage->getDataType(), destData, destImage->getDataType(), (width*numComponents), scale); 283 283 } 284 284 } 285 285 286 286 return true; 287 287 } … … 291 291 //OSG_NOTICE<<"copyImage("<<srcImage<<", "<<src_s<<", "<< src_t<<", "<<src_r<<", "<<width<<", "<<height<<", "<<depth<<std::endl; 292 292 //OSG_NOTICE<<" "<<destImage<<", "<<dest_s<<", "<< dest_t<<", "<<dest_r<<", "<<doRescale<<")"<<std::endl; 293 293 294 294 RecordRowOperator readOp(width); 295 295 WriteRowOperator writeOp; … … 303 303 readOp._pos = 0; 304 304 writeOp._pos = 0; 305 305 306 306 // read the pixels into readOp's _colour array 307 307 readRow(width, srcImage->getPixelFormat(), srcImage->getDataType(), srcImage->data(src_s,src_t+row,src_r+slice), readOp); 308 308 309 309 // pass readOp's _colour array contents over to writeOp (note this is just a pointer swap). 310 310 writeOp._colours.swap(readOp._colours); 311 311 312 312 modifyRow(width, destImage->getPixelFormat(), destImage->getDataType(), destImage->data(dest_s, dest_t+row,dest_r+slice), writeOp); 313 313 … … 316 316 } 317 317 } 318 318 319 319 return false; 320 320 } … … 328 328 _colour(colour) {} 329 329 330 inline void luminance(float& l) const { l = (_colour.r()+_colour.g()+_colour.b())*0.333333; } 331 inline void alpha(float& a) const { a = _colour.a(); } 330 inline void luminance(float& l) const { l = (_colour.r()+_colour.g()+_colour.b())*0.333333; } 331 inline void alpha(float& a) const { a = _colour.a(); } 332 332 inline void luminance_alpha(float& l,float& a) const { l = (_colour.r()+_colour.g()+_colour.b())*0.333333; a = _colour.a(); } 333 333 inline void rgb(float& r,float& g,float& b) const { r = _colour.r(); g = _colour.g(); b = _colour.b(); } … … 342 342 343 343 modifyImage(image, SetToColourOperator(colour)); 344 344 345 345 return true; 346 346 } … … 479 479 pixelFormat==GL_BGRA) 480 480 { 481 481 482 482 int num_s = minimum(image->s(), image_3d->s()); 483 483 int num_t = minimum(image->t(), image_3d->t()); … … 493 493 } 494 494 } 495 495 496 496 return image_3d.release(); 497 497 } … … 507 507 inline void rgba(float& r,float& g,float& b,float& a) const { float l = (r+g+b)*0.3333333; a *= l;} 508 508 }; 509 509 510 510 osg::Image* createImage3DWithAlpha(const ImageList& imageList, 511 511 int s_maximumImageSize, … … 523 523 modulateAlphaByLuminance = true; 524 524 } 525 525 526 526 osg::ref_ptr<osg::Image> image = createImage3D(imageList, 527 527 desiredPixelFormat,
