Results 1 to 2 of 2

Thread: Qt - change the RGB values

  1. #1
    Join Date
    Oct 2011
    Posts
    1
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Qt - change the RGB values

    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.

    Qt Code:
    1. int minmax(int v, int min, int max)
    2. {
    3. if(v>max) return max;
    4. if(v<min) return min;
    5. return v;
    6. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void Manipulations::brightness(QImage* image, int v)
    2. {
    3. uchar *point;
    4. for(int y=0; y<image->height(); ++y)
    5. {
    6. point = image->scanLine(y); //pointer to the next image row
    7. for(int x=0; x<4*image->width(); ++x)
    8. {
    9. point[x] = minmax(point[x] + v, 0, 255); //to the next byte (components) is added the value "v" causing brightening the image
    10. }
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 


    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Qt - change the RGB values

    Can anyone help me with contrast function?
    What is exactly the problem you have?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. DockWidgetArea change and layout direction change
    By mstegehu in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2012, 21:24
  2. How to change the values of the pixels in an Qimage?
    By kid17 in forum Qt Programming
    Replies: 8
    Last Post: 23rd November 2008, 20:52
  3. How to read and get the values out of the xml?
    By dark1988 in forum Qt Programming
    Replies: 6
    Last Post: 15th July 2008, 08:41
  4. QSqlTableModel cannot change values
    By raphaelf in forum Newbie
    Replies: 2
    Last Post: 23rd May 2007, 08:01
  5. Replies: 8
    Last Post: 15th May 2007, 09:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.