From 0d6754efd7bee7fb38716454660d9e15d2f0669c Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Wed, 11 Sep 2024 03:05:27 +0000 Subject: [PATCH] plug-ins: Remove GimpRGB from Lighting Effects plug-in --- plug-ins/lighting/lighting-apply.c | 34 +-- plug-ins/lighting/lighting-image.c | 96 ++++---- plug-ins/lighting/lighting-image.h | 53 +++-- plug-ins/lighting/lighting-main.c | 8 +- plug-ins/lighting/lighting-main.h | 4 +- plug-ins/lighting/lighting-preview.c | 74 ++++-- plug-ins/lighting/lighting-shade.c | 334 +++++++++++++++------------ plug-ins/lighting/lighting-shade.h | 21 +- plug-ins/lighting/lighting-ui.c | 14 +- 9 files changed, 353 insertions(+), 285 deletions(-) diff --git a/plug-ins/lighting/lighting-apply.c b/plug-ins/lighting/lighting-apply.c index 676634088f..8ceb228e4a 100644 --- a/plug-ins/lighting/lighting-apply.c +++ b/plug-ins/lighting/lighting-apply.c @@ -24,7 +24,7 @@ void compute_image (void) { gint xcount, ycount; - GimpRGB color; + gdouble color[4]; glong progress_counter = 0; GimpVector3 p; GimpImage *new_image = NULL; @@ -112,19 +112,19 @@ compute_image (void) index = 0; for (xcount = 0; xcount < width; xcount++) - { - p = int_to_pos (xcount, ycount); - color = (* ray_func) (&p); + { + p = int_to_pos (xcount, ycount); + (* ray_func) (&p, color); - row[index++] = (guchar) (color.r * 255.0); - row[index++] = (guchar) (color.g * 255.0); - row[index++] = (guchar) (color.b * 255.0); + row[index++] = (guchar) (color[0] * 255.0); + row[index++] = (guchar) (color[1] * 255.0); + row[index++] = (guchar) (color[2] * 255.0); - if (has_alpha) - row[index++] = (guchar) (color.a * 255.0); + if (has_alpha) + row[index++] = (guchar) (color[3] * 255.0); - progress_counter++; - } + progress_counter++; + } gimp_progress_update ((gdouble) progress_counter / (gdouble) maxcounter); @@ -236,37 +236,37 @@ copy_from_config (GimpProcedureConfig *config) if (color_1) { gegl_color_get_pixel (color_1, babl_format ("R'G'B'A double"), - &mapvals.lightsource[0].color); + mapvals.lightsource[0].color); g_object_unref (color_1); } if (color_2) { gegl_color_get_pixel (color_2, babl_format ("R'G'B'A double"), - &mapvals.lightsource[1].color); + mapvals.lightsource[1].color); g_object_unref (color_2); } if (color_3) { gegl_color_get_pixel (color_3, babl_format ("R'G'B'A double"), - &mapvals.lightsource[2].color); + mapvals.lightsource[2].color); g_object_unref (color_3); } if (color_4) { gegl_color_get_pixel (color_4, babl_format ("R'G'B'A double"), - &mapvals.lightsource[3].color); + mapvals.lightsource[3].color); g_object_unref (color_4); } if (color_5) { gegl_color_get_pixel (color_5, babl_format ("R'G'B'A double"), - &mapvals.lightsource[4].color); + mapvals.lightsource[4].color); g_object_unref (color_5); } if (color_6) { gegl_color_get_pixel (color_6, babl_format ("R'G'B'A double"), - &mapvals.lightsource[5].color); + mapvals.lightsource[5].color); g_object_unref (color_6); } diff --git a/plug-ins/lighting/lighting-image.c b/plug-ins/lighting/lighting-image.c index 58d653cb08..838fb5a076 100644 --- a/plug-ins/lighting/lighting-image.c +++ b/plug-ins/lighting/lighting-image.c @@ -33,7 +33,7 @@ cairo_surface_t *preview_surface = NULL; glong maxcounter; gint width, height; gint env_width, env_height; -GimpRGB background; +gdouble background[4]; gint border_x1, border_y1, border_x2, border_y2; @@ -46,8 +46,8 @@ guchar sinemap[256], spheremap[256], logmap[256]; guchar peek_map (GeglBuffer *buffer, const Babl *format, - gint x, - gint y) + gint x, + gint y) { guchar data[4]; guchar ret_val; @@ -67,28 +67,24 @@ peek_map (GeglBuffer *buffer, return ret_val; } -GimpRGB -peek (gint x, - gint y) +void +peek (gint x, + gint y, + gdouble *color) { - GimpRGB color; - gegl_buffer_sample (source_buffer, x, y, NULL, - &color, babl_format ("R'G'B'A double"), + color, babl_format ("R'G'B'A double"), GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE); if (! babl_format_has_alpha (gegl_buffer_get_format (source_buffer))) - color.a = 1.0; - - return color; + color[3] = 1.0; } -GimpRGB -peek_env_map (gint x, - gint y) +void +peek_env_map (gint x, + gint y, + gdouble *color) { - GimpRGB color; - if (x < 0) x = 0; else if (x >= env_width) @@ -99,18 +95,16 @@ peek_env_map (gint x, y = env_height - 1; gegl_buffer_sample (env_buffer, x, y, NULL, - &color, babl_format ("R'G'B'A double"), + color, babl_format ("R'G'B'A double"), GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE); - color.a = 1.0; - - return color; + color[3] = 1.0; } void -poke (gint x, - gint y, - GimpRGB *color) +poke (gint x, + gint y, + gdouble *color) { if (x < 0) x = 0; @@ -128,7 +122,7 @@ poke (gint x, gint check_bounds (gint x, - gint y) + gint y) { if (x < border_x1 || y < border_y1 || @@ -237,18 +231,17 @@ pos_to_float (gdouble x, /* Quartics bilinear interpolation stuff. */ /**********************************************/ -GimpRGB +void get_image_color (gdouble u, gdouble v, - gint *inside) + gint *inside, + gdouble *color) { gint x1; gint y1; gint x2; gint y2; - GimpRGB p[4]; - GimpRGB p_rgba; - gdouble pixel[4]; + gdouble p[4]; gdouble pixels[16]; x1 = RINT (u); @@ -257,7 +250,10 @@ get_image_color (gdouble u, if (check_bounds (x1, y1) == FALSE) { *inside = FALSE; - return background; + for (gint i = 0; i < 4; i++) + color[i] = background[i]; + + return; } x2 = (x1 + 1); @@ -266,36 +262,34 @@ get_image_color (gdouble u, if (check_bounds (x2, y2) == FALSE) { *inside = TRUE; - return peek (x1, y1); + peek (x1, y1, color); + + return; } *inside = TRUE; - p[0] = peek (x1, y1); - p[1] = peek (x2, y1); - p[2] = peek (x1, y2); - p[3] = peek (x2, y2); - + peek (x1, y1, p); for (gint i = 0; i < 4; i++) - { - pixels[(i * 4)] = p[i].r; - pixels[(i * 4) + 1] = p[i].g; - pixels[(i * 4) + 2] = p[i].b; - pixels[(i * 4) + 3] = p[i].a; - } + pixels[i] = p[i]; + peek (x2, y1, p); + for (gint i = 0; i < 4; i++) + pixels[i + 4] = p[i]; + peek (x1, y2, p); + for (gint i = 0; i < 4; i++) + pixels[i + 8] = p[i]; + peek (x2, y2, p); + for (gint i = 0; i < 4; i++) + pixels[i + 12] = p[i]; - gimp_bilinear_rgb (u, v, pixels, TRUE, pixel); - - gimp_rgba_set (&p_rgba, pixel[0], pixel[1], pixel[2], pixel[3]); - - return p_rgba; + gimp_bilinear_rgb (u, v, pixels, TRUE, color); } gdouble get_map_value (GeglBuffer *buffer, const Babl *format, - gdouble u, - gdouble v, - gint *inside) + gdouble u, + gdouble v, + gint *inside) { gint x1, y1, x2, y2; gdouble p[4]; diff --git a/plug-ins/lighting/lighting-image.h b/plug-ins/lighting/lighting-image.h index 06b0e02399..7e7b1689ef 100644 --- a/plug-ins/lighting/lighting-image.h +++ b/plug-ins/lighting/lighting-image.h @@ -23,7 +23,7 @@ extern cairo_surface_t *preview_surface; extern glong maxcounter; extern gint width,height,env_width,env_height; -extern GimpRGB background; +extern gdouble background[4]; extern gint border_x1, border_y1, border_x2, border_y2; @@ -32,39 +32,42 @@ extern guchar sinemap[256], spheremap[256], logmap[256]; guchar peek_map (GeglBuffer *buffer, const Babl *format, - gint x, - gint y); -GimpRGB peek (gint x, - gint y); -GimpRGB peek_env_map (gint x, - gint y); + gint x, + gint y); +void peek (gint x, + gint y, + gdouble *color); +void peek_env_map (gint x, + gint y, + gdouble *color); void poke (gint x, - gint y, - GimpRGB *color); + gint y, + gdouble *color); gint check_bounds (gint x, - gint y); + gint y); GimpVector3 int_to_pos (gint x, - gint y); + gint y); GimpVector3 int_to_posf (gdouble x, - gdouble y); + gdouble y); void pos_to_int (gdouble x, - gdouble y, - gint *scr_x, - gint *scr_y); + gdouble y, + gint *scr_x, + gint *scr_y); void pos_to_float (gdouble x, - gdouble y, - gdouble *xf, - gdouble *yf); -GimpRGB get_image_color (gdouble u, - gdouble v, - gint *inside); + gdouble y, + gdouble *xf, + gdouble *yf); +void get_image_color (gdouble u, + gdouble v, + gint *inside, + gdouble *color); gdouble get_map_value (GeglBuffer *buffer, const Babl *format, - gdouble u, - gdouble v, - gint *inside); + gdouble u, + gdouble v, + gint *inside); gint image_setup (GimpDrawable *drawable, - gint interactive); + gint interactive); void bumpmap_setup (GimpDrawable *bumpmap); void envmap_setup (GimpDrawable *envmap); diff --git a/plug-ins/lighting/lighting-main.c b/plug-ins/lighting/lighting-main.c index de2cb63edb..1a853ab550 100644 --- a/plug-ins/lighting/lighting-main.c +++ b/plug-ins/lighting/lighting-main.c @@ -399,7 +399,7 @@ lighting_create_procedure (GimpPlugIn *plug_in, "light-spot", SPOT_LIGHT, _("Spot"), NULL, NULL), "light-none", - G_PARAM_READWRITE); + G_PARAM_READWRITE); gimp_procedure_add_color_aux_argument (procedure, "light-color-3", _("Color"), @@ -652,7 +652,8 @@ set_default_settings (void) gimp_vector3_set (&mapvals.lightsource[0].position, -1.0, -1.0, 1.0); gimp_vector3_set (&mapvals.lightsource[0].direction, -1.0, -1.0, 1.0); - gimp_rgba_set (&mapvals.lightsource[0].color, 1.0, 1.0, 1.0, 1.0); + for (gint i = 0; i < 4; i++) + mapvals.lightsource[0].color[i] = 1.0; mapvals.lightsource[0].intensity = 1.0; mapvals.lightsource[0].type = POINT_LIGHT; mapvals.lightsource[0].active = TRUE; @@ -673,7 +674,8 @@ set_default_settings (void) for (k = 1; k < NUM_LIGHTS; k++) { - gimp_rgba_set (&mapvals.lightsource[k].color, 1.0, 1.0, 1.0, 1.0); + for (gint i = 0; i < 4; i++) + mapvals.lightsource[k].color[i] = 1.0; mapvals.lightsource[k].intensity = 1.0; mapvals.lightsource[k].type = NO_LIGHT; mapvals.lightsource[k].active = TRUE; diff --git a/plug-ins/lighting/lighting-main.h b/plug-ins/lighting/lighting-main.h index 983f9afb13..23fcf4f492 100644 --- a/plug-ins/lighting/lighting-main.h +++ b/plug-ins/lighting/lighting-main.h @@ -44,7 +44,6 @@ typedef struct gdouble specular_ref; gdouble highlight; gboolean metallic; - GimpRGB color; } MaterialSettings; typedef struct @@ -52,7 +51,7 @@ typedef struct LightType type; GimpVector3 position; GimpVector3 direction; - GimpRGB color; + gdouble color[4]; gdouble intensity; gboolean active; } LightSettings; @@ -72,7 +71,6 @@ typedef struct GimpVector3 planenormal; LightSettings lightsource[NUM_LIGHTS]; MaterialSettings material; - MaterialSettings ref_material; gdouble pixel_threshold; gdouble bumpmax,bumpmin; diff --git a/plug-ins/lighting/lighting-preview.c b/plug-ins/lighting/lighting-preview.c index 934ec5d308..b9b26e71bb 100644 --- a/plug-ins/lighting/lighting-preview.c +++ b/plug-ins/lighting/lighting-preview.c @@ -36,18 +36,24 @@ static guint preview_update_timer = 0; /* Protos */ /* ====== */ -static gboolean -interactive_preview_timer_callback ( gpointer data ); +static gboolean interactive_preview_timer_callback (gpointer data); + +void composite_behind (gdouble *color1, + gdouble *color2); static void -compute_preview (gint startx, gint starty, gint w, gint h) +compute_preview (gint startx, + gint starty, + gint w, + gint h) { gint xcnt, ycnt, f1, f2; guchar r, g, b; gdouble imagex, imagey; gint32 index = 0; - GimpRGB color; - GimpRGB lightcheck, darkcheck; + gdouble color[4]; + gdouble lightcheck[4] = { GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, 1.0 }; + gdouble darkcheck[4] = { GIMP_CHECK_DARK, GIMP_CHECK_DARK, GIMP_CHECK_DARK, 1.0 }; GimpVector3 pos; get_ray_func ray_func; @@ -88,12 +94,6 @@ compute_preview (gint startx, gint starty, gint w, gint h) precompute_init (width, height); - gimp_rgba_set (&lightcheck, - GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, GIMP_CHECK_LIGHT, - 1.0); - gimp_rgba_set (&darkcheck, GIMP_CHECK_DARK, GIMP_CHECK_DARK, - GIMP_CHECK_DARK, 1.0); - if (mapvals.bump_mapped == TRUE && mapvals.bumpmap_id != -1) { bumpmap_setup (gimp_drawable_get_by_id (mapvals.bumpmap_id)); @@ -138,9 +138,9 @@ compute_preview (gint startx, gint starty, gint w, gint h) precompute_normals (0, width, RINT (imagey)); } - color = (*ray_func) (&pos); + (*ray_func) (&pos, color); - if (color.a < 1.0) + if (color[3] < 1.0) { f1 = ((xcnt % 32) < 16); f2 = ((ycnt % 32) < 16); @@ -148,25 +148,33 @@ compute_preview (gint startx, gint starty, gint w, gint h) if (f1) { - if (color.a == 0.0) - color = lightcheck; + if (color[3] == 0.0) + { + for (gint i = 0; i < 4; i++) + color[i] = lightcheck[i]; + } else - gimp_rgb_composite (&color, - &lightcheck, - GIMP_RGB_COMPOSITE_BEHIND); + { + composite_behind (color, lightcheck); + } } else { - if (color.a == 0.0) - color = darkcheck; + if (color[3] == 0.0) + { + for (gint i = 0; i < 4; i++) + color[i] = darkcheck[i]; + } else - gimp_rgb_composite (&color, - &darkcheck, - GIMP_RGB_COMPOSITE_BEHIND); + { + composite_behind (color, darkcheck); + } } } - gimp_rgb_get_uchar (&color, &r, &g, &b); + r = (guchar) (color[0] * 255); + g = (guchar) (color[1] * 255); + b = (guchar) (color[2] * 255); GIMP_CAIRO_RGB24_SET_PIXEL((preview_rgb_data + index), r, g, b); index += 4; imagex++; @@ -497,3 +505,21 @@ interactive_preview_timer_callback (gpointer data) return FALSE; } + +void +composite_behind (gdouble *color1, + gdouble *color2) +{ + g_return_if_fail (color1 != NULL); + g_return_if_fail (color2 != NULL); + + if (color1[3] < 1.0) + { + gdouble factor = color2[3] * (1.0 - color1[3]); + + color1[0] = color2[0] * factor + color1[0] * color1[3]; + color1[1] = color2[1] * factor + color1[1] * color1[3]; + color1[2] = color2[2] * factor + color1[2] * color1[3]; + color1[3] = factor + color1[3]; + } +} diff --git a/plug-ins/lighting/lighting-shade.c b/plug-ins/lighting/lighting-shade.c index f7a1e3175f..44c31b7bae 100644 --- a/plug-ins/lighting/lighting-shade.c +++ b/plug-ins/lighting/lighting-shade.c @@ -24,16 +24,17 @@ static gint pre_h = -1; /* Phong shading */ /*****************/ -static GimpRGB +static void phong_shade (GimpVector3 *position, GimpVector3 *viewpoint, GimpVector3 *normal, GimpVector3 *lightposition, - GimpRGB *diff_col, - GimpRGB *light_col, - LightType light_type) + gdouble *diff_col, + gdouble *light_col, + LightType light_type, + gdouble *diffuse_color) { - GimpRGB diffuse_color, specular_color; + gdouble specular_color[4]; gdouble nl, rv, dist; GimpVector3 l, v, n, lnormal, h; @@ -81,30 +82,41 @@ phong_shade (GimpVector3 *position, /* Compute diffuse and specular intensity contribution */ /* =================================================== */ - diffuse_color = *light_col; - gimp_rgb_multiply (&diffuse_color, mapvals.material.diffuse_int); - diffuse_color.r *= diff_col->r; - diffuse_color.g *= diff_col->g; - diffuse_color.b *= diff_col->b; - gimp_rgb_multiply (&diffuse_color, nl); + for (gint i = 0; i < 4; i++) + diffuse_color[i] = light_col[i]; + for (gint i = 0; i < 3; i++) + diffuse_color[i] *= mapvals.material.diffuse_int; + + diffuse_color[0] *= diff_col[0]; + diffuse_color[1] *= diff_col[1]; + diffuse_color[2] *= diff_col[2]; + + for (gint i = 0; i < 3; i++) + diffuse_color[i] *= nl; + for (gint i = 0; i < 4; i++) + specular_color[i] = light_col[i]; - specular_color = *light_col; if (mapvals.material.metallic) /* for metals, specular color = diffuse color */ { - specular_color.r *= diff_col->r; - specular_color.g *= diff_col->g; - specular_color.b *= diff_col->b; + specular_color[0] *= diff_col[0]; + specular_color[1] *= diff_col[1]; + specular_color[2] *= diff_col[2]; } - gimp_rgb_multiply (&specular_color, mapvals.material.specular_ref); - gimp_rgb_multiply (&specular_color, rv); - gimp_rgb_add (&diffuse_color, &specular_color); - gimp_rgb_clamp (&diffuse_color); + for (gint i = 0; i < 3; i++) + { + specular_color[i] *= mapvals.material.specular_ref; + specular_color[i] *= rv; + } + + for (gint i = 0; i < 3; i++) + diffuse_color[i] += specular_color[i]; + for (gint i = 0; i < 4; i++) + diffuse_color[i] = CLAMP (diffuse_color[i], 0.0, 1.0); } - gimp_rgb_clamp (&diffuse_color); - - return diffuse_color; + for (gint i = 0; i < 4; i++) + diffuse_color[i] = CLAMP (diffuse_color[i], 0.0, 1.0); } void @@ -521,13 +533,13 @@ sphere_to_image (GimpVector3 *normal, /* These routines computes the color of the surface at a given point */ /*********************************************************************/ -GimpRGB -get_ray_color (GimpVector3 *position) +void +get_ray_color (GimpVector3 *position, + gdouble *color_sum) { - GimpRGB color; - GimpRGB color_int; - GimpRGB color_sum; - GimpRGB light_color; + gdouble color[4]; + gdouble color_int[4]; + gdouble light_color[4]; gint x, f; gdouble xf, yf; GimpVector3 normal, *p; @@ -539,14 +551,16 @@ get_ray_color (GimpVector3 *position) if (mapvals.transparent_background && heights[1][x] == 0) { - gimp_rgb_set_alpha (&color_sum, 0.0); + color_sum[3] = 0.0; } else { - color = get_image_color (xf, yf, &f); + get_image_color (xf, yf, &f, color); - color_sum = color; - gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int); + for (gint i = 0; i < 4; i++) + color_sum[i] = color[i]; + for (gint i = 0; i < 3; i++) + color_sum[i] *= mapvals.material.ambient_int; for (k = 0; k < NUM_LIGHTS; k++) { @@ -558,49 +572,53 @@ get_ray_color (GimpVector3 *position) else p = &mapvals.lightsource[k].direction; - color_int = mapvals.lightsource[k].color; - gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity); + for (gint i = 0; i < 4; i++) + color_int[i] = mapvals.lightsource[k].color[i]; + for (gint i = 0; i < 3; i++) + color_int[i] *= mapvals.lightsource[k].intensity; if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1) { - light_color = phong_shade (position, - &mapvals.viewpoint, - &mapvals.planenormal, - p, - &color, - &color_int, - mapvals.lightsource[k].type); + phong_shade (position, + &mapvals.viewpoint, + &mapvals.planenormal, + p, + color, + color_int, + mapvals.lightsource[k].type, + light_color); } else { normal = vertex_normals[1][(gint) RINT (xf)]; - light_color = phong_shade (position, - &mapvals.viewpoint, - &normal, - p, - &color, - &color_int, - mapvals.lightsource[k].type); + phong_shade (position, + &mapvals.viewpoint, + &normal, + p, + color, + color_int, + mapvals.lightsource[k].type, + light_color); } - gimp_rgb_add (&color_sum, &light_color); + for (gint i = 0; i < 3; i++) + color_sum[i] += light_color[i]; } } - gimp_rgb_clamp (&color_sum); - - return color_sum; + for (gint i = 0; i < 4; i++) + color_sum[i] = CLAMP (color_sum[i], 0.0, 1.0); } -GimpRGB -get_ray_color_ref (GimpVector3 *position) +void +get_ray_color_ref (GimpVector3 *position, + gdouble *color_sum) { - GimpRGB color_sum; - GimpRGB color_int; - GimpRGB light_color; - GimpRGB color, env_color; + gdouble color_int[4]; + gdouble light_color[4]; + gdouble color[4], env_color[4]; gint x, f; gdouble xf, yf; GimpVector3 normal, *p, v, r; @@ -625,13 +643,16 @@ get_ray_color_ref (GimpVector3 *position) if (mapvals.transparent_background && heights[1][x] == 0) { - gimp_rgb_set_alpha (&color_sum, 0.0); + color_sum[3] = 0.0; } else { - color = get_image_color (xf, yf, &f); - color_sum = color; - gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int); + get_image_color (xf, yf, &f, color); + + for (gint i = 0; i < 4; i++) + color_sum[i] = color[i]; + for (gint i = 0; i < 3; i++) + color_sum[i] *= mapvals.material.ambient_int; for (k = 0; k < NUM_LIGHTS; k++) { @@ -643,16 +664,19 @@ get_ray_color_ref (GimpVector3 *position) else if (mapvals.lightsource[k].type == POINT_LIGHT) p = &mapvals.lightsource[k].position; - color_int = mapvals.lightsource[k].color; - gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity); + for (gint i = 0; i < 4; i++) + color_int[i] = mapvals.lightsource[k].color[i]; + for (gint i = 0; i < 3; i++) + color_int[i] *= mapvals.lightsource[k].intensity; - light_color = phong_shade (position, - &mapvals.viewpoint, - &normal, - p, - &color, - &color_int, - mapvals.lightsource[0].type); + phong_shade (position, + &mapvals.viewpoint, + &normal, + p, + color, + color_int, + mapvals.lightsource[0].type, + light_color); } gimp_vector3_sub (&v, &mapvals.viewpoint, position); @@ -664,37 +688,39 @@ get_ray_color_ref (GimpVector3 *position) /* =============================== */ sphere_to_image (&r, &xf, &yf); - env_color = peek_env_map (RINT (env_width * xf), - RINT (env_height * yf)); + peek_env_map (RINT (env_width * xf), + RINT (env_height * yf), + env_color); tmpval = mapvals.material.diffuse_int; mapvals.material.diffuse_int = 0.; - light_color = phong_shade (position, - &mapvals.viewpoint, - &normal, - &r, - &color, - &env_color, - DIRECTIONAL_LIGHT); + phong_shade (position, + &mapvals.viewpoint, + &normal, + &r, + color, + env_color, + DIRECTIONAL_LIGHT, + light_color); mapvals.material.diffuse_int = tmpval; - gimp_rgb_add (&color_sum, &light_color); + for (gint i = 0; i < 3; i++) + color_sum[i] += light_color[i]; } - gimp_rgb_clamp (&color_sum); - - return color_sum; + for (gint i = 0; i < 4; i++) + color_sum[i] = CLAMP (color_sum[i], 0.0, 1.0); } -GimpRGB -get_ray_color_no_bilinear (GimpVector3 *position) +void +get_ray_color_no_bilinear (GimpVector3 *position, + gdouble *color_sum) { - GimpRGB color; - GimpRGB color_int; - GimpRGB color_sum; - GimpRGB light_color; + gdouble color[4]; + gdouble color_int[4]; + gdouble light_color[4]; gint x; gdouble xf, yf; GimpVector3 normal, *p; @@ -706,14 +732,16 @@ get_ray_color_no_bilinear (GimpVector3 *position) if (mapvals.transparent_background && heights[1][x] == 0) { - gimp_rgb_set_alpha (&color_sum, 0.0); + color_sum[3] = 0.0; } else { - color = peek (x, RINT (yf)); + peek (x, RINT (yf), color); - color_sum = color; - gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int); + for (gint i = 0; i < 4; i++) + color_sum[i] = color[i]; + for (gint i = 0; i < 3; i++) + color_sum[i] *= mapvals.material.ambient_int; for (k = 0; k < NUM_LIGHTS; k++) { @@ -725,49 +753,53 @@ get_ray_color_no_bilinear (GimpVector3 *position) else if (mapvals.lightsource[k].type == POINT_LIGHT) p = &mapvals.lightsource[k].position; - color_int = mapvals.lightsource[k].color; - gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity); + for (gint i = 0; i < 4; i++) + color_int[i] = mapvals.lightsource[k].color[i]; + for (gint i = 0; i < 3; i++) + color_int[i] *= mapvals.lightsource[k].intensity; if (mapvals.bump_mapped == FALSE || mapvals.bumpmap_id == -1) { - light_color = phong_shade (position, - &mapvals.viewpoint, - &mapvals.planenormal, - p, - &color, - &color_int, - mapvals.lightsource[k].type); + phong_shade (position, + &mapvals.viewpoint, + &mapvals.planenormal, + p, + color, + color_int, + mapvals.lightsource[k].type, + light_color); } else { normal = vertex_normals[1][x]; - light_color = phong_shade (position, - &mapvals.viewpoint, - &normal, - p, - &color, - &color_int, - mapvals.lightsource[k].type); + phong_shade (position, + &mapvals.viewpoint, + &normal, + p, + color, + color_int, + mapvals.lightsource[k].type, + light_color); } - gimp_rgb_add (&color_sum, &light_color); + for (gint i = 0; i < 3; i++) + color_sum[i] += light_color[i]; } } - gimp_rgb_clamp (&color_sum); - - return color_sum; + for (gint i = 0; i < 4; i++) + color_sum[i] = CLAMP (color_sum[i], 0.0, 1.0); } -GimpRGB -get_ray_color_no_bilinear_ref (GimpVector3 *position) +void +get_ray_color_no_bilinear_ref (GimpVector3 *position, + gdouble *color_sum) { - GimpRGB color_sum; - GimpRGB color_int; - GimpRGB light_color; - GimpRGB color, env_color; + gdouble color_int[4]; + gdouble light_color[4]; + gdouble color[4], env_color[4]; gint x; gdouble xf, yf; GimpVector3 normal, *p, v, r; @@ -792,13 +824,16 @@ get_ray_color_no_bilinear_ref (GimpVector3 *position) if (mapvals.transparent_background && heights[1][x] == 0) { - gimp_rgb_set_alpha (&color_sum, 0.0); + color_sum[3] = 0.0; } else { - color = peek (RINT (xf), RINT (yf)); - color_sum = color; - gimp_rgb_multiply (&color_sum, mapvals.material.ambient_int); + peek (RINT (xf), RINT (yf), color); + + for (gint i = 0; i < 4; i++) + color_sum[i] = color[i]; + for (gint i = 0; i < 3; i++) + color_sum[i] *= mapvals.material.ambient_int; for (k = 0; k < NUM_LIGHTS; k++) { @@ -810,16 +845,19 @@ get_ray_color_no_bilinear_ref (GimpVector3 *position) else if (mapvals.lightsource[k].type == POINT_LIGHT) p = &mapvals.lightsource[k].position; - color_int = mapvals.lightsource[k].color; - gimp_rgb_multiply (&color_int, mapvals.lightsource[k].intensity); + for (gint i = 0; i < 4; i++) + color_int[i] = mapvals.lightsource[k].color[i]; + for (gint i = 0; i < 3; i++) + color_int[i] *= mapvals.lightsource[k].intensity; - light_color = phong_shade (position, - &mapvals.viewpoint, - &normal, - p, - &color, - &color_int, - mapvals.lightsource[0].type); + phong_shade (position, + &mapvals.viewpoint, + &normal, + p, + color, + color_int, + mapvals.lightsource[0].type, + light_color); } gimp_vector3_sub (&v, &mapvals.viewpoint, position); @@ -831,26 +869,28 @@ get_ray_color_no_bilinear_ref (GimpVector3 *position) /* =============================== */ sphere_to_image (&r, &xf, &yf); - env_color = peek_env_map (RINT (env_width * xf), - RINT (env_height * yf)); + peek_env_map (RINT (env_width * xf), + RINT (env_height * yf), + env_color); tmpval = mapvals.material.diffuse_int; - mapvals.material.diffuse_int = 0.; + mapvals.material.diffuse_int = 0.0; - light_color = phong_shade (position, - &mapvals.viewpoint, - &normal, - &r, - &color, - &env_color, - DIRECTIONAL_LIGHT); + phong_shade (position, + &mapvals.viewpoint, + &normal, + &r, + color, + env_color, + DIRECTIONAL_LIGHT, + light_color); mapvals.material.diffuse_int = tmpval; - gimp_rgb_add (&color_sum, &light_color); + for (gint i = 0; i < 3; i++) + color_sum[i] += light_color[i]; } - gimp_rgb_clamp (&color_sum); - - return color_sum; + for (gint i = 0; i < 4; i++) + color_sum[i] = CLAMP (color_sum[i], 0.0, 1.0); } diff --git a/plug-ins/lighting/lighting-shade.h b/plug-ins/lighting/lighting-shade.h index 536df95adf..76c51a2ecb 100644 --- a/plug-ins/lighting/lighting-shade.h +++ b/plug-ins/lighting/lighting-shade.h @@ -1,18 +1,23 @@ #ifndef __LIGHTING_SHADE_H__ #define __LIGHTING_SHADE_H__ -typedef GimpRGB (* get_ray_func) (GimpVector3 *vector); +typedef void (* get_ray_func) (GimpVector3 *vector, + gdouble *color_sum); -GimpRGB get_ray_color (GimpVector3 *position); -GimpRGB get_ray_color_no_bilinear (GimpVector3 *position); -GimpRGB get_ray_color_ref (GimpVector3 *position); -GimpRGB get_ray_color_no_bilinear_ref (GimpVector3 *position); +void get_ray_color (GimpVector3 *position, + gdouble *color_sum); +void get_ray_color_no_bilinear (GimpVector3 *position, + gdouble *color_sum); +void get_ray_color_ref (GimpVector3 *position, + gdouble *color_sum); +void get_ray_color_no_bilinear_ref (GimpVector3 *position, + gdouble *color_sum); void precompute_init (gint w, - gint h); + gint h); void precompute_normals (gint x1, - gint x2, - gint y); + gint x2, + gint y); void interpol_row (gint x1, gint x2, gint y); diff --git a/plug-ins/lighting/lighting-ui.c b/plug-ins/lighting/lighting-ui.c index 7a33249dfa..5c10fc3518 100644 --- a/plug-ins/lighting/lighting-ui.c +++ b/plug-ins/lighting/lighting-ui.c @@ -849,9 +849,9 @@ save_preset_response (GtkFileChooser *chooser, g_ascii_dtostr (buffer3, blen, source->direction.z)); fprintf (fp, "Color: %s %s %s\n", - g_ascii_dtostr (buffer1, blen, source->color.r), - g_ascii_dtostr (buffer2, blen, source->color.g), - g_ascii_dtostr (buffer3, blen, source->color.b)); + g_ascii_dtostr (buffer1, blen, source->color[0]), + g_ascii_dtostr (buffer2, blen, source->color[1]), + g_ascii_dtostr (buffer3, blen, source->color[2])); fprintf (fp, "Intensity: %s\n", g_ascii_dtostr (buffer1, blen, source->intensity)); @@ -1005,10 +1005,10 @@ load_preset_response (GtkFileChooser *chooser, sizeof (buffer2) - 1, sizeof (buffer3) - 1); fscanf (fp, fmt_str, buffer1, buffer2, buffer3); - source->color.r = g_ascii_strtod (buffer1, &endptr); - source->color.g = g_ascii_strtod (buffer2, &endptr); - source->color.b = g_ascii_strtod (buffer3, &endptr); - source->color.a = 1.0; + source->color[0] = g_ascii_strtod (buffer1, &endptr); + source->color[1] = g_ascii_strtod (buffer2, &endptr); + source->color[2] = g_ascii_strtod (buffer3, &endptr); + source->color[3] = 1.0; snprintf (fmt_str, sizeof (fmt_str), " Intensity: %%%" G_GSIZE_FORMAT "s",