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