diff options
| author | Po Lu | 2022-12-22 15:50:12 +0800 |
|---|---|---|
| committer | Po Lu | 2022-12-22 15:51:15 +0800 |
| commit | f681b76a7c43ff54f1aba276f09b8fa0e0dea578 (patch) | |
| tree | 847994a0066d19183a996645f397c0a984be4d2e /src | |
| parent | e98ab3f458b25812eff1b3a7ce6429caece4c891 (diff) | |
| download | emacs-f681b76a7c43ff54f1aba276f09b8fa0e0dea578.tar.gz emacs-f681b76a7c43ff54f1aba276f09b8fa0e0dea578.zip | |
Simplify X premultipled pixel allocation code
* src/xterm.c (x_premultiply_pixel): New function.
(x_query_colors): Improve documentation.
(x_draw_fringe_bitmap, x_query_frame_background_color): Use
x_premultiply_pixel.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xterm.c | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/src/xterm.c b/src/xterm.c index 60d48165650..5947145ce06 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -7645,6 +7645,46 @@ x_after_update_window_line (struct window *w, struct glyph_row *desired_row) | |||
| 7645 | #endif | 7645 | #endif |
| 7646 | } | 7646 | } |
| 7647 | 7647 | ||
| 7648 | /* Generate a premultiplied pixel value for COLOR with ALPHA applied | ||
| 7649 | on the given display. COLOR will be modified. The display must | ||
| 7650 | use a visual that supports an alpha channel. | ||
| 7651 | |||
| 7652 | This is possibly dead code on builds which do not support | ||
| 7653 | XRender. */ | ||
| 7654 | |||
| 7655 | #ifndef USE_CAIRO | ||
| 7656 | |||
| 7657 | static unsigned long | ||
| 7658 | x_premultiply_pixel (struct x_display_info *dpyinfo, | ||
| 7659 | XColor *color, double alpha) | ||
| 7660 | { | ||
| 7661 | unsigned long pixel; | ||
| 7662 | |||
| 7663 | eassert (dpyinfo->alpha_bits); | ||
| 7664 | |||
| 7665 | /* Multiply the RGB channels. */ | ||
| 7666 | color->red *= alpha; | ||
| 7667 | color->green *= alpha; | ||
| 7668 | color->blue *= alpha; | ||
| 7669 | |||
| 7670 | /* First, allocate a fully opaque pixel. */ | ||
| 7671 | pixel = x_make_truecolor_pixel (dpyinfo, color->red, | ||
| 7672 | color->green, | ||
| 7673 | color->blue); | ||
| 7674 | |||
| 7675 | /* Next, erase the alpha component. */ | ||
| 7676 | pixel &= ~dpyinfo->alpha_mask; | ||
| 7677 | |||
| 7678 | /* And add an alpha channel. */ | ||
| 7679 | pixel |= (((unsigned long) (alpha * 65535) | ||
| 7680 | >> (16 - dpyinfo->alpha_bits)) | ||
| 7681 | << dpyinfo->alpha_offset); | ||
| 7682 | |||
| 7683 | return pixel; | ||
| 7684 | } | ||
| 7685 | |||
| 7686 | #endif | ||
| 7687 | |||
| 7648 | static void | 7688 | static void |
| 7649 | x_draw_fringe_bitmap (struct window *w, struct glyph_row *row, | 7689 | x_draw_fringe_bitmap (struct window *w, struct glyph_row *row, |
| 7650 | struct draw_fringe_bitmap_params *p) | 7690 | struct draw_fringe_bitmap_params *p) |
| @@ -7734,18 +7774,15 @@ x_draw_fringe_bitmap (struct window *w, struct glyph_row *row, | |||
| 7734 | if (FRAME_DISPLAY_INFO (f)->alpha_bits | 7774 | if (FRAME_DISPLAY_INFO (f)->alpha_bits |
| 7735 | && f->alpha_background < 1.0) | 7775 | && f->alpha_background < 1.0) |
| 7736 | { | 7776 | { |
| 7777 | /* Extend the background color with an alpha channel | ||
| 7778 | according to f->alpha_background. */ | ||
| 7737 | bg.pixel = background; | 7779 | bg.pixel = background; |
| 7738 | x_query_colors (f, &bg, 1); | 7780 | x_query_colors (f, &bg, 1); |
| 7739 | bg.red *= f->alpha_background; | ||
| 7740 | bg.green *= f->alpha_background; | ||
| 7741 | bg.blue *= f->alpha_background; | ||
| 7742 | 7781 | ||
| 7743 | background = x_make_truecolor_pixel (FRAME_DISPLAY_INFO (f), | 7782 | background |
| 7744 | bg.red, bg.green, bg.blue); | 7783 | = x_premultiply_pixel (FRAME_DISPLAY_INFO (f), |
| 7745 | background &= ~FRAME_DISPLAY_INFO (f)->alpha_mask; | 7784 | &bg, |
| 7746 | background |= (((unsigned long) (f->alpha_background * 0xffff) | 7785 | f->alpha_background); |
| 7747 | >> (16 - FRAME_DISPLAY_INFO (f)->alpha_bits)) | ||
| 7748 | << FRAME_DISPLAY_INFO (f)->alpha_offset); | ||
| 7749 | } | 7786 | } |
| 7750 | 7787 | ||
| 7751 | /* Draw the bitmap. I believe these small pixmaps can be cached | 7788 | /* Draw the bitmap. I believe these small pixmaps can be cached |
| @@ -8894,7 +8931,11 @@ x_color_cells (Display *dpy, int *ncells) | |||
| 8894 | 8931 | ||
| 8895 | 8932 | ||
| 8896 | /* On frame F, translate pixel colors to RGB values for the NCOLORS | 8933 | /* On frame F, translate pixel colors to RGB values for the NCOLORS |
| 8897 | colors in COLORS. Use cached information, if available. */ | 8934 | colors in COLORS. Use cached information, if available. |
| 8935 | |||
| 8936 | Pixel values are in unsigned normalized format, meaning that | ||
| 8937 | extending missing bits is done straightforwardly without any | ||
| 8938 | complex colorspace conversions. */ | ||
| 8898 | 8939 | ||
| 8899 | void | 8940 | void |
| 8900 | x_query_colors (struct frame *f, XColor *colors, int ncolors) | 8941 | x_query_colors (struct frame *f, XColor *colors, int ncolors) |
| @@ -8942,6 +8983,7 @@ x_query_colors (struct frame *f, XColor *colors, int ncolors) | |||
| 8942 | colors[i].green = (g * gmult) >> 16; | 8983 | colors[i].green = (g * gmult) >> 16; |
| 8943 | colors[i].blue = (b * bmult) >> 16; | 8984 | colors[i].blue = (b * bmult) >> 16; |
| 8944 | } | 8985 | } |
| 8986 | |||
| 8945 | return; | 8987 | return; |
| 8946 | } | 8988 | } |
| 8947 | 8989 | ||
| @@ -8984,16 +9026,10 @@ x_query_frame_background_color (struct frame *f, XColor *bgcolor) | |||
| 8984 | { | 9026 | { |
| 8985 | bg.pixel = background; | 9027 | bg.pixel = background; |
| 8986 | x_query_colors (f, &bg, 1); | 9028 | x_query_colors (f, &bg, 1); |
| 8987 | bg.red *= f->alpha_background; | 9029 | |
| 8988 | bg.green *= f->alpha_background; | 9030 | background |
| 8989 | bg.blue *= f->alpha_background; | 9031 | = x_premultiply_pixel (FRAME_DISPLAY_INFO (f), |
| 8990 | 9032 | &bg, f->alpha_background); | |
| 8991 | background = x_make_truecolor_pixel (FRAME_DISPLAY_INFO (f), | ||
| 8992 | bg.red, bg.green, bg.blue); | ||
| 8993 | background &= ~FRAME_DISPLAY_INFO (f)->alpha_mask; | ||
| 8994 | background |= (((unsigned long) (f->alpha_background * 0xffff) | ||
| 8995 | >> (16 - FRAME_DISPLAY_INFO (f)->alpha_bits)) | ||
| 8996 | << FRAME_DISPLAY_INFO (f)->alpha_offset); | ||
| 8997 | } | 9033 | } |
| 8998 | #endif | 9034 | #endif |
| 8999 | } | 9035 | } |