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