aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2025-01-26 22:15:48 -0800
committerPaul Eggert2025-01-26 23:05:51 -0800
commit028fae966142b6e2330b9250fb4cdf2cbd8e1446 (patch)
tree8f837233159d513997b5f2890f68cdd0240b6565 /src
parentf885806fdf1aa862ad55d124e9795794fed0b964 (diff)
downloademacs-028fae966142b6e2330b9250fb4cdf2cbd8e1446.tar.gz
emacs-028fae966142b6e2330b9250fb4cdf2cbd8e1446.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/image.c41
1 files 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,
1971 return best; 1971 return best;
1972} 1972}
1973 1973
1974static Lisp_Object
1975make_color_name (unsigned int red, unsigned int green, unsigned int blue)
1976{
1977 return make_formatted_string ("#%04x%04x%04x", red, green, blue);
1978}
1979
1974/* Return the `background' field of IMG. If IMG doesn't have one yet, 1980/* Return the `background' field of IMG. If IMG doesn't have one yet,
1975 it is guessed heuristically. If non-zero, XIMG is an existing 1981 it is guessed heuristically. If non-zero, XIMG is an existing
1976 Emacs_Pix_Context object (device context with the image selected on 1982 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)
1993 RGB_PIXEL_COLOR bg 1999 RGB_PIXEL_COLOR bg
1994 = four_corners_best (pimg, img->corners, img->width, img->height); 2000 = four_corners_best (pimg, img->corners, img->width, img->height);
1995#ifdef USE_CAIRO 2001#ifdef USE_CAIRO
1996 { 2002 Lisp_Object color_name = make_color_name (RED16_FROM_ULONG (bg),
1997 char color_name[30]; 2003 GREEN16_FROM_ULONG (bg),
1998 snprintf (color_name, sizeof color_name, "#%04x%04x%04x", 2004 BLUE16_FROM_ULONG (bg));
1999 (unsigned int) RED16_FROM_ULONG (bg), 2005 bg = image_alloc_image_color (f, img, color_name, 0);
2000 (unsigned int) GREEN16_FROM_ULONG (bg),
2001 (unsigned int) BLUE16_FROM_ULONG (bg));
2002 bg = image_alloc_image_color (f, img, build_string (color_name), 0);
2003 }
2004#endif 2006#endif
2005 img->background = bg; 2007 img->background = bg;
2006 2008
@@ -7383,15 +7385,11 @@ image_build_heuristic_mask (struct frame *f, struct image *img,
7383 if (i == 3 && NILP (how)) 7385 if (i == 3 && NILP (how))
7384 { 7386 {
7385#ifndef USE_CAIRO 7387#ifndef USE_CAIRO
7386 char color_name[30]; 7388 Lisp_Object color_name = make_color_name (rgb[0], rgb[1], rgb[2]);
7387 int len = snprintf (color_name, sizeof color_name, "#%04x%04x%04x", 7389 bg = image_alloc_image_color (f, img, color_name, 0);
7388 rgb[0] + 0u, rgb[1] + 0u, rgb[2] + 0u); 7390# ifdef HAVE_NTGUI
7389 eassert (len < sizeof color_name); 7391 bg &= 0x00ffffff; /* Filter out palette info. */
7390 bg = ( 7392# endif
7391#ifdef HAVE_NTGUI
7392 0x00ffffff & /* Filter out palette info. */
7393#endif /* HAVE_NTGUI */
7394 image_alloc_image_color (f, img, build_string (color_name), 0));
7395#else /* USE_CAIRO */ 7393#else /* USE_CAIRO */
7396 bg = lookup_rgb_color (f, rgb[0], rgb[1], rgb[2]); 7394 bg = lookup_rgb_color (f, rgb[0], rgb[1], rgb[2]);
7397#endif /* USE_CAIRO */ 7395#endif /* USE_CAIRO */
@@ -8535,12 +8533,9 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
8535#ifndef USE_CAIRO 8533#ifndef USE_CAIRO
8536 img->background = lookup_rgb_color (f, bg->red, bg->green, bg->blue); 8534 img->background = lookup_rgb_color (f, bg->red, bg->green, bg->blue);
8537#else /* USE_CAIRO */ 8535#else /* USE_CAIRO */
8538 char color_name[30]; 8536 Lisp_Object color_name
8539 int len = snprintf (color_name, sizeof color_name, "#%04x%04x%04x", 8537 = make_color_name (bg->red, bg->green, bg->blue);
8540 bg->red, bg->green, bg->blue); 8538 img->background = image_alloc_image_color (f, img, color_name, 0);
8541 eassert (len < sizeof color_name);
8542 img->background
8543 = image_alloc_image_color (f, img, build_string (color_name), 0);
8544#endif /* USE_CAIRO */ 8539#endif /* USE_CAIRO */
8545 img->background_valid = 1; 8540 img->background_valid = 1;
8546 } 8541 }