2
* FIG : Facility for Interactive Generation of figures
3
* Copyright (c) 1989-2000 by Brian V. Smith
5
* Any party obtaining a copy of these files is granted, free of charge, a
6
* full and unrestricted irrevocable, world-wide, paid up, royalty-free,
7
* nonexclusive right and license to deal in this software and
8
* documentation files (the "Software"), including without limitation the
9
* rights to use, copy, modify, merge, publish, distribute, sublicense,
10
* and/or sell copies of the Software, and to permit persons who receive
11
* copies from any such party to do so, with the only requirement being
12
* that this copyright notice remain intact.
17
#include "resources.h"
20
#include "w_msgpanel.h"
23
/* attempt to read a XPM (color pixmap) file */
24
/* the filename is passed since XpmReadFileToXpmImage needs a name
25
instead of a FILE pointer. This is fine because it handles compressed files */
27
/* return codes: PicSuccess (1) : success
28
FileInvalid (-2) : invalid file
32
read_xpm(filename,filetype,pic)
43
/* make scale factor smaller for metric */
44
float scale = (appres.INCHES ?
46
2.54*PIX_PER_CM)/(float)DISPLAY_PIX_PER_INCH;
48
status = XpmReadFileToXpmImage(filename, &image, NULL);
49
/* if out of colors, try switching colormaps and reading again */
50
if (status == XpmColorFailed) {
51
if (!switch_colormap())
53
status = XpmReadFileToXpmImage(pic->file, &image, NULL);
55
if (status == XpmSuccess) {
56
/* now look up the colors in the image and put them in the pic colormap */
57
for (i=0; i<image.ncolors; i++) {
58
c = (image.colorTable + i)->c_color;
59
if (c == NULL || *c == '\0') { /* use white for null color */
61
file_msg("white used for *NULL color");
63
if (XParseColor(tool_d, tool_cm, c, &exact_def) == 0) {
64
file_msg("Error parsing color %s",c);
65
exact_def.red = exact_def.green = exact_def.blue = 65535;
67
pic->cmap[i].red = exact_def.red >> 8;
68
pic->cmap[i].green = exact_def.green >> 8;
69
pic->cmap[i].blue = exact_def.blue >> 8;
71
pic->subtype = T_PIC_XPM;
72
pic->numcols = image.ncolors;
74
pic->bitmap = (unsigned char *) malloc(image.width*image.height*sizeof(unsigned char));
75
if (pic->bitmap == NULL) {
76
file_msg("cannot allocate space for XPM image");
79
for (i=0; i<image.width*image.height; i++)
80
pic->bitmap[i] = (unsigned char) image.data[i]; /* int to unsigned char */
81
pic->hw_ratio = (float) image.height / image.width;
82
pic->bit_size.x = image.width;
83
pic->size_x = image.width * scale;
84
pic->bit_size.y = image.height;
85
pic->size_y = image.height * scale;
86
XpmFreeXpmImage(&image); /* get rid of the image */
87
/* if monochrome display map bitmap */
88
if (tool_cells <= 2 || appres.monochrome)