PDA

View Full Version : Qt - change the RGB values



t-basic
26th October 2011, 09:04
Hello!
I'm just start with Qt and C++. I want to write a function to manipulate the image contrast. I know I need to change each component of the pixel, separate Red Green and Blue. Each RGB component is 4 bytes. So the image is generally the form of an array: BGRABGRA ... Blue, Green, Red and Alpha. In Qt documentation I found that, the components of a pixel can be referenced using a QRgb. Below I have written the function of brightness.



int minmax(int v, int min, int max)
{
if(v>max) return max;
if(v<min) return min;
return v;
}


void Manipulations::brightness(QImage* image, int v)
{
uchar *point;
for(int y=0; y<image->height(); ++y)
{
point = image->scanLine(y); //pointer to the next image row
for(int x=0; x<4*image->width(); ++x)
{
point[x] = minmax(point[x] + v, 0, 255); //to the next byte (components) is added the value "v" causing brightening the image
}
}
}



I learned that instead of using the pointer to a single byte (UCHAR * point) may be the result of the function scanLine (int) or bits () cast to the type (QRgb *) and the components can be accessed using int qRed (QRgb), int qGreen (QRgb), int qBlue (QRgb) and the value of this pixel replaced by a new object QRgb (int red, int green, int blue). Can anyone help me with contrast function? I am a beginner of OOP.

I apologize for my poor English.

high_flyer
26th October 2011, 11:55
Can anyone help me with contrast function?
What is exactly the problem you have?