
在計(jì)算機(jī)圖形學(xué)領(lǐng)域時(shí)常聽到gamma correction ,gamma correction 控制了圖像整體的亮度,reproduce colors也需要gamma correction的一些理論知識(shí),gamma correction不僅僅是控制了圖像的亮度,而且還控制了RGB各個(gè)分量的比例,我們知道渲染器是線性的,而顯示器并非線性,其實(shí)電子打在屏幕上從而產(chǎn)生亮點(diǎn),電子的運(yùn)動(dòng)受電壓控制,這兩者是指數(shù)關(guān)系的,所以產(chǎn)生的亮度也跟電壓成指數(shù)關(guān)系,而發(fā)送給顯示器的voltages范圍是0~1:


對(duì)于我們輸入的圖像,如果直接顯示,那么就會(huì)篇暗,根據(jù)已知電壓與顯示亮度的關(guān)系,進(jìn)行g(shù)amma correction ,其實(shí)就是對(duì)gamma曲線的修正。一般生產(chǎn)廠家不加說(shuō)明,他們的伽碼值大約等于2.5.


代碼:
gammaCorrection = 1 / gamma
colour = GetPixelColour(x, y)
newRed = 255 * (Red(colour) / 255) ^ gammaCorrection
newGreen = 255 * (Green(colour) / 255) ^ gammaCorrection
newBlue = 255 * (Blue(colour) / 255) ^ gammaCorrection
PutPixelColour(x, y) = RGB(newRed, newGreen, newBlue)
知道m(xù)onitor不是一個(gè)線性的,那么我們?cè)谶M(jìn)行顏色加法時(shí),我們得到的顏色并不是真正的顏色值的相加,比如gamma factor是2.2
red = add (r1, r2);
red= add (0.235,0.156);
對(duì)于一個(gè)線性設(shè)備,red = 0.391,對(duì)于未經(jīng)修正的montior red=0.126;
因?yàn)橛幸粋€(gè)冪函數(shù)的運(yùn)算:C_out = C_in2.2
現(xiàn)在使用gamma correction :C_corrected= C_out1.0/2.2
0.3912.2 = 0.126
0.1261.0/2.2 = 0.39
我們看到使用伽碼校正以后我們能得到我們預(yù)想的顏色值0.39.






There are two ways to do gamma correction:
- Using the renderer. The renderer (the graphics card or GPU) is a linear device. Modern renderers have the support of gamma correction via sRGB textures and framebuffer formats. See the following OpenGL extensions for more details: GL_ARB_framebuffer_sRGB and GL_EXT_texture_sRGB. With these extensions you can get gamma corrected values for free but gamma correction factor is set to 2.2. You can’t change it.
- Using a software gamma correction. The gamma correction is applied to the final scene buffer thanks to apixel shader and you can set the gamma correction you want.
In OpenGL, using GL_ARB_framebuffer_sRGB is really simple: once your FBO is bound, just enable the sRGB space with
glEnable(GL_FRAMEBUFFER_SRGB);
gamma-correction