1 #define SUBSYSTEM APPLICATION_EXEC "_image: "
2 
3 #define IMAGE_BMP_TAG 0x4d42							/* BMP image tag */
4 
5 struct __PACKED__ bmp_header_info {
6 	uint32_t bi_size;							/* Structure size in bytes */
7 
8 	int32_t bi_width;							/* Width in pixels */
9 	int32_t bi_height;							/* Height in pixels */
10 
11 	uint16_t bi_planes;							/* Number of planes (always 1) */
12 	uint16_t bi_bitcount;							/* Bits per pixel */
13 
14 	uint32_t bi_compression;						/* Type of compression */
15 	uint32_t bi_sizeimage;							/* Image size in bytes */
16 	uint32_t bi_xpelspermeter;						/* Horizontal resolution in pixels per meter */
17 	uint32_t bi_ypelspermeter;						/* Vertical resolution in pixels per meter */
18 
19 	uint32_t bi_clrused;							/* Number of colors in color index */
20 	uint32_t bi_clrimportant;						/* Number of required colors */
21 };
22 
23 struct __PACKED__ bmp_header {
24 	uint16_t bf_type;							/* Image type */
25 
26 	uint32_t bf_size;							/* File size in bytes */
27 
28 	int16_t bf_reserved1;							/* Reserved */
29 	int16_t bf_reserved2;							/* Reserved */
30 
31 	uint32_t bf_offbits;							/* Offset to bitmap bits */
32 
33 	struct bmp_header_info i;						/* Bitmap info */
34 };
35 
36 #if ! defined(PROG_DISABLE_IMAGE)
37 #define IMAGE_CEL_TAG 0x5353694b						/* CEL image tag */
38 #define IMAGE_CEL_COLOR 33							/* CEL color type */
39 
40 struct __PACKED__ cel_header {
41 	int32_t id;								/* Identifier */
42 
43 	int8_t type;								/* Image type */
44 	int8_t bpp;								/* Bits per pixel */
45 
46 	int8_t dummy[2];							/* Reserved */
47 
48 	uint16_t width;								/* Width in pixels */
49 	uint16_t height;							/* height in pixels */
50 	uint16_t xoffset;							/* X offset in pixels */
51 	uint16_t yoffset;							/* Y offset in pixels */
52 
53 	int8_t reserved[16];							/* Reserved */
54 };
55 #endif
56 
57 #if ! defined(PROG_DISABLE_IMAGE)
58 struct __PACKED__ pix_header {
59 	uint16_t width;								/* Image width */
60 	uint16_t height;							/* Image height */
61 
62 	uint16_t xoffset;							/* Reserved */
63 	uint16_t yoffset;							/* Reserved */
64 
65 	uint16_t bpp;								/* Bits per pixel */
66 };
67 #endif
68 
69 #if ! defined(PROG_DISABLE_IMAGE)
70 #define IMAGE_PPM_TAG "P6"							/* PPM image tag */
71 #endif
72 
73 #if ! defined(PROG_DISABLE_IMAGE)
74 #define IMAGE_RAS_TAG 0x59a66a95						/* Sun raster image tag */
75 #define IMAGE_RAS_STANDARD 1							/* Sun raster color type */
76 
77 struct __PACKED__ ras_header {
78 	int32_t ras_magic;							/* Magic number */
79 
80 	int32_t ras_width;							/* Width in pixels */
81 	int32_t ras_height;							/* Height in pixels */
82 	int32_t ras_depth;							/* Bits per pixel */
83 	int32_t ras_length;							/* Image length in bytes */
84 
85 	int32_t ras_type;							/* Image type */
86 
87 	int32_t ras_maptype;							/* Colormap type */
88 	int32_t ras_maplength;							/* Colormap length in bytes */
89 };
90 #endif
91 
92 #if ! defined(PROG_DISABLE_IMAGE)
93 #define IMAGE_RGB_TAG 474							/* RGB image tag */
94 #define IMAGE_RGB_STORAGE_VERBATIM 0						/* RGB pixels are unpacked */
95 #define IMAGE_RGB_STORAGE_RLE 1							/* RGB pixels are RLE packed */
96 
97 struct __PACKED__ rgb_header {
98 	int16_t magic;								/* Identification tag */
99 
100 	int8_t storage;								/* Storage format */
101 	int8_t bpc;								/* Bytes per pixel */
102 
103 	uint16_t dimension;							/* Number of dimensions */
104 	uint16_t xsize;								/* Width in pixels */
105 	uint16_t ysize;								/* Height in pixels */
106 	uint16_t zsize;								/* Depth in pixels */
107 
108 	int32_t pixmin;								/* Minimum pixel value */
109 	int32_t pixmax;								/* Maxmimum pixel value */
110 
111 	int8_t dummy[4];							/* Reserved */
112 
113 	int8_t imagename[80];							/* Image name */
114 
115 	int32_t colormap;							/* Colormap id */
116 
117 	int8_t reserved[404];							/* Reserved */
118 };
119 #endif
120 
121 #if ! defined(PROG_DISABLE_IMAGE)
122 #define IMAGE_RLA_ASPECT_1K_SQUARE_N "1k_square"				/* RLA aspect names */
123 #define IMAGE_RLA_ASPECT_1K_SQUARE_W 1024
124 #define IMAGE_RLA_ASPECT_1K_SQUARE_H 1024
125 #define IMAGE_RLA_ASPECT_2K_SQUARE_N "2k_square"
126 #define IMAGE_RLA_ASPECT_2K_SQUARE_W 2048
127 #define IMAGE_RLA_ASPECT_2K_SQUARE_H 2048
128 #define IMAGE_RLA_ASPECT_3K_SQUARE_N "3k_square"
129 #define IMAGE_RLA_ASPECT_3K_SQUARE_W 3072
130 #define IMAGE_RLA_ASPECT_3K_SQUARE_H 3072
131 #define IMAGE_RLA_ASPECT_4K_SQUARE_N "4k_square"
132 #define IMAGE_RLA_ASPECT_4K_SQUARE_W 4096
133 #define IMAGE_RLA_ASPECT_4K_SQUARE_H 4096
134 #define IMAGE_RLA_ASPECT_5K_SQUARE_N "5k_square"
135 #define IMAGE_RLA_ASPECT_5K_SQUARE_W 5120
136 #define IMAGE_RLA_ASPECT_5K_SQUARE_H 5120
137 #define IMAGE_RLA_ASPECT_6K_SQUARE_N "6k_square"
138 #define IMAGE_RLA_ASPECT_6K_SQUARE_W 6144
139 #define IMAGE_RLA_ASPECT_6K_SQUARE_H 6144
140 #define IMAGE_RLA_ASPECT_7K_SQUARE_N "7k_square"
141 #define IMAGE_RLA_ASPECT_7K_SQUARE_W 7168
142 #define IMAGE_RLA_ASPECT_7K_SQUARE_H 7168
143 #define IMAGE_RLA_ASPECT_8K_SQUARE_N "8k_square"
144 #define IMAGE_RLA_ASPECT_8K_SQUARE_W 8192
145 #define IMAGE_RLA_ASPECT_8K_SQUARE_H 8192
146 #define IMAGE_RLA_ASPECT_ABEKAS_N "Abekas"
147 #define IMAGE_RLA_ASPECT_ABEKAS_W 720
148 #define IMAGE_RLA_ASPECT_ABEKAS_H 486
149 #define IMAGE_RLA_ASPECT_CREATOR_N "Creator"
150 #define IMAGE_RLA_ASPECT_CREATOR_W 640
151 #define IMAGE_RLA_ASPECT_CREATOR_H 484
152 #define IMAGE_RLA_ASPECT_IMAGENODE_N "ImageNode"
153 #define IMAGE_RLA_ASPECT_IMAGENODE_W 512
154 #define IMAGE_RLA_ASPECT_IMAGENODE_H 486
155 #define IMAGE_RLA_ASPECT_IRIS_8_10_N "Iris-8-10"
156 #define IMAGE_RLA_ASPECT_IRIS_8_10_W 3000
157 #define IMAGE_RLA_ASPECT_IRIS_8_10_H 2400
158 #define IMAGE_RLA_ASPECT_CCIR_PAL_N "ccir_pal"
159 #define IMAGE_RLA_ASPECT_CCIR_PAL_W 720
160 #define IMAGE_RLA_ASPECT_CCIR_PAL_H 576
161 #define IMAGE_RLA_ASPECT_FULL_1024_N "full_1024"
162 #define IMAGE_RLA_ASPECT_FULL_1024_W 1024
163 #define IMAGE_RLA_ASPECT_FULL_1024_H 768
164 #define IMAGE_RLA_ASPECT_FULL_1280_N "full_1280"
165 #define IMAGE_RLA_ASPECT_FULL_1280_W 1280
166 #define IMAGE_RLA_ASPECT_FULL_1280_H 1024
167 #define IMAGE_RLA_ASPECT_IRIS_1400_N "iris_1400"
168 #define IMAGE_RLA_ASPECT_IRIS_1400_W 1022
169 #define IMAGE_RLA_ASPECT_IRIS_1400_H 768
170 #define IMAGE_RLA_ASPECT_IRIS_2400_N "iris_2400"
171 #define IMAGE_RLA_ASPECT_IRIS_2400_W 1024
172 #define IMAGE_RLA_ASPECT_IRIS_2400_H 768
173 #define IMAGE_RLA_ASPECT_IRIS_NTSC_N "iris_ntsc"
174 #define IMAGE_RLA_ASPECT_IRIS_NTSC_W 636
175 #define IMAGE_RLA_ASPECT_IRIS_NTSC_H 484
176 #define IMAGE_RLA_ASPECT_IRIS_PAL_N "iris_pal"
177 #define IMAGE_RLA_ASPECT_IRIS_PAL_W 768
178 #define IMAGE_RLA_ASPECT_IRIS_PAL_H 576
179 #define IMAGE_RLA_ASPECT_MATRIX_2K_N "matrix_2k"
180 #define IMAGE_RLA_ASPECT_MATRIX_2K_W 2048
181 #define IMAGE_RLA_ASPECT_MATRIX_2K_H 1366
182 #define IMAGE_RLA_ASPECT_MATRIX_2K_NTSC_N "matrix_2k_ntsc"
183 #define IMAGE_RLA_ASPECT_MATRIX_2K_NTSC_W 1821
184 #define IMAGE_RLA_ASPECT_MATRIX_2K_NTSC_H 1366
185 #define IMAGE_RLA_ASPECT_MATRIX_4K_N "matrix_4k"
186 #define IMAGE_RLA_ASPECT_MATRIX_4K_W 4096
187 #define IMAGE_RLA_ASPECT_MATRIX_4K_H 2732
188 #define IMAGE_RLA_ASPECT_MATRIX_4K_NTSC_N "matrix_4k_ntsc"
189 #define IMAGE_RLA_ASPECT_MATRIX_4K_NTSC_W 3642
190 #define IMAGE_RLA_ASPECT_MATRIX_4K_NTSC_H 2732
191 #define IMAGE_RLA_ASPECT_NTSC_4D_N "ntsc_4d"
192 #define IMAGE_RLA_ASPECT_NTSC_4D_W 646
193 #define IMAGE_RLA_ASPECT_NTSC_4D_H 485
194 #define IMAGE_RLA_ASPECT_NTSC_512_N "ntsc_512"
195 #define IMAGE_RLA_ASPECT_NTSC_512_W 512
196 #define IMAGE_RLA_ASPECT_NTSC_512_H 484
197 #define IMAGE_RLA_ASPECT_NTSC_512_FLD_N "ntsc_512_fld"
198 #define IMAGE_RLA_ASPECT_NTSC_512_FLD_W 512
199 #define IMAGE_RLA_ASPECT_NTSC_512_FLD_H 242
200 #define IMAGE_RLA_ASPECT_NTSC_636_N "ntsc_636"
201 #define IMAGE_RLA_ASPECT_NTSC_636_W 636
202 #define IMAGE_RLA_ASPECT_NTSC_636_H 484
203 #define IMAGE_RLA_ASPECT_NTSC_636_FLD_N "ntsc_636_fld"
204 #define IMAGE_RLA_ASPECT_NTSC_636_FLD_W 636
205 #define IMAGE_RLA_ASPECT_NTSC_636_FLD_H 242
206 #define IMAGE_RLA_ASPECT_NTSC_640_N "ntsc_640"
207 #define IMAGE_RLA_ASPECT_NTSC_640_W 640
208 #define IMAGE_RLA_ASPECT_NTSC_640_H 486
209 #define IMAGE_RLA_ASPECT_NTSC_640_FLD_N "ntsc_640_fld"
210 #define IMAGE_RLA_ASPECT_NTSC_640_FLD_W 640
211 #define IMAGE_RLA_ASPECT_NTSC_640_FLD_H 243
212 #define IMAGE_RLA_ASPECT_PAL_768_N "pal_768"
213 #define IMAGE_RLA_ASPECT_PAL_768_W 768
214 #define IMAGE_RLA_ASPECT_PAL_768_H 576
215 #define IMAGE_RLA_ASPECT_PAL_780_N "pal_780"
216 #define IMAGE_RLA_ASPECT_PAL_780_W 780
217 #define IMAGE_RLA_ASPECT_PAL_780_H 576
218 #define IMAGE_RLA_ASPECT_PIXAR_N "pixar"
219 #define IMAGE_RLA_ASPECT_PIXAR_W 1024
220 #define IMAGE_RLA_ASPECT_PIXAR_H 768
221 #define IMAGE_RLA_ASPECT_PIXAR_NTSC_N "pixar_ntsc"
222 #define IMAGE_RLA_ASPECT_PIXAR_NTSC_W 640
223 #define IMAGE_RLA_ASPECT_PIXAR_NTSC_H 486
224 #define IMAGE_RLA_ASPECT_PV_2K_N "pv_2k"
225 #define IMAGE_RLA_ASPECT_PV_2K_W 2048
226 #define IMAGE_RLA_ASPECT_PV_2K_H 1638
227 #define IMAGE_RLA_ASPECT_PV_3K_N "pv_3k"
228 #define IMAGE_RLA_ASPECT_PV_3K_W 3072
229 #define IMAGE_RLA_ASPECT_PV_3K_H 2457
230 #define IMAGE_RLA_ASPECT_PV_NTSC_N "pv_ntsc"
231 #define IMAGE_RLA_ASPECT_PV_NTSC_W 646
232 #define IMAGE_RLA_ASPECT_PV_NTSC_H 486
233 #define IMAGE_RLA_ASPECT_PV_PAL_N "pv_pal"
234 #define IMAGE_RLA_ASPECT_PV_PAL_W 768
235 #define IMAGE_RLA_ASPECT_PV_PAL_H 576
236 #define IMAGE_RLA_ASPECT_QNT_PAL_N "qnt_pal"
237 #define IMAGE_RLA_ASPECT_QNT_PAL_W 720
238 #define IMAGE_RLA_ASPECT_QNT_PAL_H 576
239 #define IMAGE_RLA_ASPECT_QTL_NTSC_N "qtl_ntsc"
240 #define IMAGE_RLA_ASPECT_QTL_NTSC_W 720
241 #define IMAGE_RLA_ASPECT_QTL_NTSC_H 486
242 #define IMAGE_RLA_ASPECT_SCREEN_N "screen"
243 #define IMAGE_RLA_ASPECT_SCREEN_W 1280
244 #define IMAGE_RLA_ASPECT_SCREEN_H 1024
245 #define IMAGE_RLA_ASPECT_SHIBA_SOKU_N "shiba_soku"
246 #define IMAGE_RLA_ASPECT_SHIBA_SOKU_W 1600
247 #define IMAGE_RLA_ASPECT_SHIBA_SOKU_H 1045
248 #define IMAGE_RLA_ASPECT_SONY_HDTV_N "sony_hdtv"
249 #define IMAGE_RLA_ASPECT_SONY_HDTV_W 1920
250 #define IMAGE_RLA_ASPECT_SONY_HDTV_H 1035
251 #define IMAGE_RLA_ASPECT_TEK_NTSC_N "tek_ntsc"
252 #define IMAGE_RLA_ASPECT_TEK_NTSC_W 720
253 #define IMAGE_RLA_ASPECT_TEK_NTSC_H 486
254 #define IMAGE_RLA_ASPECT_TEK_PAL_N "tek_pal"
255 #define IMAGE_RLA_ASPECT_TEK_PAL_W 720
256 #define IMAGE_RLA_ASPECT_TEK_PAL_H 576
257 #define IMAGE_RLA_ASPECT_TEXTURE_512_N "texture_512"
258 #define IMAGE_RLA_ASPECT_TEXTURE_512_W 512
259 #define IMAGE_RLA_ASPECT_TEXTURE_512_H 512
260 #define IMAGE_RLA_ASPECT_TGA_486_N "tga_486"
261 #define IMAGE_RLA_ASPECT_TGA_486_W 512
262 #define IMAGE_RLA_ASPECT_TGA_486_H 486
263 #define IMAGE_RLA_ASPECT_TGA_NTSC_N "tga_ntsc"
264 #define IMAGE_RLA_ASPECT_TGA_NTSC_W 512
265 #define IMAGE_RLA_ASPECT_TGA_NTSC_H 482
266 #define IMAGE_RLA_ASPECT_VC_NTSC_N "vc_ntsc"
267 #define IMAGE_RLA_ASPECT_VC_NTSC_W 640
268 #define IMAGE_RLA_ASPECT_VC_NTSC_H 486
269 #define IMAGE_RLA_ASPECT_VFR_COMP_N "vfr_comp"
270 #define IMAGE_RLA_ASPECT_VFR_COMP_W 768
271 #define IMAGE_RLA_ASPECT_VFR_COMP_H 486
272 #define IMAGE_RLA_ASPECT_VFR_RGB_N "vfr_rgb"
273 #define IMAGE_RLA_ASPECT_VFR_RGB_W 720
274 #define IMAGE_RLA_ASPECT_VFR_RGB_H 486
275 #define IMAGE_RLA_ASPECT_VST_HIRES_N "vst_hires"
276 #define IMAGE_RLA_ASPECT_VST_HIRES_W 1024
277 #define IMAGE_RLA_ASPECT_VST_HIRES_H 768
278 #define IMAGE_RLA_ASPECT_VST_NTSC_N "vst_ntsc"
279 #define IMAGE_RLA_ASPECT_VST_NTSC_W 756
280 #define IMAGE_RLA_ASPECT_VST_NTSC_H 486
281 #define IMAGE_RLA_ASPECT_VST_PAL_N "vst_pal"
282 #define IMAGE_RLA_ASPECT_VST_PAL_W 738
283 #define IMAGE_RLA_ASPECT_VST_PAL_H 576
284 #define IMAGE_RLA_ASPECT_VST_PAL2_N "vst_pal2"
285 #define IMAGE_RLA_ASPECT_VST_PAL2_W 740
286 #define IMAGE_RLA_ASPECT_VST_PAL2_H 578
287 #define IMAGE_RLA_ASPECT_VST_TARGA_N "vst_targa"
288 #define IMAGE_RLA_ASPECT_VST_TARGA_W 512
289 #define IMAGE_RLA_ASPECT_VST_TARGA_H 486
290 #define IMAGE_RLA_ASPECT_VTC_MVBHM_N "vtc_mvbhm"
291 #define IMAGE_RLA_ASPECT_VTC_MVBHM_W 1440
292 #define IMAGE_RLA_ASPECT_VTC_MVBHM_H 1200
293 #define IMAGE_RLA_ASPECT_VTE_720_N "vte_720"
294 #define IMAGE_RLA_ASPECT_VTE_720_W 720
295 #define IMAGE_RLA_ASPECT_VTE_720_H 576
296 #define IMAGE_RLA_ASPECT_WINDOW_N "window"
297 #define IMAGE_RLA_ASPECT_WINDOW_W 1024
298 #define IMAGE_RLA_ASPECT_WINDOW_H 820
299 
300 struct rla_header_aspect {
301 	uint16_t w;								/* RLA aspect width */
302 	uint16_t h;								/* RLA aspect height */
303 
304 	char *s;								/* RLA aspect name */
305 };
306 
307 static const struct rla_header_aspect rla_header_aspect_t[] = {
308 	{ IMAGE_RLA_ASPECT_1K_SQUARE_W, IMAGE_RLA_ASPECT_1K_SQUARE_H, IMAGE_RLA_ASPECT_1K_SQUARE_N },
309 	{ IMAGE_RLA_ASPECT_2K_SQUARE_W, IMAGE_RLA_ASPECT_2K_SQUARE_H, IMAGE_RLA_ASPECT_2K_SQUARE_N },
310 	{ IMAGE_RLA_ASPECT_3K_SQUARE_W, IMAGE_RLA_ASPECT_3K_SQUARE_H, IMAGE_RLA_ASPECT_3K_SQUARE_N },
311 	{ IMAGE_RLA_ASPECT_4K_SQUARE_W, IMAGE_RLA_ASPECT_4K_SQUARE_H, IMAGE_RLA_ASPECT_4K_SQUARE_N },
312 	{ IMAGE_RLA_ASPECT_5K_SQUARE_W, IMAGE_RLA_ASPECT_5K_SQUARE_H, IMAGE_RLA_ASPECT_5K_SQUARE_N },
313 	{ IMAGE_RLA_ASPECT_6K_SQUARE_W, IMAGE_RLA_ASPECT_6K_SQUARE_H, IMAGE_RLA_ASPECT_6K_SQUARE_N },
314 	{ IMAGE_RLA_ASPECT_7K_SQUARE_W, IMAGE_RLA_ASPECT_7K_SQUARE_H, IMAGE_RLA_ASPECT_7K_SQUARE_N },
315 	{ IMAGE_RLA_ASPECT_8K_SQUARE_W, IMAGE_RLA_ASPECT_8K_SQUARE_H, IMAGE_RLA_ASPECT_8K_SQUARE_N },
316 	{ IMAGE_RLA_ASPECT_ABEKAS_W, IMAGE_RLA_ASPECT_ABEKAS_H, IMAGE_RLA_ASPECT_ABEKAS_N },
317 	{ IMAGE_RLA_ASPECT_CREATOR_W, IMAGE_RLA_ASPECT_CREATOR_H, IMAGE_RLA_ASPECT_CREATOR_N },
318 	{ IMAGE_RLA_ASPECT_IMAGENODE_W, IMAGE_RLA_ASPECT_IMAGENODE_H, IMAGE_RLA_ASPECT_IMAGENODE_N },
319 	{ IMAGE_RLA_ASPECT_IRIS_8_10_W, IMAGE_RLA_ASPECT_IRIS_8_10_H, IMAGE_RLA_ASPECT_IRIS_8_10_N },
320 	{ IMAGE_RLA_ASPECT_CCIR_PAL_W, IMAGE_RLA_ASPECT_CCIR_PAL_H, IMAGE_RLA_ASPECT_CCIR_PAL_N },
321 	{ IMAGE_RLA_ASPECT_FULL_1024_W, IMAGE_RLA_ASPECT_FULL_1024_H, IMAGE_RLA_ASPECT_FULL_1024_N },
322 	{ IMAGE_RLA_ASPECT_FULL_1280_W, IMAGE_RLA_ASPECT_FULL_1280_H, IMAGE_RLA_ASPECT_FULL_1280_N },
323 	{ IMAGE_RLA_ASPECT_IRIS_1400_W, IMAGE_RLA_ASPECT_IRIS_1400_H, IMAGE_RLA_ASPECT_IRIS_1400_N },
324 	{ IMAGE_RLA_ASPECT_IRIS_2400_W, IMAGE_RLA_ASPECT_IRIS_2400_H, IMAGE_RLA_ASPECT_IRIS_2400_N },
325 	{ IMAGE_RLA_ASPECT_IRIS_NTSC_W, IMAGE_RLA_ASPECT_IRIS_NTSC_H, IMAGE_RLA_ASPECT_IRIS_NTSC_N },
326 	{ IMAGE_RLA_ASPECT_IRIS_PAL_W, IMAGE_RLA_ASPECT_IRIS_PAL_H, IMAGE_RLA_ASPECT_IRIS_PAL_N },
327 	{ IMAGE_RLA_ASPECT_MATRIX_2K_W, IMAGE_RLA_ASPECT_MATRIX_2K_H, IMAGE_RLA_ASPECT_MATRIX_2K_N },
328 	{ IMAGE_RLA_ASPECT_MATRIX_2K_NTSC_W, IMAGE_RLA_ASPECT_MATRIX_2K_NTSC_H, IMAGE_RLA_ASPECT_MATRIX_2K_NTSC_N },
329 	{ IMAGE_RLA_ASPECT_MATRIX_4K_W, IMAGE_RLA_ASPECT_MATRIX_4K_H, IMAGE_RLA_ASPECT_MATRIX_4K_N },
330 	{ IMAGE_RLA_ASPECT_MATRIX_4K_NTSC_W, IMAGE_RLA_ASPECT_MATRIX_4K_NTSC_H, IMAGE_RLA_ASPECT_MATRIX_4K_NTSC_N },
331 	{ IMAGE_RLA_ASPECT_NTSC_4D_W, IMAGE_RLA_ASPECT_NTSC_4D_H, IMAGE_RLA_ASPECT_NTSC_4D_N },
332 	{ IMAGE_RLA_ASPECT_NTSC_512_W, IMAGE_RLA_ASPECT_NTSC_512_H, IMAGE_RLA_ASPECT_NTSC_512_N },
333 	{ IMAGE_RLA_ASPECT_NTSC_512_FLD_W, IMAGE_RLA_ASPECT_NTSC_512_FLD_H, IMAGE_RLA_ASPECT_NTSC_512_FLD_N },
334 	{ IMAGE_RLA_ASPECT_NTSC_636_W, IMAGE_RLA_ASPECT_NTSC_636_H, IMAGE_RLA_ASPECT_NTSC_636_N },
335 	{ IMAGE_RLA_ASPECT_NTSC_636_FLD_W, IMAGE_RLA_ASPECT_NTSC_636_FLD_H, IMAGE_RLA_ASPECT_NTSC_636_FLD_N },
336 	{ IMAGE_RLA_ASPECT_NTSC_640_W, IMAGE_RLA_ASPECT_NTSC_640_H, IMAGE_RLA_ASPECT_NTSC_640_N },
337 	{ IMAGE_RLA_ASPECT_NTSC_640_FLD_W, IMAGE_RLA_ASPECT_NTSC_640_FLD_H, IMAGE_RLA_ASPECT_NTSC_640_FLD_N },
338 	{ IMAGE_RLA_ASPECT_PAL_768_W, IMAGE_RLA_ASPECT_PAL_768_H, IMAGE_RLA_ASPECT_PAL_768_N },
339 	{ IMAGE_RLA_ASPECT_PAL_780_W, IMAGE_RLA_ASPECT_PAL_780_H, IMAGE_RLA_ASPECT_PAL_780_N },
340 	{ IMAGE_RLA_ASPECT_PIXAR_W, IMAGE_RLA_ASPECT_PIXAR_H, IMAGE_RLA_ASPECT_PIXAR_N },
341 	{ IMAGE_RLA_ASPECT_PIXAR_NTSC_W, IMAGE_RLA_ASPECT_PIXAR_NTSC_H, IMAGE_RLA_ASPECT_PIXAR_NTSC_N },
342 	{ IMAGE_RLA_ASPECT_PV_2K_W, IMAGE_RLA_ASPECT_PV_2K_H, IMAGE_RLA_ASPECT_PV_2K_N },
343 	{ IMAGE_RLA_ASPECT_PV_3K_W, IMAGE_RLA_ASPECT_PV_3K_H, IMAGE_RLA_ASPECT_PV_3K_N },
344 	{ IMAGE_RLA_ASPECT_PV_NTSC_W, IMAGE_RLA_ASPECT_PV_NTSC_H, IMAGE_RLA_ASPECT_PV_NTSC_N },
345 	{ IMAGE_RLA_ASPECT_PV_PAL_W, IMAGE_RLA_ASPECT_PV_PAL_H, IMAGE_RLA_ASPECT_PV_PAL_N },
346 	{ IMAGE_RLA_ASPECT_QNT_PAL_W, IMAGE_RLA_ASPECT_QNT_PAL_H, IMAGE_RLA_ASPECT_QNT_PAL_N },
347 	{ IMAGE_RLA_ASPECT_QTL_NTSC_W, IMAGE_RLA_ASPECT_QTL_NTSC_H, IMAGE_RLA_ASPECT_QTL_NTSC_N },
348 	{ IMAGE_RLA_ASPECT_SCREEN_W, IMAGE_RLA_ASPECT_SCREEN_H, IMAGE_RLA_ASPECT_SCREEN_N },
349 	{ IMAGE_RLA_ASPECT_SHIBA_SOKU_W, IMAGE_RLA_ASPECT_SHIBA_SOKU_H, IMAGE_RLA_ASPECT_SHIBA_SOKU_N },
350 	{ IMAGE_RLA_ASPECT_SONY_HDTV_W, IMAGE_RLA_ASPECT_SONY_HDTV_H, IMAGE_RLA_ASPECT_SONY_HDTV_N },
351 	{ IMAGE_RLA_ASPECT_TEK_NTSC_W, IMAGE_RLA_ASPECT_TEK_NTSC_H, IMAGE_RLA_ASPECT_TEK_NTSC_N },
352 	{ IMAGE_RLA_ASPECT_TEK_PAL_W, IMAGE_RLA_ASPECT_TEK_PAL_H, IMAGE_RLA_ASPECT_TEK_PAL_N },
353 	{ IMAGE_RLA_ASPECT_TEXTURE_512_W, IMAGE_RLA_ASPECT_TEXTURE_512_H, IMAGE_RLA_ASPECT_TEXTURE_512_N },
354 	{ IMAGE_RLA_ASPECT_TGA_486_W, IMAGE_RLA_ASPECT_TGA_486_H, IMAGE_RLA_ASPECT_TGA_486_N },
355 	{ IMAGE_RLA_ASPECT_TGA_NTSC_W, IMAGE_RLA_ASPECT_TGA_NTSC_H, IMAGE_RLA_ASPECT_TGA_NTSC_N },
356 	{ IMAGE_RLA_ASPECT_VC_NTSC_W, IMAGE_RLA_ASPECT_VC_NTSC_H, IMAGE_RLA_ASPECT_VC_NTSC_N },
357 	{ IMAGE_RLA_ASPECT_VFR_COMP_W, IMAGE_RLA_ASPECT_VFR_COMP_H, IMAGE_RLA_ASPECT_VFR_COMP_N },
358 	{ IMAGE_RLA_ASPECT_VFR_RGB_W, IMAGE_RLA_ASPECT_VFR_RGB_H, IMAGE_RLA_ASPECT_VFR_RGB_N },
359 	{ IMAGE_RLA_ASPECT_VST_HIRES_W, IMAGE_RLA_ASPECT_VST_HIRES_H, IMAGE_RLA_ASPECT_VST_HIRES_N },
360 	{ IMAGE_RLA_ASPECT_VST_NTSC_W, IMAGE_RLA_ASPECT_VST_NTSC_H, IMAGE_RLA_ASPECT_VST_NTSC_N },
361 	{ IMAGE_RLA_ASPECT_VST_PAL_W, IMAGE_RLA_ASPECT_VST_PAL_H, IMAGE_RLA_ASPECT_VST_PAL_N },
362 	{ IMAGE_RLA_ASPECT_VST_PAL2_W, IMAGE_RLA_ASPECT_VST_PAL2_H, IMAGE_RLA_ASPECT_VST_PAL2_N },
363 	{ IMAGE_RLA_ASPECT_VST_TARGA_W, IMAGE_RLA_ASPECT_VST_TARGA_H, IMAGE_RLA_ASPECT_VST_TARGA_N },
364 	{ IMAGE_RLA_ASPECT_VTC_MVBHM_W, IMAGE_RLA_ASPECT_VTC_MVBHM_H, IMAGE_RLA_ASPECT_VTC_MVBHM_N },
365 	{ IMAGE_RLA_ASPECT_VTE_720_W, IMAGE_RLA_ASPECT_VTE_720_H, IMAGE_RLA_ASPECT_VTE_720_N },
366 	{ IMAGE_RLA_ASPECT_WINDOW_W, IMAGE_RLA_ASPECT_WINDOW_H, IMAGE_RLA_ASPECT_WINDOW_N },
367 
368 	{ 0, 0, NULL }
369 };
370 
371 struct __PACKED__ rla_header_cs {
372 	uint16_t left;								/* Window leftmost coordinate in pixels */
373 	uint16_t right;								/* Window rightmost coordinate in pixels */
374 	uint16_t bottom;							/* Window bottom coordinate in pixels */
375 	uint16_t top;								/* Window top coordinate in pixels */
376 };
377 
378 struct __PACKED__ rla_header {
379 	struct rla_header_cs window;						/* Image dimensions */
380 	struct rla_header_cs active_window;					/* Active image dimensions */
381 
382 	uint16_t frame;								/* Frame number (greater than 0) */
383 	uint16_t storage_type;							/* Image channel type (0 = int, 4 = float) */
384 	uint16_t num_chan;							/* Number of image channels */
385 	uint16_t num_matte;							/* Number of matte channels */
386 	uint16_t num_aux;							/* Number of auxiliary channels */
387 
388 	uint16_t revision;							/* Revision identifier (always 0xfffe) */
389 
390 	int8_t gamma[16];							/* Gamma correction value (greater than 0.0) */
391 
392 	int8_t red_pri[24];							/* Red chromaticity (0.670 0.080) */
393 	int8_t green_pri[24];							/* Green chromaticity (0.210 0.710) */
394 	int8_t blue_pri[24];							/* Blue chromaticity (0.140 0.330) */
395 	int8_t white_pt[24];							/* White point (0.310 0.316) */
396 
397 	uint32_t job_num;							/* Job number (any integer) */
398 
399 	int8_t name[128];							/* Original file name of the image */
400 	int8_t desc[128];							/* Image description */
401 	int8_t program[64];							/* Program name that created image */
402 	int8_t machine[32];							/* Machine name that created image */
403 	int8_t user[32];							/* User login name that created image */
404 	int8_t date[20];							/* Image creation date */
405 
406 	int8_t aspect[24];							/* Aspect format */
407 	int8_t aspect_ratio[8];							/* Aspect ratio (width divided by height) */
408 
409 	int8_t chan[32];							/* Color space (rgb, xyz, sampled or raw) */
410 
411 	uint16_t field;								/* Image contains field-rendered data (0 = no, 1 = yes) */
412 
413 	int8_t time[12];							/* Time spent when created image */
414 	int8_t filter[32];							/* Possible post-process filter name applied to image */
415 
416 	uint16_t chan_bits;							/* Image channel bit depth (1-32) */
417 	uint16_t matte_type;							/* Matte channel type (0 = int, 4 = float) */
418 	uint16_t matte_bits;							/* Matte channel bit depth (1-32) */
419 	uint16_t aux_type;							/* Auxiliary channel type (0 = int, 4 = float) */
420 	uint16_t aux_bits;							/* Auxiliary channel bit depth (1-32) */
421 
422 	int8_t aux[32];								/* Auxiliary channel data */
423 
424 	int8_t space[36];							/* Reserved */
425 
426 	uint32_t next;								/* Next image offset from beginning of the file (0 if only one image) */
427 };
428 #endif
429 
430 #define IMAGE_TGA_FOOTER_SIGNATURE "TRUEVISION-XFILE."				/* Targa image tag */
431 #define IMAGE_TGA_STORAGE_VERBATIM 2						/* Targa pixels are unpacked */
432 #define IMAGE_TGA_STORAGE_RLE 10						/* Targa pixels are RLE packed */
433 
434 struct __PACKED__ tga_header_cs {
435 	uint16_t o;								/* Offset to colormap table */
436 	uint16_t n;								/* Number of colormap entries */
437 
438 	uint8_t b;								/* Bits per pixel */
439 };
440 
441 struct __PACKED__ tga_header_is {
442 	int16_t x;								/* X origin */
443 	int16_t y;								/* Y origin */
444 	uint16_t w;								/* Image width in pixels */
445 	uint16_t h;								/* Image height in pixels */
446 
447 	uint8_t b;								/* Bits per pixel */
448 	uint8_t a;								/* Alpha channel depth */
449 };
450 
451 struct __PACKED__ tga_header {
452 	uint8_t d;								/* ID length in bytes */
453 	uint8_t m;								/* Color map type */
454 	uint8_t t;								/* Image type */
455 
456 	struct tga_header_cs c;							/* Color map specification */
457 	struct tga_header_is i;							/* Image specification */
458 };
459 
460 struct __PACKED__ tga_footer {
461 	uint32_t a;								/* Extension area offset */
462 	uint32_t b;								/* Developer area offset */
463 
464 	int8_t s[18];								/* Truevision signature */
465 };
466 
467 struct __PACKED__ tga_extens_dt {
468 	uint16_t m;								/* Month (1-12) */
469 	uint16_t d;								/* Day (1-31) */
470 	uint16_t y;								/* Year (4 digits) */
471 	uint16_t h;								/* Hour (0-23) */
472 	uint16_t i;								/* Minute (0-59) */
473 	uint16_t s;								/* Second (0-59) */
474 };
475 
476 struct __PACKED__ tga_extens_jt {
477 	uint16_t h;								/* Hours (0-65535) */
478 	uint16_t i;								/* Minutes (0-59) */
479 	uint16_t s;								/* Seconds (0-59) */
480 };
481 
482 struct __PACKED__ tga_extens_vt {
483 	uint16_t v;								/* Version number * 100 */
484 	uint8_t w;								/* Version letter */
485 };
486 
487 struct __PACKED__ tga_extens_pa {
488 	uint16_t n;								/* Pixel width / gamma numerator */
489 	uint16_t d;								/* Pixel height / gamma denominator */
490 };
491 
492 struct __PACKED__ tga_extens {
493 	uint16_t t;								/* Extension area size in bytes */
494 
495 	int8_t n[41];								/* Author name */
496 	int8_t c[324];								/* Author comment */
497 
498 	struct tga_extens_dt e;							/* Creation date */
499 
500 	int8_t d[41];								/* Job name */
501 
502 	struct tga_extens_jt f;							/* Job time */
503 
504 	int8_t s[41];								/* Software id */
505 
506 	struct tga_extens_vt v;							/* Software version */
507 
508 	uint32_t k;								/* Key color */
509 
510 	struct tga_extens_pa p;							/* Pixel aspect ratio */
511 	struct tga_extens_pa g;							/* Gamma value */
512 
513 	uint32_t x;								/* Color correction offset */
514 	uint32_t y;								/* Postage stamp offset */
515 	uint32_t l;								/* Scan line offset */
516 
517 	uint8_t a;								/* Attributes type */
518 };
519 
520 static const char *img_suffix[] = {
521 	NULL,									/* Image type suffixes (offset IMAGE_FORMAT_*) */
522 	"bmp", "cel", "pix", "ppm", "ras", "rgb", "rla", "svg", "tga",
523 
524 	NULL
525 };
526 
527 static int image_bmp_read_op(struct t_img *);
528 static void image_bmp_read_it(struct t_img *, uint32_t, uint16_t, int32_t);
529 
530 #if defined(PROG_HAS_LIBRSVG) && \
531 LIBRSVG_MAJOR_VERSION > 2 || (LIBRSVG_MAJOR_VERSION == 2 && LIBRSVG_MINOR_VERSION >= 36)
532 static void image_svg_read_ca(RsvgHandle *);
533 static void image_svg_read_cb(RsvgHandle *, cairo_t *);
534 static int image_svg_read_op(struct t_img *, GdkPixbuf *);
535 #endif
536 
537 static int image_tga_read_op(struct t_img *);
538 static void image_tga_read_it(struct t_img *, uint8_t, uint8_t, int16_t);
539 
540 /*
541 static void image_read_it_bgr_15(struct pixel_rgba_8 *, struct pixel_ac_1 *, uint32_t, uint32_t);
542 static void image_read_it_bgr_16(struct pixel_rgba_8 *, struct pixel_ac_1 *, uint32_t, uint32_t);
543 */
544 
545 static void image_read_it_bgr_24(struct pixel_rgba_8 *, struct pixel_bgr_8 *, uint32_t, uint32_t);
546 static void image_read_it_bgra_32(struct pixel_rgba_8 *, struct pixel_bgra_8 *, uint32_t, uint32_t);
547 static void image_read_it_abgr_32(struct pixel_rgba_8 *, struct pixel_abgr_8 *, uint32_t, uint32_t);
548 static struct t_img *image_read_file(unsigned int);
549 
550 #if ! defined(PROG_DISABLE_IMAGE)
551 static int image_bmp_header(int32_t, int32_t, uint16_t, unsigned int);
552 static int image_bmp_channs(struct pixel_rgba_8 *, int32_t, int32_t, unsigned int);
553 #endif
554 
555 #if ! defined(PROG_DISABLE_IMAGE)
556 static int image_cel_header(int8_t, uint16_t, uint16_t, uint16_t, unsigned int);
557 static int image_cel_channs(struct pixel_rgba_8 *, uint16_t, uint16_t, unsigned int);
558 #endif
559 
560 #if ! defined(PROG_DISABLE_IMAGE)
561 static int image_pix_header(uint16_t, uint16_t, uint16_t, unsigned int);
562 static int image_pix_channs(struct pixel_rgba_8 *, uint16_t, uint16_t, unsigned int);
563 static int image_pix_mattes(struct pixel_rgba_8 *, uint16_t, uint16_t, unsigned int);
564 #endif
565 
566 #if ! defined(PROG_DISABLE_IMAGE)
567 static int image_ppm_header(uint16_t, uint16_t, uint16_t, unsigned int);
568 static int image_ppm_channs(struct pixel_rgba_8 *, uint16_t, uint16_t, unsigned int);
569 #endif
570 
571 #if ! defined(PROG_DISABLE_IMAGE)
572 static int image_ras_header(int8_t, uint16_t, uint16_t, uint16_t, unsigned int);
573 static int image_ras_channs(struct pixel_rgba_8 *, uint16_t, uint16_t, unsigned int);
574 #endif
575 
576 #if ! defined(PROG_DISABLE_IMAGE)
577 static int image_rgb_header(int8_t, uint16_t, uint16_t, uint16_t, int8_t, unsigned int);
578 static int image_rgb_channs(struct pixel_rgba_8 *, uint16_t, uint16_t, unsigned int);
579 #endif
580 
581 #if ! defined(PROG_DISABLE_IMAGE)
582 static int image_rla_header(uint16_t, uint16_t, unsigned int);
583 static int image_rla_offset(uint16_t, unsigned int);
584 static int image_rla_channs(struct pixel_rgba_8 *, uint16_t, uint16_t, unsigned int);
585 static size_t image_rla_channs_op(int8_t, uint8_t, unsigned int);
586 #endif
587 
588 #if ! defined(PROG_DISABLE_IMAGE)
589 static int image_tga_write_header(uint8_t, uint16_t, uint16_t, uint8_t, unsigned int);
590 static void image_tga_write_header_aux(uint8_t, uint8_t *);
591 static void image_tga_write_header_ltr(uint8_t, uint8_t *);
592 static void image_tga_write_header_ttb(uint8_t, uint8_t *);
593 static int image_tga_write_channs(struct pixel_rgba_8 *, uint16_t, uint16_t, unsigned int);
594 static int image_tga_write_footer(uint32_t, unsigned int);
595 static int image_tga_write_extens(uint16_t, uint16_t, time_t, time_t, unsigned int);
596 static void image_tga_write_extens_aspect(struct tga_extens *, uint16_t, uint16_t);
597 static void image_tga_write_extens_time(struct tga_extens *, time_t, time_t);
598 #endif
599 
600 static int image_get_type_by_suffix(char *);
601