1 /* Definitions for Xconq images.
2    Copyright (C) 1992-2000 Stanley T. Shebs.
3 
4 Xconq is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.  See the file COPYING.  */
8 
9 /*! \file kernel/imf.h
10  * \brief Definitions for the image manipulation routines
11  */
12 
13 /*!
14  * An image family is like a Mac Finder icon family, but allows
15  * multiple kinds of images of an arbitrary set of sizes.  Individual
16  * images in a family may have both "lisp" form and "raw" form, the
17  * former being used for reading and writing, while the raw form is an
18  * intermediary for conversion to and from platform-specific
19  * representations.
20  */
21 typedef struct a_image {
22     short w;					/*!< Nominal size of the image - width */
23     short h;					/*!< Nominal size of the image - height */
24     short istile;				/*!< True if image may be used as tile */
25     short isterrain;			/*!< True if image may be used for basic terrain. */
26     short isconnection;			/*!< True if image may be used for conns. */
27     short isborder;			/*!< True if image may be used for bords. */
28     short istransition;			/*!< True if image is a transition. */
29     short numsubimages;		/*!< Number of sub images. */
30     short subx;					/*!< Subimage x. */
31     short suby;					/*!< Subimage y. */
32     char *embedname;				/*!< Name of an embedded subimage (imf name) */
33     short embedx;					/*!< Position to draw an embedded subimage - x. */
34     short embedy;					/*!< Position to draw an embedded subimage - y. */
35     short embedw;					/*!< Size of space for embedded subimage - width. */
36     short embedh;					/*!< Size of space for embedded subimage - height. */
37     Obj *monodata;				/*!< Monochrome data, in GDL form */
38     Obj *colrdata;					/*!< Color data, in GDL form */
39     Obj *maskdata;				/*!< Mask data, in GDL form */
40     Obj *filedata;					/*!< How to find data in a file */
41     struct a_file_image *file_image;	/*!< Pointer to file image */
42     short actualw;					/*!< Actual Size of image - width. */
43     short actualh;					/*!< Actual size of image - height. */
44     short pixelsize;				/*!< Number of bits per pixel */
45     short orig_pixelsize;			/*!< Pixels before modification */
46     Obj *palette;					/*!< Color palette, in list form */
47     Obj *notes;					/*!< designer notes about the image */
48     short synthetic;				/*!< True if image was computed */
49     char *rawmonodata;				/*!< Monochrome data, as array of bytes */
50     char *rawcolrdata;				/*!< Color data, as array of bytes */
51     char *rawmaskdata;				/*!< Mask data, as array of bytes */
52     int *rawpalette;				/*!< Color palette, in raw form */
53     short numcolors;				/*!< Number of colors in raw palette */
54     short r;						/*!< Solid color data as RGB values - red. */
55     short g;						/*!< Solid color data as RGB values - green. */
56     short b;						/*!< Solid color data as RGB values - blue.  */
57     short bboxx;					/*<! Position of actual data within image - x. */
58     short bboxy;					/*<! Position of actual data within image - y. */
59     short bboxw;					/*<! Dimensions of actual data within image - width. */
60     short bboxh;					/*<! Dimensions of actual data within image -height. */
61     short hexgridx;                                     /*<! Hex grid width in cells. */
62     short hexgridy;                                     /*<! Hex grid height in cells. */
63     char *hook;					/*<! Pointer to interface-specific data */
64     struct a_image **subimages;		/*<! Pointer to collection of subimages */
65     struct a_image *next;			/*<! Pointer to next image in family */
66 } Image;
67 
68 typedef struct a_image_family {
69     char *name;					/* Name of the family */
70     short ersatz;					/* True if this image is a substitute */
71     struct a_image_file *location;  		/* File or whatever to look for data */
72     Obj *notes;					/* designer notes about the image family */
73     char *hook;					/* Pointer to interface-specific data */
74     short numsizes;				/* Number of images in the list */
75     Image *images;				/* Pointer to chain of images */
76     struct a_image_family *next;		/* Pointer to next image family in a list */
77 } ImageFamily;
78 
79 /* Image files are files that contain raw image data in a standard
80    format, such as GIF or PNG.  We get actual usable images by
81    extracting from the images in these files. */
82 
83 typedef struct a_image_file {
84     char *name;			/* Name of the file */
85     short loaded;		/* True if it has already been loaded */
86     struct a_image_file *next;	/* Link to the next file. */
87 } ImageFile;
88 
89 /* Structure holding data about a file image, which is the raw result
90    of loading from an image file.  A file image often holds an array
91    of smaller images that will be extracted to make up image
92    families. */
93 
94 typedef struct a_file_image {
95     char *name;
96     short type;
97     short loaded;
98     short width, height;
99     char *data;
100     short numcolors;
101     int *palette;
102     short numtransparent;
103     char *transparent;
104     struct a_file_image *next;
105 } FileImage;
106 
107 extern ImageFamily **images;
108 extern int numimages;
109 extern ImageFile *image_files;
110 extern FileImage *file_images;
111 extern ImageFamily *(*imf_load_hook)(ImageFamily *imf);
112 extern ImageFamily *(*imf_interp_hook)(ImageFamily *imf, Image *img,
113 				       int force);
114 extern int use_clip_mask;
115 
116 /* Flag that indicates limited GDI memory in Windows ME and below. */
117 extern short poor_memory;
118 
119 /* (should remove these fixed limits someday) */
120 
121 #define MAXIMAGEFAMILIES 3000
122 
123 /* Some handy macros. */
124 
125 #define computed_rowbytes(w, pixelsize) (((w * pixelsize) + 7) / 8)
126 
127 #define hextoi(c) (((c) >= '0' && (c) <= '9') ? ((c) - '0') : ((c) - 'a' + 10))
128 
129 #define for_all_images(imf,img) \
130   for ((img) = (imf)->images; (img) != NULL; (img) = (img)->next)
131 
132 typedef void (*readimf_hook)(ImageFamily *, int);
133 
134 extern ImageFamily *clone_imf(ImageFamily *imf);
135 extern ImageFamily *get_imf(char *name);
136 extern ImageFamily *find_imf(char *name);
137 extern Image *find_img(ImageFamily *imf, int w, int h);
138 extern Image *get_img(ImageFamily *imf, int w, int h);
139 extern int valid_imf_name(char *name);
140 
141 extern ImageFile *get_image_file(char *name);
142 extern void load_image_families(FILE *fp, int loadnow, readimf_hook callback);
143 extern int load_imf_file(char *filename, readimf_hook callback);
144 extern void interp_imf_form(Obj *form, char *filename, readimf_hook callback);
145 
146 extern ImageFamily *interp_imf(Obj *form);
147 extern void interp_imf_contents(ImageFamily *imf, Obj *form);
148 extern void interp_image(ImageFamily *imf, Obj *size, Obj *parts);
149 extern void interp_bytes(Obj *datalist, int numbytes, char *destaddr,
150 			 int jump);
151 
152 extern Image *best_image_in_range(ImageFamily *imf, int w, int h,
153 				  int wmin, int hmin, int wmax, int hmax);
154 #define best_image(imf, w, h)  best_image_in_range(imf, w, h, 0, 0, -1, -1)
155 extern Image *smallest_image(ImageFamily *imf);
156 extern int emblem_position(Image *uimg, char *ename, ImageFamily *eimf,
157 			   int sw, int sh, int vpuh, int vphh,
158 			   int *exxp, int *eyyp, int *ewp, int *ehp);
159 
160 extern void blacken_masked_area(ImageFamily *imf, Image *img,
161 				int r, int g, int b);
162 extern void blacken_mono_masked_area(ImageFamily *imf, Image *img,
163 				     int r, int g, int b);
164 
165 extern void make_raw_palette(Image *img);
166 
167 extern void sort_all_images(void);
168 
169 extern void check_imf(ImageFamily *imf);
170 
171 extern void write_imf(FILE *fp, ImageFamily *imf);
172 
173 extern void make_generic_image_data(ImageFamily *imf);
174 
175 extern void validify_imf_name(char *buf);
176 extern void compute_image_bboxes(ImageFamily *imf);
177 extern void compute_image_bbox(Image *img);
178 extern void write_imf_dir(char *filename, ImageFamily **imfimages, int num);
179 extern char *find_color_name(int r, int g, int b);
180 extern void parse_lisp_palette_entry(Obj *palentry, int *c,
181 				     int *r, int *g, int *b);
182 
183 extern void make_image_from_file_image(ImageFamily *imf,
184 				  Image *img, Image *subimg, int subi);
185 extern void load_file_image(FileImage *fimg);
186 extern void copy_from_file_image(Image *img, FileImage *fimg,
187 				 int xoffset, int yoffset,
188 				 int actualw, int actualh);
189 extern int get_gif(FileImage *fimg);
190 extern void make_raw_mono_data(Image *img, int force);
191 extern FileImage *get_file_image(char *fname);
192 
193 extern ImageFamily *get_generic_images(char *name);
194