
在計算機圖形學領域時常聽到gamma correction ,gamma correction 控制了圖像整體的亮度,reproduce colors也需要gamma correction的一些理論知識,gamma correction不僅僅是控制了圖像的亮度,而且還控制了RGB各個分量的比例,我們知道渲染器是線性的,而顯示器并非線性,其實電子打在屏幕上從而產生亮點,電子的運動受電壓控制,這兩者是指數關系的,所以產生的亮度也跟電壓成指數關系,而發送給顯示器的voltages范圍是0~1:


對于我們輸入的圖像,如果直接顯示,那么就會篇暗,根據已知電壓與顯示亮度的關系,進行gamma correction ,其實就是對gamma曲線的修正。一般生產廠家不加說明,他們的伽碼值大約等于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)
知道monitor不是一個線性的,那么我們在進行顏色加法時,我們得到的顏色并不是真正的顏色值的相加,比如gamma factor是2.2
red = add (r1, r2);
red= add (0.235,0.156);
對于一個線性設備,red = 0.391,對于未經修正的montior red=0.126;
因為有一個冪函數的運算:C_out = C_in2.2
現在使用gamma correction :C_corrected= C_out1.0/2.2
0.3912.2 = 0.126
0.1261.0/2.2 = 0.39
我們看到使用伽碼校正以后我們能得到我們預想的顏色值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