Go to the documentation of this file.00001 #ifndef OPENTISSUE_GPU_IMAGE_IMAGE_ALPHA_MODULATION_H
00002 #define OPENTISSUE_GPU_IMAGE_IMAGE_ALPHA_MODULATION_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/gpu/image/image.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace image
00017 {
00018
00028 void alpha_modulation(
00029 OpenTissue::image::Image<unsigned char> & image
00030 , OpenTissue::image::Image<unsigned char> const & alpha
00031 )
00032 {
00033 using std::min;
00034
00035 assert(image.channels()==4 || !"alpha_modulation(): image must have four channels");
00036 assert(alpha.channels()==1 || !"alpha_modulation(): alpha must have 1 channels");
00037 assert( image.width() == alpha.width() || !"alpha_modulation(): alpha and image dimensions did not fit");
00038 assert( image.height() == alpha.height() || !"alpha_modulation(): alpha and image dimensions did not fit");
00039
00040 unsigned char * ival = static_cast<unsigned char*>( image.get_data() );
00041 unsigned char const * aval = static_cast<unsigned char const *>( alpha.get_data() );
00042
00043 size_t pixels = image.width()*image.height();
00044
00045 float factor = 1.0f/255.0f;
00046
00047 for(size_t i=0;i<pixels;++i)
00048 {
00049 float a = factor*(*aval++);
00050 float ir = factor*(*(ival));
00051 float ig = factor*(*(ival+1));
00052 float ib = factor*(*(ival+2));
00053 float ia = factor*(*(ival+3));
00054
00055 *ival++ = static_cast<unsigned char>( min(ir,1.0f)*255.0f );
00056 *ival++ = static_cast<unsigned char>( min(ig,1.0f)*255.0f );
00057 *ival++ = static_cast<unsigned char>( min(ib,1.0f)*255.0f );
00058 *ival++ = static_cast<unsigned char>( min(ia*a,1.0f)*255.0f );
00059 }
00060 }
00061
00062 }
00063 }
00064
00065
00066 #endif