2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * This module is all original code
20 * Copyright 1993, Robert Nation
21 * You may use this code for any purpose, as long as the original
22 * copyright remains in the source code and all documentation
25 Changed 02/12/97 by Dan Espen:
26 - added routines to determine color closeness, for color use reduction.
27 Some of the logic comes from pixy2, so the copyright is below.
30 * Copyright 1996, Romano Giannetti. No guarantees or warantees or anything
31 * are provided or implied in any way whatsoever. Use this program at your
32 * own risk. Permission to use this program for any purpose is given,
33 * as long as the copyright is kept intact.
35 * Romano Giannetti - Dipartimento di Ingegneria dell'Informazione
36 * via Diotisalvi, 2 PISA
37 * mailto:romano@iet.unipi.it
38 * http://www.iet.unipi.it/~romano
44 * Routines to handle initialization, loading, and removing of xpm's or mono-
57 #include "PictureBase.h"
58 #include "PictureUtils.h"
64 static Visual
*FvwmVisual
;
66 static Colormap FvwmCmap
;
68 static unsigned int FvwmDepth
;
69 Display
*Pdpy
; /* Save area for display pointer */
70 Bool PUseDynamicColors
;
77 void PictureSetupWhiteAndBlack(void);
80 void PictureInitCMap(Display
*dpy
) {
84 /* if fvwm has not set this env-var it is using the default visual */
85 envp
= getenv("FVWM_VISUALID");
86 if (envp
!= NULL
&& *envp
> 0) {
87 /* convert the env-vars to a visual and colormap */
89 XVisualInfo vizinfo
, *xvi
;
91 sscanf(envp
, "%lx", &vizinfo
.visualid
);
92 xvi
= XGetVisualInfo(dpy
, VisualIDMask
, &vizinfo
, &viscount
);
93 Pvisual
= xvi
->visual
;
95 /* Note: if FVWM_VISUALID is set, FVWM_COLORMAP is set too */
96 sscanf(getenv("FVWM_COLORMAP"), "%lx", &Pcmap
);
99 int screen
= DefaultScreen(dpy
);
101 Pvisual
= DefaultVisual(dpy
, screen
);
102 Pdepth
= DefaultDepth(dpy
, screen
);
103 Pcmap
= DefaultColormap(dpy
, screen
);
107 PictureSetupWhiteAndBlack();
108 PictureSaveFvwmVisual();
110 /* initialise color limit */
111 PUseDynamicColors
= 0;
112 PictureInitColors(PICTURE_CALLED_BY_MODULE
, True
, NULL
, False
, True
);
116 void PictureInitCMapRoot(
117 Display
*dpy
, Bool init_color_limit
, PictureColorLimitOption
*opt
,
118 Bool use_my_color_limit
, Bool init_dither
)
120 int screen
= DefaultScreen(dpy
);
124 Pvisual
= DefaultVisual(dpy
, screen
);
125 Pdepth
= DefaultDepth(dpy
, screen
);
126 Pcmap
= DefaultColormap(dpy
, screen
);
129 PictureSetupWhiteAndBlack();
130 PictureSaveFvwmVisual();
132 /* initialise color limit */
134 PICTURE_CALLED_BY_MODULE
, init_color_limit
, opt
,
135 use_my_color_limit
, init_dither
);
139 void PictureSetupWhiteAndBlack(void)
145 c
.flags
= DoRed
|DoGreen
|DoBlue
;
146 c
.red
= c
.green
= c
.blue
= 65535;
147 XAllocColor(Pdpy
, Pcmap
, &c
);
148 PWhitePixel
= c
.pixel
;
149 c
.red
= c
.green
= c
.blue
= 0;
150 XAllocColor(Pdpy
, Pcmap
, &c
);
151 PBlackPixel
= c
.pixel
;
155 PWhitePixel
= WhitePixel(Pdpy
, DefaultScreen(Pdpy
));
156 PBlackPixel
= BlackPixel(Pdpy
, DefaultScreen(Pdpy
));
162 void PictureUseDefaultVisual(void)
164 int screen
= DefaultScreen(Pdpy
);
166 Pvisual
= DefaultVisual(Pdpy
, screen
);
167 Pdepth
= DefaultDepth(Pdpy
, screen
);
168 Pcmap
= DefaultColormap(Pdpy
, screen
);
169 PWhitePixel
= WhitePixel(Pdpy
, DefaultScreen(Pdpy
));
170 PBlackPixel
= BlackPixel(Pdpy
, DefaultScreen(Pdpy
));
174 void PictureUseFvwmVisual(void)
176 Pvisual
= FvwmVisual
;
179 PWhitePixel
= FvwmWhitePixel
;
180 PBlackPixel
= FvwmBlackPixel
;
184 void PictureSaveFvwmVisual(void)
186 FvwmVisual
= Pvisual
;
189 FvwmWhitePixel
= PWhitePixel
;
190 FvwmBlackPixel
= PBlackPixel
;
194 Pixel
PictureWhitePixel(void)
199 Pixel
PictureBlackPixel(void)
204 GC
PictureDefaultGC(Display
*dpy
, Window win
)
208 if (Pdepth
== DefaultDepth(dpy
, DefaultScreen(dpy
)))
210 return DefaultGC(dpy
, DefaultScreen(dpy
));
216 xgcv
.foreground
= PictureBlackPixel();
217 xgcv
.background
= PictureWhitePixel();
218 gc
= fvwmlib_XCreateGC(dpy
, win
, 0, NULL
);
224 static char* imagePath
= FVWM_IMAGEPATH
;
226 void PictureSetImagePath( const char* newpath
)
228 static int need_to_free
= 0;
229 setPath( &imagePath
, newpath
, need_to_free
);
235 char* PictureGetImagePath(void)
242 * Find the specified image file somewhere along the given path.
244 * There is a possible race condition here: We check the file and later
245 * do something with it. By then, the file might not be accessible.
249 char* PictureFindImageFile(const char* icon
, const char* pathlist
, int type
)
254 const char *render_opts
;
256 if (pathlist
== NULL
)
258 pathlist
= imagePath
;
265 full_filename
= searchPath(pathlist
, icon
, ".gz", type
);
267 /* With USE_SVG, rendering options may be appended to the
268 original filename, hence seachPath() won't find the file.
269 So we hide any such appended options and try once more. */
270 if (USE_SVG
&& !full_filename
&&
271 (render_opts
= strrchr(icon
, ':')))
273 length
= render_opts
- icon
;
274 tmpbuf
= (char *)safemalloc(length
+ 1);
275 strncpy(tmpbuf
, icon
, length
);
278 full_filename
= searchPath(pathlist
, tmpbuf
, ".gz", type
);
282 /* Prepending (the previously appended) options
283 will leave any file suffix exposed. Callers
284 who want to access the file on disk will have
285 to remove these prepended options themselves.
286 The format is ":svg_opts:/path/to/file.svg". */
287 tmpbuf
= CatString3(render_opts
, ":", full_filename
);
289 full_filename
= safestrdup(tmpbuf
);
293 return full_filename
;