C++ how to draw a tone curve (gamma) to graph using setpixel function

旧城冷巷雨未停 提交于 2019-12-12 02:46:15

问题


As title mentions. I'm trying to draw a gamma tone curve but i do not have any idea how to do it. I can do linear tone curve just fine, but when it comes to drawing gamma tone curve, i totally just lose it. As referenced from http://www.mediachance.com/pseam/help/curves.html (1st or 2nd drawing)

Codes as below

#include <math.h>

static COLORREF red=RGB(255,0,0);
static COLORREF blue=RGB(0,0,255);
static COLORREF green=RGB(0,255,0);

The part where i should incorporate in to draw the gamma tone curve

for(int y=0; y<bih.biHeight; y++)
            {                       
                for(int x=0; x<bih.biWidth; x++)
                {   
                SetPixel(hdc, x, bih.biHeight-x, red);
}

// The X axis of the graph

HPEN hLinePen1;
                COLORREF qLineColor1;
                qLineColor1 = RGB(255, 0, 0);
                hLinePen1 = CreatePen(PS_SOLID, 2, qLineColor1);
                hPenOld1 = (HPEN)SelectObject(hdc, hLinePen1);
                line(hdc,0, bih.biHeight, bih.biWidth, bih.biHeight);
                SelectObject(hdc, hPenOld1);
                DeleteObject(hLinePen1);
// The Y axis of the graph

                HPEN hLinePen2;
                COLORREF qLineColor2;
                qLineColor2 = RGB(255, 0, 0);
                hLinePen2 = CreatePen(PS_SOLID, 2, qLineColor2);
                hPenOld2 = (HPEN)SelectObject(hdc, hLinePen2);
                line(hdc,0, bih.biHeight, 0, bih.biWidth-bih.biHeight);
                SelectObject(hdc, hPenOld2);
                DeleteObject(hLinePen2);

回答1:


Drawing a graph should be simple. For each X point you have, calculate the corresponding Y value - in the case of Gamma on a scale of 0-255 that will be y = round(pow(x/255., gamma)*255). Then just draw a line from the previous point to the current point.



来源:https://stackoverflow.com/questions/9014685/c-how-to-draw-a-tone-curve-gamma-to-graph-using-setpixel-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!