(C++) SetPixelClx
February 24, 2017 · View on GitHub
(C++) SetPixelClx
SetPixelClx is a CLX graphics code snippet to set the color of a pixel.
//--------------------------------------------------------------------------- #include <QExtCtrls.hpp> #include <cassert> //--------------------------------------------------------------------------- //From http://www.richelbilderbeek.nl/CppSetPixelClx.htm void SetPixelClx( TImage * const image, const int x, const int y, const unsigned char red, const unsigned char green, const unsigned char blue) { assert(image!=0 && "Image is NULL"); assert(image->Picture->Bitmap!=0 && "Bitmap is NULL"); assert(image->Picture->Bitmap->PixelFormat == pf32bit && "Bitmap must be 32 bit"); assert( x >= 0 && "x coordinat is below zero"); assert( y >= 0 && "y coordinat is below zero"); assert( x < image->Picture->Bitmap->Width && "x coordinat is beyond image width"); assert( y < image->Picture->Bitmap->Height && "y coordinat is beyond image height"); static_cast<unsigned char*>(image->Picture->Bitmap->ScanLine[y])[x*4+2] = red; static_cast<unsigned char*>(image->Picture->Bitmap->ScanLine[y])[x*4+1] = green; static_cast<unsigned char*>(image->Picture->Bitmap->ScanLine[y])[x*4+0] = blue; } //--------------------------------------------------------------------------- //From http://www.richelbilderbeek.nl void SetPixelClx( TImage * const image, const int x, const int y, const TColor color) { assert(image!=0 && "Image is NULL"); assert(image->Picture->Bitmap!=0 && "Bitmap is NULL"); assert(image->Picture->Bitmap->PixelFormat == pf32bit && "Bitmap must be 32 bit"); assert( x >= 0 && "x coordinat is below zero"); assert( y >= 0 && "y coordinat is below zero"); assert( x < image->Picture->Bitmap->Width && "x coordinat is beyond image width"); assert( y < image->Picture->Bitmap->Height && "y coordinat is beyond image height"); static_cast<unsigned char*>(image->Picture->Bitmap->ScanLine[y])[x*4+2] = GetRValue(color); static_cast<unsigned char*>(image->Picture->Bitmap->ScanLine[y])[x*4+1] = GetGValue(color); static_cast<unsigned char*>(image->Picture->Bitmap->ScanLine[y])[x*4+0] = GetBValue(color); }