app: no more GimpRGB/GimpHSL/GimpHSV usage in paint code at all anymore.

I'm a bit unsure about the GimpMyBrushCore which doesn't have much
indication on which color space we are working in, but the new code
should not be worse than the old one (if wrong, color-wise, it should be
the same wrong as before).
This commit is contained in:
Jehan 2023-12-22 15:24:22 +09:00
parent fcfb574715
commit d55325829f
5 changed files with 34 additions and 41 deletions

View File

@ -621,7 +621,7 @@ gimp_gegl_smudge_with_paint (GeglBuffer *accum_buffer,
const GeglRectangle *accum_rect,
GeglBuffer *canvas_buffer,
const GeglRectangle *canvas_rect,
const GimpRGB *brush_color,
GeglColor *brush_color,
GeglBuffer *paint_buffer,
gboolean no_erasing,
gdouble flow,
@ -643,16 +643,11 @@ gimp_gegl_smudge_with_paint (GeglBuffer *accum_buffer,
if (! canvas_rect)
canvas_rect = gegl_buffer_get_extent (canvas_buffer);
/* convert brush color from double to float */
/* convert brush color to linear RGBA float */
if (brush_color)
{
const gdouble *brush_color_ptr = &brush_color->r;
gint b;
for (b = 0; b < 4; b++)
brush_color_float[b] = brush_color_ptr[b];
brush_a *= brush_color_ptr[3];
gegl_color_get_pixel (brush_color, babl_format ("RGBA float"), brush_color_float);
brush_a *= brush_color_float[3];
}
gegl_parallel_distribute_area (

View File

@ -56,7 +56,7 @@ void gimp_gegl_smudge_with_paint (GeglBuffer *accum_buffer,
const GeglRectangle *accum_rect,
GeglBuffer *canvas_buffer,
const GeglRectangle *canvas_rect,
const GimpRGB *brush_color,
GeglColor *brush_color,
GeglBuffer *paint_buffer,
gboolean no_erasing,
gdouble flow,

View File

@ -391,8 +391,7 @@ gimp_mybrush_core_create_brushes (GimpMybrushCore *mybrush,
GimpMybrushOptions *options = GIMP_MYBRUSH_OPTIONS (paint_options);
GimpContext *context = GIMP_CONTEXT (paint_options);
GeglColor *color;
GimpRGB fg;
GimpHSV hsv;
gfloat hsv[3];
gint n_strokes;
gint i;
@ -408,11 +407,7 @@ gimp_mybrush_core_create_brushes (GimpMybrushCore *mybrush,
else
color = gimp_context_get_foreground (context);
gegl_color_get_rgba_with_space (color, &fg.r, &fg.g, &fg.b, &fg.a, NULL);
gimp_pickable_srgb_to_image_color (GIMP_PICKABLE (drawable),
&fg, &fg);
gimp_rgb_to_hsv (&fg, &hsv);
gegl_color_get_pixel (color, babl_format_with_space ("HSV float", gimp_drawable_get_space (drawable)), hsv);
n_strokes = gimp_symmetry_get_size (sym);
@ -431,13 +426,13 @@ gimp_mybrush_core_create_brushes (GimpMybrushCore *mybrush,
{
mypaint_brush_set_base_value (brush,
MYPAINT_BRUSH_SETTING_COLOR_H,
hsv.h);
hsv[0]);
mypaint_brush_set_base_value (brush,
MYPAINT_BRUSH_SETTING_COLOR_S,
hsv.s);
hsv[1]);
mypaint_brush_set_base_value (brush,
MYPAINT_BRUSH_SETTING_COLOR_V,
hsv.v);
hsv[2]);
}
mypaint_brush_set_base_value (brush,

View File

@ -357,6 +357,9 @@ gimp_mypaint_surface_draw_dab (MyPaintSurface *base_surface,
GeglBufferIterator *iter;
GeglRectangle dabRect;
GimpComponentMask component_mask = surface->component_mask;
/* XXX What spaces should we be working from and to? */
const Babl *rgb_to_hsl_fish = babl_fish (babl_format ("R'G'B' float"), babl_format ("HSL float"));
const Babl *hsl_to_rgb_fish = babl_fish (babl_format ("HSL float"), babl_format ("R'G'B' float"));
const float one_over_radius2 = 1.0f / (radius * radius);
const double angle_rad = angle / 360 * 2 * M_PI;
@ -454,22 +457,27 @@ gimp_mypaint_surface_draw_dab (MyPaintSurface *base_surface,
a = alpha + dst_alpha - alpha * dst_alpha;
if (a > 0.0f)
{
GimpHSL pixel_hsl, out_hsl;
GimpRGB pixel_rgb = {color_r, color_g, color_b};
GimpRGB out_rgb = {r, g, b};
float pixel_hsl[3], out_hsl[3];
float pixel_rgb[3] = {color_r, color_g, color_b};
float out_rgb[3] = {r, g, b};
float src_term = alpha / a;
float dst_term = 1.0f - src_term;
gimp_rgb_to_hsl (&pixel_rgb, &pixel_hsl);
gimp_rgb_to_hsl (&out_rgb, &out_hsl);
/* Here I am completely unsure if the conversion are
* right, regarding color spaces. What is the color space
* of color_r/g/b arguments?
* TODO: this code should be double-checked.
*/
babl_process (rgb_to_hsl_fish, pixel_rgb, pixel_hsl, 1);
babl_process (rgb_to_hsl_fish, out_rgb, out_hsl, 1);
out_hsl.h = pixel_hsl.h;
out_hsl.s = pixel_hsl.s;
gimp_hsl_to_rgb (&out_hsl, &out_rgb);
out_hsl[0] = pixel_hsl[0];
out_hsl[1] = pixel_hsl[1];
babl_process (hsl_to_rgb_fish, out_hsl, out_rgb, 1);
r = (float)out_rgb.r * src_term + r * dst_term;
g = (float)out_rgb.g * src_term + g * dst_term;
b = (float)out_rgb.b * src_term + b * dst_term;
r = (float)out_rgb[0] * src_term + r * dst_term;
g = (float)out_rgb[1] * src_term + g * dst_term;
b = (float)out_rgb[2] * src_term + b * dst_term;
}
}

View File

@ -359,8 +359,7 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
gdouble flow;
gdouble grad_point;
/* brush color */
GeglColor *brush_color = NULL;
GimpRGB brush_rgb; /* whether use single color or pixmap */
GeglColor *brush_color = NULL; /* whether use single color or pixmap */
/* accum buffer */
gint x, y;
GeglBuffer *accum_buffer;
@ -505,10 +504,6 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
TRUE);
}
if (brush_color)
/* Convert to linear RGBA */
gegl_color_get_pixel (brush_color, babl_format ("RGBA double"), &brush_rgb);
gimp_gegl_smudge_with_paint (accum_buffer,
GEGL_RECTANGLE (paint_buffer_x - x,
paint_buffer_y - y,
@ -521,7 +516,7 @@ gimp_smudge_motion (GimpPaintCore *paint_core,
dest_pickable_off_y,
paint_buffer_width,
paint_buffer_height),
brush_color ? &brush_rgb : NULL,
brush_color,
paint_buffer,
options->no_erasing,
flow,