Gamma correction on i.MX6

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Gamma correction on i.MX6

Gamma correction on i.MX6

Gamma correction

Displays usually presents a nonlinear bright response. For example, a frame buffer value of 100 will almost never give half the brightness of a value of 200. Historically, this is due to the physics of CRT monitors, but newer display technologies emulate the behavior. This is not only for compatibility, but for solid reasons based in the science of human visual perception.

A first-order approximation to the non-linearity of a CRT is:

L = ν ^ γ

where L is the radiance (light intensity) from the display, ν is the voltage applied to the CRT gun (normally proportional to the digital value in the frame buffer), and γ (Greek letter “gamma”) is a constant particular to the monitor; it's the unknown parameter that makes it all work. It usually ranges from about 2.0 to about 2.5. One useful fact is that the gamma curve is linear in log-log space (i.e. logL as a function of logν), and γ is just the slope of that line.

Example of gamma correction

GammaFunctionGraph.png

The dotted line indicates a linear transfer function (γ=1), the framebuffer gamma; the solid line shows how a typical CRT behaves; the dashed line represents the inverse function, the corrected gamma.

How to correct gamma on i.MX using DP (Display Processor)?

Gamma correction can be performed by IC (Image Converter) or DP (Display Processor) sub-blocks inside IPU. Current Linux kernel (3.10) provided by Freescale has an IOCTL that changes the related gamma parameters registers DP_GAMMA_C_SYNC<i> and DP_GAMMA_S_SYNC<i> on Display Processor block.

The steps below shows how to change the gamma using user space applications:

1 - Declare a variable as mxcfb_gamma:

struct mxcfb_gamma fb_gamma;

2 - Enable the gama correction:

fb_gamma.enable = 1;

3 - Set the constk and slopek values, where i = 0 to 15 and x and y are respectively the new constk and slopek constant values:

fb_gamma.constk[i] = x;

fb_gamma.slopek[i] = y;

4 - Open the framebuffer device and call MXCFB_SET_GAMMA:

fd_fb = open("/dev/fb0", O_RDWR, 0)

ioctl(fd_fb, MXCFB_SET_GAMMA, &fb_gamma)

Running the code above will immediately change the gamma value.

Comments

opengl es2.0输出到framebuffer图像失真问题

描述:

    1. 下位机使用Opengl Es2.0进行渲染.
     2. 片选着色器不使用gamma校正, 通过cat /dev/fb0到文件中,发现framebuffer中的图像很明显.
     3. 片选着色器使用gamma校正(gamma值为2.2), 通过cat /dev/fb0到文件中,发现framebuffer中的图像跟原图像差别不大, 每个像素点相差1分量.
     4. framebuffer大小为720p. 不使用gamma校正的帧率是50 fps,使用gamma校正的帧率是20fps, 经过测试发现降低帧率的原因为程序消耗大量时间在交换(函数:eglSwapBuffers)前表面和后台表面上了.
     5. 问题:

   若不使用 GAMMA校正,则图像失真

  若使用GAMMA校正,则 eglSwapBuffers函数消耗的时间非常长,导致帧频很低.


我使用下面链接的方法, 通过测试, 发现没有任何效果. 请帮忙提供一些资料, 最好是一个可以使用的范例.
https://community.freescale.com/docs/DOC-98062
https://github.com/rogeriorps/ipu-examples/commit/8c828cede9f3d3ef329368b2e3d06c604264ec8d

Hello Author,

Can you please guide me, what am i missing in my steps ? 

The red colour on my LCD is little off, it does not exactly looks like perfect red. So i want to calibrate this LCD. And i am looking for the suggestion to do that: 

 

here is gamma correction steps, i already tried and did not get the good result 

Gamma correction on i.MX6 

ipu-examples release notes - v0.1 

 

ipu-examples/framebuffer_ex1.c at master · rogeriorps/ipu-examples · GitHub 

Tried above gamma correction sample code but LCD calibration  become more bad.

 

 

here is my  platform and  setting for LVDS interface :[ Android 4.4  kernel 3.10 ]

LCD panel uses (HX8282 -Source driver / HX8696 -Gate Driver)    ---SPI interface is not out from the Panel for control so i can not set the panel registers. 

====(drivers/video/mxc/mxc_lcdif.c)===================================

static struct fb_videomode lcdif_modedb[] = {                                  

{
/* lcd 1024x600 @ 60 Hz , pixel clk @ 66MHz */
"HiMAX-WSVGA", 60, 1024, 600, 25000 , 155, 160, 8, 23, 4, 4,
FB_SYNC_CLK_LAT_FALL,
FB_VMODE_NONINTERLACED,
0,},

};

===( DTS file ) ===========:

mxcfb1: fb@0 {
compatible = "fsl,mxc_sdc_fb";
disp_dev = "ldb";
interface_pix_fmt = "RGB24";
default_bpp = <24>;/*<24>;*/
int_clk = <0>;
late_init = <0>;
status = "okay";
};

================================================================

Questions : 

1) I used the ipu example code for gamma correction, where Gout array is :

int gout[16] = {0,2,4,8,16,32,64,96,128,160,192,224,255,255,255,255};  this setting do not have any impact on my LCD color, is there any other gout value for my processor imx6dl , which i need to use or How will i calculate these value , any suggestion ?

 

2) Reference manual section: 38.4.9.6 Gamma correction says" Required gamma correction slope for a specific panel/display should be provided by the display manufacturer "  , can you point me,   what will be  the value i  will be suing  from gamma slope in the sample code ? 

 

3) Regarding Data format,    My LCD support RGB stripe(LCD document does not provide good details about this), And "RGB24" is working for me with reasonable  result.  Android HAL is using HAL_PIXEL_FORMAT_RGB_565 . is there anything i need to look from this perspective, In terms of IPU Color space conversion ? 

 

4) Any other pointer or reference for LCD panel calibration ?  

  

Thanks

Robin Singh

Hi robinsingh‌,

The gamma function I described changes all colors, in practice, only luminance (Y) is affected.

To change only one color, I suggest you to change the CSC array on display processor. It can also be done in user space by calling IOCTL.

Check the SW on this link:

i.MX6 CSC setting sample source code 

You can change from user space many things like brightness,contrast,saturation,hue, and gamma.

Best Regards,

Rogerio

No ratings
Version history
Last update:
‎11-01-2013 10:26 AM
Updated by: