]>
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 /* Visual Age cannot deal with old, non-ansi, code */
49 CreateOldColorTable(XpmColor
* ct
, int ncolors
, XpmColor
*** oldct
)
52 CreateOldColorTable(ct
, ncolors
, oldct
)
58 XpmColor
**colorTable
, **color
;
61 colorTable
= (XpmColor
**) XpmMalloc(ncolors
* sizeof(XpmColor
*));
66 for (a
= 0, color
= colorTable
; a
< ncolors
; a
++, color
++, ct
++)
73 /* Visual Age cannot deal with old, non-ansi, code */
74 static void FreeOldColorTable(XpmColor
** colorTable
, int ncolors
)
77 FreeOldColorTable(colorTable
, ncolors
)
78 XpmColor
**colorTable
;
87 for (a
= 0, color
= colorTable
; a
< ncolors
; a
++, color
++) {
88 for (b
= 0, sptr
= (char **) *color
; b
<= NKEYS
; b
++, sptr
++)
100 * Free the computed color table
103 /* Visual Age cannot deal with old, non-ansi, code */
104 void xpmFreeColorTable(XpmColor
* colorTable
, int ncolors
)
107 xpmFreeColorTable(colorTable
, ncolors
)
108 XpmColor
*colorTable
;
117 for (a
= 0, color
= colorTable
; a
< ncolors
; a
++, color
++) {
118 for (b
= 0, sptr
= (char **) color
; b
<= NKEYS
; b
++, sptr
++)
127 * Free array of extensions
130 /* Visual Age cannot deal with old, non-ansi, code */
131 void XpmFreeExtensions(XpmExtension
* extensions
, int nextensions
)
134 XpmFreeExtensions(extensions
, nextensions
)
135 XpmExtension
*extensions
;
139 unsigned int i
, j
, nlines
;
144 for (i
= 0, ext
= extensions
; i
< nextensions
; i
++, ext
++) {
147 nlines
= ext
->nlines
;
148 for (j
= 0, sptr
= ext
->lines
; j
< nlines
; j
++, sptr
++)
159 * Return the XpmAttributes structure size
165 return sizeof(XpmAttributes
);
169 * Init returned data to free safely later on
172 /* Visual Age cannot deal with old, non-ansi, code */
174 xpmInitAttributes(XpmAttributes
* attributes
)
177 xpmInitAttributes(attributes
)
178 XpmAttributes
*attributes
;
182 attributes
->pixels
= NULL
;
183 attributes
->npixels
= 0;
184 attributes
->colorTable
= NULL
;
185 attributes
->ncolors
= 0;
186 /* 3.2 backward compatibility code */
187 attributes
->hints_cmt
= NULL
;
188 attributes
->colors_cmt
= NULL
;
189 attributes
->pixels_cmt
= NULL
;
191 if (attributes
->valuemask
& XpmReturnExtensions
) {
192 attributes
->extensions
= NULL
;
193 attributes
->nextensions
= 0;
195 if (attributes
->valuemask
& XpmReturnAllocPixels
) {
196 attributes
->alloc_pixels
= NULL
;
197 attributes
->nalloc_pixels
= 0;
203 * Fill in the XpmAttributes with the XpmImage and the XpmInfo
206 /* Visual Age cannot deal with old, non-ansi, code */
207 void xpmSetAttributes(XpmAttributes
* attributes
, XpmImage
* image
, XpmInfo
* info
)
210 xpmSetAttributes(attributes
, image
, info
)
211 XpmAttributes
*attributes
;
216 if (attributes
->valuemask
& XpmReturnColorTable
) {
217 attributes
->colorTable
= image
->colorTable
;
218 attributes
->ncolors
= image
->ncolors
;
220 /* avoid deletion of copied data */
222 image
->colorTable
= NULL
;
224 /* 3.2 backward compatibility code */
225 else if (attributes
->valuemask
& XpmReturnInfos
) {
228 ErrorStatus
= CreateOldColorTable(image
->colorTable
, image
->ncolors
,
230 &attributes
->colorTable
);
232 /* if error just say we can't return requested data */
233 if (ErrorStatus
!= XpmSuccess
) {
234 attributes
->valuemask
&= ~XpmReturnInfos
;
235 if (!(attributes
->valuemask
& XpmReturnPixels
)) {
236 XpmFree(attributes
->pixels
);
237 attributes
->pixels
= NULL
;
238 attributes
->npixels
= 0;
240 attributes
->ncolors
= 0;
242 attributes
->ncolors
= image
->ncolors
;
243 attributes
->hints_cmt
= info
->hints_cmt
;
244 attributes
->colors_cmt
= info
->colors_cmt
;
245 attributes
->pixels_cmt
= info
->pixels_cmt
;
247 /* avoid deletion of copied data */
249 image
->colorTable
= NULL
;
250 info
->hints_cmt
= NULL
;
251 info
->colors_cmt
= NULL
;
252 info
->pixels_cmt
= NULL
;
256 if (attributes
->valuemask
& XpmReturnExtensions
) {
257 attributes
->extensions
= info
->extensions
;
258 attributes
->nextensions
= info
->nextensions
;
260 /* avoid deletion of copied data */
261 info
->extensions
= NULL
;
262 info
->nextensions
= 0;
264 if (info
->valuemask
& XpmHotspot
) {
265 attributes
->valuemask
|= XpmHotspot
;
266 attributes
->x_hotspot
= info
->x_hotspot
;
267 attributes
->y_hotspot
= info
->y_hotspot
;
269 attributes
->valuemask
|= XpmCharsPerPixel
;
270 attributes
->cpp
= image
->cpp
;
271 attributes
->valuemask
|= XpmSize
;
272 attributes
->width
= image
->width
;
273 attributes
->height
= image
->height
;
277 * Free the XpmAttributes structure members
278 * but the structure itself
281 /* Visual Age cannot deal with old, non-ansi, code */
282 void XpmFreeAttributes(XpmAttributes
* attributes
)
285 XpmFreeAttributes(attributes
)
286 XpmAttributes
*attributes
;
289 if (attributes
->valuemask
& XpmReturnPixels
&& attributes
->npixels
) {
290 XpmFree(attributes
->pixels
);
291 attributes
->pixels
= NULL
;
292 attributes
->npixels
= 0;
294 if (attributes
->valuemask
& XpmReturnColorTable
) {
295 xpmFreeColorTable(attributes
->colorTable
, attributes
->ncolors
);
296 attributes
->colorTable
= NULL
;
297 attributes
->ncolors
= 0;
299 /* 3.2 backward compatibility code */
300 else if (attributes
->valuemask
& XpmInfos
) {
301 if (attributes
->colorTable
) {
302 FreeOldColorTable((XpmColor
**) attributes
->colorTable
,
303 attributes
->ncolors
);
304 attributes
->colorTable
= NULL
;
305 attributes
->ncolors
= 0;
307 if (attributes
->hints_cmt
) {
308 XpmFree(attributes
->hints_cmt
);
309 attributes
->hints_cmt
= NULL
;
311 if (attributes
->colors_cmt
) {
312 XpmFree(attributes
->colors_cmt
);
313 attributes
->colors_cmt
= NULL
;
315 if (attributes
->pixels_cmt
) {
316 XpmFree(attributes
->pixels_cmt
);
317 attributes
->pixels_cmt
= NULL
;
319 if (attributes
->pixels
) {
320 XpmFree(attributes
->pixels
);
321 attributes
->pixels
= NULL
;
322 attributes
->npixels
= 0;
326 if (attributes
->valuemask
& XpmReturnExtensions
327 && attributes
->nextensions
) {
328 XpmFreeExtensions(attributes
->extensions
, attributes
->nextensions
);
329 attributes
->extensions
= NULL
;
330 attributes
->nextensions
= 0;
332 if (attributes
->valuemask
& XpmReturnAllocPixels
333 && attributes
->nalloc_pixels
) {
334 XpmFree(attributes
->alloc_pixels
);
335 attributes
->alloc_pixels
= NULL
;
336 attributes
->nalloc_pixels
= 0;
338 attributes
->valuemask
= 0;