Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Graphics code snippet to bleach a Extctrls::TImage. To darken a Extctrls::TImage use Darken.
The tool BarbaImage uses Bleach as one of its image operations.
#include <Extctrls.hpp>
//Bleach an image by fraction f
// * f = 0.0 denotes no bleaching (image untouched)
// * f = 1.0 denotes max bleaching (image white)
//From http://www.richelbilderbeek.nl/CppBleach.htm
const Extctrls::TImage * const source,
Extctrls::TImage * const target)
{
assert(f >= 0.0);
assert(f <= 1.0);
assert(source!=0 && "Image is NULL");
assert(source->Picture->Bitmap!=0 && "Image bitmap is NULL");
assert(source->Picture->Bitmap->PixelFormat == pf24bit && "Image bitmap must be 24 bit");
assert(target!=0 && "Image is NULL");
assert(target->Picture->Bitmap!=0 && "Image bitmap is NULL");
assert(target->Picture->Bitmap->PixelFormat == pf24bit && "Image bitmap must be 24 bit");
//Get the width and height from the source
const int width = source->Picture->Bitmap->Width;
const int height = source->Picture->Bitmap->Height;
//Set the target's width and height
target->Picture->Bitmap->Width = width;
target->Picture->Bitmap->Height = height;
{
const unsigned char * lineSource
= static_cast<const unsigned char *>(
source->Picture->Bitmap->ScanLine[y]);
= static_cast<unsigned char *>(
target->Picture->Bitmap->ScanLine[y]);
{
const int r = lineSource[x*3+2]; //Red;
const int g = lineSource[x*3+1]; //Green;
const int b = lineSource[x*3+0]; //Blue;
const int max_dist_r = 256 - r;
const int max_dist_g = 256 - g;
const int max_dist_b = 256 - b;
const double dist_r = static_cast<double>(max_dist_r) * f;
const double dist_g = static_cast<double>(max_dist_g) * f;
const double dist_b = static_cast<double>(max_dist_b) * f;
const int new_r = r + static_cast<int>(dist_r);
const int new_g = g + static_cast<int>(dist_g);
const int new_b = b + static_cast<int>(dist_b);
assert(new_r >= 0);
assert(new_r < 256);
assert(new_g >= 0);
assert(new_g < 256);
assert(new_b >= 0);
assert(new_b < 256);
lineTarget[x*3+2] = new_r; //Red
lineTarget[x*3+1] = new_g; //Green
lineTarget[x*3+0] = new_b; //Blue
}
}
}
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.