| 1 |
/* |
| 2 |
* options.c: FIASCO options handling |
| 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 |
|
| 10 |
/* |
| 11 |
* $Date: 2000/10/28 17:39:31 $ |
| 12 |
* $Author: hafner $ |
| 13 |
* $Revision: 5.5 $ |
| 14 |
* $State: Exp $ |
| 15 |
*/ |
| 16 |
|
| 17 |
#define _DEFAULT_SOURCE 1 /* New name for SVID & BSD source defines */ |
| 18 |
#define _BSD_SOURCE 1 /* Make sure strdup() is in string.h */ |
| 19 |
#define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include <stdbool.h> |
| 24 |
#include <string.h> |
| 25 |
#include <stdlib.h> |
| 26 |
#include <stdio.h> |
| 27 |
|
| 28 |
#include "nstring.h" |
| 29 |
|
| 30 |
#include "types.h" |
| 31 |
#include "macros.h" |
| 32 |
#include "error.h" |
| 33 |
|
| 34 |
#include "wfa.h" |
| 35 |
#include "misc.h" |
| 36 |
#include "bit-io.h" |
| 37 |
#include "fiasco.h" |
| 38 |
#include "options.h" |
| 39 |
|
| 40 |
fiasco_c_options_t * |
| 41 |
fiasco_c_options_new (void) |
| 42 |
/* |
| 43 |
* FIASCO options constructor. |
| 44 |
* Allocate memory for the FIASCO coder options structure and |
| 45 |
* fill in default values. |
| 46 |
* |
| 47 |
* Return value: |
| 48 |
* pointer to the new option structure |
| 49 |
*/ |
| 50 |
{ |
| 51 |
c_options_t *options = calloc (1, sizeof (c_options_t)); |
| 52 |
fiasco_c_options_t *public = calloc (1, sizeof (fiasco_c_options_t)); |
| 53 |
|
| 54 |
if (!options || !public) |
| 55 |
{ |
| 56 |
set_error (_("Out of memory.")); |
| 57 |
return NULL; |
| 58 |
} |
| 59 |
public->private = options; |
| 60 |
public->delete = fiasco_c_options_delete; |
| 61 |
public->set_tiling = fiasco_c_options_set_tiling; |
| 62 |
public->set_frame_pattern = fiasco_c_options_set_frame_pattern; |
| 63 |
public->set_basisfile = fiasco_c_options_set_basisfile; |
| 64 |
public->set_chroma_quality = fiasco_c_options_set_chroma_quality; |
| 65 |
public->set_video_param = fiasco_c_options_set_video_param; |
| 66 |
public->set_quantization = fiasco_c_options_set_quantization; |
| 67 |
public->set_progress_meter = fiasco_c_options_set_progress_meter; |
| 68 |
public->set_smoothing = fiasco_c_options_set_smoothing; |
| 69 |
public->set_title = fiasco_c_options_set_title; |
| 70 |
public->set_comment = fiasco_c_options_set_comment; |
| 71 |
|
| 72 |
strcpy (options->id, "COFIASCO"); |
| 73 |
|
| 74 |
/* |
| 75 |
* Set default value of fiasco options |
| 76 |
*/ |
| 77 |
options->basis_name = strdup ("small.fco"); |
| 78 |
options->lc_min_level = 4; |
| 79 |
options->lc_max_level = 12; |
| 80 |
options->p_min_level = 8; |
| 81 |
options->p_max_level = 10; |
| 82 |
options->images_level = 5; |
| 83 |
options->max_states = MAXSTATES; |
| 84 |
options->chroma_max_states = 40; |
| 85 |
options->max_elements = MAXEDGES; |
| 86 |
options->tiling_exponent = 4; |
| 87 |
options->tiling_method = FIASCO_TILING_VARIANCE_DSC; |
| 88 |
options->id_domain_pool = strdup ("rle"); |
| 89 |
options->id_d_domain_pool = strdup ("rle"); |
| 90 |
options->id_rpf_model = strdup ("adaptive"); |
| 91 |
options->id_d_rpf_model = strdup ("adaptive"); |
| 92 |
options->rpf_mantissa = 3; |
| 93 |
options->rpf_range = FIASCO_RPF_RANGE_1_50; |
| 94 |
options->dc_rpf_mantissa = 5; |
| 95 |
options->dc_rpf_range = FIASCO_RPF_RANGE_1_00; |
| 96 |
options->d_rpf_mantissa = 3; |
| 97 |
options->d_rpf_range = FIASCO_RPF_RANGE_1_50; |
| 98 |
options->d_dc_rpf_mantissa = 5; |
| 99 |
options->d_dc_rpf_range = FIASCO_RPF_RANGE_1_00; |
| 100 |
options->chroma_decrease = 2.0; |
| 101 |
options->prediction = NO; |
| 102 |
options->delta_domains = YES; |
| 103 |
options->normal_domains = YES; |
| 104 |
options->search_range = 16; |
| 105 |
options->fps = 25; |
| 106 |
options->pattern = strdup ("IPPPPPPPPP"); |
| 107 |
options->reference_filename = NULL; |
| 108 |
options->half_pixel_prediction = NO; |
| 109 |
options->cross_B_search = YES; |
| 110 |
options->B_as_past_ref = YES; |
| 111 |
options->check_for_underflow = NO; |
| 112 |
options->check_for_overflow = NO; |
| 113 |
options->second_domain_block = NO; |
| 114 |
options->full_search = NO; |
| 115 |
options->progress_meter = FIASCO_PROGRESS_NONE; |
| 116 |
options->smoothing = 70; |
| 117 |
options->comment = strdup (""); |
| 118 |
options->title = strdup (""); |
| 119 |
|
| 120 |
return public; |
| 121 |
} |
| 122 |
|
| 123 |
void |
| 124 |
fiasco_c_options_delete (fiasco_c_options_t *options) |
| 125 |
/* |
| 126 |
* FIASCO options destructor. |
| 127 |
* Free memory of FIASCO options struct. |
| 128 |
* |
| 129 |
* No return value. |
| 130 |
* |
| 131 |
* Side effects: |
| 132 |
* structure 'options' is discarded. |
| 133 |
*/ |
| 134 |
{ |
| 135 |
c_options_t *this = cast_c_options (options); |
| 136 |
|
| 137 |
if (!this) |
| 138 |
return; |
| 139 |
|
| 140 |
Free (this->id_domain_pool); |
| 141 |
Free (this->id_d_domain_pool); |
| 142 |
Free (this->id_rpf_model); |
| 143 |
Free (this->id_d_rpf_model); |
| 144 |
Free (this->pattern); |
| 145 |
Free (this->comment); |
| 146 |
Free (this->title); |
| 147 |
|
| 148 |
Free (this); |
| 149 |
|
| 150 |
return; |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
int |
| 156 |
fiasco_c_options_set_tiling(fiasco_c_options_t * const optionsP, |
| 157 |
fiasco_tiling_e const method, |
| 158 |
unsigned int const exponent) { |
| 159 |
/*---------------------------------------------------------------------------- |
| 160 |
Set tiling 'method' and 'exponent'. |
| 161 |
|
| 162 |
See type 'fiasco_tiling_e' for a list of valid tiling methods. |
| 163 |
|
| 164 |
The image is subdivided into 2^`exponent' tiles. |
| 165 |
|
| 166 |
Return value: |
| 167 |
1 on success |
| 168 |
0 otherwise |
| 169 |
-----------------------------------------------------------------------------*/ |
| 170 |
c_options_t * const this = (c_options_t *) cast_c_options(optionsP); |
| 171 |
|
| 172 |
int retval; |
| 173 |
|
| 174 |
if (!this) { |
| 175 |
retval = 0; |
| 176 |
} else { |
| 177 |
switch (method) { |
| 178 |
case FIASCO_TILING_SPIRAL_ASC: |
| 179 |
case FIASCO_TILING_SPIRAL_DSC: |
| 180 |
case FIASCO_TILING_VARIANCE_ASC: |
| 181 |
case FIASCO_TILING_VARIANCE_DSC: |
| 182 |
this->tiling_method = method; |
| 183 |
break; |
| 184 |
} |
| 185 |
this->tiling_exponent = exponent; |
| 186 |
|
| 187 |
retval = 1; |
| 188 |
} |
| 189 |
return retval; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
int |
| 195 |
fiasco_c_options_set_frame_pattern (fiasco_c_options_t *options, |
| 196 |
const char *pattern) |
| 197 |
/* |
| 198 |
* Set `pattern' of input frames. |
| 199 |
* `pattern' has to be a sequence of the following |
| 200 |
* characters (case insensitive): |
| 201 |
* 'i' intra frame |
| 202 |
* 'p' predicted frame |
| 203 |
* 'b' bidirectional predicted frame |
| 204 |
* E.g. pattern = 'IBBPBBPBB' |
| 205 |
* |
| 206 |
* When coding video frames the prediction type of input frame N is determined |
| 207 |
* by reading `pattern' [N] (`pattern' is periodically extended). |
| 208 |
* |
| 209 |
* Return value: |
| 210 |
* 1 on success |
| 211 |
* 0 otherwise |
| 212 |
*/ |
| 213 |
{ |
| 214 |
c_options_t *this = (c_options_t *) cast_c_options (options); |
| 215 |
|
| 216 |
if (!this) |
| 217 |
{ |
| 218 |
return 0; |
| 219 |
} |
| 220 |
else if (!pattern) |
| 221 |
{ |
| 222 |
set_error (_("Parameter `%s' not defined (NULL)."), "pattern"); |
| 223 |
return 0; |
| 224 |
} |
| 225 |
else if (strlen (pattern) < 1) |
| 226 |
{ |
| 227 |
set_error (_("Frame type pattern doesn't contain any character.")); |
| 228 |
return 0; |
| 229 |
} |
| 230 |
else |
| 231 |
{ |
| 232 |
const char *str; |
| 233 |
bool_t parse_error = NO; |
| 234 |
int c = 0; |
| 235 |
|
| 236 |
for (str = pattern; *str && !parse_error; str++) |
| 237 |
switch (*str) |
| 238 |
{ |
| 239 |
case 'i': |
| 240 |
case 'I': |
| 241 |
case 'b': |
| 242 |
case 'B': |
| 243 |
case 'p': |
| 244 |
case 'P': |
| 245 |
break; |
| 246 |
default: |
| 247 |
c = *str; |
| 248 |
parse_error = YES; |
| 249 |
} |
| 250 |
|
| 251 |
if (parse_error) |
| 252 |
{ |
| 253 |
set_error (_("Frame type pattern contains invalid character `%c' " |
| 254 |
"(choose I, B or P)."), c); |
| 255 |
return 0; |
| 256 |
} |
| 257 |
else |
| 258 |
{ |
| 259 |
Free (this->pattern); |
| 260 |
this->pattern = strdup (pattern); |
| 261 |
|
| 262 |
return 1; |
| 263 |
} |
| 264 |
} |
| 265 |
} |
| 266 |
|
| 267 |
int |
| 268 |
fiasco_c_options_set_basisfile (fiasco_c_options_t *options, |
| 269 |
const char *filename) |
| 270 |
/* |
| 271 |
* Set `filename' of FIASCO initial basis. |
| 272 |
* |
| 273 |
* Return value: |
| 274 |
* 1 on success (if the file is readable) |
| 275 |
* 0 otherwise |
| 276 |
*/ |
| 277 |
{ |
| 278 |
c_options_t *this = (c_options_t *) cast_c_options (options); |
| 279 |
|
| 280 |
if (!this) |
| 281 |
{ |
| 282 |
return 0; |
| 283 |
} |
| 284 |
else if (!filename) |
| 285 |
{ |
| 286 |
set_error (_("Parameter `%s' not defined (NULL)."), "filename"); |
| 287 |
return 0; |
| 288 |
} |
| 289 |
else |
| 290 |
{ |
| 291 |
/* Skip this because basis file may be linked with program, not |
| 292 |
in a separate file. See get_linked_basis(). NETPBM |
| 293 |
FILE *file = open_file (filename, "FIASCO_DATA", READ_ACCESS); |
| 294 |
if (file) |
| 295 |
{ |
| 296 |
fclose (file); |
| 297 |
return 1; |
| 298 |
} |
| 299 |
else |
| 300 |
{ |
| 301 |
set_error (_("Can't read basis file `%s'.\n%s."), filename, |
| 302 |
get_system_error ()); |
| 303 |
return 0; |
| 304 |
} |
| 305 |
*/ return 1; |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
int |
| 310 |
fiasco_c_options_set_chroma_quality (fiasco_c_options_t *options, |
| 311 |
float quality_factor, |
| 312 |
unsigned dictionary_size) |
| 313 |
/* |
| 314 |
* Set color compression parameters. |
| 315 |
* When coding chroma channels (Cb and Cr) |
| 316 |
* - approximation quality is given by `quality_factor' * `Y quality' and |
| 317 |
* - `dictionary_size' gives the number of dictionary elements. |
| 318 |
* |
| 319 |
* If 'quality' <= 0 then the luminancy coding quality is also during |
| 320 |
* chroma channel coding. |
| 321 |
* |
| 322 |
* Return value: |
| 323 |
* 1 on success |
| 324 |
* 0 otherwise |
| 325 |
*/ |
| 326 |
{ |
| 327 |
c_options_t *this = (c_options_t *) cast_c_options (options); |
| 328 |
|
| 329 |
if (!this) |
| 330 |
{ |
| 331 |
return 0; |
| 332 |
} |
| 333 |
else if (!dictionary_size) |
| 334 |
{ |
| 335 |
set_error (_("Size of chroma compression dictionary has to be " |
| 336 |
"a positive number.")); |
| 337 |
return 0; |
| 338 |
} |
| 339 |
else if (quality_factor <= 0) |
| 340 |
{ |
| 341 |
set_error (_("Quality of chroma channel compression has to be " |
| 342 |
"positive value.")); |
| 343 |
return 0; |
| 344 |
} |
| 345 |
else |
| 346 |
{ |
| 347 |
this->chroma_decrease = quality_factor; |
| 348 |
this->chroma_max_states = dictionary_size; |
| 349 |
|
| 350 |
return 1; |
| 351 |
} |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
void |
| 357 |
fiasco_c_options_set_optimizations( |
| 358 |
fiasco_c_options_t * const optionsP, |
| 359 |
unsigned int const minBlockLevel, |
| 360 |
unsigned int const maxBlockLevel, |
| 361 |
unsigned int const maxElements, |
| 362 |
unsigned int const dictionarySize, |
| 363 |
unsigned int const optimizationLevel, |
| 364 |
bool * const succeededP) { |
| 365 |
/*---------------------------------------------------------------------------- |
| 366 |
Set various optimization parameters. |
| 367 |
- During compression only image blocks of size |
| 368 |
{'minBlockLevel', ... ,'maxBlockLevel'} are considered. |
| 369 |
The smaller this set of blocks is the faster the coder runs |
| 370 |
and the worse the image quality will be. |
| 371 |
- An individual approximation may use at most `max_elements' |
| 372 |
elements of the dictionary which itself contains at most |
| 373 |
'dictionarySize' elements. The smaller these values are |
| 374 |
the faster the coder runs and the worse the image quality will be. |
| 375 |
- 'optimizationLevel' enables some additional low level optimizations. |
| 376 |
0: standard approximation method |
| 377 |
1: significantly increases the approximation quality, |
| 378 |
running time is twice as high as with the standard method |
| 379 |
2: hardly increases the approximation quality of method 1, |
| 380 |
running time is twice as high as with method 1 |
| 381 |
(this method just remains for completeness) |
| 382 |
|
| 383 |
Return value: |
| 384 |
1 on success |
| 385 |
0 otherwise |
| 386 |
-----------------------------------------------------------------------------*/ |
| 387 |
c_options_t * const this = (c_options_t *) cast_c_options(optionsP); |
| 388 |
|
| 389 |
if (!this) { |
| 390 |
*succeededP = false; |
| 391 |
} else if (!dictionarySize) { |
| 392 |
set_error (_("Size of dictionary has to be a positive number.")); |
| 393 |
*succeededP = false; |
| 394 |
} else if (!maxElements) { |
| 395 |
set_error (_("At least one dictionary element has to be used " |
| 396 |
"in an approximation.")); |
| 397 |
*succeededP = false; |
| 398 |
} else if (maxBlockLevel < 4) { |
| 399 |
set_error (_("Maximum image block size has to be at least level 4.")); |
| 400 |
*succeededP = false; |
| 401 |
} else if (minBlockLevel < 4) { |
| 402 |
set_error (_("Minimum image block size has to be at least level 4.")); |
| 403 |
*succeededP = false; |
| 404 |
} else if (maxBlockLevel < minBlockLevel) { |
| 405 |
set_error (_("Maximum block size has to be larger or " |
| 406 |
"equal minimum block size.")); |
| 407 |
*succeededP = false; |
| 408 |
} else { |
| 409 |
this->lc_min_level = minBlockLevel; |
| 410 |
this->lc_max_level = maxBlockLevel; |
| 411 |
this->max_states = dictionarySize; |
| 412 |
this->max_elements = maxElements; |
| 413 |
this->second_domain_block = optimizationLevel > 0 ? YES : NO; |
| 414 |
this->check_for_overflow = optimizationLevel > 1 ? YES : NO; |
| 415 |
this->check_for_underflow = optimizationLevel > 1 ? YES : NO; |
| 416 |
this->full_search = optimizationLevel > 1 ? YES : NO; |
| 417 |
|
| 418 |
*succeededP = true; |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
int |
| 425 |
fiasco_c_options_set_prediction (fiasco_c_options_t *options, |
| 426 |
int intra_prediction, |
| 427 |
unsigned min_block_level, |
| 428 |
unsigned max_block_level) |
| 429 |
/* |
| 430 |
* Set minimum and maximum size of image block prediction to |
| 431 |
* `min_block_level' and `max_block_level'. |
| 432 |
* (For either motion compensated prediction of inter frames |
| 433 |
* or DC based prediction of intra frames) |
| 434 |
* Prediction of intra frames is only used if `intra_prediction' != 0. |
| 435 |
* |
| 436 |
* Return value: |
| 437 |
* 1 on success |
| 438 |
* 0 otherwise |
| 439 |
*/ |
| 440 |
{ |
| 441 |
c_options_t *this = (c_options_t *) cast_c_options (options); |
| 442 |
|
| 443 |
if (!this) |
| 444 |
{ |
| 445 |
return 0; |
| 446 |
} |
| 447 |
else if (max_block_level < 6) |
| 448 |
{ |
| 449 |
set_error (_("Maximum prediction block size has to be " |
| 450 |
"at least level 6")); |
| 451 |
return 0; |
| 452 |
} |
| 453 |
else if (min_block_level < 6) |
| 454 |
{ |
| 455 |
set_error (_("Minimum prediction block size has to be " |
| 456 |
"at least level 6")); |
| 457 |
return 0; |
| 458 |
} |
| 459 |
else if (max_block_level < min_block_level) |
| 460 |
{ |
| 461 |
set_error (_("Maximum prediction block size has to be larger or " |
| 462 |
"equal minimum block size.")); |
| 463 |
return 0; |
| 464 |
} |
| 465 |
else |
| 466 |
{ |
| 467 |
this->p_min_level = min_block_level; |
| 468 |
this->p_max_level = max_block_level; |
| 469 |
this->prediction = intra_prediction; |
| 470 |
|
| 471 |
return 1; |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
int |
| 476 |
fiasco_c_options_set_video_param (fiasco_c_options_t *options, |
| 477 |
unsigned frames_per_second, |
| 478 |
int half_pixel_prediction, |
| 479 |
int cross_B_search, |
| 480 |
int B_as_past_ref) |
| 481 |
/* |
| 482 |
* Set various parameters used for video compensation. |
| 483 |
* 'frames_per_second' defines the frame rate which should be |
| 484 |
* used when the video is decoded. This value has no effect during coding, |
| 485 |
* it is just passed to the FIASCO output file. |
| 486 |
* If 'half_pixel_prediction' is not 0 then half pixel precise |
| 487 |
* motion compensated prediction is used. |
| 488 |
* If 'cross_B_search' is not 0 then the fast Cross-B-Search algorithm is |
| 489 |
* used to determine the motion vectors of interpolated prediction. Otherwise |
| 490 |
* exhaustive search (in the given search range) is used. |
| 491 |
* If 'B_as_past_ref' is not 0 then B frames are allowed to be used |
| 492 |
* for B frame predicion. |
| 493 |
* |
| 494 |
* Return value: |
| 495 |
* 1 on success |
| 496 |
* 0 otherwise |
| 497 |
*/ |
| 498 |
{ |
| 499 |
c_options_t *this = (c_options_t *) cast_c_options (options); |
| 500 |
|
| 501 |
if (!this) |
| 502 |
{ |
| 503 |
return 0; |
| 504 |
} |
| 505 |
else |
| 506 |
{ |
| 507 |
this->fps = frames_per_second; |
| 508 |
this->half_pixel_prediction = half_pixel_prediction; |
| 509 |
this->cross_B_search = cross_B_search; |
| 510 |
this->B_as_past_ref = B_as_past_ref; |
| 511 |
|
| 512 |
return 1; |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
int |
| 517 |
fiasco_c_options_set_quantization (fiasco_c_options_t *options, |
| 518 |
unsigned mantissa, |
| 519 |
fiasco_rpf_range_e range, |
| 520 |
unsigned dc_mantissa, |
| 521 |
fiasco_rpf_range_e dc_range) |
| 522 |
/* |
| 523 |
* Set accuracy of coefficients quantization. |
| 524 |
* DC coefficients (of the constant dictionary vector f(x,y) = 1) |
| 525 |
* are quantized to values of the interval [-`dc_range', `dc_range'] using |
| 526 |
* #`dc_mantissa' bits. All other quantized coefficients are quantized in |
| 527 |
* an analogous way using the parameters `range' and `mantissa'. |
| 528 |
* |
| 529 |
* Return value: |
| 530 |
* 1 on success |
| 531 |
* 0 otherwise |
| 532 |
*/ |
| 533 |
{ |
| 534 |
c_options_t *this = (c_options_t *) cast_c_options (options); |
| 535 |
|
| 536 |
if (!this) |
| 537 |
{ |
| 538 |
return 0; |
| 539 |
} |
| 540 |
else if (mantissa < 2 || mantissa > 8 || dc_mantissa < 2 || dc_mantissa > 8) |
| 541 |
{ |
| 542 |
set_error (_("Number of RPF mantissa bits `%d', `%d' have to be in " |
| 543 |
"the interval [2,8]."), mantissa, dc_mantissa); |
| 544 |
return 0; |
| 545 |
} |
| 546 |
else |
| 547 |
{ |
| 548 |
if ((range == FIASCO_RPF_RANGE_0_75 |
| 549 |
|| range == FIASCO_RPF_RANGE_1_00 |
| 550 |
|| range == FIASCO_RPF_RANGE_1_50 |
| 551 |
|| range == FIASCO_RPF_RANGE_2_00) |
| 552 |
&& |
| 553 |
(dc_range == FIASCO_RPF_RANGE_0_75 |
| 554 |
|| dc_range == FIASCO_RPF_RANGE_1_00 |
| 555 |
|| dc_range == FIASCO_RPF_RANGE_1_50 |
| 556 |
|| dc_range == FIASCO_RPF_RANGE_2_00)) |
| 557 |
{ |
| 558 |
this->rpf_range = range; |
| 559 |
this->dc_rpf_range = dc_range; |
| 560 |
this->rpf_mantissa = mantissa; |
| 561 |
this->dc_rpf_mantissa = dc_mantissa; |
| 562 |
|
| 563 |
return 1; |
| 564 |
} |
| 565 |
else |
| 566 |
{ |
| 567 |
set_error (_("Invalid RPF ranges `%d', `%d' specified."), |
| 568 |
range, dc_range); |
| 569 |
return 0; |
| 570 |
} |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
int |
| 575 |
fiasco_c_options_set_progress_meter (fiasco_c_options_t *options, |
| 576 |
fiasco_progress_e type) |
| 577 |
/* |
| 578 |
* Set type of progress meter. |
| 579 |
* |
| 580 |
* Return value: |
| 581 |
* 1 on success |
| 582 |
* 0 otherwise |
| 583 |
*/ |
| 584 |
{ |
| 585 |
c_options_t *this = (c_options_t *) cast_c_options (options); |
| 586 |
|
| 587 |
if (!this) |
| 588 |
{ |
| 589 |
return 0; |
| 590 |
} |
| 591 |
switch (type) |
| 592 |
{ |
| 593 |
case FIASCO_PROGRESS_BAR: |
| 594 |
case FIASCO_PROGRESS_PERCENT: |
| 595 |
case FIASCO_PROGRESS_NONE: |
| 596 |
this->progress_meter = type; |
| 597 |
break; |
| 598 |
default: |
| 599 |
set_error (_("Invalid progress meter `%d' specified " |
| 600 |
"(valid values are 0, 1, or 2)."), type); |
| 601 |
return 0; |
| 602 |
} |
| 603 |
return 1; |
| 604 |
} |
| 605 |
|
| 606 |
int |
| 607 |
fiasco_c_options_set_smoothing (fiasco_c_options_t *options, int smoothing) |
| 608 |
/* |
| 609 |
* Define `smoothing'-percentage along partitioning borders. |
| 610 |
* |
| 611 |
* Return value: |
| 612 |
* 1 on success |
| 613 |
* 0 otherwise |
| 614 |
*/ |
| 615 |
{ |
| 616 |
c_options_t *this = (c_options_t *) cast_c_options (options); |
| 617 |
|
| 618 |
if (!this) |
| 619 |
{ |
| 620 |
return 0; |
| 621 |
} |
| 622 |
else if (smoothing < -1 || smoothing > 100) |
| 623 |
{ |
| 624 |
set_error (_("Smoothing percentage must be in the range [-1, 100].")); |
| 625 |
return 0; |
| 626 |
} |
| 627 |
else |
| 628 |
{ |
| 629 |
this->smoothing = smoothing; |
| 630 |
return 1; |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
int |
| 635 |
fiasco_c_options_set_comment (fiasco_c_options_t *options, const char *comment) |
| 636 |
/* |
| 637 |
* Define `comment' of FIASCO stream. |
| 638 |
* |
| 639 |
* Return value: |
| 640 |
* 1 on success |
| 641 |
* 0 otherwise |
| 642 |
*/ |
| 643 |
{ |
| 644 |
c_options_t *this = (c_options_t *) cast_c_options (options); |
| 645 |
|
| 646 |
if (!this) |
| 647 |
{ |
| 648 |
return 0; |
| 649 |
} |
| 650 |
else if (!comment) |
| 651 |
{ |
| 652 |
set_error (_("Parameter `%s' not defined (NULL)."), "title"); |
| 653 |
return 0; |
| 654 |
} |
| 655 |
else |
| 656 |
{ |
| 657 |
this->comment = strdup (comment); |
| 658 |
return 1; |
| 659 |
} |
| 660 |
} |
| 661 |
|
| 662 |
int |
| 663 |
fiasco_c_options_set_title (fiasco_c_options_t *options, const char *title) |
| 664 |
/* |
| 665 |
* Define `title' of FIASCO stream. |
| 666 |
* |
| 667 |
* Return value: |
| 668 |
* 1 on success |
| 669 |
* 0 otherwise |
| 670 |
*/ |
| 671 |
{ |
| 672 |
c_options_t *this = (c_options_t *) cast_c_options (options); |
| 673 |
|
| 674 |
if (!this) |
| 675 |
{ |
| 676 |
return 0; |
| 677 |
} |
| 678 |
else if (!title) |
| 679 |
{ |
| 680 |
set_error (_("Parameter `%s' not defined (NULL)."), "title"); |
| 681 |
return 0; |
| 682 |
} |
| 683 |
else |
| 684 |
{ |
| 685 |
this->title = strdup (title); |
| 686 |
return 1; |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
c_options_t * |
| 691 |
cast_c_options (fiasco_c_options_t *options) |
| 692 |
/* |
| 693 |
* Cast generic pointer `options' to type c_options_t. |
| 694 |
* Check whether `options' is a valid object of type c_options_t. |
| 695 |
* |
| 696 |
* Return value: |
| 697 |
* pointer to options struct on success |
| 698 |
* NULL otherwise |
| 699 |
*/ |
| 700 |
{ |
| 701 |
c_options_t *this = (c_options_t *) options->private; |
| 702 |
if (this) |
| 703 |
{ |
| 704 |
if (!streq (this->id, "COFIASCO")) |
| 705 |
{ |
| 706 |
set_error (_("Parameter `options' doesn't match required type.")); |
| 707 |
return NULL; |
| 708 |
} |
| 709 |
} |
| 710 |
else |
| 711 |
{ |
| 712 |
set_error (_("Parameter `%s' not defined (NULL)."), "options"); |
| 713 |
} |
| 714 |
|
| 715 |
return this; |
| 716 |
} |
| 717 |
|
| 718 |
/************************************************************************** |
| 719 |
*************************************************************************** |
| 720 |
DECODER |
| 721 |
*************************************************************************** |
| 722 |
**************************************************************************/ |
| 723 |
|
| 724 |
fiasco_d_options_t * |
| 725 |
fiasco_d_options_new (void) |
| 726 |
/* |
| 727 |
* FIASCO options constructor. |
| 728 |
* Allocate memory for the FIASCO coder options structure and |
| 729 |
* fill in default values. |
| 730 |
* |
| 731 |
* Return value: |
| 732 |
* pointer to the new option structure |
| 733 |
*/ |
| 734 |
{ |
| 735 |
d_options_t *options = calloc (1, sizeof (d_options_t)); |
| 736 |
fiasco_d_options_t *public = calloc (1, sizeof (fiasco_d_options_t)); |
| 737 |
|
| 738 |
if (!options || !public) |
| 739 |
{ |
| 740 |
set_error (_("Out of memory.")); |
| 741 |
return NULL; |
| 742 |
} |
| 743 |
public->private = options; |
| 744 |
public->delete = fiasco_d_options_delete; |
| 745 |
public->set_smoothing = fiasco_d_options_set_smoothing; |
| 746 |
public->set_magnification = fiasco_d_options_set_magnification; |
| 747 |
public->set_4_2_0_format = fiasco_d_options_set_4_2_0_format; |
| 748 |
|
| 749 |
strcpy (options->id, "DOFIASCO"); |
| 750 |
|
| 751 |
/* |
| 752 |
* Set default value of fiasco decoder options |
| 753 |
*/ |
| 754 |
options->smoothing = 70; |
| 755 |
options->magnification = 0; |
| 756 |
options->image_format = FORMAT_4_4_4; |
| 757 |
|
| 758 |
return public; |
| 759 |
} |
| 760 |
|
| 761 |
void |
| 762 |
fiasco_d_options_delete (fiasco_d_options_t *options) |
| 763 |
/* |
| 764 |
* FIASCO options destructor. |
| 765 |
* Free memory of FIASCO options struct. |
| 766 |
* |
| 767 |
* No return value. |
| 768 |
* |
| 769 |
* Side effects: |
| 770 |
* structure 'options' is discarded. |
| 771 |
*/ |
| 772 |
{ |
| 773 |
d_options_t *this = cast_d_options (options); |
| 774 |
|
| 775 |
if (!this) |
| 776 |
return; |
| 777 |
|
| 778 |
Free (this); |
| 779 |
|
| 780 |
return; |
| 781 |
} |
| 782 |
|
| 783 |
int |
| 784 |
fiasco_d_options_set_smoothing (fiasco_d_options_t *options, int smoothing) |
| 785 |
/* |
| 786 |
* Define `smoothing'-percentage along partitioning borders. |
| 787 |
* |
| 788 |
* Return value: |
| 789 |
* 1 on success |
| 790 |
* 0 otherwise |
| 791 |
*/ |
| 792 |
{ |
| 793 |
d_options_t *this = (d_options_t *) cast_d_options (options); |
| 794 |
|
| 795 |
if (!this) |
| 796 |
{ |
| 797 |
return 0; |
| 798 |
} |
| 799 |
else if (smoothing < -1 || smoothing > 100) |
| 800 |
{ |
| 801 |
set_error (_("Smoothing percentage must be in the range [-1, 100].")); |
| 802 |
return 0; |
| 803 |
} |
| 804 |
else |
| 805 |
{ |
| 806 |
this->smoothing = smoothing; |
| 807 |
return 1; |
| 808 |
} |
| 809 |
} |
| 810 |
|
| 811 |
int |
| 812 |
fiasco_d_options_set_magnification (fiasco_d_options_t *options, int level) |
| 813 |
/* |
| 814 |
* Set magnification-'level' of decoded image. |
| 815 |
* 0: width x height of original image |
| 816 |
* 1: (2 * width) x (2 * height) of original image |
| 817 |
* -1: (width / 2 ) x (height / 2) of original image |
| 818 |
* etc. |
| 819 |
* |
| 820 |
* Return value: |
| 821 |
* 1 on success |
| 822 |
* 0 otherwise |
| 823 |
*/ |
| 824 |
{ |
| 825 |
d_options_t *this = (d_options_t *) cast_d_options (options); |
| 826 |
|
| 827 |
if (!this) |
| 828 |
{ |
| 829 |
return 0; |
| 830 |
} |
| 831 |
else |
| 832 |
{ |
| 833 |
this->magnification = level; |
| 834 |
return 1; |
| 835 |
} |
| 836 |
} |
| 837 |
|
| 838 |
int |
| 839 |
fiasco_d_options_set_4_2_0_format (fiasco_d_options_t *options, int format) |
| 840 |
/* |
| 841 |
* Set image format to 4:2:0 or 4:4:4. |
| 842 |
* |
| 843 |
* Return value: |
| 844 |
* 1 on success |
| 845 |
* 0 otherwise |
| 846 |
*/ |
| 847 |
{ |
| 848 |
d_options_t *this = (d_options_t *) cast_d_options (options); |
| 849 |
|
| 850 |
if (!this) |
| 851 |
{ |
| 852 |
return 0; |
| 853 |
} |
| 854 |
else |
| 855 |
{ |
| 856 |
this->image_format = format ? FORMAT_4_2_0 : FORMAT_4_4_4; |
| 857 |
return 1; |
| 858 |
} |
| 859 |
} |
| 860 |
|
| 861 |
d_options_t * |
| 862 |
cast_d_options (fiasco_d_options_t *options) |
| 863 |
/* |
| 864 |
* Cast generic pointer `options' to type d_options_t. |
| 865 |
* Check whether `options' is a valid object of type d_options_t. |
| 866 |
* |
| 867 |
* Return value: |
| 868 |
* pointer to options struct on success |
| 869 |
* NULL otherwise |
| 870 |
*/ |
| 871 |
{ |
| 872 |
d_options_t *this = (d_options_t *) options->private; |
| 873 |
|
| 874 |
if (this) |
| 875 |
{ |
| 876 |
if (!streq (this->id, "DOFIASCO")) |
| 877 |
{ |
| 878 |
set_error (_("Parameter `options' doesn't match required type.")); |
| 879 |
return NULL; |
| 880 |
} |
| 881 |
} |
| 882 |
else |
| 883 |
{ |
| 884 |
set_error (_("Parameter `%s' not defined (NULL)."), "options"); |
| 885 |
} |
| 886 |
|
| 887 |
return this; |
| 888 |
} |
| 889 |
|
| 890 |
|