479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
1 |
/*
|
2 |
* XPM image handling functions
|
|
3 |
*/
|
|
4 |
||
5 |
#include "ctwm.h" |
|
6 |
||
479.1.26
by Matthew Fuller
Pull includes we don't need in image_xpm.h and add the necessary ones |
7 |
#include <stdio.h> |
491.1.14
by Matthew Fuller
Remove incorrect pre-ANSI potential override prototypes for malloc() |
8 |
#include <stdlib.h> |
479.1.26
by Matthew Fuller
Pull includes we don't need in image_xpm.h and add the necessary ones |
9 |
#include <string.h> |
10 |
||
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
11 |
#include <X11/xpm.h> |
12 |
||
479.1.26
by Matthew Fuller
Pull includes we don't need in image_xpm.h and add the necessary ones |
13 |
#include "screen.h" |
14 |
||
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
15 |
#include "image.h" |
16 |
#include "image_xpm.h" |
|
17 |
||
480.1.17
by Matthew Fuller
const-ify all these image names we pass through this process. |
18 |
static Image *LoadXpmImage(const char *name, ColorPair cp); |
19 |
static void xpmErrorMessage(int status, const char *name, const char *fullname); |
|
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
20 |
|
21 |
static int reportxpmerror = 1; |
|
22 |
||
479.1.29
by Matthew Fuller
Split the rest of the image* function definitions, and make indent. |
23 |
|
480.1.1
by Matthew Fuller
Shuffle the public function to the front and comment appropriately. |
24 |
/*
|
25 |
* External entry point
|
|
26 |
*/
|
|
27 |
Image * |
|
480.1.17
by Matthew Fuller
const-ify all these image names we pass through this process. |
28 |
GetXpmImage(const char *name, ColorPair cp) |
480.1.1
by Matthew Fuller
Shuffle the public function to the front and comment appropriately. |
29 |
{
|
480.1.2
by Matthew Fuller
Add comments, restrict the scope of some variables, be a little more |
30 |
/* For non-animated requests, just load the file */
|
480.1.1
by Matthew Fuller
Shuffle the public function to the front and comment appropriately. |
31 |
if(! strchr(name, '%')) { |
501.1.9
by Matthew Fuller
Convert pointer values from None -> NULL in image*. |
32 |
return LoadXpmImage(name, cp); |
480.1.1
by Matthew Fuller
Shuffle the public function to the front and comment appropriately. |
33 |
}
|
480.1.2
by Matthew Fuller
Add comments, restrict the scope of some variables, be a little more |
34 |
|
480.1.11
by Matthew Fuller
Take the magic in LoadXpmImage() for putting together animations, and |
35 |
/* Else it's animated, so load/return the series */
|
36 |
return get_image_anim_cp(name, cp, LoadXpmImage); |
|
480.1.1
by Matthew Fuller
Shuffle the public function to the front and comment appropriately. |
37 |
}
|
38 |
||
39 |
||
40 |
||
41 |
/*
|
|
42 |
* Internal backend
|
|
43 |
*/
|
|
479.1.29
by Matthew Fuller
Split the rest of the image* function definitions, and make indent. |
44 |
static Image * |
480.1.17
by Matthew Fuller
const-ify all these image names we pass through this process. |
45 |
LoadXpmImage(const char *name, ColorPair cp) |
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
46 |
{
|
47 |
char *fullname; |
|
48 |
Image *image; |
|
49 |
int status; |
|
50 |
Colormap stdcmap = Scr->RootColormaps.cwins[0]->colormap->c; |
|
51 |
XpmAttributes attributes; |
|
52 |
static XpmColorSymbol overrides[] = { |
|
53 |
{"Foreground", NULL, 0}, |
|
54 |
{"Background", NULL, 0}, |
|
55 |
{"HiShadow", NULL, 0}, |
|
56 |
{"LoShadow", NULL, 0} |
|
57 |
};
|
|
58 |
||
59 |
fullname = ExpandPixmapPath(name); |
|
60 |
if(! fullname) { |
|
501.1.9
by Matthew Fuller
Convert pointer values from None -> NULL in image*. |
61 |
return NULL; |
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
62 |
}
|
63 |
||
480.1.19
by Matthew Fuller
Add an AllocImage() to ensure new Image's are initialized properly, |
64 |
image = AllocImage(); |
501.1.9
by Matthew Fuller
Convert pointer values from None -> NULL in image*. |
65 |
if(image == NULL) { |
480.1.2
by Matthew Fuller
Add comments, restrict the scope of some variables, be a little more |
66 |
free(fullname); |
501.1.9
by Matthew Fuller
Convert pointer values from None -> NULL in image*. |
67 |
return NULL; |
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
68 |
}
|
69 |
||
70 |
attributes.valuemask = 0; |
|
71 |
attributes.valuemask |= XpmSize; |
|
72 |
attributes.valuemask |= XpmReturnPixels; |
|
73 |
attributes.valuemask |= XpmColormap; |
|
74 |
attributes.valuemask |= XpmDepth; |
|
75 |
attributes.valuemask |= XpmVisual; |
|
76 |
attributes.valuemask |= XpmCloseness; |
|
77 |
attributes.valuemask |= XpmColorSymbols; |
|
78 |
||
79 |
attributes.numsymbols = 4; |
|
80 |
attributes.colorsymbols = overrides; |
|
81 |
overrides[0].pixel = cp.fore; |
|
82 |
overrides[1].pixel = cp.back; |
|
83 |
overrides[2].pixel = cp.shadd; |
|
84 |
overrides[3].pixel = cp.shadc; |
|
85 |
||
86 |
||
87 |
attributes.colormap = AlternateCmap ? AlternateCmap : stdcmap; |
|
88 |
attributes.depth = Scr->d_depth; |
|
89 |
attributes.visual = Scr->d_visual; |
|
90 |
attributes.closeness = 65535; /* Never fail */ |
|
91 |
status = XpmReadFileToPixmap(dpy, Scr->Root, fullname, |
|
92 |
&(image->pixmap), &(image->mask), &attributes); |
|
93 |
if(status != XpmSuccess) { |
|
94 |
xpmErrorMessage(status, name, fullname); |
|
480.1.22
by Matthew Fuller
Nope, we do need to have the free in both branches here, to avoid the |
95 |
free(fullname); |
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
96 |
free(image); |
501.1.9
by Matthew Fuller
Convert pointer values from None -> NULL in image*. |
97 |
return NULL; |
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
98 |
}
|
480.1.22
by Matthew Fuller
Nope, we do need to have the free in both branches here, to avoid the |
99 |
free(fullname); |
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
100 |
image->width = attributes.width; |
101 |
image->height = attributes.height; |
|
501.1.9
by Matthew Fuller
Convert pointer values from None -> NULL in image*. |
102 |
return image; |
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
103 |
}
|
104 |
||
479.1.29
by Matthew Fuller
Split the rest of the image* function definitions, and make indent. |
105 |
static void |
480.1.17
by Matthew Fuller
const-ify all these image names we pass through this process. |
106 |
xpmErrorMessage(int status, const char *name, const char *fullname) |
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
107 |
{
|
108 |
switch(status) { |
|
109 |
case XpmSuccess: |
|
480.1.2
by Matthew Fuller
Add comments, restrict the scope of some variables, be a little more |
110 |
/* No error */
|
111 |
return; |
|
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
112 |
|
113 |
case XpmColorError: |
|
114 |
if(reportxpmerror) |
|
115 |
fprintf(stderr, |
|
116 |
"Could not parse or alloc requested color : %s\n", |
|
117 |
fullname); |
|
118 |
return; |
|
119 |
||
120 |
case XpmOpenFailed: |
|
480.1.5
by Matthew Fuller
Take out dev dropping. |
121 |
if(reportxpmerror && reportfilenotfound) { |
479.1.2
by Matthew Fuller
Break out XPM functions into image_xpm. Start laying a little |
122 |
fprintf(stderr, "unable to locate XPM file : %s\n", fullname); |
123 |
}
|
|
124 |
return; |
|
125 |
||
126 |
case XpmFileInvalid: |
|
127 |
fprintf(stderr, "invalid XPM file : %s\n", fullname); |
|
128 |
return; |
|
129 |
||
130 |
case XpmNoMemory: |
|
131 |
if(reportxpmerror) { |
|
132 |
fprintf(stderr, "Not enough memory for XPM file : %s\n", fullname); |
|
133 |
}
|
|
134 |
return; |
|
135 |
||
136 |
case XpmColorFailed: |
|
137 |
if(reportxpmerror) { |
|
138 |
fprintf(stderr, "Color not found in : %s\n", fullname); |
|
139 |
}
|
|
140 |
return; |
|
141 |
||
142 |
default : |
|
143 |
fprintf(stderr, "Unknown error in : %s\n", fullname); |
|
144 |
return; |
|
145 |
}
|
|
146 |
}
|