vi_gamma.c 1.05 KB
#include <math.h>

void vi_gamma(unsigned int gamma_enable, unsigned int gamma_dither_enable,
	      unsigned int rgb, unsigned int rand, unsigned int sync,
	      unsigned int *gamma_rgb, unsigned int *gamma_sync)
{
    static unsigned int blank, nblak_reg, sqrt_rgb, dither_rgb, ngamma_rgb, ngamma_sync,
	ogamma_rgb, ogamma_sync, oblank_reg, nblank_reg;

    *gamma_rgb  = ogamma_rgb;
    *gamma_sync = ogamma_sync;
    
    blank      = sync ? ((rgb & (1 << 7)) >> 7) : oblank_reg;
    nblank_reg = blank;

    if (gamma_dither_enable)
    {
	sqrt_rgb = (int) sqrt((float) ((rgb << 6) | rand));
    }
    else
    {
	sqrt_rgb = (int) sqrt((float) (rgb << 6));
    }

    if (rgb != 0xff)
    {
	dither_rgb = rgb + (gamma_dither_enable & (rand >> 5));
    }
    else
    {
	dither_rgb = 255;
    }

    ngamma_rgb  = 
	sync ? ((rgb & (15 << 1)) >> 1) :
	    ((blank ? 0 : 127) & (gamma_enable ?
			  sqrt_rgb:
			    ((dither_rgb & (127 << 1)) >> 1)));

    ngamma_sync = sync;

    ogamma_rgb  = ngamma_rgb;
    ogamma_sync = ngamma_sync;
    oblank_reg  = nblank_reg;    
}