1 /*
2  *  fiasco.h
3  *
4  *  Written by:		Ullrich Hafner
5  *
6  *  This file is part of FIASCO (Fractal Image And Sequence COdec)
7  *  Copyright (C) 1994-2000 Ullrich Hafner
8  *
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 2 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
22  */
23 
24 /*
25  *  $Date: 2000/10/28 17:39:28 $
26  *  $Author: hafner $
27  *  $Revision: 5.6 $
28  *  $State: Exp $
29  */
30 
31 #include "pnm.h"
32 
33 #undef __BEGIN_DECLS
34 #undef __END_DECLS
35 #ifdef __cplusplus
36 # define __BEGIN_DECLS extern "C" {
37 # define __END_DECLS }
38 #else
39 # define __BEGIN_DECLS /* empty */
40 # define __END_DECLS /* empty */
41 #endif
42 
43 #ifndef _FIASCO_H
44 #define _FIASCO_H 1
45 
46 __BEGIN_DECLS
47 
48 /****************************************************************************
49 			  FIASCO data types
50 ****************************************************************************/
51 
52 /*
53  *  Verbosity level:
54  *  FIASCO_NO_VERBOSITY:       No output at all.
55  *  FIASCO_SOME_VERBOSITY:     Show progress meter during coding
56  *  FIASCO_ULTIMATE_VERBOSITY: Show debugging output
57  */
58 typedef enum {FIASCO_NO_VERBOSITY,
59 	      FIASCO_SOME_VERBOSITY,
60 	      FIASCO_ULTIMATE_VERBOSITY} fiasco_verbosity_e;
61 
62 /*
63  *  Image tiling methods:
64  *  VARIANCE_ASC:  Tiles are sorted by variance.
65  *                 The first tile has the lowest variance.
66  *  VARIANCE_DSC:  Tiles are sorted by variance.
67  *                 The first tile has the largest variance.
68  *  SPIRAL_ASC:    Tiles are sorted like a spiral starting
69  *                 in the middle of the image.
70  *  SPIRAL_DSC:    Tiles are sorted like a spiral starting
71  *                 in the upper left corner.
72  */
73 typedef enum {FIASCO_TILING_SPIRAL_ASC,
74 	      FIASCO_TILING_SPIRAL_DSC,
75 	      FIASCO_TILING_VARIANCE_ASC,
76 	      FIASCO_TILING_VARIANCE_DSC} fiasco_tiling_e;
77 
78 /*
79  *  Range of reduced precision format:
80  *  FIASCO_RPF_RANGE_0_75: use interval [-0.75,0.75]
81  *  FIASCO_RPF_RANGE_1_00: use interval [-1.00,1.00]
82  *  FIASCO_RPF_RANGE_1_50: use interval [-1.50,0.75]
83  *  FIASCO_RPF_RANGE_2_00: use interval [-2.00,2.00]
84  */
85 typedef enum {FIASCO_RPF_RANGE_0_75,
86 	      FIASCO_RPF_RANGE_1_00,
87 	      FIASCO_RPF_RANGE_1_50,
88 	      FIASCO_RPF_RANGE_2_00} fiasco_rpf_range_e;
89 
90 /*
91  *  Type of progress meter to be used during coding
92  *  FIASCO_PROGRESS_NONE:    no output at all
93  *  FIASCO_PROGRESS_BAR:     RPM style progress bar using 50 hash marks ######
94  *  FIASCO_PROGRESS_PERCENT: percentage meter 50%
95  */
96 typedef enum {FIASCO_PROGRESS_NONE,
97 	      FIASCO_PROGRESS_BAR,
98 	      FIASCO_PROGRESS_PERCENT} fiasco_progress_e;
99 
100 /*
101  * Class to encapsulate FIASCO images.
102  */
103 typedef struct fiasco_image
104 {
105    void		(*delete)	(struct fiasco_image *image);
106    unsigned	(*get_width)	(struct fiasco_image *image);
107    unsigned	(*get_height)	(struct fiasco_image *image);
108    int		(*is_color)	(struct fiasco_image *image);
109    void *private;
110 } fiasco_image_t;
111 
112 /*
113  * Class to store internal state of decoder.
114  */
115 typedef struct fiasco_decoder
116 {
117    int			(*delete)	 (struct fiasco_decoder *decoder);
118    int			(*write_frame)   (struct fiasco_decoder *decoder,
119 					  const char *filename);
120    fiasco_image_t *	(*get_frame)     (struct fiasco_decoder *decoder);
121    unsigned		(*get_length)    (struct fiasco_decoder *decoder);
122    unsigned		(*get_rate)	 (struct fiasco_decoder *decoder);
123    unsigned		(*get_width)	 (struct fiasco_decoder *decoder);
124    unsigned		(*get_height)	 (struct fiasco_decoder *decoder);
125    const char *		(*get_title)	 (struct fiasco_decoder *decoder);
126    const char *		(*get_comment)	 (struct fiasco_decoder *decoder);
127    int			(*is_color)	 (struct fiasco_decoder *decoder);
128    void *private;
129 } fiasco_decoder_t;
130 
131 /*
132  * Class to encapsulate advanced coder options.
133  */
134 typedef struct fiasco_c_options
135 {
136    void (*delete)            (struct fiasco_c_options *options);
137    int (*set_tiling)         (struct fiasco_c_options *options,
138 			      fiasco_tiling_e method,
139 			      unsigned exponent);
140    int (*set_frame_pattern)  (struct fiasco_c_options *options,
141 			      const char *pattern);
142    int (*set_basisfile)      (struct fiasco_c_options *options,
143 			      const char *filename);
144    int (*set_chroma_quality) (struct fiasco_c_options *options,
145 			      float quality_factor,
146 			      unsigned dictionary_size);
147    int (*set_optimizations)  (struct fiasco_c_options *options,
148 			      unsigned min_block_level,
149 			      unsigned max_block_level,
150 			      unsigned max_elements,
151 			      unsigned dictionary_size,
152 			      unsigned optimization_level);
153    int (*set_prediction)     (struct fiasco_c_options *options,
154 			      int intra_prediction,
155 			      unsigned min_block_level,
156 			      unsigned max_block_level);
157    int (*set_video_param)    (struct fiasco_c_options *options,
158 			      unsigned frames_per_second,
159 			      int half_pixel_prediction,
160 			      int cross_B_search,
161 			      int B_as_past_ref);
162    int (*set_quantization)   (struct fiasco_c_options *options,
163 			      unsigned mantissa,
164 			      fiasco_rpf_range_e range,
165 			      unsigned dc_mantissa,
166 			      fiasco_rpf_range_e dc_range);
167    int (*set_progress_meter) (struct fiasco_c_options *options,
168 			      fiasco_progress_e type);
169    int (*set_smoothing)      (struct fiasco_c_options *options,
170 			      int smoothing);
171    int (*set_comment)        (struct fiasco_c_options *options,
172 			      const char *comment);
173    int (*set_title)          (struct fiasco_c_options *options,
174 			      const char *title);
175    void *private;
176 } fiasco_c_options_t;
177 
178 /*
179  * Class to encapsulate advanced decoder options.
180  */
181 typedef struct fiasco_d_options
182 {
183    void (*delete)            (struct fiasco_d_options *options);
184    int (*set_smoothing)      (struct fiasco_d_options *options,
185 			      int smoothing);
186    int (*set_magnification)  (struct fiasco_d_options *options,
187 			      int level);
188    int (*set_4_2_0_format)   (struct fiasco_d_options *options,
189 			      int format);
190    void *private;
191 } fiasco_d_options_t;
192 
193 /*
194  * Class to convert internal FIASCO image structure to a XImage structure.
195  * Method `renderer()' is used to convert internal image to XImage.
196  * Method `delete()' is used to delete and free internal image.
197  */
198 typedef struct fiasco_renderer
199 {
200    int  (*render) (const struct fiasco_renderer *this,
201 		   unsigned char *data,
202 		   const fiasco_image_t *fiasco_image);
203    void (*delete) (struct fiasco_renderer *this);
204    void *private;
205 } fiasco_renderer_t;
206 
207 /****************************************************************************
208 		       miscellaneous functions
209 ****************************************************************************/
210 
211 /* Get last error message of FIASCO library */
212 const char *fiasco_get_error_message (void);
213 
214 /* Set verbosity of FIASCO library */
215 void fiasco_set_verbosity (fiasco_verbosity_e level);
216 
217 /* Get verbosity of FIASCO library */
218 fiasco_verbosity_e fiasco_get_verbosity (void);
219 
220 /****************************************************************************
221 			  decoder functions
222 ****************************************************************************/
223 
224 /* Decode FIASCO image or sequence */
225 fiasco_decoder_t *fiasco_decoder_new (const char *filename,
226 				      const fiasco_d_options_t *options);
227 
228 /* Flush and discard FIASCO decoder */
229 int fiasco_decoder_delete (fiasco_decoder_t *decoder);
230 
231 /* Decode next FIASCO frame and write to PNM image 'filename' */
232 int fiasco_decoder_write_frame (fiasco_decoder_t *decoder,
233 				const char *filename);
234 
235 /* Decode next FIASCO frame to FIASCO image structure */
236 fiasco_image_t *fiasco_decoder_get_frame (fiasco_decoder_t *decoder);
237 
238 /* Get width of FIASCO image or sequence */
239 unsigned fiasco_decoder_get_width (fiasco_decoder_t *decoder);
240 
241 /* Get height of FIASCO image or sequence */
242 unsigned fiasco_decoder_get_height (fiasco_decoder_t *decoder);
243 
244 /* Get width of FIASCO image or sequence */
245 int fiasco_decoder_is_color (fiasco_decoder_t *decoder);
246 
247 /* Get frame rate of FIASCO sequence */
248 unsigned fiasco_decoder_get_rate (fiasco_decoder_t *decoder);
249 
250 /* Get number of frames of FIASCO file */
251 unsigned fiasco_decoder_get_length (fiasco_decoder_t *decoder);
252 
253 /* Get title of FIASCO file */
254 const char *
255 fiasco_decoder_get_title (fiasco_decoder_t *decoder);
256 
257 /* Get comment of FIASCO file */
258 const char *
259 fiasco_decoder_get_comment (fiasco_decoder_t *decoder);
260 
261 /****************************************************************************
262 			  image functions
263 ****************************************************************************/
264 
265 /* Create FIASCO image (from PNM image file) */
266 fiasco_image_t *
267 fiasco_image_new_file(const char * const filename);
268 
269 /* Create FIASCO image (from PNM image stream) */
270 fiasco_image_t *
271 fiasco_image_new_stream(FILE *       const ifP,
272                         unsigned int const width,
273                         unsigned int const height,
274                         xelval       const maxval,
275                         int          const format);
276 
277 /* Discard FIASCO image */
278 void fiasco_image_delete (fiasco_image_t *image);
279 
280 /* Get width of FIASCO image or sequence */
281 unsigned fiasco_image_get_width (fiasco_image_t *image);
282 
283 /* Get height of FIASCO image or sequence */
284 unsigned fiasco_image_get_height (fiasco_image_t *image);
285 
286 /* Get width of FIASCO image or sequence */
287 int fiasco_image_is_color (fiasco_image_t *image);
288 
289 /****************************************************************************
290 			  renderer functions
291 ****************************************************************************/
292 
293 /* Constructor of FIASCO image structure to a XImage renderer */
294 fiasco_renderer_t *
295 fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask,
296 		     unsigned long blue_mask, unsigned bpp,
297 		     int double_resolution);
298 
299 /* Destructor of FIASCO image structure to a XImage renderer */
300 void
301 fiasco_renderer_delete (fiasco_renderer_t *renderer);
302 
303 /* FIASCO image structure to a XImage renderer */
304 int
305 fiasco_renderer_render (const fiasco_renderer_t *renderer,
306 			unsigned char *ximage,
307 			const fiasco_image_t *fiasco_image);
308 
309 /****************************************************************************
310 			   coder functions
311 ****************************************************************************/
312 
313 /* Encode image or sequence by FIASCO */
314 int fiasco_coder (char const * const *inputname,
315 		  const char *outputname,
316 		  float quality,
317 		  const fiasco_c_options_t *options);
318 
319 /****************************************************************************
320 		 coder options functions
321 ****************************************************************************/
322 
323 /* FIASCO additional options constructor */
324 fiasco_c_options_t *fiasco_c_options_new (void);
325 
326 /* FIASCO additional options destructor */
327 void fiasco_c_options_delete (fiasco_c_options_t *options);
328 
329 /* Define `smoothing'-percentage along partitioning borders.*/
330 int fiasco_c_options_set_smoothing (fiasco_c_options_t *options,
331 				    int smoothing);
332 
333 /* Set type of frame prediction for sequence of frames */
334 int fiasco_c_options_set_frame_pattern (fiasco_c_options_t *options,
335 					const char *pattern);
336 
337 /* Set method and number of tiles for image tiling */
338 int fiasco_c_options_set_tiling (fiasco_c_options_t *options,
339 				 fiasco_tiling_e method,
340 				 unsigned exponent);
341 
342 /* Set FIASCO initial basis file */
343 int fiasco_c_options_set_basisfile (fiasco_c_options_t *options,
344 				    const char *filename);
345 
346 /* Set quality and dictionary size of chroma compression */
347 int fiasco_c_options_set_chroma_quality (fiasco_c_options_t *options,
348 					 float quality_factor,
349 					 unsigned dictionary_size);
350 
351 /*
352  *  Since FIASCO internally works with binary trees, all functions
353  *  (which are handling image geometry) rather expect the `level' of
354  *  the corresponding binary tree than the traditional `width' and
355  *  `height' arguments.  Refer to following table to convert these
356  *  values:
357  *
358  *  level | width | height
359  *  ------+-------+--------
360  *    0   |    1  |    1
361  *    1   |    1  |    2
362  *    2   |    2  |    2
363  *    3   |    2  |    4
364  *    4   |    4  |    4
365  *    5   |    4  |    8
366  *    6   |    8  |    8
367  *    7   |    8  |   16
368  *
369  */
370 
371 /* Set various optimization parameters. */
372 int fiasco_c_options_set_optimizations (fiasco_c_options_t *options,
373 					unsigned min_block_level,
374 					unsigned max_block_level,
375 					unsigned max_elements,
376 					unsigned dictionary_size,
377 					unsigned optimization_level);
378 
379 /* Set minimum and maximum size of image block prediction */
380 int fiasco_c_options_set_prediction (fiasco_c_options_t *options,
381 				     int intra_prediction,
382 				     unsigned min_block_level,
383 				     unsigned max_block_level);
384 
385 /*  Set various parameters used for video compensation */
386 int fiasco_c_options_set_video_param (fiasco_c_options_t *options,
387 				      unsigned frames_per_second,
388 				      int half_pixel_prediction,
389 				      int cross_B_search,
390 				      int B_as_past_ref);
391 
392 /* Set accuracy of coefficients quantization */
393 int fiasco_c_options_set_quantization (fiasco_c_options_t *options,
394 				       unsigned mantissa,
395 				       fiasco_rpf_range_e range,
396 				       unsigned dc_mantissa,
397 				       fiasco_rpf_range_e dc_range);
398 
399 /* Set type of progress meter */
400 int fiasco_c_options_set_progress_meter (fiasco_c_options_t *options,
401 					 fiasco_progress_e type);
402 
403 /*  Set comment of FIASCO stream */
404 int fiasco_c_options_set_comment (fiasco_c_options_t *options,
405 				  const char *comment);
406 
407 /*  Set title of FIASCO stream */
408 int fiasco_c_options_set_title (fiasco_c_options_t *options,
409 				const char *title);
410 
411 /****************************************************************************
412 		 decoder options functions
413 ****************************************************************************/
414 
415 /* FIASCO additional options constructor */
416 fiasco_d_options_t *fiasco_d_options_new (void);
417 
418 /* FIASCO additional options destructor */
419 void fiasco_d_options_delete (fiasco_d_options_t *options);
420 
421 
422 /* Define `smoothing'-percentage along partitioning borders.*/
423 int fiasco_d_options_set_smoothing (fiasco_d_options_t *options,
424 				  int smoothing);
425 
426 /* Set magnification-'level' of decoded image */
427 int fiasco_d_options_set_magnification (fiasco_d_options_t *options,
428 				      int level);
429 
430 /* Set image format to 4:2:0 or 4:4:4 */
431 int fiasco_d_options_set_4_2_0_format (fiasco_d_options_t *options,
432 				     int format);
433 
434 __END_DECLS
435 
436 #endif /* not _FIASCO_H */
437