vi_gamma.pl 959 Bytes

sub vi_gamma
{
    $gamma_enable        = $_[0];
    $gamma_dither_enable = $_[1];
    $rgb                 = $_[2];
    $rand                = $_[3];
    $sync                = $_[4];

    $_[5] = sprintf("0x%.2x", $ogamma_rgb);
    $_[6] = $ogamma_sync;

    $blank      = $sync ? ((oct($rgb) & (1 << 7)) >> 7) : $oblank_reg;
    $nblank_reg = $blank;

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

    if ($rgb ne "0xff")
    {
	$dither_rgb = oct($rgb) + ($gamma_dither_enable & (oct($rand) >> 5));
    }
    else
    {
	$dither_rgb = 255;
    }

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

    $ngamma_sync = $sync;

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

1;

#EOF