| 1 |
/* Copyright 1990,91 GROUPE BULL -- See license conditions in file COPYRIGHT */ |
| 2 |
/*****************************************************************************\ |
| 3 |
* XpmCrIFData.c: * |
| 4 |
* * |
| 5 |
* XPM library * |
| 6 |
* Parse an Xpm array and create the image and possibly its mask * |
| 7 |
* * |
| 8 |
* Developed by Arnaud Le Hors * |
| 9 |
|
| 10 |
.VERSION |
| 11 |
090818 last modif |
| 12 |
\*****************************************************************************/ |
| 13 |
|
| 14 |
#include "xpmP.h" |
| 15 |
|
| 16 |
/* UIM/X Modification: To support transparent colors, |
| 17 |
** we need to pass the widget on which |
| 18 |
** the pixmap will be drawn. |
| 19 |
*/ |
| 20 |
#include <Xm/Xm.h> |
| 21 |
|
| 22 |
extern int UxxpmCreateImage(); |
| 23 |
|
| 24 |
|
| 25 |
int |
| 26 |
UxXpmCreateImageFromData(display, w, data, image_return, |
| 27 |
shapeimage_return, attributes) |
| 28 |
Display *display; |
| 29 |
Widget w; |
| 30 |
char **data; |
| 31 |
XImage **image_return; |
| 32 |
XImage **shapeimage_return; |
| 33 |
XpmAttributes *attributes; |
| 34 |
{ |
| 35 |
xpmData mdata; |
| 36 |
int ErrorStatus; |
| 37 |
xpmInternAttrib attrib; |
| 38 |
|
| 39 |
/* |
| 40 |
* initialize return values |
| 41 |
*/ |
| 42 |
if (image_return) |
| 43 |
*image_return = NULL; |
| 44 |
if (shapeimage_return) |
| 45 |
*shapeimage_return = NULL; |
| 46 |
|
| 47 |
if ((ErrorStatus = xpmOpenArray(data, &mdata)) != XpmSuccess) |
| 48 |
return (ErrorStatus); |
| 49 |
|
| 50 |
xpmInitInternAttrib(&attrib); |
| 51 |
|
| 52 |
ErrorStatus = xpmParseData(&mdata, &attrib, attributes); |
| 53 |
|
| 54 |
if (ErrorStatus == XpmSuccess) { |
| 55 |
/* UIM/X Modification: To support transparent colors, |
| 56 |
** we need to pass the widget on which |
| 57 |
** the pixmap will be drawn. |
| 58 |
*/ |
| 59 |
ErrorStatus = UxxpmCreateImage(display, w, &attrib, image_return, |
| 60 |
shapeimage_return, attributes); |
| 61 |
} |
| 62 |
if (ErrorStatus >= 0) |
| 63 |
xpmSetAttributes(&attrib, attributes); |
| 64 |
else if (attributes) |
| 65 |
XpmFreeAttributes(attributes); |
| 66 |
|
| 67 |
xpmFreeInternAttrib(&attrib); |
| 68 |
XpmDataClose(&mdata); |
| 69 |
|
| 70 |
return (ErrorStatus); |
| 71 |
} |
| 72 |
|
| 73 |
int |
| 74 |
UxXpmCreatePixmapFromData(display, d, w, data, pixmap_return, |
| 75 |
shapemask_return, attributes) |
| 76 |
Display *display; |
| 77 |
Drawable d; |
| 78 |
Widget w; |
| 79 |
char **data; |
| 80 |
Pixmap *pixmap_return; |
| 81 |
Pixmap *shapemask_return; |
| 82 |
XpmAttributes *attributes; |
| 83 |
{ |
| 84 |
XImage *image, **imageptr = NULL; |
| 85 |
XImage *shapeimage, **shapeimageptr = NULL; |
| 86 |
int ErrorStatus; |
| 87 |
XGCValues gcv; |
| 88 |
GC gc; |
| 89 |
|
| 90 |
/* |
| 91 |
* initialize return values |
| 92 |
*/ |
| 93 |
if (pixmap_return) { |
| 94 |
*pixmap_return = 0; /* was: *pixmap_return = NULL; */ |
| 95 |
imageptr = ℑ |
| 96 |
} |
| 97 |
if (shapemask_return) { |
| 98 |
*shapemask_return = 0; /* = NULL; */ |
| 99 |
shapeimageptr = &shapeimage; |
| 100 |
} |
| 101 |
|
| 102 |
/* |
| 103 |
* create the images |
| 104 |
*/ |
| 105 |
|
| 106 |
/* UIM/X Modification: To support transparent colors, |
| 107 |
** we need to pass the widget on which |
| 108 |
** the pixmap will be drawn. |
| 109 |
*/ |
| 110 |
ErrorStatus = UxXpmCreateImageFromData(display, w, data, imageptr, |
| 111 |
shapeimageptr, attributes); |
| 112 |
if (ErrorStatus < 0) |
| 113 |
return (ErrorStatus); |
| 114 |
|
| 115 |
/* |
| 116 |
* create the pixmaps |
| 117 |
*/ |
| 118 |
if (imageptr && image) { |
| 119 |
*pixmap_return = XCreatePixmap(display, d, image->width, |
| 120 |
image->height, image->depth); |
| 121 |
gcv.function = GXcopy; |
| 122 |
gc = XCreateGC(display, *pixmap_return, GCFunction, &gcv); |
| 123 |
|
| 124 |
XPutImage(display, *pixmap_return, gc, image, 0, 0, 0, 0, |
| 125 |
image->width, image->height); |
| 126 |
|
| 127 |
#ifdef Debug |
| 128 |
/* |
| 129 |
* XDestroyImage free the image data but mnemosyne don't know about it |
| 130 |
* so I free them by hand to avoid mnemalyse report it as lost data. |
| 131 |
*/ |
| 132 |
free(image->data); |
| 133 |
#endif |
| 134 |
XDestroyImage(image); |
| 135 |
XFreeGC(display, gc); |
| 136 |
} |
| 137 |
if (shapeimageptr && shapeimage) { |
| 138 |
*shapemask_return = XCreatePixmap(display, d, shapeimage->width, |
| 139 |
shapeimage->height, |
| 140 |
shapeimage->depth); |
| 141 |
gcv.function = GXcopy; |
| 142 |
gc = XCreateGC(display, *shapemask_return, GCFunction, &gcv); |
| 143 |
|
| 144 |
XPutImage(display, *shapemask_return, gc, shapeimage, 0, 0, 0, 0, |
| 145 |
shapeimage->width, shapeimage->height); |
| 146 |
|
| 147 |
#ifdef Debug |
| 148 |
/* |
| 149 |
* XDestroyImage free the image data but mnemosyne don't know about it |
| 150 |
* so I free them by hand to avoid mnemalyse report it as lost data. |
| 151 |
*/ |
| 152 |
free(shapeimage->data); |
| 153 |
#endif |
| 154 |
XDestroyImage(shapeimage); |
| 155 |
XFreeGC(display, gc); |
| 156 |
} |
| 157 |
return (ErrorStatus); |
| 158 |
} |
| 159 |
/*--------------------------------------------------------------------- |
| 160 |
* $Date: 2009-08-18 15:23:20 $ $Revision: 1.3 $ |
| 161 |
*--------------------------------------------------------------------- |
| 162 |
* |
| 163 |
* |
| 164 |
* Copyright (c) 1990-1992, Visual Edge Software Ltd. |
| 165 |
* |
| 166 |
* ALL RIGHTS RESERVED. Permission to use, copy, modify, and |
| 167 |
* distribute this software and its documentation for any purpose |
| 168 |
* and without fee is hereby granted, provided that the above |
| 169 |
* copyright notice appear in all copies and that both that |
| 170 |
* copyright notice and this permission notice appear in supporting |
| 171 |
* documentation, and that the name of Visual Edge Software not be |
| 172 |
* used in advertising or publicity pertaining to distribution of |
| 173 |
* the software without specific, written prior permission. The year |
| 174 |
* included in the notice is the year of the creation of the work. |
| 175 |
*-------------------------------------------------------------------*/ |
| 176 |
/* |
| 177 |
* Copyright 1990, 1991 GROUPE BULL |
| 178 |
* |
| 179 |
* Permission to use, copy, modify, and distribute this software and its |
| 180 |
* documentation for any purpose and without fee is hereby granted, provided |
| 181 |
* that the above copyright notice appear in all copies and that both that |
| 182 |
* copyright notice and this permission notice appear in supporting |
| 183 |
* documentation, and that the name of GROUPE BULL not be used in advertising |
| 184 |
* or publicity pertaining to distribution of the software without specific, |
| 185 |
* written prior permission. GROUPE BULL makes no representations about the |
| 186 |
* suitability of this software for any purpose. It is provided "as is" |
| 187 |
* without express or implied warranty. |
| 188 |
* |
| 189 |
* GROUPE BULL disclaims all warranties with regard to this software, |
| 190 |
* including all implied warranties of merchantability and fitness, |
| 191 |
* in no event shall GROUPE BULL be liable for any special, |
| 192 |
* indirect or consequential damages or any damages |
| 193 |
* whatsoever resulting from loss of use, data or profits, |
| 194 |
* whether in an action of contract, negligence or other tortious |
| 195 |
* action, arising out of or in connection with the use |
| 196 |
* or performance of this software. |
| 197 |
* |
| 198 |
*/ |
| 199 |
|
| 200 |
/*****************************************************************************\ |
| 201 |
* XpmRdFToI.c: * |
| 202 |
* * |
| 203 |
* XPM library * |
| 204 |
* Parse an XPM file and create the image and possibly its mask * |
| 205 |
* * |
| 206 |
* Developed by Arnaud Le Hors * |
| 207 |
\*****************************************************************************/ |
| 208 |
|
| 209 |
extern xpmDataType xpmDataTypes[]; |
| 210 |
|
| 211 |
/* UIM/X Modification: To support transparent colors, |
| 212 |
** we need to pass the widget on which |
| 213 |
** the pixmap will be drawn. |
| 214 |
*/ |
| 215 |
|
| 216 |
int |
| 217 |
UxXpmReadFileToImage(display, w, filename, image_return, |
| 218 |
shapeimage_return, attributes) |
| 219 |
Display *display; |
| 220 |
Widget w; |
| 221 |
char *filename; |
| 222 |
XImage **image_return; |
| 223 |
XImage **shapeimage_return; |
| 224 |
XpmAttributes *attributes; |
| 225 |
{ |
| 226 |
xpmData mdata; |
| 227 |
char buf[BUFSIZ]; |
| 228 |
int l, n = 0; |
| 229 |
int ErrorStatus; |
| 230 |
xpmInternAttrib attrib; |
| 231 |
|
| 232 |
/* |
| 233 |
* initialize return values |
| 234 |
*/ |
| 235 |
if (image_return) |
| 236 |
*image_return = NULL; |
| 237 |
if (shapeimage_return) |
| 238 |
*shapeimage_return = NULL; |
| 239 |
|
| 240 |
if ((ErrorStatus = xpmReadFile(filename, &mdata)) != XpmSuccess) |
| 241 |
return (ErrorStatus); |
| 242 |
|
| 243 |
xpmInitInternAttrib(&attrib); |
| 244 |
|
| 245 |
/* |
| 246 |
* parse the header file |
| 247 |
*/ |
| 248 |
mdata.Bos = '\0'; |
| 249 |
mdata.Eos = '\n'; |
| 250 |
mdata.Bcmt = mdata.Ecmt = NULL; |
| 251 |
xpmNextWord(&mdata, buf); /* skip the first word */ |
| 252 |
l = xpmNextWord(&mdata, buf); /* then get the second word */ |
| 253 |
if ((l == 3 && !strncmp("XPM", buf, 3)) || |
| 254 |
(l == 4 && !strncmp("XPM2", buf, 4))) { |
| 255 |
if (l == 3) |
| 256 |
n = 1; /* handle XPM as XPM2 C */ |
| 257 |
else { |
| 258 |
l = xpmNextWord(&mdata, buf); /* get the type key word */ |
| 259 |
|
| 260 |
/* |
| 261 |
* get infos about this type |
| 262 |
*/ |
| 263 |
while (xpmDataTypes[n].type |
| 264 |
&& strncmp(xpmDataTypes[n].type, buf, l)) |
| 265 |
n++; |
| 266 |
} |
| 267 |
if (xpmDataTypes[n].type) { |
| 268 |
if (n == 0) { /* natural type */ |
| 269 |
mdata.Bcmt = xpmDataTypes[n].Bcmt; |
| 270 |
mdata.Ecmt = xpmDataTypes[n].Ecmt; |
| 271 |
xpmNextString(&mdata); /* skip the end of headerline */ |
| 272 |
mdata.Bos = xpmDataTypes[n].Bos; |
| 273 |
} else { |
| 274 |
xpmNextString(&mdata); /* skip the end of headerline */ |
| 275 |
mdata.Bcmt = xpmDataTypes[n].Bcmt; |
| 276 |
mdata.Ecmt = xpmDataTypes[n].Ecmt; |
| 277 |
mdata.Bos = xpmDataTypes[n].Bos; |
| 278 |
mdata.Eos = '\0'; |
| 279 |
xpmNextString(&mdata); /* skip the assignment line */ |
| 280 |
} |
| 281 |
mdata.Eos = xpmDataTypes[n].Eos; |
| 282 |
|
| 283 |
ErrorStatus = xpmParseData(&mdata, &attrib, attributes); |
| 284 |
|
| 285 |
if (ErrorStatus == XpmSuccess) |
| 286 |
ErrorStatus = UxxpmCreateImage(display, w, &attrib, image_return, |
| 287 |
shapeimage_return, attributes); |
| 288 |
} else |
| 289 |
ErrorStatus = XpmFileInvalid; |
| 290 |
} else |
| 291 |
ErrorStatus = XpmFileInvalid; |
| 292 |
|
| 293 |
if (ErrorStatus >= 0) |
| 294 |
xpmSetAttributes(&attrib, attributes); |
| 295 |
else if (attributes) |
| 296 |
XpmFreeAttributes(attributes); |
| 297 |
|
| 298 |
xpmFreeInternAttrib(&attrib); |
| 299 |
XpmDataClose(&mdata); |
| 300 |
|
| 301 |
return (ErrorStatus); |
| 302 |
} |
| 303 |
/*--------------------------------------------------------------------- |
| 304 |
* $Date: 2009-08-18 15:23:20 $ $Revision: 1.3 $ |
| 305 |
*--------------------------------------------------------------------- |
| 306 |
* |
| 307 |
* |
| 308 |
* Copyright (c) 1992, Visual Edge Software Ltd. |
| 309 |
* |
| 310 |
* ALL RIGHTS RESERVED. Permission to use, copy, modify, and |
| 311 |
* distribute this software and its documentation for any purpose |
| 312 |
* and without fee is hereby granted, provided that the above |
| 313 |
* copyright notice appear in all copies and that both that |
| 314 |
* copyright notice and this permission notice appear in supporting |
| 315 |
* documentation, and that the name of Visual Edge Software not be |
| 316 |
* used in advertising or publicity pertaining to distribution of |
| 317 |
* the software without specific, written prior permission. The year |
| 318 |
* included in the notice is the year of the creation of the work. |
| 319 |
*-------------------------------------------------------------------*/ |
| 320 |
/* |
| 321 |
* Copyright 1990, 1991 GROUPE BULL |
| 322 |
* |
| 323 |
* Permission to use, copy, modify, and distribute this software and its |
| 324 |
* documentation for any purpose and without fee is hereby granted, provided |
| 325 |
* that the above copyright notice appear in all copies and that both that |
| 326 |
* copyright notice and this permission notice appear in supporting |
| 327 |
* documentation, and that the name of GROUPE BULL not be used in advertising |
| 328 |
* or publicity pertaining to distribution of the software without specific, |
| 329 |
* written prior permission. GROUPE BULL makes no representations about the |
| 330 |
* suitability of this software for any purpose. It is provided "as is" |
| 331 |
* without express or implied warranty. |
| 332 |
* |
| 333 |
* GROUPE BULL disclaims all warranties with regard to this software, |
| 334 |
* including all implied warranties of merchantability and fitness, |
| 335 |
* in no event shall GROUPE BULL be liable for any special, |
| 336 |
* indirect or consequential damages or any damages |
| 337 |
* whatsoever resulting from loss of use, data or profits, |
| 338 |
* whether in an action of contract, negligence or other tortious |
| 339 |
* action, arising out of or in connection with the use |
| 340 |
* or performance of this software. |
| 341 |
* |
| 342 |
*/ |
| 343 |
|
| 344 |
/*****************************************************************************\ |
| 345 |
* XpmRdFToP.c: * |
| 346 |
* * |
| 347 |
* XPM library * |
| 348 |
* Parse an XPM file and create the pixmap and possibly its mask * |
| 349 |
* * |
| 350 |
* Developed by Arnaud Le Hors * |
| 351 |
\*****************************************************************************/ |
| 352 |
|
| 353 |
/* UIM/X Modification: To support transparent colors, |
| 354 |
** we need to pass the widget on which |
| 355 |
** the pixmap will be drawn. |
| 356 |
*/ |
| 357 |
|
| 358 |
int |
| 359 |
UxXpmReadFileToPixmap(display, d, w, filename, pixmap_return, |
| 360 |
shapemask_return, attributes) |
| 361 |
Display *display; |
| 362 |
Drawable d; |
| 363 |
Widget w; |
| 364 |
char *filename; |
| 365 |
Pixmap *pixmap_return; |
| 366 |
Pixmap *shapemask_return; |
| 367 |
XpmAttributes *attributes; |
| 368 |
{ |
| 369 |
XImage *image, **imageptr = NULL; |
| 370 |
XImage *shapeimage, **shapeimageptr = NULL; |
| 371 |
int ErrorStatus; |
| 372 |
XGCValues gcv; |
| 373 |
GC gc; |
| 374 |
|
| 375 |
/* |
| 376 |
* initialize return values |
| 377 |
*/ |
| 378 |
if (pixmap_return) { |
| 379 |
*pixmap_return = 0; /* was = NULL; */ |
| 380 |
imageptr = ℑ |
| 381 |
} |
| 382 |
if (shapemask_return) { |
| 383 |
*shapemask_return = 0; /* was = NULL; */ |
| 384 |
shapeimageptr = &shapeimage; |
| 385 |
} |
| 386 |
|
| 387 |
/* |
| 388 |
* create the images |
| 389 |
*/ |
| 390 |
|
| 391 |
/* UIM/X Modification: To support transparent colors, |
| 392 |
** we need to pass the widget on which |
| 393 |
** the pixmap will be drawn. |
| 394 |
*/ |
| 395 |
ErrorStatus = UxXpmReadFileToImage(display, w, filename, imageptr, |
| 396 |
shapeimageptr, attributes); |
| 397 |
if (ErrorStatus < 0) |
| 398 |
return (ErrorStatus); |
| 399 |
|
| 400 |
/* |
| 401 |
* create the pixmaps |
| 402 |
*/ |
| 403 |
if (imageptr && image) { |
| 404 |
*pixmap_return = XCreatePixmap(display, d, image->width, |
| 405 |
image->height, image->depth); |
| 406 |
gcv.function = GXcopy; |
| 407 |
gc = XCreateGC(display, *pixmap_return, GCFunction, &gcv); |
| 408 |
|
| 409 |
XPutImage(display, *pixmap_return, gc, image, 0, 0, 0, 0, |
| 410 |
image->width, image->height); |
| 411 |
|
| 412 |
#ifdef Debug |
| 413 |
/* |
| 414 |
* XDestroyImage free the image data but mnemosyne don't know about it |
| 415 |
* so I free them by hand to avoid mnemalyse report it as lost data. |
| 416 |
*/ |
| 417 |
free(image->data); |
| 418 |
#endif |
| 419 |
XDestroyImage(image); |
| 420 |
XFreeGC(display, gc); |
| 421 |
} |
| 422 |
if (shapeimageptr && shapeimage) { |
| 423 |
*shapemask_return = XCreatePixmap(display, d, shapeimage->width, |
| 424 |
shapeimage->height, |
| 425 |
shapeimage->depth); |
| 426 |
gcv.function = GXcopy; |
| 427 |
gc = XCreateGC(display, *shapemask_return, GCFunction, &gcv); |
| 428 |
|
| 429 |
XPutImage(display, *shapemask_return, gc, shapeimage, 0, 0, 0, 0, |
| 430 |
shapeimage->width, shapeimage->height); |
| 431 |
|
| 432 |
#ifdef Debug |
| 433 |
/* |
| 434 |
* XDestroyImage free the image data but mnemosyne don't know about it |
| 435 |
* so I free them by hand to avoid mnemalyse report it as lost data. |
| 436 |
*/ |
| 437 |
free(shapeimage->data); |
| 438 |
#endif |
| 439 |
XDestroyImage(shapeimage); |
| 440 |
XFreeGC(display, gc); |
| 441 |
} |
| 442 |
return (ErrorStatus); |
| 443 |
} |