[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 028fae96614 03/18: Simplify building of color names in image.c
From: |
Paul Eggert |
Subject: |
master 028fae96614 03/18: Simplify building of color names in image.c |
Date: |
Mon, 27 Jan 2025 02:06:08 -0500 (EST) |
branch: master
commit 028fae966142b6e2330b9250fb4cdf2cbd8e1446
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>
Simplify building of color names in image.c
* src/image.c (make_color_name): New function.
(image_background, image_build_heuristic_mask, png_load_body): Use it.
---
src/image.c | 41 ++++++++++++++++++-----------------------
1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/src/image.c b/src/image.c
index 4350c415d9c..901063c9bde 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1971,6 +1971,12 @@ four_corners_best (Emacs_Pix_Context pimg, int *corners,
return best;
}
+static Lisp_Object
+make_color_name (unsigned int red, unsigned int green, unsigned int blue)
+{
+ return make_formatted_string ("#%04x%04x%04x", red, green, blue);
+}
+
/* Return the `background' field of IMG. If IMG doesn't have one yet,
it is guessed heuristically. If non-zero, XIMG is an existing
Emacs_Pix_Context object (device context with the image selected on
@@ -1993,14 +1999,10 @@ image_background (struct image *img, struct frame *f,
Emacs_Pix_Context pimg)
RGB_PIXEL_COLOR bg
= four_corners_best (pimg, img->corners, img->width, img->height);
#ifdef USE_CAIRO
- {
- char color_name[30];
- snprintf (color_name, sizeof color_name, "#%04x%04x%04x",
- (unsigned int) RED16_FROM_ULONG (bg),
- (unsigned int) GREEN16_FROM_ULONG (bg),
- (unsigned int) BLUE16_FROM_ULONG (bg));
- bg = image_alloc_image_color (f, img, build_string (color_name), 0);
- }
+ Lisp_Object color_name = make_color_name (RED16_FROM_ULONG (bg),
+ GREEN16_FROM_ULONG (bg),
+ BLUE16_FROM_ULONG (bg));
+ bg = image_alloc_image_color (f, img, color_name, 0);
#endif
img->background = bg;
@@ -7383,15 +7385,11 @@ image_build_heuristic_mask (struct frame *f, struct
image *img,
if (i == 3 && NILP (how))
{
#ifndef USE_CAIRO
- char color_name[30];
- int len = snprintf (color_name, sizeof color_name, "#%04x%04x%04x",
- rgb[0] + 0u, rgb[1] + 0u, rgb[2] + 0u);
- eassert (len < sizeof color_name);
- bg = (
-#ifdef HAVE_NTGUI
- 0x00ffffff & /* Filter out palette info. */
-#endif /* HAVE_NTGUI */
- image_alloc_image_color (f, img, build_string (color_name), 0));
+ Lisp_Object color_name = make_color_name (rgb[0], rgb[1], rgb[2]);
+ bg = image_alloc_image_color (f, img, color_name, 0);
+# ifdef HAVE_NTGUI
+ bg &= 0x00ffffff; /* Filter out palette info. */
+# endif
#else /* USE_CAIRO */
bg = lookup_rgb_color (f, rgb[0], rgb[1], rgb[2]);
#endif /* USE_CAIRO */
@@ -8535,12 +8533,9 @@ png_load_body (struct frame *f, struct image *img,
struct png_load_context *c)
#ifndef USE_CAIRO
img->background = lookup_rgb_color (f, bg->red, bg->green, bg->blue);
#else /* USE_CAIRO */
- char color_name[30];
- int len = snprintf (color_name, sizeof color_name, "#%04x%04x%04x",
- bg->red, bg->green, bg->blue);
- eassert (len < sizeof color_name);
- img->background
- = image_alloc_image_color (f, img, build_string (color_name), 0);
+ Lisp_Object color_name
+ = make_color_name (bg->red, bg->green, bg->blue);
+ img->background = image_alloc_image_color (f, img, color_name, 0);
#endif /* USE_CAIRO */
img->background_valid = 1;
}
- master updated (b06364f1b66 -> 1ed769a3cb7), Paul Eggert, 2025/01/27
- master f885806fdf1 02/18: Simplify make_formatted_string API, Paul Eggert, 2025/01/27
- master 17a8bf53f39 05/18: Fix x-show-tip bignum crash, Paul Eggert, 2025/01/27
- master 2e8ef091041 11/18: Protect against GCing of last_mouse_window, Paul Eggert, 2025/01/27
- master bcfd4d21b0a 01/18: Fix unlikely time zone abbreviation bug, Paul Eggert, 2025/01/27
- master c50e8c24247 04/18: Prefer make_formatted_string in svg_load_image, Paul Eggert, 2025/01/27
- master 028fae96614 03/18: Simplify building of color names in image.c,
Paul Eggert <=
- master 6ff06ff738e 06/18: Beware large stack growth in pgtk_menu_show, Paul Eggert, 2025/01/27
- master 06fd3f4e98d 08/18: Use gtk_disable_setlocale, Paul Eggert, 2025/01/27
- master 8d8272d02e3 13/18: Ignore -fanalyzer-null-argument in pgtkterm.c, Paul Eggert, 2025/01/27
- master f8b8dddce90 14/18: Minor format_string tuneup, Paul Eggert, 2025/01/27
- master a5c47258ffe 17/18: Fix unlikely eassert failure in invalid_radix_integer, Paul Eggert, 2025/01/27
- master f809302fe55 16/18: Fix unlikely eassert failure in xg_set_widget_bg, Paul Eggert, 2025/01/27
- master c0d83876f18 09/18: Avoid undefined behavior with botched pgtk menu, Paul Eggert, 2025/01/27
- master 1ed769a3cb7 18/18: Pacify -Wanalyzer-use-of-uninitialized-value, Paul Eggert, 2025/01/27
- master a1e4f6a35c7 07/18: Avoid unlikely int overflow., Paul Eggert, 2025/01/27
- master ff65cc9944d 10/18: Pacify GCC in pgtkselect malloc alignment, Paul Eggert, 2025/01/27