简体   繁体   中英

How can I decrease the brightness by coming to original form of image in C++ without using opencv?

How can I decrease the brightness by reading the original form of image in C++, if I don´t want to use opencv or something else? I tried many things and this is what I got. I deeply appreciate your help.

void MyArea::on_brightness_increase()
{
//  m_refpixbuf1 = m_refpiximage->copy();
    nPixelvalue = m_refpixbuf1->get_pixels();

    wincenter = wincenter + 10;
    pixmax2 = wincenter + (winwidth / 2);
    pixmin2 = wincenter - (winwidth / 2);

    nimage_height = m_refpiximage->get_height();
    nimage_width = m_refpiximage->get_width();
    nimage_size = nimage_height*nimage_width*3;


    for(int i=0;i<nimage_size;i++)
    {
        if(nPixelvalue[i]<=250)
            nPixelvalue[i] +=5;
        else
            nPixelvalue[i] = 255;

        if(nPixelvalue[i+1] <= 250)
            nPixelvalue[i+1] +=5;
        else
            nPixelvalue[i+1] = 255;

        if(nPixelvalue[i+2] <= 250)
            nPixelvalue[i+2] +=5;
        else
            nPixelvalue[i+2] = 255;
    }
    get_window()->invalidate(false);
}

void MyArea::on_brightness_decrease()
{
//  m_refpixbuf1 = m_refpiximage->copy();
    nPixelvalue2 = m_refpixbuf3->get_pixels();

    wincenter = wincenter - 10;

    pixmax2 = wincenter + (winwidth / 2);
    pixmin2 = wincenter - (winwidth / 2);

    nimage_height = m_refpiximage->get_height();
    nimage_width = m_refpiximage->get_width();
    nimage_size = nimage_height*nimage_width*3;

    for (int i=0;i<nimage_size;i++)
    {
        if(nPixelvalue2[i] >=5)
            nPixelvalue2[i] -=5;
        else
            nPixelvalue2[i] = 0;

        if(nPixelvalue2[i+1] >=5)
            nPixelvalue2[i+1] -=5;
        else
            nPixelvalue2[i] = 0;
        if(nPixelvalue2[i+2] >=5)
            nPixelvalue2[i+2] -=5;
        else
            nPixelvalue2[i+2] = 0;
    }
    get_window()->invalidate(false);
}

First, what you need to do is create a struct for your pixels for your image class

struct pixel {
    public float red; // 0 = 0, 1 = 255
    public float blue; // 0 = 0, 1 = 255
    public float green; // 0 = 0, 1 = 255
    // appropriate methods, constructors
    // if you don't want hdr pixels, cap your members at 1.0
}

You then want to create a method that increases brightness. see here for the formula of brightness:

https://en.wikipedia.org/wiki/Brightness

配方亮度

Think of a method so that you use to increase or decrease brightness. Add it to the pixel struct, and call it for each pixel in your image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM