]>
git.saurik.com Git - wxWidgets.git/blob - src/xpm/attrib.c
2 * Copyright (C) 1989-95 GROUPE BULL
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 * Except as contained in this notice, the name of GROUPE BULL shall not be
22 * used in advertising or otherwise to promote the sale, use or other dealings
23 * in this Software without prior written authorization from GROUPE BULL.
26 /*****************************************************************************\
30 * Functions related to the XpmAttributes structure *
32 * Developed by Arnaud Le Hors *
33 \*****************************************************************************/
37 /* 3.2 backward compatibility code */
38 LFUNC(CreateOldColorTable
, int, (XpmColor
*ct
, int ncolors
,
41 LFUNC(FreeOldColorTable
, void, (XpmColor
**colorTable
, int ncolors
));
44 * Create a colortable compatible with the old style colortable
47 CreateOldColorTable(ct
, ncolors
, oldct
)
52 XpmColor
**colorTable
, **color
;
55 colorTable
= (XpmColor
**) XpmMalloc(ncolors
* sizeof(XpmColor
*));
60 for (a
= 0, color
= colorTable
; a
< ncolors
; a
++, color
++, ct
++)
67 FreeOldColorTable(colorTable
, ncolors
)
68 XpmColor
**colorTable
;
76 for (a
= 0, color
= colorTable
; a
< ncolors
; a
++, color
++) {
77 for (b
= 0, sptr
= (char **) *color
; b
<= NKEYS
; b
++, sptr
++)
89 * Free the computed color table
92 xpmFreeColorTable(colorTable
, ncolors
)
101 for (a
= 0, color
= colorTable
; a
< ncolors
; a
++, color
++) {
102 for (b
= 0, sptr
= (char **) color
; b
<= NKEYS
; b
++, sptr
++)
111 * Free array of extensions
114 XpmFreeExtensions(extensions
, nextensions
)
115 XpmExtension
*extensions
;
118 unsigned int i
, j
, nlines
;
123 for (i
= 0, ext
= extensions
; i
< nextensions
; i
++, ext
++) {
126 nlines
= ext
->nlines
;
127 for (j
= 0, sptr
= ext
->lines
; j
< nlines
; j
++, sptr
++)
138 * Return the XpmAttributes structure size
144 return sizeof(XpmAttributes
);
148 * Init returned data to free safely later on
151 xpmInitAttributes(attributes
)
152 XpmAttributes
*attributes
;
155 attributes
->pixels
= NULL
;
156 attributes
->npixels
= 0;
157 attributes
->colorTable
= NULL
;
158 attributes
->ncolors
= 0;
159 /* 3.2 backward compatibility code */
160 attributes
->hints_cmt
= NULL
;
161 attributes
->colors_cmt
= NULL
;
162 attributes
->pixels_cmt
= NULL
;
164 if (attributes
->valuemask
& XpmReturnExtensions
) {
165 attributes
->extensions
= NULL
;
166 attributes
->nextensions
= 0;
168 if (attributes
->valuemask
& XpmReturnAllocPixels
) {
169 attributes
->alloc_pixels
= NULL
;
170 attributes
->nalloc_pixels
= 0;
176 * Fill in the XpmAttributes with the XpmImage and the XpmInfo
179 xpmSetAttributes(attributes
, image
, info
)
180 XpmAttributes
*attributes
;
184 if (attributes
->valuemask
& XpmReturnColorTable
) {
185 attributes
->colorTable
= image
->colorTable
;
186 attributes
->ncolors
= image
->ncolors
;
188 /* avoid deletion of copied data */
190 image
->colorTable
= NULL
;
192 /* 3.2 backward compatibility code */
193 else if (attributes
->valuemask
& XpmReturnInfos
) {
196 ErrorStatus
= CreateOldColorTable(image
->colorTable
, image
->ncolors
,
198 &attributes
->colorTable
);
200 /* if error just say we can't return requested data */
201 if (ErrorStatus
!= XpmSuccess
) {
202 attributes
->valuemask
&= ~XpmReturnInfos
;
203 if (!(attributes
->valuemask
& XpmReturnPixels
)) {
204 XpmFree(attributes
->pixels
);
205 attributes
->pixels
= NULL
;
206 attributes
->npixels
= 0;
208 attributes
->ncolors
= 0;
210 attributes
->ncolors
= image
->ncolors
;
211 attributes
->hints_cmt
= info
->hints_cmt
;
212 attributes
->colors_cmt
= info
->colors_cmt
;
213 attributes
->pixels_cmt
= info
->pixels_cmt
;
215 /* avoid deletion of copied data */
217 image
->colorTable
= NULL
;
218 info
->hints_cmt
= NULL
;
219 info
->colors_cmt
= NULL
;
220 info
->pixels_cmt
= NULL
;
224 if (attributes
->valuemask
& XpmReturnExtensions
) {
225 attributes
->extensions
= info
->extensions
;
226 attributes
->nextensions
= info
->nextensions
;
228 /* avoid deletion of copied data */
229 info
->extensions
= NULL
;
230 info
->nextensions
= 0;
232 if (info
->valuemask
& XpmHotspot
) {
233 attributes
->valuemask
|= XpmHotspot
;
234 attributes
->x_hotspot
= info
->x_hotspot
;
235 attributes
->y_hotspot
= info
->y_hotspot
;
237 attributes
->valuemask
|= XpmCharsPerPixel
;
238 attributes
->cpp
= image
->cpp
;
239 attributes
->valuemask
|= XpmSize
;
240 attributes
->width
= image
->width
;
241 attributes
->height
= image
->height
;
245 * Free the XpmAttributes structure members
246 * but the structure itself
249 XpmFreeAttributes(attributes
)
250 XpmAttributes
*attributes
;
252 if (attributes
->valuemask
& XpmReturnPixels
&& attributes
->npixels
) {
253 XpmFree(attributes
->pixels
);
254 attributes
->pixels
= NULL
;
255 attributes
->npixels
= 0;
257 if (attributes
->valuemask
& XpmReturnColorTable
) {
258 xpmFreeColorTable(attributes
->colorTable
, attributes
->ncolors
);
259 attributes
->colorTable
= NULL
;
260 attributes
->ncolors
= 0;
262 /* 3.2 backward compatibility code */
263 else if (attributes
->valuemask
& XpmInfos
) {
264 if (attributes
->colorTable
) {
265 FreeOldColorTable((XpmColor
**) attributes
->colorTable
,
266 attributes
->ncolors
);
267 attributes
->colorTable
= NULL
;
268 attributes
->ncolors
= 0;
270 if (attributes
->hints_cmt
) {
271 XpmFree(attributes
->hints_cmt
);
272 attributes
->hints_cmt
= NULL
;
274 if (attributes
->colors_cmt
) {
275 XpmFree(attributes
->colors_cmt
);
276 attributes
->colors_cmt
= NULL
;
278 if (attributes
->pixels_cmt
) {
279 XpmFree(attributes
->pixels_cmt
);
280 attributes
->pixels_cmt
= NULL
;
282 if (attributes
->pixels
) {
283 XpmFree(attributes
->pixels
);
284 attributes
->pixels
= NULL
;
285 attributes
->npixels
= 0;
289 if (attributes
->valuemask
& XpmReturnExtensions
290 && attributes
->nextensions
) {
291 XpmFreeExtensions(attributes
->extensions
, attributes
->nextensions
);
292 attributes
->extensions
= NULL
;
293 attributes
->nextensions
= 0;
295 if (attributes
->valuemask
& XpmReturnAllocPixels
296 && attributes
->nalloc_pixels
) {
297 XpmFree(attributes
->alloc_pixels
);
298 attributes
->alloc_pixels
= NULL
;
299 attributes
->nalloc_pixels
= 0;
301 attributes
->valuemask
= 0;