[gimp] app: when creating palette only snap to black/white when present
- From: Øyvind "pippin" Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: when creating palette only snap to black/white when present
- Date: Fri, 1 May 2020 00:20:29 +0000 (UTC)
commit d4387987b55eda4647f53778dc861cdf7b18be2e
Author: Øyvind Kolås <pippin gimp org>
Date: Fri May 1 02:19:15 2020 +0200
app: when creating palette only snap to black/white when present
By only doing the snapping to white/black for whitest/blackest palette
entries when the original RGB data contained these colors we permit
choosing near white/black colors in the cases where this might be
a desirable result as the whitest/blackest colors.
app/core/gimpimage-convert-indexed.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
---
diff --git a/app/core/gimpimage-convert-indexed.c b/app/core/gimpimage-convert-indexed.c
index 3f1b72c9b7..e1532fc581 100644
--- a/app/core/gimpimage-convert-indexed.c
+++ b/app/core/gimpimage-convert-indexed.c
@@ -544,6 +544,8 @@ static void compute_color_lin8 (QuantizeObj *quantobj,
static guchar found_cols[MAXNUMCOLORS][3];
static gint num_found_cols;
static gboolean needs_quantize;
+static gboolean had_white;
+static gboolean had_black;
/**********************************************************/
@@ -851,6 +853,8 @@ gimp_image_convert_indexed (GimpImage *image,
* need to quantize or color-dither.
*/
needs_quantize = FALSE;
+ had_black = FALSE;
+ had_white = FALSE;
num_found_cols = 0;
/* Build the histogram */
@@ -1162,6 +1166,18 @@ generate_histogram_gray (CFHistogram histogram,
}
}
+static void
+check_white_or_black (const guchar *data)
+{
+ if (data[RED] == 255 &&
+ data[GREEN] == 255 &&
+ data[BLUE] == 255)
+ had_white = TRUE;
+ if (data[RED] ==0 &&
+ data[GREEN]==0 &&
+ data[BLUE] ==0)
+ had_black = TRUE;
+}
static void
generate_histogram_rgb (CFHistogram histogram,
@@ -1241,6 +1257,7 @@ generate_histogram_rgb (CFHistogram histogram,
data[RED],
data[GREEN],
data[BLUE]);
+ check_white_or_black (data);
(*colfreq)++;
}
@@ -1265,6 +1282,7 @@ generate_histogram_rgb (CFHistogram histogram,
data[RED],
data[GREEN],
data[BLUE]);
+ check_white_or_black (data);
(*colfreq)++;
}
@@ -1342,6 +1360,8 @@ generate_histogram_rgb (CFHistogram histogram,
found_cols[num_found_cols-1][0] = data[RED];
found_cols[num_found_cols-1][1] = data[GREEN];
found_cols[num_found_cols-1][2] = data[BLUE];
+
+ check_white_or_black (data);
}
}
}
@@ -2796,13 +2816,13 @@ snap_to_black_and_white (QuantizeObj *quantobj)
}
}
- if (white_dist < POW2(24)) /* 24 units in sRGB ~= deltaE of 9.5 */
+ if (had_white && white_dist < POW2(32))
{
quantobj->cmap[whitest].red =
quantobj->cmap[whitest].green =
quantobj->cmap[whitest].blue = 255;
}
- if (black_dist < POW2(24))
+ if (had_black && black_dist < POW2(32))
{
quantobj->cmap[blackest].red =
quantobj->cmap[blackest].green =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]