summaryrefslogtreecommitdiff
path: root/support/dktools/dk4bifto.c
blob: 7611b37361becff2f95042180834225c63d66881 (plain)
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*
Copyright (C) 2017-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: dk4bifto.ctr
*/

/**	@file dk4bifto.c The dk4bifto module.
*/


#line 8 "dk4bifto.ctr"
#ifndef	DK4CONF_H_INCLUDED
#include "dk4conf.h"
#endif

#ifndef	DK4MEM_H_INCLUDED
#include "dk4mem.h"
#endif

#ifndef	DK4STRD_H_INCLUDED
#include "dk4strd.h"
#endif

#ifndef	DK4BIF_H_INCLUDED
#include "dk4bif.h"
#endif

#ifndef	BIF_H_INCLUDED
#include "bif.h"
#endif

#ifndef	DK4UNUSED_H_INCLUDED
#include "dk4unused.h"
#endif

#if DK4_HAVE_ASSERT_H
#ifndef	ASSERT_H_INCLUDED
#include <assert.h>
#define	ASSERT_H_INCLUDED 1
#endif
#endif





#line 42 "dk4bifto.ctr"



/**	Compare two frames by frame number.
	@param	l	Pointer to left frame.
	@param	r	Pointer to right frame.
	@param	cr	Comparison criteria (ignored).
	@return	Comparison result.
*/

static
int
dk4biftool_frame_compare(
	const void	*l,
	const void	*r,
	int			 DK4_ARG_UNUSED(cr)
)
{
	const dk4_bif_frame_t	*pl;		/* Left side object */
	const dk4_bif_frame_t	*pr;		/* Right side object */
	int			 back	= 0;

	DK4_UNUSED_ARG(cr)
	if (NULL != l) {
		if (NULL != r) {
			pl = (const dk4_bif_frame_t *)l;
			pr = (const dk4_bif_frame_t *)r;
			if (pl->fno > pr->fno) {
				back = 1;
			}
			else {
				if (pl->fno < pr->fno) {
					back = -1;
				}
			}
		}
		else {
			back = 1;
		}
	}
	else {
		if (NULL != r) {
			back = -1;
		}
	}
	return back;
}



int
dk4biftool_nc_bif_init(
	dk4_bif_t					*bptr,
	dkChar		const			*fn,
	int							 ty,
	int							 honly,
	dk4_cs_conv_ctx_t	const	*pcsctx,
	dk4_er_t					*erp
)
{
	int		 back	= 0;
	

#line 104 "dk4bifto.ctr"
#if	DK4_USE_ASSERT
	assert(NULL != bptr);
#endif
	/*
		Initialize all structure members
	*/
	if (NULL != pcsctx) {
		DK4_MEMCPY(&(bptr->cs_ctx), pcsctx, sizeof(dk4_cs_conv_ctx_t));
	}
	else {
		dk4cs_context_init(&(bptr->cs_ctx), erp);
	}
	bptr->tsdata = NULL;
	bptr->s_frames = NULL;
	bptr->i_frames = NULL;
	bptr->filename = NULL;
	bptr->cf = NULL;
	bptr->n_frames = 0;
	bptr->imgtype = ty;
	bptr->hdronly = honly;
	if (NULL != fn) {
		bptr->filename = dk4str_dup(fn, erp);
		if (NULL != bptr->filename) {
			back = 1;
		}
#if TRACE_DEBUG
		else {								

#line 131 "dk4bifto.ctr"
		}
#endif
	}
	else {
		back = 1;
	}
	if (1 == back) {
		back = 0;
		bptr->s_frames = dk4sto_open(erp);
		if (NULL != bptr->s_frames) {
			(void)dk4sto_set_comp(bptr->s_frames, dk4biftool_frame_compare, 0);
			bptr->i_frames = dk4sto_it_open(bptr->s_frames, erp);
			if (NULL != bptr->i_frames) {
				back = 1;
			}
#if TRACE_DEBUG
			else {							

#line 148 "dk4bifto.ctr"
			}
#endif
		}
#if TRACE_DEBUG
		else {								

#line 153 "dk4bifto.ctr"
		}
#endif
	}
	

#line 157 "dk4bifto.ctr"
	return back;
}



void
dk4biftool_nc_frame_init(
	dk4_bif_frame_t	*fptr
)
{
	

#line 168 "dk4bifto.ctr"
#if	DK4_USE_ASSERT
	assert(NULL != fptr);
#endif
	fptr->bg[0] = fptr->bg[1] = fptr->bg[2] = fptr->bg[3] = 0;
	fptr->bglbd[0] = fptr->bglbd[1] = fptr->bglbd[2] = fptr->bglbd[3] = 0;
	dk4pxres_setup(&(fptr->resampler), 8, 8);
	fptr->tsdata = NULL;
	fptr->res_x = fptr->res_y = -1.0;
	fptr->fno   = 0;
	fptr->n_comp = 0;
	fptr->dim_x = fptr->dim_y = (dk4_bif_dim_t)0L;
	fptr->l_cs = fptr->f_cs  = -1;
	fptr->hbg   = 0;
	fptr->fmres	= 0;
	fptr->fmrmv = 0U;
	fptr->l_bdepth = fptr->r_bdepth = 8;
	

#line 185 "dk4bifto.ctr"
}



int
dk4biftool_nc_add_frame(
	dk4_bif_t		*bptr,
	dk4_er_t		*erp
)
{
	dk4_bif_frame_t	*fptr;			/* New frame */
	int				 back	= 0;
	

#line 198 "dk4bifto.ctr"
#if	DK4_USE_ASSERT
	assert(NULL != bptr);
#endif
	if (SIZE_MAX > bptr->n_frames) {
		/*
			Allocate memory for frame, test allocation
		*/
		fptr = dk4mem_new(dk4_bif_frame_t,1,erp);
		if (NULL != fptr) {
			/*
				Initialize frame structure
			*/
			dk4biftool_nc_frame_init(fptr);
			fptr->fno = bptr->n_frames;
			bptr->n_frames += 1;
			/*
				Add frame structure to storage
			*/
			if (0 != dk4sto_add(bptr->s_frames, fptr, erp)) {
				bptr->cf = fptr;
				back = 1;
			}
			else {						

#line 221 "dk4bifto.ctr"
				dk4mem_free(fptr);
			}
		}
	}
	else {								

#line 226 "dk4bifto.ctr"
		/*	Too many frames in bitmap image file, numeric overflow
		*/
		dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW);
	}
	

#line 231 "dk4bifto.ctr"
	return back;
}



dk4_bif_t *
dk4biftool_nc_new_for_one_frame(
	dkChar		const			*fn,
	int							 ty,
	int							 honly,
	dk4_cs_conv_ctx_t	const	*pcsctx,
	dk4_er_t					*erp
)
{
	dk4_bif_t	*back	= NULL;
	int			 ok		= 0;
	

#line 248 "dk4bifto.ctr"
	/*
		Allocate memory for bitmap image file
	*/
	back = dk4mem_new(dk4_bif_t,1,erp);
	if (NULL == back) {
		goto finished;
	}
	/*	Initialize bitmap image file, allocate resources for components
	*/
	if (0 == dk4biftool_nc_bif_init(back, fn, ty, honly, pcsctx, erp)) {
		goto finished;
	}
	/*	Add the first frame
	*/
	if (0 == dk4biftool_nc_add_frame(back, erp)) {
		goto finished;
	}
	/*	Indicate success
	*/
	ok = 1;

	finished:
	if ((NULL != back) && (0 == ok)) {		

#line 271 "dk4bifto.ctr"
		dk4bif_close(back);
		back = NULL;
	}
	

#line 275 "dk4bifto.ctr"
	return back;
}


/* vim: set ai sw=4 ts=4 : */