Restructure how we look for Read files slightly.
[fvwm.git] / libs / PictureBase.h
blob459a713c566793479404b5fbf6260d4d6114e67f
1 /* -*-c-*- */
3 #ifndef Picture_Base_H
4 #define Picture_Base_H
6 #include "config.h"
8 #ifdef HAVE_XRENDER
9 #define XRenderSupport 1
10 #else
11 #define XRenderSupport 0
12 #endif
14 #ifdef XPM
15 #define XpmSupport 1
16 #else
17 #define XpmSupport 0
18 #endif
20 #ifdef HAVE_PNG
21 #define PngSupport 1
22 #else
23 #define PngSupport 0
24 #endif
26 extern Bool Pdefault;
27 extern Visual *Pvisual;
28 extern Colormap Pcmap;
29 extern unsigned int Pdepth;
30 extern Display *Pdpy; /* Save area for display pointer */
31 extern Bool PUseDynamicColors;
33 typedef struct
35 int color_limit;
36 int strict;
37 int allocate;
38 int not_dynamic;
39 int use_named_table;
40 } PictureColorLimitOption;
42 /**
43 * Set a colon-separated path, with environment variable expansions.
44 * Expand '+' to be the value of the previous path.
46 * Parameters:
47 * p_path pointer to the path variable
48 * newpath new value for *p_path
49 * free_old_path set true if we should free the memory pointed to
50 * by p_path on entry
52 * The value of newpath is copied into a newly-allocated place, to which
53 * '*p_path' will point to upon return. The memory region pointed to by
54 * '*p_path' upon entry will be freed if 'free_old_path' is true.
56 **/
57 void setPath(char** p_path, const char* newpath, int free_old_path);
59 /**
60 * Search along colon-separated path for filename, with optional suffix.
62 * Parameters:
63 * path colon-separated path of directory names
64 * filename basename of file to search for
65 * suffix if non-NULL, filename may have this suffix
66 * type mode sought for file
68 * For each DIR in the path, search for DIR/filename then
69 * DIR/<filename><suffix> (if suffix is non-NULL). Return the full path of
70 * the first found.
72 * The parameter type is a mask consisting of one or more of R_OK, W_OK, X_OK
73 * and F_OK. R_OK, W_OK and X_OK request checking whether the file exists and
74 * has read, write and execute permissions, respectively. F_OK just requests
75 * checking for the existence of the file.
77 * Returns: full pathname of sought-after file, or NULL. The return value
78 * points to allocated memory that the caller must free.
80 **/
81 char* searchPath(
82 const char* path, const char* filename, const char* suffix, int type);
84 /* This routine called during modules initialization. Fvwm has its own code
85 * in fvwm.c */
86 void PictureInitCMap(Display *dpy);
88 /* as above but force to use the default visual. If use_my_color_limit is True
89 * also enable color limitation (independent than the fvwm one). */
90 void PictureInitCMapRoot(
91 Display *dpy, Bool init_color_limit, PictureColorLimitOption *opt,
92 Bool use_my_color_limit, Bool init_dither);
94 /* Analogue of the Xlib WhitePixel and BlackPixel functions but use the
95 Pvisual */
96 Pixel PictureWhitePixel(void);
97 Pixel PictureBlackPixel(void);
99 /* for initialization of the white and black pixel (for fvwm as PictureInitCMap*
100 * do this) */
101 void PictureSetupWhiteAndBlack(void);
103 /* Analogue of the Xlib DefaultGC function but take care of the Pdepth:
104 - If Pdepth == DefaultDepth return the DefaultGC
105 - If Pdepth != DefaultDepth and first call create a static gc with the win
106 and return the gc
107 - If Pdepth != DefaultDepth and already called return the static gc */
108 GC PictureDefaultGC(Display *dpy, Window win);
110 /* these can be used to switch visuals before calling GetPicture */
111 /* do NOT use with CachePicture */
112 void PictureUseDefaultVisual(void);
113 void PictureUseFvwmVisual(void);
114 void PictureSaveFvwmVisual(void);
116 /** Returns current setting of the image path **/
117 char* PictureGetImagePath(void);
120 /** Sets image path to newpath. Environment variables are expanded, and '+'
121 is expanded to previous value of imagepath. The new path is in
122 newly-allocated memory, so newpath may be freed or re-used. **/
123 void PictureSetImagePath(const char* newpath);
126 /** Search for file along pathlist. If pathlist is NULL, will use the current
127 imagepath setting. If filename is not found, but filename.gz is found,
128 will return the latter. Mode is typically R_OK. See searchPath() for
129 more details. **/
130 char* PictureFindImageFile(
131 const char* filename, const char* pathlist, int mode);
133 typedef struct FvwmPictureThing
135 struct FvwmPictureThing *next;
136 char *name;
137 unsigned long stamp; /* should be FileStamp */
138 unsigned long fpa_mask;
139 Pixmap picture;
140 Pixmap mask;
141 Pixmap alpha;
142 unsigned int depth;
143 unsigned int width;
144 unsigned int height;
145 unsigned int count;
146 Pixel *alloc_pixels;
147 int nalloc_pixels;
148 Bool no_limit;
149 } FvwmPicture;
151 typedef struct
153 unsigned alpha : 1;
154 unsigned alloc_pixels : 1;
155 } FvwmPictureFlags;
157 #define FPAM_NO_ALLOC_PIXELS (1) /* do not return the allocated pixels
158 * this is used only if PUseDynamicColors,
159 * if not the allocated pixels are never
160 * returned */
161 #define FPAM_NO_COLOR_LIMIT (1 << 1) /* do not use color limitation */
162 #define FPAM_NO_ALPHA (1 << 2) /* do not return the alpha channel */
163 #define FPAM_DITHER (1 << 3) /* dither the image */
164 #define FPAM_TINT (1 << 4) /* tint the image */
165 #define FPAM_MONOCHROME (1 << 5) /* reduce the color depth to 1-bit */
167 typedef struct
169 unsigned mask : 6;
170 XColor tint;
171 int tint_percent;
172 } FvwmPictureAttributes;
174 /* tint no yet implemented */
175 #define PICTURE_FPA_AGREE(p,fpa) (p->fpa_mask == fpa.mask)
177 #define FRAM_HAVE_ADDED_ALPHA (1)
178 #define FRAM_HAVE_TINT (1 << 1)
179 #define FRAM_HAVE_UNIFORM_COLOR (1 << 2)
180 #define FRAM_DEST_IS_A_WINDOW (1 << 3)
181 #define FRAM_HAVE_ICON_CSET (1 << 4)
183 #include "Colorset.h"
185 typedef struct
187 unsigned mask : 5;
188 int added_alpha_percent;
189 Pixel tint;
190 int tint_percent;
191 Pixel uniform_pixel;
192 colorset_t *colorset;
193 } FvwmRenderAttributes;
195 #define PICTURE_HAS_ALPHA(picture,cset) \
196 ((picture && picture->alpha != None) || \
197 (cset >= 0 && Colorset[cset].icon_alpha_percent < 100))
198 /* alpha limit if we cannot use the alpha channel */
199 #define PICTURE_ALPHA_LIMIT 130
201 typedef struct
203 Colormap cmap;
204 int dither;
205 int no_limit;
206 Bool is_8;
207 unsigned long *pixels_table;
208 int pixels_table_size;
209 } PictureImageColorAllocator;
211 #endif /* Picture_Base_H */