~ubuntu-branches/ubuntu/saucy/darktable/saucy

« back to all changes in this revision

Viewing changes to src/gui/contrast.c

  • Committer: Bazaar Package Importer
  • Author(s): David Bremner
  • Date: 2011-07-12 09:36:46 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110712093646-yp9dbxan44dmw15h
Tags: 0.9-1
* New upstream release.
* Remove all patches now upstream; only patch for
  -Wno-error=unused-but-set-variable remains.
* Bump Standards-Version to 3.9.2 (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    This file is part of darktable,
3
 
    copyright (c) 2009--2010 Henrik Andersson.
 
3
    copyright (c) 2009--2011 Henrik Andersson.
4
4
 
5
5
    darktable is free software: you can redistribute it and/or modify
6
6
    it under the terms of the GNU General Public License as published by
24
24
 
25
25
#define CONTRAST_STEP 0.1
26
26
#define CONTRAST_AMOUNT 0.4
 
27
#define BRIGHTNESS_STEP 0.1
 
28
#define BRIGHTNESS_AMOUNT 1.0
27
29
 
28
30
GtkStyle *_main_window_orginal_style;
29
31
GtkStyle *_module_orginal_style;
33
35
void
34
36
_gui_contrast_apply ()
35
37
{
 
38
  /* calculate contrast multipliers */
36
39
  float contrast = dt_conf_get_float ("ui_contrast");
37
 
  float amount=contrast*CONTRAST_AMOUNT;
38
 
  float increase = 1.0+amount;
39
 
  float decrease = 1.0-amount;
 
40
  float contrast_amount = contrast*CONTRAST_AMOUNT;
 
41
  float contrast_increase = 1.0+contrast_amount;
 
42
  float contrast_decrease = 1.0-contrast_amount;
 
43
 
 
44
  /* calculate a brightness multiplier */
 
45
  float brightness = (1.0 + ((-0.2 + dt_conf_get_float ("ui_brightness")) * BRIGHTNESS_AMOUNT) );
40
46
 
41
47
  gchar rc[4096]= {0};
42
48
  g_snprintf (rc,4096,"\
65
71
",
66
72
              /* clearlooks-default */
67
73
              //text[NORMAL]
68
 
              (int)(255*CLIP ((_main_window_orginal_style->text[GTK_STATE_NORMAL].red * increase)/65535.0)),
69
 
              (int)(255*CLIP ((_main_window_orginal_style->text[GTK_STATE_NORMAL].green * increase)/65535.0)),
70
 
              (int)(255*CLIP ((_main_window_orginal_style->text[GTK_STATE_NORMAL].blue * increase)/65535.0)),
 
74
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->text[GTK_STATE_NORMAL].red * contrast_increase)/65535.0)*brightness),0,255),
 
75
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->text[GTK_STATE_NORMAL].green * contrast_increase)/65535.0)*brightness),0,255),
 
76
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->text[GTK_STATE_NORMAL].blue * contrast_increase)/65535.0)*brightness),0,255),
71
77
              //text[ACTIVE]
72
 
              (int)(255*CLIP ((_main_window_orginal_style->text[GTK_STATE_ACTIVE].red * increase)/65535.0)),
73
 
              (int)(255*CLIP ((_main_window_orginal_style->text[GTK_STATE_ACTIVE].green * increase)/65535.0)),
74
 
              (int)(255*CLIP ((_main_window_orginal_style->text[GTK_STATE_ACTIVE].blue * increase)/65535.0)),
 
78
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->text[GTK_STATE_ACTIVE].red * contrast_increase)/65535.0)*brightness),0,255),
 
79
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->text[GTK_STATE_ACTIVE].green * contrast_increase)/65535.0)*brightness),0,255),
 
80
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->text[GTK_STATE_ACTIVE].blue * contrast_increase)/65535.0)*brightness),0,255),
75
81
              //text[INSENSITIVE]
76
 
              (int)(255*CLIP ((_main_window_orginal_style->text[GTK_STATE_INSENSITIVE].red * increase)/65535.0)),
77
 
              (int)(255*CLIP ((_main_window_orginal_style->text[GTK_STATE_INSENSITIVE].green * increase)/65535.0)),
78
 
              (int)(255*CLIP ((_main_window_orginal_style->text[GTK_STATE_INSENSITIVE].blue * increase)/65535.0)),
 
82
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->text[GTK_STATE_INSENSITIVE].red * contrast_increase)/65535.0)*brightness),0,255),
 
83
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->text[GTK_STATE_INSENSITIVE].green * contrast_increase)/65535.0)*brightness),0,255),
 
84
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->text[GTK_STATE_INSENSITIVE].blue * contrast_increase)/65535.0)*brightness),0,255),
79
85
              // bg[NORMAL]
80
 
              (int)(255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_NORMAL].red * decrease)/65535.0)),
81
 
              (int)(255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_NORMAL].green * decrease)/65535.0)),
82
 
              (int)(255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_NORMAL].blue * decrease)/65535.0)),
 
86
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_NORMAL].red * contrast_decrease)/65535.0)*brightness),0,255),
 
87
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_NORMAL].green * contrast_decrease)/65535.0)*brightness),0,255),
 
88
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_NORMAL].blue * contrast_decrease)/65535.0)*brightness),0,255),
83
89
              // bg[ACTIVE[
84
 
              (int)(255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_ACTIVE].red * decrease)/65535.0)),
85
 
              (int)(255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_ACTIVE].green * decrease)/65535.0)),
86
 
              (int)(255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_ACTIVE].blue * decrease)/65535.0)),
 
90
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_ACTIVE].red * contrast_decrease)/65535.0)*brightness),0,255),
 
91
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_ACTIVE].green * contrast_decrease)/65535.0)*brightness),0,255),
 
92
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_ACTIVE].blue * contrast_decrease)/65535.0)*brightness),0,255),
87
93
              // bg[SELECTED]
88
 
              (int)(255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_SELECTED].red * decrease)/65535.0)),
89
 
              (int)(255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_SELECTED].green * decrease)/65535.0)),
90
 
              (int)(255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_SELECTED].blue * decrease)/65535.0)),
 
94
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_SELECTED].red * contrast_decrease)/65535.0)*brightness),0,255),
 
95
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_SELECTED].green * contrast_decrease)/65535.0)*brightness),0,255),
 
96
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->bg[GTK_STATE_SELECTED].blue * contrast_decrease)/65535.0)*brightness),0,255),
91
97
 
92
98
              // base[NORMAL]
93
 
              (int)(255*CLIP ((_main_window_orginal_style->base[GTK_STATE_NORMAL].red * decrease)/65535.0)),
94
 
              (int)(255*CLIP ((_main_window_orginal_style->base[GTK_STATE_NORMAL].green * decrease)/65535.0)),
95
 
              (int)(255*CLIP ((_main_window_orginal_style->base[GTK_STATE_NORMAL].blue * decrease)/65535.0)),
 
99
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->base[GTK_STATE_NORMAL].red * contrast_decrease)/65535.0)*brightness),0,255),
 
100
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->base[GTK_STATE_NORMAL].green * contrast_decrease)/65535.0)*brightness),0,255),
 
101
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->base[GTK_STATE_NORMAL].blue * contrast_decrease)/65535.0)*brightness),0,255),
96
102
              // base[ACTIVE]
97
 
              (int)(255*CLIP ((_main_window_orginal_style->base[GTK_STATE_ACTIVE].red * decrease)/65535.0)),
98
 
              (int)(255*CLIP ((_main_window_orginal_style->base[GTK_STATE_ACTIVE].green * decrease)/65535.0)),
99
 
              (int)(255*CLIP ((_main_window_orginal_style->base[GTK_STATE_ACTIVE].blue * decrease)/65535.0)),
 
103
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->base[GTK_STATE_ACTIVE].red * contrast_decrease)/65535.0)*brightness),0,255),
 
104
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->base[GTK_STATE_ACTIVE].green * contrast_decrease)/65535.0)*brightness),0,255),
 
105
              (int)CLAMP((255*CLIP ((_main_window_orginal_style->base[GTK_STATE_ACTIVE].blue * contrast_decrease)/65535.0)*brightness),0,255),
100
106
 
101
107
              /* clearlooks-brightbg */
102
 
              (int)(255*CLIP ((_module_orginal_style->bg[GTK_STATE_NORMAL].red * (1.0+(amount*0.1)) )/65535.0)),
103
 
              (int)(255*CLIP ((_module_orginal_style->bg[GTK_STATE_NORMAL].green * (1.0+(amount*0.1)) )/65535.0)),
104
 
              (int)(255*CLIP ((_module_orginal_style->bg[GTK_STATE_NORMAL].blue * (1.0+(amount*0.1)) )/65535.0))
 
108
              (int)CLAMP((255*CLIP ((_module_orginal_style->bg[GTK_STATE_NORMAL].red * (1.0+(contrast_amount*0.1)) )/65535.0)*brightness),0,255),
 
109
              (int)CLAMP((255*CLIP ((_module_orginal_style->bg[GTK_STATE_NORMAL].green * (1.0+(contrast_amount*0.1)) )/65535.0)*brightness),0,255),
 
110
              (int)CLAMP((255*CLIP ((_module_orginal_style->bg[GTK_STATE_NORMAL].blue * (1.0+(contrast_amount*0.1)) )/65535.0)*brightness),0,255)
105
111
 
106
112
 
107
113
             );
108
114
 
109
 
// fprintf(stderr,"RC: %s\n",rc);
110
 
 
111
115
  gtk_rc_parse_string (rc);
112
116
 
113
 
  //  GtkWidget *window = glade_xml_get_widget (darktable.gui->main_window, "main_window");
 
117
  /* apply newly parsed colors */
114
118
  gtk_rc_reset_styles (gtk_settings_get_default());
115
119
}
116
120
 
118
122
dt_gui_contrast_init ()
119
123
{
120
124
  /* create a copy of orginal style of window */
121
 
  GtkWidget *window = glade_xml_get_widget (darktable.gui->main_window, "main_window");
 
125
  GtkWidget *window = darktable.gui->widgets.main_window;
122
126
 
123
127
  /* realize window to enshure style is applied before copy */
124
128
  gtk_widget_realize(window);
125
129
  _main_window_orginal_style = gtk_style_copy (window->style);
126
130
 
127
 
 
128
131
  /* get clearlooks-brightbg orginal style */
129
 
  window = glade_xml_get_widget (darktable.gui->main_window, "import_eventbox");
 
132
  window = darktable.gui->widgets.import_eventbox;
130
133
  gtk_widget_realize(window);
131
134
  _module_orginal_style = gtk_style_copy (window->style);
132
135
 
133
 
 
134
136
  /* apply current contrast value */
135
137
  _gui_contrast_apply ();
136
138
}
163
165
  }
164
166
}
165
167
 
 
168
 
 
169
void dt_gui_brightness_increase()
 
170
{
 
171
  float brightness = dt_conf_get_float ("ui_brightness");
 
172
  if (brightness < 1.0)
 
173
  {
 
174
    /* calculate new brightness and store value */
 
175
    brightness = fmin (1.0,brightness+BRIGHTNESS_STEP);
 
176
    dt_conf_set_float ("ui_brightness",brightness);
 
177
    /* apply new brightness setting */
 
178
    _gui_contrast_apply ();
 
179
  }
 
180
}
 
181
 
 
182
void dt_gui_brightness_decrease()
 
183
{
 
184
  float brightness = dt_conf_get_float ("ui_brightness");
 
185
  if (brightness > 0.0)
 
186
  {
 
187
    /* calculate new brightness and store value */
 
188
    brightness = fmax (0.0,brightness-BRIGHTNESS_STEP);
 
189
    dt_conf_set_float ("ui_brightness",brightness);
 
190
    /* apply new brightness setting */
 
191
    _gui_contrast_apply ();
 
192
  }
 
193
}