File: tim.h

package info (click to toggle)
xmoto 0.5.11+dfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 80,908 kB
  • sloc: cpp: 96,757; ansic: 22,196; sh: 4,940; makefile: 1,073; yacc: 289; sed: 16
file content (306 lines) | stat: -rw-r--r-- 10,619 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/*=============================================================================
XMOTO

This file is part of XMOTO.

XMOTO is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

XMOTO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with XMOTO; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
=============================================================================*/

/* tim.h */
#ifndef __TIM_H__ /* TIM */
#define __TIM_H__

#ifdef __cplusplus /* C/C++ glue */
extern "C" {
#endif

/*==============================================================================
Basic defines
==============================================================================*/

#ifndef NULL
#define NULL 0
#endif

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

/*==============================================================================
Return values
==============================================================================*/

typedef enum _tim_retval_t {
	TIM_RV_OK = 0,										/* Everything's OK */
	TIM_RV_ERR_INVALID_PARAM = -1,		/* Parametres parsed to function are not 
	                                     right */
	TIM_RV_ERR_COULD_NOT_PERFORM = -2,/* Could not perform the specified action */      
	TIM_RV_ERR_INTERNAL_LIMIT = -3,		/* Internal limit (array bound) reached */    
	TIM_RV_ERR_MEMORY = -4,						/* Some memoryrelated problem */
	TIM_RV_ERR_NOT_FOUND = -5,				/* Something wasn't found */
	TIM_RV_ERR_LIBRARY = -6,					/* Error occurred in some external library */
	TIM_RV_ERR_INVALID_FORMAT = -7		/* Invalid parameter format */		
} tim_retval_t;

/*==============================================================================
Types: Memory system
==============================================================================*/

/* Function callback types */
typedef void *(*tim_callback_alloc_t)(int nSize);
typedef void *(*tim_callback_realloc_t)(void *pvBlock,int nSize);
typedef void (*tim_callback_free_t)(void *pvBlock);

/* Memory system struct */
typedef struct _tim_memory_t {
	/* Memory callbacks */
	tim_callback_alloc_t tim_callback_alloc;
	tim_callback_realloc_t tim_callback_realloc;
	tim_callback_free_t tim_callback_free;
} tim_memory_t;

/*==============================================================================
Types: File I/O system
==============================================================================*/

/* I/O modes */
typedef enum _tim_io_mode_t {
	TIM_IM_READ,TIM_IM_WRITE
} tim_io_mode_t;

/* Seek modes */
typedef enum _tim_seek_mode_t {
	TIM_SM_ABS,TIM_SM_REL,TIM_SM_END
} tim_seek_mode_t;

/* Function callback types */
typedef void *(*tim_callback_open_t)(char *pcWhere,tim_io_mode_t IOMode);
typedef void (*tim_callback_close_t)(void *pvHandle);
typedef int (*tim_callback_seek_t)(void *pvHandle,int nOffset,tim_seek_mode_t SeekMode);
typedef int (*tim_callback_read_t)(void *pvHandle,void *pvBuf,int nSize);
typedef int (*tim_callback_write_t)(void *pvHandle,void *pvBuf,int nSize);
typedef int (*tim_callback_eof_t)(void *pvHandle);

/* I/O system struct */
typedef struct _tim_io_t {
	/* I/O callbacks */
	tim_callback_open_t tim_callback_open;
	tim_callback_close_t tim_callback_close;
	tim_callback_seek_t tim_callback_seek;
	tim_callback_read_t tim_callback_read;
	tim_callback_write_t tim_callback_write;
	tim_callback_eof_t tim_callback_eof;
} tim_io_t;

/*==============================================================================
Types: Pixels
==============================================================================*/

/* Pixel types */
typedef enum _tim_pixel_type_t {
	TIM_PT_RGB24,TIM_PT_RGBA32,TIM_PT_UNKNOWN
} tim_pixel_type_t;

/* 24-bit RGB */
typedef struct _tim_rgb_t {
	unsigned char r,g,b;
} tim_rgb24_t;

/* 32-bit RGBA */
typedef struct _tim_rgba_t {
	unsigned char r,g,b,a;
} tim_rgba32_t;

/*==============================================================================
Types: Images
==============================================================================*/

/* Time&date info */
typedef struct _tim_date_t {
	int nYear,nMonth,nDay,nHour,nMinute,nSecond;
} tim_date_t;

/* Image info struct */
typedef struct _tim_image_info_t {
	int nWidth,nHeight;											/* Width and height of image */
	tim_pixel_type_t PixelType;							/* Pixel type */
	
	/* Extended info */
	char cImageDescription[64];
	char cCameraManufacturer[64];
	char cCameraModel[64];
	int nOrientation;
	char cExposureTime[16];
	char cExposureProgram[32];
	tim_date_t OriginalDate;
	int nFlash;
} tim_image_info_t;

/* Image struct */
typedef struct _tim_image_t {
	/* Image information */
	tim_image_info_t Info;
	
	/* Session */
	struct _tim_session_t *pSession;				/* Image of this session */
	
	/* Data */
	union {
		tim_rgb24_t *pRGB;
		tim_rgba32_t *pRGBA;
		void *pvData;
	};
	
	/* Placement in linked list of images in session */
	struct _tim_image_t *pNext,*pPrev;
} tim_image_t;

/*==============================================================================
Types: File formats
==============================================================================*/

#define TIM_MAX_FILE_FORMATS									32
#define TIM_MAX_EXTENSIONS_PER_FILE_FORMAT		4

/* File format hints */
typedef struct _tim_file_format_hint_t {
	char cTag[32];						/* Name tag of this hint */
	char cValue[256];					/* Value of hint */
	
	struct _tim_file_format_hint_t *pNext,*pPrev;
} tim_file_format_hint_t;

/* Function callback types */
typedef int (*tim_callback_load_t)(struct _tim_session_t *pSession,tim_image_t **ppImage,
                                   tim_image_info_t *pInfo,char *pcSource);
typedef int (*tim_callback_save_t)(tim_image_t *pImage,char *pcTarget);

/* File format struct */
typedef struct _tim_file_format_t {
	/* Extensions */
	int nNumExtensions;
	char *pcExtensions[TIM_MAX_EXTENSIONS_PER_FILE_FORMAT];
	
	/* Hints */
	tim_file_format_hint_t *pFirstHint,*pLastHint;
	
	/* Session */
	struct _tim_session_t *pSession;
	
	/* Callbacks */
	tim_callback_load_t tim_callback_load;
	tim_callback_save_t tim_callback_save;
} tim_file_format_t;

/*==============================================================================
General types
==============================================================================*/

/* Main session struct */
typedef struct _tim_session_t {
	/* User callbacks */
	tim_memory_t Memory;			/* Memory handling */
	tim_io_t IO;							/* File I/O */
	
	/* Images in session */
	tim_image_t *pFirstImage,*pLastImage;
	
	/* File formats */
	int nNumFileFormats;
	tim_file_format_t FileFormats[TIM_MAX_FILE_FORMATS];
} tim_session_t;

/*==============================================================================
Globals
==============================================================================*/

/* CRT Memory system */
extern tim_memory_t g_Memory_CRT;

/* stdio I/O system */
extern tim_io_t g_IO_Stdio;

/*==============================================================================
Function prototypes
==============================================================================*/

/* Memory */
void *tim_alloc(tim_session_t *pSession,int nSize);
void *tim_realloc(tim_session_t *pSession,void *pvBlock,int nSize);
void tim_free(tim_session_t *pSession,void *pvBlock);
char *tim_strdup(tim_session_t *pSession,const char *pcString);

/* File I/O */
void *tim_open(tim_session_t *pSession,char *pcWhere,tim_io_mode_t IOMode);
void tim_close(tim_session_t *pSession,void *pvHandle);
int tim_seek(tim_session_t *pSession,void *pvHandle,int nOffset,tim_seek_mode_t SeekMode);
int tim_read(tim_session_t *pSession,void *pvHandle,void *pvBuf,int nSize);
int tim_write(tim_session_t *pSession,void *pvHandle,void *pvBuf,int nSize);
int tim_eof(tim_session_t *pSession,void *pvHandle);

/* File format management */
int tim_remove_hint(tim_session_t *pSession,char *pcExt,char *pcTag);
int tim_is_hint(tim_session_t *pSession,const char *pcExt,const char *pcTag);
const char *tim_get_hint(tim_session_t *pSession,const char *pcExt,const char *pcTag,const char *pcDefaultValue);
int tim_set_hint(tim_session_t *pSession,const char *pcExt,const char *pcTag,char *pcValue);
float tim_get_hint_float(tim_session_t *pSession,char *pcExt,char *pcTag,float fDefaultValue);
int tim_get_hint_int(tim_session_t *pSession,const char *pcExt,const char *pcTag,int nDefaultValue);
int tim_set_hint_float(tim_session_t *pSession,char *pcExt,char *pcTag,float fValue);
int tim_set_hint_int(tim_session_t *pSession,const char *pcExt,const char *pcTag,int nValue);

int tim_add_extension_to_file_format(tim_file_format_t *p,const char *pcExtension);
tim_file_format_t *tim_create_file_format(tim_session_t *pSession,const char *pcExtension,
																					tim_callback_save_t SaveCallback,
																					tim_callback_load_t LoadCallback);	
tim_file_format_t *tim_find_file_format(tim_session_t *pSession,const char *pcExtension);

/* Image management */
tim_image_t *tim_create_image(tim_session_t *pSession,int nWidth,int nHeight,
                              tim_pixel_type_t PixelType);
void tim_destroy_image(tim_image_t *p);
int tim_is_image_readable(tim_session_t *pSession,char *pcFileName);
int tim_is_image_writable(tim_session_t *pSession,char *pcFileName);
int tim_get_image_info(tim_session_t *pSession,char *pcFileName,tim_image_info_t *pInfo);
int tim_read_image(tim_session_t *pSession,char *pcFileName,tim_image_t **ppImage);
int tim_write_image(tim_image_t *pImage,char *pcFileName);

/* Session */
int tim_init_session(tim_session_t *pSession,tim_memory_t *pMemory,tim_io_t *pIO);
void tim_free_session(tim_session_t *pSession);

/* stdio driver */
void *tim_stdio_open(char *pcWhere,tim_io_mode_t IOMode);
void tim_stdio_close(void *pvHandle);
int tim_stdio_seek(void *pvHandle,int nOffset,tim_seek_mode_t SeekMode);
int tim_stdio_read(void *pvHandle,void *pvBuf,int nSize);
int tim_stdio_write(void *pvHandle,void *pvBuf,int nSize);
int tim_stdio_eof(void *pvHandle);

/* JPEG support */
int tim_add_jpeg_support(tim_session_t *pSession);

/* PNG support */
int tim_add_png_support(tim_session_t *pSession);

#ifdef __cplusplus /* C/C++ glue */
}
#endif

#endif