diff options
| author | Gerd Moellmann | 2000-09-20 10:59:45 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-09-20 10:59:45 +0000 |
| commit | f72c62ad9cf6bf5345845d8e113a48bf5038366b (patch) | |
| tree | d20f4883cab52db1c091b721b0404c57a3ed7016 /src | |
| parent | 499393791f8b47e873e8f9568b220a6ab151de79 (diff) | |
| download | emacs-f72c62ad9cf6bf5345845d8e113a48bf5038366b.tar.gz emacs-f72c62ad9cf6bf5345845d8e113a48bf5038366b.zip | |
(xpm_init_color_cache) [ALLOC_XPM_COLORS]: If color
symbols are specified, add color translations to the cache.
(xpm_color_bucket, xpm_cache_color) [ALLOC_XPM_COLORS]: New
functions.
(xpm_lookup_color) [ALLOC_XPM_COLORS]: Use xpm_color_bucket and
xpm_cache_color.
(xpm_load) [ALLOC_XPM_COLORS]: Pass frame and XPM attributes
structures to xpm_init_color_cache.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xfns.c | 87 |
1 files changed, 69 insertions, 18 deletions
diff --git a/src/xfns.c b/src/xfns.c index ede3ce8ffff..8cc65c4c4f2 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -6823,9 +6823,12 @@ static struct image_type xpm_type = | |||
| 6823 | 6823 | ||
| 6824 | #ifdef ALLOC_XPM_COLORS | 6824 | #ifdef ALLOC_XPM_COLORS |
| 6825 | 6825 | ||
| 6826 | static void xpm_init_color_cache P_ ((void)); | 6826 | static void xpm_init_color_cache P_ ((struct frame *, XpmAttributes *)); |
| 6827 | static void xpm_free_color_cache P_ ((void)); | 6827 | static void xpm_free_color_cache P_ ((void)); |
| 6828 | static int xpm_lookup_color P_ ((struct frame *, char *, XColor *)); | 6828 | static int xpm_lookup_color P_ ((struct frame *, char *, XColor *)); |
| 6829 | static int xpm_color_bucket P_ ((char *)); | ||
| 6830 | static struct xpm_cached_color *xpm_cache_color P_ ((struct frame *, char *, | ||
| 6831 | XColor *, int)); | ||
| 6829 | 6832 | ||
| 6830 | /* An entry in a hash table used to cache color definitions of named | 6833 | /* An entry in a hash table used to cache color definitions of named |
| 6831 | colors. This cache is necessary to speed up XPM image loading in | 6834 | colors. This cache is necessary to speed up XPM image loading in |
| @@ -6850,16 +6853,32 @@ struct xpm_cached_color | |||
| 6850 | #define XPM_COLOR_CACHE_BUCKETS 1001 | 6853 | #define XPM_COLOR_CACHE_BUCKETS 1001 |
| 6851 | struct xpm_cached_color **xpm_color_cache; | 6854 | struct xpm_cached_color **xpm_color_cache; |
| 6852 | 6855 | ||
| 6853 | |||
| 6854 | /* Initialize the color cache. */ | 6856 | /* Initialize the color cache. */ |
| 6855 | 6857 | ||
| 6856 | static void | 6858 | static void |
| 6857 | xpm_init_color_cache () | 6859 | xpm_init_color_cache (f, attrs) |
| 6860 | struct frame *f; | ||
| 6861 | XpmAttributes *attrs; | ||
| 6858 | { | 6862 | { |
| 6859 | size_t nbytes = XPM_COLOR_CACHE_BUCKETS * sizeof *xpm_color_cache; | 6863 | size_t nbytes = XPM_COLOR_CACHE_BUCKETS * sizeof *xpm_color_cache; |
| 6860 | xpm_color_cache = (struct xpm_cached_color **) xmalloc (nbytes); | 6864 | xpm_color_cache = (struct xpm_cached_color **) xmalloc (nbytes); |
| 6861 | memset (xpm_color_cache, 0, nbytes); | 6865 | memset (xpm_color_cache, 0, nbytes); |
| 6862 | init_color_table (); | 6866 | init_color_table (); |
| 6867 | |||
| 6868 | if (attrs->valuemask & XpmColorSymbols) | ||
| 6869 | { | ||
| 6870 | int i; | ||
| 6871 | XColor color; | ||
| 6872 | |||
| 6873 | for (i = 0; i < attrs->numsymbols; ++i) | ||
| 6874 | if (XParseColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), | ||
| 6875 | attrs->colorsymbols[i].value, &color)) | ||
| 6876 | { | ||
| 6877 | color.pixel = lookup_rgb_color (f, color.red, color.green, | ||
| 6878 | color.blue); | ||
| 6879 | xpm_cache_color (f, attrs->colorsymbols[i].name, &color, -1); | ||
| 6880 | } | ||
| 6881 | } | ||
| 6863 | } | 6882 | } |
| 6864 | 6883 | ||
| 6865 | 6884 | ||
| @@ -6884,6 +6903,49 @@ xpm_free_color_cache () | |||
| 6884 | } | 6903 | } |
| 6885 | 6904 | ||
| 6886 | 6905 | ||
| 6906 | /* Return the bucket index for color named COLOR_NAME in the color | ||
| 6907 | cache. */ | ||
| 6908 | |||
| 6909 | static int | ||
| 6910 | xpm_color_bucket (color_name) | ||
| 6911 | char *color_name; | ||
| 6912 | { | ||
| 6913 | unsigned h = 0; | ||
| 6914 | char *s; | ||
| 6915 | |||
| 6916 | for (s = color_name; *s; ++s) | ||
| 6917 | h = (h << 2) ^ *s; | ||
| 6918 | return h %= XPM_COLOR_CACHE_BUCKETS; | ||
| 6919 | } | ||
| 6920 | |||
| 6921 | |||
| 6922 | /* On frame F, cache values COLOR for color with name COLOR_NAME. | ||
| 6923 | BUCKET, if >= 0, is a precomputed bucket index. Value is the cache | ||
| 6924 | entry added. */ | ||
| 6925 | |||
| 6926 | static struct xpm_cached_color * | ||
| 6927 | xpm_cache_color (f, color_name, color, bucket) | ||
| 6928 | struct frame *f; | ||
| 6929 | char *color_name; | ||
| 6930 | XColor *color; | ||
| 6931 | int bucket; | ||
| 6932 | { | ||
| 6933 | size_t nbytes; | ||
| 6934 | struct xpm_cached_color *p; | ||
| 6935 | |||
| 6936 | if (bucket < 0) | ||
| 6937 | bucket = xpm_color_bucket (color_name); | ||
| 6938 | |||
| 6939 | nbytes = sizeof *p + strlen (color_name); | ||
| 6940 | p = (struct xpm_cached_color *) xmalloc (nbytes); | ||
| 6941 | strcpy (p->name, color_name); | ||
| 6942 | p->color = *color; | ||
| 6943 | p->next = xpm_color_cache[bucket]; | ||
| 6944 | xpm_color_cache[bucket] = p; | ||
| 6945 | return p; | ||
| 6946 | } | ||
| 6947 | |||
| 6948 | |||
| 6887 | /* Look up color COLOR_NAME for frame F in the color cache. If found, | 6949 | /* Look up color COLOR_NAME for frame F in the color cache. If found, |
| 6888 | return the cached definition in *COLOR. Otherwise, make a new | 6950 | return the cached definition in *COLOR. Otherwise, make a new |
| 6889 | entry in the cache and allocate the color. Value is zero if color | 6951 | entry in the cache and allocate the color. Value is zero if color |
| @@ -6895,13 +6957,8 @@ xpm_lookup_color (f, color_name, color) | |||
| 6895 | char *color_name; | 6957 | char *color_name; |
| 6896 | XColor *color; | 6958 | XColor *color; |
| 6897 | { | 6959 | { |
| 6898 | unsigned h = 0; | ||
| 6899 | const char *s; | ||
| 6900 | struct xpm_cached_color *p; | 6960 | struct xpm_cached_color *p; |
| 6901 | 6961 | int h = xpm_color_bucket (color_name); | |
| 6902 | for (s = color_name; *s; ++s) | ||
| 6903 | h = (h << 2) ^ *s; | ||
| 6904 | h %= XPM_COLOR_CACHE_BUCKETS; | ||
| 6905 | 6962 | ||
| 6906 | for (p = xpm_color_cache[h]; p; p = p->next) | 6963 | for (p = xpm_color_cache[h]; p; p = p->next) |
| 6907 | if (strcmp (p->name, color_name) == 0) | 6964 | if (strcmp (p->name, color_name) == 0) |
| @@ -6912,17 +6969,11 @@ xpm_lookup_color (f, color_name, color) | |||
| 6912 | else if (XParseColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), | 6969 | else if (XParseColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), |
| 6913 | color_name, color)) | 6970 | color_name, color)) |
| 6914 | { | 6971 | { |
| 6915 | size_t nbytes; | ||
| 6916 | color->pixel = lookup_rgb_color (f, color->red, color->green, | 6972 | color->pixel = lookup_rgb_color (f, color->red, color->green, |
| 6917 | color->blue); | 6973 | color->blue); |
| 6918 | nbytes = sizeof *p + strlen (color_name); | 6974 | p = xpm_cache_color (f, color_name, color, h); |
| 6919 | p = (struct xpm_cached_color *) xmalloc (nbytes); | ||
| 6920 | strcpy (p->name, color_name); | ||
| 6921 | p->color = *color; | ||
| 6922 | p->next = xpm_color_cache[h]; | ||
| 6923 | xpm_color_cache[h] = p; | ||
| 6924 | } | 6975 | } |
| 6925 | 6976 | ||
| 6926 | return p != NULL; | 6977 | return p != NULL; |
| 6927 | } | 6978 | } |
| 6928 | 6979 | ||
| @@ -7080,7 +7131,7 @@ xpm_load (f, img) | |||
| 7080 | /* Create a pixmap for the image, either from a file, or from a | 7131 | /* Create a pixmap for the image, either from a file, or from a |
| 7081 | string buffer containing data in the same format as an XPM file. */ | 7132 | string buffer containing data in the same format as an XPM file. */ |
| 7082 | #ifdef ALLOC_XPM_COLORS | 7133 | #ifdef ALLOC_XPM_COLORS |
| 7083 | xpm_init_color_cache (); | 7134 | xpm_init_color_cache (f, &attrs); |
| 7084 | #endif | 7135 | #endif |
| 7085 | 7136 | ||
| 7086 | specified_file = image_spec_value (img->spec, QCfile, NULL); | 7137 | specified_file = image_spec_value (img->spec, QCfile, NULL); |