On Wed, 2002-11-27 at 19:16, Denis Oliver Kropp wrote:
> Quoting Sven Neumann ([EMAIL PROTECTED]):
> > Hi,
> >
> > Antonino Daplas <[EMAIL PROTECTED]> writes:
> >
> > > Because color adjustment of the primary layer requires
> > > administrative/exclusive level, it's a bit too difficult to use them
> > > normally. So, I thought of adding this as a --dfb: option. Also,
> > > setting of the gamma ramp is now "visual format blind".
> > >
> > > Several new options are available:
> > >
> > > For gamma control: 'gamma_all', 'gamma_red', 'gamma_green', and
> > > 'gamma_blue'.
> > >
> > > They're self-explanatory. The range of values is from 0 - 1000 (gamma
> > > 0.0 - 10.0), where the normal (gamma 1.0) is 100.
> >
> > hmm, why don't you use doubles here? Seems confusing to use an
> > arbitrary mapping to integers. I'd also suggest to rename 'gamma_all'
> > to 'gamma'.
>
> float, please, 32 bit should be enough ;)
>
> > > For color adjustment: 'brightness', 'contrast', and 'saturation'. The
> > > range of values is from 0 - 255, where 128 is the normal value.
> >
> > again, a rather arbitrary choice. Since the internal API uses a range
> > of 0 to 0xFFFF it might make sense to map this to 0.0 - 2.0 with 1.0
> > being the standard value.
>
> I'd suggest that we change the color adjustment from 16 bit unsigned
> to 16 bit signed and take -1.0 - 1.0 as the float version.
>
Thanks for all your suggestions. Attached is a new patch (reverse the
previous patch if applied) with the following changes:
all color attribute parameters are in floats
gamma range is from 0.1 - 10.0
color attribute range is from -1.0 to +1.0.
Tony
diff -Naur DirectFB-cvs/src/core/fbdev/fbdev.c DirectFB-coloradjust/src/core/fbdev/fbdev.c
--- DirectFB-cvs/src/core/fbdev/fbdev.c 2002-11-27 06:44:01.000000000 +0000
+++ DirectFB-coloradjust/src/core/fbdev/fbdev.c 2002-11-27 23:10:55.000000000 +0000
@@ -26,6 +26,7 @@
#include "config.h"
+#include <math.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
@@ -1616,17 +1617,82 @@
return DFB_OK;
}
+#define DAC_WIDTH 256
+
+static signed short
+dfb_fbdev_calc_brightness(signed short color, float bright)
+{
+ int b = (int)(256.0 * bright);
+
+ color += b;
+
+ if (color > DAC_WIDTH - 1)
+ color = DAC_WIDTH - 1;
+ if (color < 0)
+ color = 0;
+
+ return color;
+}
+
+static signed short
+dfb_fbdev_calc_saturation(signed short color, float sat)
+{
+ if (sat > 0.0) {
+ float s = 1.0 - sat;
+
+ color = (signed short)(((float)color - 128.0*(1.0 - s))/s);
+ }
+ else if (sat < 0.0) {
+ float s = 1.0 + sat;
+
+ color = (signed short)((float)color*s + 128.0*(1.0 - s));
+ }
+
+ if (color > DAC_WIDTH - 1)
+ color = DAC_WIDTH - 1;
+ if (color < 0)
+ color = 0;
+
+ return color;
+}
+
+static signed short
+dfb_fbdev_calc_contrast(signed short color, float contrast)
+{
+ if (contrast > 0.0) {
+ signed short c = (signed short)(256.0*(1.0 + contrast) - 256.0);
+
+ color = ((color + c/2)/c) * c;
+ }
+ else if (contrast < 0.0) {
+
+ color = (signed short)((float)color * (1.0 + contrast));
+ }
+
+ if (color > DAC_WIDTH - 1)
+ color = DAC_WIDTH - 1;
+ if (color < 0)
+ color = 0;
+
+ return color;
+}
+
/*
* some fbdev drivers use the palette as gamma ramp in >8bpp modes, to have
* correct colors, the gamme ramp has to be initialized.
+ *
+ * Assumes 8-bit DAC
*/
-
-static __u16 dfb_fbdev_calc_gamma(int n, int max)
+static __u16 dfb_fbdev_calc_gamma(int n, float gamma, int max)
{
- int ret = 65535.0 * ((float)((float)n/(max)));
- if (ret > 65535) ret = 65535;
- if (ret < 0) ret = 0;
- return ret;
+ float ret = pow((double)n/(double)max, 1.0/gamma) *
+ (double)max + 0.5;
+ ret = (float)DAC_WIDTH * (ret/(float)max);
+ if (ret > 255.0)
+ ret = 255.0;
+ if (ret < 0.0)
+ ret = 0.0;
+ return (int) ret;
}
static DFBResult dfb_fbdev_set_gamma_ramp( DFBSurfacePixelFormat format )
@@ -1636,9 +1702,9 @@
int red_size = 0;
int green_size = 0;
int blue_size = 0;
- int red_max = 0;
- int green_max = 0;
- int blue_max = 0;
+ float gamma_red = 0;
+ float gamma_blue = 0;
+ float gamma_green = 0;
struct fb_cmap *cmap;
@@ -1670,45 +1736,42 @@
return DFB_OK;
}
- /*
- * ++Tony: The gamma ramp must be set differently if in DirectColor,
- * ie, to mimic TrueColor, index == color[index].
- */
- if (dfb_fbdev->shared->fix.visual == FB_VISUAL_DIRECTCOLOR) {
- red_max = 65536 / (256/red_size);
- green_max = 65536 / (256/green_size);
- blue_max = 65536 / (256/blue_size);
- }
- else {
- red_max = red_size;
- green_max = green_size;
- blue_max = blue_size;
- }
-
/* assume green to have most weight */
dfb_fbdev->shared->temp_cmap.len = green_size;
cmap = &dfb_fbdev->shared->current_cmap;
- for (i = 0; i < red_size; i++)
- cmap->red[i] = dfb_fbdev_calc_gamma( i, red_max );
-
- for (i = 0; i < green_size; i++)
- cmap->green[i] = dfb_fbdev_calc_gamma( i, green_max );
-
- for (i = 0; i < blue_size; i++)
- cmap->blue[i] = dfb_fbdev_calc_gamma( i, blue_max );
-
- /* ++Tony: Some drivers use the upper byte, some use the lower */
- if (dfb_fbdev->shared->fix.visual == FB_VISUAL_DIRECTCOLOR) {
- for (i = 0; i < red_size; i++)
- cmap->red[i] |= cmap->red[i] << 8;
-
- for (i = 0; i < green_size; i++)
- cmap->green[i] |= cmap->green[i] << 8;
-
- for (i = 0; i < blue_size; i++)
- cmap->blue[i] |= cmap->blue[i] << 8;
+ if (dfb_config->gamma < 0.0) {
+ gamma_red = dfb_config->gamma_red;
+ gamma_green = dfb_config->gamma_green;
+ gamma_blue = dfb_config->gamma_blue;
+ }
+ else {
+ gamma_red = dfb_config->gamma;
+ gamma_green = dfb_config->gamma;
+ gamma_blue = dfb_config->gamma;
+ }
+
+ for (i = 0; i < red_size; i++) {
+ cmap->red[i] = dfb_fbdev_calc_gamma( i, gamma_red, red_size );
+ cmap->red[i] = dfb_fbdev_calc_brightness( cmap->red[i], dfb_config->brightness );
+ cmap->red[i] = dfb_fbdev_calc_saturation( cmap->red[i], dfb_config->saturation );
+ cmap->red[i] = dfb_fbdev_calc_contrast( cmap->red[i], dfb_config->contrast );
+ cmap->red[i] |= cmap->red[i] << 8;
+ }
+ for (i = 0; i < green_size; i++) {
+ cmap->green[i] = dfb_fbdev_calc_gamma( i, gamma_green, green_size );
+ cmap->green[i] = dfb_fbdev_calc_brightness( cmap->green[i], dfb_config->brightness );
+ cmap->green[i] = dfb_fbdev_calc_saturation( cmap->green[i], dfb_config->saturation );
+ cmap->green[i] = dfb_fbdev_calc_contrast( cmap->green[i], dfb_config->contrast );
+ cmap->green[i] |= cmap->green[i] << 8;
+ }
+ for (i = 0; i < blue_size; i++) {
+ cmap->blue[i] = dfb_fbdev_calc_gamma( i, gamma_blue, blue_size );
+ cmap->blue[i] = dfb_fbdev_calc_brightness( cmap->blue[i], dfb_config->brightness );
+ cmap->blue[i] = dfb_fbdev_calc_saturation( cmap->blue[i], dfb_config->saturation );
+ cmap->blue[i] = dfb_fbdev_calc_contrast( cmap->blue[i], dfb_config->contrast );
+ cmap->blue[i] |= cmap->blue[i] << 8;
}
if (ioctl( dfb_fbdev->fd, FBIOPUTCMAP, cmap ) < 0) {
@@ -1727,6 +1790,9 @@
int red_val;
int green_val;
int blue_val;
+ float gamma_red = 0;
+ float gamma_blue = 0;
+ float gamma_green = 0;
int i = 0;
struct fb_cmap cmap;
@@ -1744,13 +1810,23 @@
cmap.blue = (__u16*)alloca( 2 * 256 );
cmap.transp = (__u16*)alloca( 2 * 256 );
+ if (dfb_config->gamma < 0.0) {
+ gamma_red = dfb_config->gamma_red;
+ gamma_green = dfb_config->gamma_green;
+ gamma_blue = dfb_config->gamma_blue;
+ }
+ else {
+ gamma_red = dfb_config->gamma;
+ gamma_green = dfb_config->gamma;
+ gamma_blue = dfb_config->gamma;
+ }
for (red_val = 0; red_val < 8 ; red_val++) {
for (green_val = 0; green_val < 8 ; green_val++) {
for (blue_val = 0; blue_val < 4 ; blue_val++) {
- cmap.red[i] = dfb_fbdev_calc_gamma( red_val, 7 );
- cmap.green[i] = dfb_fbdev_calc_gamma( green_val, 7 );
- cmap.blue[i] = dfb_fbdev_calc_gamma( blue_val, 3 );
+ cmap.red[i] = dfb_fbdev_calc_gamma( red_val, gamma_red, 7 );
+ cmap.green[i] = dfb_fbdev_calc_gamma( green_val, gamma_green, 7 );
+ cmap.blue[i] = dfb_fbdev_calc_gamma( blue_val, gamma_blue, 3 );
cmap.transp[i] = (i ? 0x2000 : 0xffff);
i++;
}
diff -Naur DirectFB-cvs/src/misc/conf.c DirectFB-coloradjust/src/misc/conf.c
--- DirectFB-cvs/src/misc/conf.c 2002-11-11 15:32:30.000000000 +0000
+++ DirectFB-coloradjust/src/misc/conf.c 2002-11-27 23:14:37.000000000 +0000
@@ -117,6 +117,20 @@
"Allow translucent windows\n"
" videoram-limit=<amount> "
"Limit amount of Video RAM in kb\n"
+ " brightness=<amount> "
+ "Set brightness (-1.0 - +1.0, 0.0 normal)\n"
+ " saturation=<amount> "
+ "Set saturation (-1.0 - +1.0, 0.0 normal)\n"
+ " contrast =<amount> "
+ "Set contrast (-1.0 - +1.0, 0.0 normal)\n"
+ " gamma =<gamma> "
+ "Set gamma of all channels (0.1 - 10.0)\n"
+ " gamma_red =<gamma> "
+ "Set gamma of red channel (0.1 - 10.0)\n"
+ " gamma_green=<gamma> "
+ "Set gamma of green channel (0.1 - 10.0)\n"
+ " gamma_blue =<gamma> "
+ "Set gamma of blue channel (0.1 - 10.0)\n"
" matrox-tv-standard=[pal|ntsc] "
"Matrox TV standard (default=pal)\n"
" [no-]matrox-sgram "
@@ -249,6 +263,13 @@
dfb_config->mouse_motion_compression = true;
dfb_config->window_policy = -1;
dfb_config->buffer_mode = -1;
+ dfb_config->brightness = 0.0;
+ dfb_config->saturation = 0.0;
+ dfb_config->contrast = 0.0;
+ dfb_config->gamma = -1.0;
+ dfb_config->gamma_red = 1.0;
+ dfb_config->gamma_green = 1.0;
+ dfb_config->gamma_blue = 1.0;
sigemptyset( &dfb_config->dont_catch );
@@ -399,6 +420,153 @@
return DFB_INVARG;
}
} else
+ if (strcmp (name, "brightness" ) == 0) {
+ if (value) {
+ float brightness;
+
+ if (sscanf( value, "%f", &brightness ) < 1) {
+ ERRORMSG("DirectFB/Config 'brightness': Could not parse value!\n");
+ return DFB_INVARG;
+ }
+
+ if (brightness < -1.0)
+ brightness = -1.0;
+ if (brightness > 1.0)
+ brightness = 1.0;
+
+ dfb_config->brightness = brightness;
+ }
+ else {
+ ERRORMSG("DirectFB/Config 'brightness': No value specified!\n");
+ return DFB_INVARG;
+ }
+ } else
+ if (strcmp (name, "saturation" ) == 0) {
+ if (value) {
+ float saturation;
+
+ if (sscanf( value, "%f", &saturation ) < 1) {
+ ERRORMSG("DirectFB/Config 'saturation': Could not parse value!\n");
+ return DFB_INVARG;
+ }
+
+ if (saturation < -1.0)
+ saturation = -1.0;
+ if (saturation > 1.0)
+ saturation = 1.0;
+
+ dfb_config->saturation = saturation;
+ }
+ else {
+ ERRORMSG("DirectFB/Config 'saturation': No value specified!\n");
+ return DFB_INVARG;
+ }
+ } else
+ if (strcmp (name, "contrast" ) == 0) {
+ if (value) {
+ float contrast;
+
+ if (sscanf( value, "%f", &contrast ) < 1) {
+ ERRORMSG("DirectFB/Config 'contrast': Could not parse value!\n");
+ return DFB_INVARG;
+ }
+
+ if (contrast < -1.0)
+ contrast = -1.0;
+ if (contrast > 1.0)
+ contrast = 1.0;
+
+ dfb_config->contrast = contrast;
+ }
+ else {
+ ERRORMSG("DirectFB/Config 'contrast': No value specified!\n");
+ return DFB_INVARG;
+ }
+ } else
+ if (strcmp (name, "gamma" ) == 0) {
+ if (value) {
+ float gamma;
+
+ if (sscanf( value, "%f", &gamma ) < 1) {
+ ERRORMSG("DirectFB/Config 'gamma': Could not parse value!\n");
+ return DFB_INVARG;
+ }
+
+ if (gamma < 0.1)
+ gamma = 0.1;
+ if (gamma > 10.0)
+ gamma = 10.0;
+
+ dfb_config->gamma = gamma;
+ }
+ else {
+ ERRORMSG("DirectFB/Config 'gamma': No value specified!\n");
+ return DFB_INVARG;
+ }
+ } else
+ if (strcmp (name, "gamma_red" ) == 0) {
+ if (value) {
+ float gamma;
+
+ if (sscanf( value, "%f", &gamma ) < 1) {
+ ERRORMSG("DirectFB/Config 'gamma_red': Could not parse value!\n");
+ return DFB_INVARG;
+ }
+
+ if (gamma < 0.1)
+ gamma = 0.1;
+ if (gamma > 10.0)
+ gamma = 10.0;
+
+ dfb_config->gamma_red = gamma;
+ }
+ else {
+ ERRORMSG("DirectFB/Config 'gamma_red': No value specified!\n");
+ return DFB_INVARG;
+ }
+ } else
+ if (strcmp (name, "gamma_green" ) == 0) {
+ if (value) {
+ float gamma;
+
+ if (sscanf( value, "%f", &gamma ) < 1) {
+ ERRORMSG("DirectFB/Config 'gamma_green': Could not parse value!\n");
+ return DFB_INVARG;
+ }
+
+ if (gamma < 0.1)
+ gamma = 0.1;
+ if (gamma > 10.0)
+ gamma = 10.0;
+
+ dfb_config->gamma_green = gamma;
+ }
+ else {
+ ERRORMSG("DirectFB/Config 'gamma_green': No value specified!\n");
+ return DFB_INVARG;
+ }
+ } else
+ if (strcmp (name, "gamma_blue" ) == 0) {
+ if (value) {
+ float gamma;
+
+ if (sscanf( value, "%f", &gamma ) < 1) {
+ ERRORMSG("DirectFB/Config 'gamma_blue': Could not parse value!\n");
+ return DFB_INVARG;
+ }
+
+ if (gamma < 0.1)
+ gamma = 0.1;
+ if (gamma > 10.0)
+ gamma = 10.0;
+
+ dfb_config->gamma_blue = gamma;
+ }
+ else {
+ ERRORMSG("DirectFB/Config 'gamma_blue': No value specified!\n");
+ return DFB_INVARG;
+ }
+ } else
if (strcmp (name, "quiet" ) == 0) {
dfb_config->quiet = true;
} else
diff -Naur DirectFB-cvs/src/misc/conf.h DirectFB-coloradjust/src/misc/conf.h
--- DirectFB-cvs/src/misc/conf.h 2002-10-22 20:29:07.000000000 +0000
+++ DirectFB-coloradjust/src/misc/conf.h 2002-11-27 23:16:16.000000000 +0000
@@ -104,6 +104,20 @@
int videoram_limit; /* limit amount of video
memory used by DirectFB */
+ float brightness; /* brightness control */
+
+ float saturation; /* saturation control */
+
+ float contrast; /* contrast control */
+
+ float gamma; /* gamma control all components */
+
+ float gamma_red; /* red gamma control */
+
+ float gamma_green; /* green gamma control */
+
+ float gamma_blue; /* blue gamma control */
+
sigset_t dont_catch; /* don't catch these signals */
char *screenshot_dir; /* dump screen content into