From c0ac01c5766e9d8e339256f77a70c6dd1a9eaeaa Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 9 Dec 2008 09:25:12 +0000 Subject: [PATCH] Added setImageToColour function --- include/osgVolume/ImageUtils | 3 +++ src/osgVolume/ImageUtils.cpp | 32 +++++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/osgVolume/ImageUtils b/include/osgVolume/ImageUtils index 9ed63c99e..a49f72060 100644 --- a/include/osgVolume/ImageUtils +++ b/include/osgVolume/ImageUtils @@ -129,6 +129,9 @@ extern OSGVOLUME_EXPORT bool offsetAndScaleImage(osg::Image* image, const osg::V /** Compute source image to destination image.*/ extern OSGVOLUME_EXPORT bool copyImage(const osg::Image* srcImage, int src_s, int src_t, int src_r, int width, int height, int depth, osg::Image* destImage, int dest_s, int dest_t, int dest_r, bool doRescale = false); + +/** Compute the min max colour values in the image.*/ +extern OSGVOLUME_EXPORT bool clearImageToColor(osg::Image* image, const osg::Vec4& colour); } diff --git a/src/osgVolume/ImageUtils.cpp b/src/osgVolume/ImageUtils.cpp index 831fba249..385886589 100644 --- a/src/osgVolume/ImageUtils.cpp +++ b/src/osgVolume/ImageUtils.cpp @@ -17,8 +17,6 @@ #include #include -using namespace osgVolume; - namespace osgVolume { @@ -87,9 +85,7 @@ struct OffsetAndScaleOperator } }; -} - -bool osgVolume::computeMinMax(const osg::Image* image, osg::Vec4& minValue, osg::Vec4& maxValue) +bool computeMinMax(const osg::Image* image, osg::Vec4& minValue, osg::Vec4& maxValue) { if (!image) return false; @@ -111,7 +107,7 @@ bool osgVolume::computeMinMax(const osg::Image* image, osg::Vec4& minValue, osg: minValue.a()<=maxValue.a(); } -bool osgVolume::offsetAndScaleImage(osg::Image* image, const osg::Vec4& offset, const osg::Vec4& scale) +bool offsetAndScaleImage(osg::Image* image, const osg::Vec4& offset, const osg::Vec4& scale) { if (!image) return false; @@ -199,7 +195,7 @@ struct WriteRowOperator 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(); } }; -bool osgVolume::copyImage(const osg::Image* srcImage, int src_s, int src_t, int src_r, int width, int height, int depth, +bool copyImage(const osg::Image* srcImage, int src_s, int src_t, int src_r, int width, int height, int depth, osg::Image* destImage, int dest_s, int dest_t, int dest_r, bool doRescale) { if ((src_s+width) > (dest_s + destImage->s())) @@ -323,3 +319,25 @@ bool osgVolume::copyImage(const osg::Image* srcImage, int src_s, int src_t, int } + +struct SetToColourOperator +{ + SetToColourOperator(const osg::Vec4& colour): + _colour(colour) {} + + inline void luminance(float& l) const { l = (_colour.r()+_colour.g()+_colour.b())*0.333333; } + inline void alpha(float& a) const { a = _colour.a(); } + inline void luminance_alpha(float& l,float& a) const { l = (_colour.r()+_colour.g()+_colour.b())*0.333333; a = _colour.a(); } + inline void rgb(float& r,float& g,float& b) const { r = _colour.r(); g = _colour.g(); b = _colour.b(); } + inline void rgba(float& r,float& g,float& b,float& a) const { r = _colour.r(); g = _colour.g(); b = _colour.b(); a = _colour.a(); } + + osg::Vec4 _colour; +}; + +bool clearImageToColor(osg::Image* image, const osg::Vec4& colour) +{ + modifyImage(image, SetToColourOperator(colour)); +} + +} +