libgimpwidgets: some more cleanup in GimpColorSelect

This commit is contained in:
Michael Natterer 2015-10-08 22:24:13 +02:00
parent 494ec0ace5
commit 560d481083
1 changed files with 34 additions and 104 deletions

View File

@ -852,43 +852,33 @@ gimp_color_select_image_fill (GtkWidget *preview,
gtk_widget_get_allocation (preview, &allocation); gtk_widget_get_allocation (preview, &allocation);
csf.update = update_procs[fill_type]; csf.buffer = g_alloca (csf.width * 3);
csf.width = allocation.width; csf.width = allocation.width;
csf.height = allocation.height; csf.height = allocation.height;
csf.hsv = *hsv; csf.hsv = *hsv;
csf.rgb = *rgb; csf.rgb = *rgb;
csf.update = update_procs[fill_type];
csf.buffer = g_alloca (csf.width * 3);
for (csf.y = 0; csf.y < csf.height; csf.y++) for (csf.y = 0; csf.y < csf.height; csf.y++)
{ {
{ if (csf.update)
if (csf.update) (* csf.update) (&csf);
(* csf.update) (&csf);
gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview), gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
0, csf.y, csf.width, 1, 0, csf.y, csf.width, 1,
GIMP_RGB_IMAGE, GIMP_RGB_IMAGE,
csf.buffer, csf.width * 3); csf.buffer, csf.width * 3);
}
} }
} }
static void static void
color_select_update_red (ColorSelectFill *csf) color_select_update_red (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gint i, r; gint i, r;
p = csf->buffer;
r = (csf->height - csf->y + 1) * 255 / csf->height; r = (csf->height - csf->y + 1) * 255 / csf->height;
r = CLAMP (r, 0, 255);
if (r < 0)
r = 0;
if (r > 255)
r = 255;
for (i = 0; i < csf->width; i++) for (i = 0; i < csf->width; i++)
{ {
@ -901,17 +891,11 @@ color_select_update_red (ColorSelectFill *csf)
static void static void
color_select_update_green (ColorSelectFill *csf) color_select_update_green (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gint i, g; gint i, g;
p = csf->buffer;
g = (csf->height - csf->y + 1) * 255 / csf->height; g = (csf->height - csf->y + 1) * 255 / csf->height;
g = CLAMP (g, 0, 255);
if (g < 0)
g = 0;
if (g > 255)
g = 255;
for (i = 0; i < csf->width; i++) for (i = 0; i < csf->width; i++)
{ {
@ -924,17 +908,11 @@ color_select_update_green (ColorSelectFill *csf)
static void static void
color_select_update_blue (ColorSelectFill *csf) color_select_update_blue (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gint i, b; gint i, b;
p = csf->buffer;
b = (csf->height - csf->y + 1) * 255 / csf->height; b = (csf->height - csf->y + 1) * 255 / csf->height;
b = CLAMP (b, 0, 255);
if (b < 0)
b = 0;
if (b > 255)
b = 255;
for (i = 0; i < csf->width; i++) for (i = 0; i < csf->width; i++)
{ {
@ -947,15 +925,12 @@ color_select_update_blue (ColorSelectFill *csf)
static void static void
color_select_update_hue (ColorSelectFill *csf) color_select_update_hue (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gfloat h, f; gfloat h, f;
gint r, g, b; gint r, g, b;
gint i; gint i;
p = csf->buffer;
h = csf->y * 360.0 / csf->height; h = csf->y * 360.0 / csf->height;
h = CLAMP (360 - h, 0, 360); h = CLAMP (360 - h, 0, 360);
h /= 60; h /= 60;
@ -1008,18 +983,12 @@ color_select_update_hue (ColorSelectFill *csf)
static void static void
color_select_update_saturation (ColorSelectFill *csf) color_select_update_saturation (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gint s; gint s;
gint i; gint i;
p = csf->buffer;
s = csf->y * 255 / csf->height; s = csf->y * 255 / csf->height;
s = CLAMP (s, 0, 255);
if (s < 0)
s = 0;
if (s > 255)
s = 255;
s = 255 - s; s = 255 - s;
@ -1034,18 +1003,12 @@ color_select_update_saturation (ColorSelectFill *csf)
static void static void
color_select_update_value (ColorSelectFill *csf) color_select_update_value (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gint v; gint v;
gint i; gint i;
p = csf->buffer;
v = csf->y * 255 / csf->height; v = csf->y * 255 / csf->height;
v = CLAMP (v, 0, 255);
if (v < 0)
v = 0;
if (v > 255)
v = 255;
v = 255 - v; v = 255 - v;
@ -1060,19 +1023,14 @@ color_select_update_value (ColorSelectFill *csf)
static void static void
color_select_update_red_green (ColorSelectFill *csf) color_select_update_red_green (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gint i, r, b; gint i, r, b;
gfloat g, dg; gfloat g, dg;
p = csf->buffer;
b = ROUND (csf->rgb.b * 255.0); b = ROUND (csf->rgb.b * 255.0);
r = (csf->height - csf->y + 1) * 255 / csf->height;
if (r < 0) r = (csf->height - csf->y + 1) * 255 / csf->height;
r = 0; r = CLAMP (r, 0, 255);
if (r > 255)
r = 255;
g = 0; g = 0;
dg = 255.0 / csf->width; dg = 255.0 / csf->width;
@ -1090,19 +1048,14 @@ color_select_update_red_green (ColorSelectFill *csf)
static void static void
color_select_update_red_blue (ColorSelectFill *csf) color_select_update_red_blue (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gint i, r, g; gint i, r, g;
gfloat b, db; gfloat b, db;
p = csf->buffer;
g = ROUND (csf->rgb.g * 255.0); g = ROUND (csf->rgb.g * 255.0);
r = (csf->height - csf->y + 1) * 255 / csf->height;
if (r < 0) r = (csf->height - csf->y + 1) * 255 / csf->height;
r = 0; r = CLAMP (r, 0, 255);
if (r > 255)
r = 255;
b = 0; b = 0;
db = 255.0 / csf->width; db = 255.0 / csf->width;
@ -1120,19 +1073,14 @@ color_select_update_red_blue (ColorSelectFill *csf)
static void static void
color_select_update_green_blue (ColorSelectFill *csf) color_select_update_green_blue (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gint i, g, r; gint i, g, r;
gfloat b, db; gfloat b, db;
p = csf->buffer;
r = ROUND (csf->rgb.r * 255.0); r = ROUND (csf->rgb.r * 255.0);
g = (csf->height - csf->y + 1) * 255 / csf->height;
if (g < 0) g = (csf->height - csf->y + 1) * 255 / csf->height;
g = 0; g = CLAMP (g, 0, 255);
if (g > 255)
g = 255;
b = 0; b = 0;
db = 255.0 / csf->width; db = 255.0 / csf->width;
@ -1150,19 +1098,13 @@ color_select_update_green_blue (ColorSelectFill *csf)
static void static void
color_select_update_hue_saturation (ColorSelectFill *csf) color_select_update_hue_saturation (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gfloat h, v, s, ds; gfloat h, v, s, ds;
gint f; gint f;
gint i; gint i;
p = csf->buffer;
h = 360 - (csf->y * 360 / csf->height); h = 360 - (csf->y * 360 / csf->height);
h = CLAMP (h, 0, 359);
if (h < 0)
h = 0;
if (h > 359)
h = 359;
h /= 60; h /= 60;
f = (h - (int) h) * 255; f = (h - (int) h) * 255;
@ -1240,19 +1182,13 @@ color_select_update_hue_saturation (ColorSelectFill *csf)
static void static void
color_select_update_hue_value (ColorSelectFill *csf) color_select_update_hue_value (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gfloat h, v, dv, s; gfloat h, v, dv, s;
gint f; gint f;
gint i; gint i;
p = csf->buffer;
h = 360 - (csf->y * 360 / csf->height); h = 360 - (csf->y * 360 / csf->height);
h = CLAMP (h, 0, 359);
if (h < 0)
h = 0;
if (h > 359)
h = 359;
h /= 60; h /= 60;
f = (h - (int) h) * 255; f = (h - (int) h) * 255;
@ -1330,19 +1266,13 @@ color_select_update_hue_value (ColorSelectFill *csf)
static void static void
color_select_update_saturation_value (ColorSelectFill *csf) color_select_update_saturation_value (ColorSelectFill *csf)
{ {
guchar *p; guchar *p = csf->buffer;
gfloat h, v, dv, s; gfloat h, v, dv, s;
gint f; gint f;
gint i; gint i;
p = csf->buffer;
s = (gfloat) csf->y / csf->height; s = (gfloat) csf->y / csf->height;
s = CLAMP (s, 0.0, 1.0);
if (s < 0)
s = 0;
if (s > 1)
s = 1;
s = 1 - s; s = 1 - s;