问题
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