1 #ifndef EXPORT_H_HEADER_INCLUDED
2 #define EXPORT_H_HEADER_INCLUDED
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 /****h* libAfterImage/export.h
9  * NAME
10  * export - Image output into different file formats.
11  * SEE ALSO
12  * Structures :
13  *          ASXpmExportParams
14  *          ASPngExportParams
15  *          ASJpegExportParams
16  *          ASGifExportParams
17  *          ASImageExportParams
18  *
19  * Functions :
20  *  		ASImage2file()
21  *
22  * Other libAfterImage modules :
23  *          ascmap.h asfont.h asimage.h asvisual.h blender.h export.h
24  *          import.h transform.h ximage.h
25  * AUTHOR
26  * Sasha Vasko <sasha at aftercode dot net>
27  ******************/
28 
29 /****d* libAfterImage/ExportFlags
30  * NAME
31  * EXPORT_GRAYSCALE - save image as grayscale.
32  * NAME
33  * EXPORT_ALPHA - save alpha channel if format permits
34  * NAME
35  * EXPORT_APPEND - if format allows multiple images - image will be
36  * appended
37  * FUNCTION
38  * Some common flags that could be used while writing images into
39  * different file formats.
40  * SOURCE
41  */
42 #define EXPORT_GRAYSCALE			(0x01<<0)
43 #define EXPORT_ALPHA				(0x01<<1)
44 #define EXPORT_APPEND				(0x01<<3)  /* adds subimage  */
45 #define EXPORT_ANIMATION_REPEATS	(0x01<<4)  /* number of loops to repeat GIF animation */
46 /*****/
47 
48 /****s* libAfterImage/ASXpmExportParams
49  * NAME
50  * ASXpmExportParams - parameters for export into XPM file.
51  * SOURCE
52  */
53 typedef struct
54 {
55 	ASImageFileTypes type;
56 	ASFlagType flags ;
57 	int dither ;
58 	int opaque_threshold ;
59 	int max_colors ;
60 }ASXpmExportParams ;
61 /*******/
62 /****s* libAfterImage/ASPngExportParams
63  * NAME
64  * ASPngExportParams - parameters for export into PNG file.
65  * SOURCE
66  */
67 typedef struct
68 {
69 	ASImageFileTypes type;
70 	ASFlagType flags ;
71 	int compression ;
72 }ASPngExportParams ;
73 /*******/
74 /****s* libAfterImage/ASJpegExportParams
75  * NAME
76  * ASJpegExportParams - parameters for export into JPEG file.
77  * SOURCE
78  */
79 typedef struct
80 {
81 	ASImageFileTypes type;
82 	ASFlagType flags ;
83 	int quality ;
84 }ASJpegExportParams ;
85 /*******/
86 /****s* libAfterImage/ASGifExportParams
87  * NAME
88  * ASGifExportParams - parameters for export into GIF file.
89  * SOURCE
90  */
91 typedef struct
92 {
93 	ASImageFileTypes type;
94 	ASFlagType flags ;
95 	int dither ;
96 	int opaque_threshold ;
97 	unsigned short animate_delay ;
98 	unsigned short animate_repeats ;
99 }ASGifExportParams ;
100 /*******/
101 /****s* libAfterImage/ASTiffExportParams
102  * NAME
103  * ASTiffExportParams - parameters for export into TIFF file.
104  * SOURCE
105  */
106 typedef struct
107 {
108 	ASImageFileTypes type;
109 	ASFlagType flags ;
110 	CARD32 rows_per_strip ;
111 
112 /* these are suitable compressions : */
113 #define TIFF_COMPRESSION_NONE 		1
114 #define	TIFF_COMPRESSION_OJPEG		6	/* !6.0 JPEG */
115 #define	TIFF_COMPRESSION_JPEG		7
116 #define	TIFF_COMPRESSION_PACKBITS	32773	/* Macintosh RLE */
117 #define	TIFF_COMPRESSION_DEFLATE  	32946	/* Deflate compression */
118 	/* you should be able to use other values from tiff.h as well */
119 	CARD32 compression_type ;
120 	int jpeg_quality ;
121 
122 	int opaque_threshold ;
123 }ASTiffExportParams ;
124 /*******/
125 /****s* libAfterImage/ASImageExportParams
126  * NAME
127  * ASImageExportParams - union of structures holding parameters for
128  *   export into different file formats.
129  * DESCRIPTION
130  * Treatment of this union depends on what type of export was requested.
131  * SEE ALSO
132  * ASImageFileTypes
133  * SOURCE
134  */
135 typedef union ASImageExportParams
136 {
137 	ASImageFileTypes   type;
138 	ASXpmExportParams  xpm;
139 	ASPngExportParams  png;
140 	ASJpegExportParams jpeg;
141 	ASGifExportParams  gif;
142 	ASTiffExportParams tiff;
143 }ASImageExportParams;
144 /******/
145 
146 typedef Bool (*as_image_writer_func)( ASImage *im, const char *path,
147 									  ASImageExportParams *params );
148 extern as_image_writer_func as_image_file_writers[ASIT_Unknown];
149 
150 
151 /****f* libAfterImage/export/ASImage2file()
152  * NAME
153  * ASImage2file()
154  * SYNOPSIS
155  * Bool ASImage2file( ASImage *im, const char *dir, const char *file,
156 					  ASImageFileTypes type, ASImageExportParams *params );
157  * INPUTS
158  * im			- Image to write out.
159  * dir          - directory name to write file into (optional,
160  *                could be NULL)
161  * file         - file name with or without directory name.
162  * type         - output file format. ( see ASImageFileTypes )
163  * params       - pointer to ASImageExportParams union's member for the
164  *                above type, with additional export parameters, such as
165  *                quality, compression, etc. If NULL then all defaults
166  *                will be used.
167  * RETURN VALUE
168  * True on success. False - failure.
169  * DESCRIPTION
170  * ASImage2file will construct filename out of dir and file components
171  * and then will call specific filter to write out file in requested
172  * format.
173  * NOTES
174  * Some formats support compression, others support lossy compression,
175  * yet others allows you to limit number of colors and colordepth.
176  * Each specific filter will try to interpret those parameters in its
177  * own way.
178  * EXAMPLE
179  * asmerge.c: ASMerge.3
180  *********/
181 
182 Bool
183 ASImage2file( ASImage *im, const char *dir, const char *file,
184 			  ASImageFileTypes type, ASImageExportParams *params );
185 
186 
187 Bool
188 ASImage2PNGBuff( ASImage *im, CARD8 **buffer, int *size, ASImageExportParams *params );
189 Bool
190 ASImage2xpmRawBuff( ASImage *im, CARD8 **buffer, int *size, ASImageExportParams *params );
191 
192 
193 Bool ASImage2xpm ( ASImage *im, const char *path, ASImageExportParams *params );
194 Bool ASImage2png ( ASImage *im, const char *path, ASImageExportParams *params );
195 Bool ASImage2jpeg( ASImage *im, const char *path, ASImageExportParams *params );
196 Bool ASImage2xcf ( ASImage *im, const char *path, ASImageExportParams *params );
197 Bool ASImage2ppm ( ASImage *im, const char *path, ASImageExportParams *params );
198 Bool ASImage2bmp ( ASImage *im, const char *path, ASImageExportParams *params );
199 Bool ASImage2ico ( ASImage *im, const char *path, ASImageExportParams *params );
200 Bool ASImage2gif ( ASImage *im, const char *path, ASImageExportParams *params );
201 Bool ASImage2tiff( ASImage *im, const char *path, ASImageExportParams *params );
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 
207 
208 #endif
209