0

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);
Newbie
  • 145
  • 2
  • 7
  • 23
  • do you have the code for "I can do linear tone curve just fine, but when it comes to drawing gamma tone curve", or a link? – desgraci Sep 05 '13 at 14:37

1 Answers1

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.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • Hi Mark, do you have an example? To add on, i've been drawing graphs with the X and Y axis based on height and width, i do not know where do the 255 comes in. – Newbie Jan 26 '12 at 06:42
  • Hi Mark, I did execute the formula inside. Unfortunately, it does not work, but i do know that is the formula, thank you! – Newbie Jan 26 '12 at 14:27
  • I was assuming that you wanted to apply the gamma to values in the range 0 to 255, as are common in image processing. The other common possibility is the range 0 to 1, and that formula would be `y = round(pow(x, gamma) * height)`. – Mark Ransom Jan 26 '12 at 14:33
  • I do not know the reason why, but it does not work. For linear graph, it works. This is troubling me for a whole day already – Newbie Jan 26 '12 at 14:46
  • It works, finally! I do not know why it works now, i think i was too tired implementing the algorithm yesterday! – Newbie Jan 26 '12 at 22:53