iceWing
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Gimage.h
Go to the documentation of this file.
1 /* -*- mode: C; tab-width: 4; c-basic-offset: 4; -*- */
2 
3 /*
4  * Author: Frank Loemker
5  *
6  * Copyright (C) 1999-2009
7  * Frank Loemker, Applied Computer Science, Faculty of Technology,
8  * Bielefeld University, Germany
9  *
10  * This file is part of iceWing, a graphical plugin shell.
11  *
12  * iceWing is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * iceWing is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25  */
26 
27 #ifndef iw_Gimage_H
28 #define iw_Gimage_H
29 
30 #include <sys/time.h>
31 #include <glib.h>
32 
33 #define IW_FOURCC(a,b,c,d) \
34  ((unsigned int)((((unsigned int)d)<<24)+(((unsigned int)c)<<16)+(((unsigned int)b)<<8)+a))
35 
36 #define IW_CTAB_SIZE 256
37 typedef guchar (*iwColtab)[3];
38 
40 
41 /* Color formats of the data for prev_render...() */
42 #define IW_RGB ((iwColtab)0)
43 #define IW_BGR ((iwColtab)1)
44 #define IW_YUV ((iwColtab)2)
45 #define IW_YUV_CAL ((iwColtab)3) /* !Not rendered correctly! */
46 #define IW_HSV ((iwColtab)4)
47 #define IW_LUV ((iwColtab)5) /* !Not rendered correctly! */
48 #define IW_LAB ((iwColtab)6) /* !Not rendered correctly! */
49 #define IW_BW ((iwColtab)7) /* Only the first plane is used */
50 #define IW_GRAY IW_BW /* Only the first plane is used */
51 #define IW_INDEX (iw_def_col_tab)
52 
53 #define IW_COLFORMAT_MAX IW_BW /* Last 'special' definition */
54 
55 #define IW_COLMAX 255
56 #define IW_COLCNT 256
57 
58  /* For iw_movie_read(): Return the next/previous frame */
59 #define IW_MOVIE_NEXT_FRAME (-1)
60 #define IW_MOVIE_PREV_FRAME (-2)
61 
62 extern char *iwColorText[]; /* PRIVATE, only for next macro */
63 #define IW_COLOR_TEXT(i) \
64  ((i)->ctab <= IW_COLFORMAT_MAX ? iwColorText[(long)(i)->ctab]:"PALETTE")
65 
66 typedef struct _iwImgFileData iwImgFileData;
67 typedef struct _iwMovie iwMovie;
68 
69 typedef struct iwColor {
70  guchar r,g,b;
71 } iwColor;
72 
73 /* Possible image file formats */
74 typedef enum {
79 
80  IW_IMG_FORMAT_MOVIE, /* First movie format */
87 
90 } iwImgFormat;
91 
92 extern char *iwImgFormatText[]; /* All formats */
93 extern char *iwImgFormatTextBM[]; /* Only bitmap formats */
94 
95 /* Possible image data types */
96 typedef enum {
102 } iwType;
103 
104 extern int iwTypeSize[]; /* PRIVATE, only for next macros */
105 extern double iwTypeMin[]; /* PRIVATE, only for next macros */
106 extern double iwTypeMax[]; /* PRIVATE, only for next macros */
107 /* Size of image data type in bytes */
108 #define IW_TYPE_SIZE(i) (iwTypeSize[(i)->type])
109 /* Min. representable value for the image data type */
110 #define IW_TYPE_MIN(i) (iwTypeMin[(i)->type])
111 /* Max. representable value for the image data type */
112 #define IW_TYPE_MAX(i) (iwTypeMax[(i)->type])
113 
114 typedef struct iwImage {
115  guchar **data;
116  int planes; /* Number of image planes */
117  iwType type; /* Real data type of "data" (instead of guchar) */
118  int width, height; /* Image width/height in pixels */
119  int rowstride; /* 0 : data[0] - data[planes] contain the different image planes;
120  >0: image planes are interleaved in data[0],
121  value is distance in bytes between two lines */
122  iwColtab ctab; /* Color format of data, e.g. for rendering with prev_render() */
123  void *reserved;
124 } iwImage;
125 
126 typedef enum {
128  IW_IMG_STATUS_OPEN, /* Unable to open file */
129  IW_IMG_STATUS_READ, /* Read error */
130  IW_IMG_STATUS_WRITE, /* Write error */
131  IW_IMG_STATUS_MEM, /* Unable to allocate memory */
132  IW_IMG_STATUS_FORMAT, /* File format not supported (png, ...)*/
133  IW_IMG_STATUS_ERR, /* Another error */
135 } iwImgStatus;
136 
137 /* Flags specifying what to free during iw_img_free() */
138 typedef enum {
139  IW_IMG_FREE_PLANE = 1 << 0, /* img->data[x] */
140  IW_IMG_FREE_PLANEPTR = 1 << 1, /* img->data */
141  IW_IMG_FREE_CTAB = 1 << 2, /* img->ctab */
142  IW_IMG_FREE_STRUCT = 1 << 3 /* img */
143 } iwImgFree;
144 #define IW_IMG_FREE_DATA ((iwImgFree)(IW_IMG_FREE_PLANE | IW_IMG_FREE_CTAB | IW_IMG_FREE_PLANEPTR))
145 #define IW_IMG_FREE_ALL ((iwImgFree)(-1))
146 
147 #ifdef __cplusplus
148 extern "C" {
149 #endif
150 
151 /*********************************************************************
152  Allocate memory for img->data and img->data[] according to the
153  other settings in img.
154  Return: TRUE if memory could be allocated.
155 *********************************************************************/
156 gboolean iw_img_allocate (iwImage *img);
157 
158 /*********************************************************************
159  Allocate memory only for img->data (and NOT img->data[]) according
160  to the other settings in img.
161  Return: TRUE if memory could be allocated.
162 *********************************************************************/
163 gboolean iw_img_alloc_planeptr (iwImage *img);
164 
165 /*********************************************************************
166  Initialise image img by setting everything to 0.
167  Do NOT allocate any memory.
168 *********************************************************************/
169 void iw_img_init (iwImage *img);
170 
171 /*********************************************************************
172  Allocate a new image and set everything to 0. -> Do NOT allocate
173  any image data.
174 *********************************************************************/
175 iwImage* iw_img_new (void);
176 
177 /*********************************************************************
178  Allocate and initialise a new img and allocate memory for
179  img->data and img->data[].
180 *********************************************************************/
181 iwImage* iw_img_new_alloc (int width, int height, int planes, iwType type);
182 
183 /*********************************************************************
184  Free parts of the image. 'what' specifies what to free.
185 *********************************************************************/
186 void iw_img_free (iwImage *img, iwImgFree what);
187 
188 /*********************************************************************
189  If src has an own indexed color tabel, allocate a new one for dst
190  and copy the table. Otherwise set the ctab entry of dst to the one
191  of src.
192 *********************************************************************/
193 void iw_img_copy_ctab (const iwImage *src, iwImage *dst);
194 
195 /*********************************************************************
196  Copy src to dst, allocate all plane pointer, planes, and color
197  tables, and return a pointer to dst, or NULL on error (no mem).
198 *********************************************************************/
199 iwImage* iw_img_copy (const iwImage *src, iwImage *dst);
200 
201 /*********************************************************************
202  Return a copy of the image img. All plane pointer, planes, and
203  color tables are also copied.
204 *********************************************************************/
205 iwImage* iw_img_duplicate (const iwImage *img);
206 
207 /*********************************************************************
208  Load image from file fname in 'planed' form.
209 *********************************************************************/
210 iwImage* iw_img_load (const char *fname, iwImgStatus *status);
211 
212 /*********************************************************************
213  Load image from file fname and return an interleaved image.
214 *********************************************************************/
215 iwImage* iw_img_load_interleaved (const char *fname, iwImgStatus *status);
216 
217 /*********************************************************************
218  Close movie file if it is != NULL and free all associated data.
219 *********************************************************************/
220 void iw_movie_close (iwMovie *movie);
221 
222 /*********************************************************************
223  Open the movie file fname for reading.
224 *********************************************************************/
225 iwMovie* iw_movie_open (const char *fname, iwImgStatus *status);
226 
227 /*********************************************************************
228  Open the movie 'fname' (if not already open) and return its frame
229  'frame'.
230  ATTENTION: The returned frame is a pointer to an internally used
231  image which is freed by iw_movie_close().
232 *********************************************************************/
233 iwImage* iw_movie_read (iwMovie **movie, const char *fname,
234  int frame, iwImgStatus *status);
235 
236 /*********************************************************************
237  Return frame rate of 'movie'.
238 *********************************************************************/
239 float iw_movie_get_framerate (const iwMovie *movie);
240 
241 /*********************************************************************
242  Return number of frames of 'movie'.
243 *********************************************************************/
244 int iw_movie_get_framecnt (const iwMovie *movie);
245 
246 /*********************************************************************
247  Return the number of the frame, which was the result of the
248  last call to iw_movie_read()
249 *********************************************************************/
250 int iw_movie_get_framepos (iwMovie *movie);
251 
252 /*********************************************************************
253  Initialise struct holding settings for saving images.
254 *********************************************************************/
256 
257 /*********************************************************************
258  Free struct created with iw_img_create_data().
259 *********************************************************************/
260 void iw_img_data_free (iwImgFileData *data);
261 
262 /*********************************************************************
263  Set parameters used for MOVIE saving.
264 *********************************************************************/
265 void iw_img_data_set_movie (iwImgFileData *data, iwMovie **movie, float framerate);
266 
267 /*********************************************************************
268  Set quality parameter (used for JPEG saving),
269 *********************************************************************/
270 void iw_img_data_set_quality (iwImgFileData *data, int quality);
271 
272 /*********************************************************************
273  If 'format' == IW_IMG_FORMAT_UNKNOWN return a format based on the
274  extension of fname. Otherwise return 'format'.
275 *********************************************************************/
276 iwImgFormat iw_img_save_get_format (iwImgFormat format, const char *fname);
277 
278 /*********************************************************************
279  Save 'img' in file 'fname' in the format 'format'. If
280  'format' == IW_IMG_FORMAT_UNKNOWN the extension of fname is used.
281 *********************************************************************/
282 iwImgStatus iw_img_save (const iwImage *img, iwImgFormat format,
283  const char *fname, const iwImgFileData *data);
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 
289 #endif /* iw_Gimage_H */