diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-06-28 17:21:21 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2023-06-28 17:21:21 +0000 |
commit | 0d513aca5cbbb8db0a9d127e101ac3b534cc8bf0 (patch) | |
tree | 3e8db9f13fb33464324c6986e7d80540a42a86c7 /converter/other/fiasco/lib | |
parent | 7dd37058c4c8e0f6ca272e329162a52f958e4951 (diff) | |
download | netpbm-mirror-0d513aca5cbbb8db0a9d127e101ac3b534cc8bf0.tar.gz netpbm-mirror-0d513aca5cbbb8db0a9d127e101ac3b534cc8bf0.tar.xz netpbm-mirror-0d513aca5cbbb8db0a9d127e101ac3b534cc8bf0.zip |
promote Stable to Super Stable
git-svn-id: http://svn.code.sf.net/p/netpbm/code/super_stable@4557 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other/fiasco/lib')
-rw-r--r-- | converter/other/fiasco/lib/arith.c | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/arith.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/bit-io.c | 5 | ||||
-rw-r--r-- | converter/other/fiasco/lib/bit-io.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/dither.c | 16 | ||||
-rw-r--r-- | converter/other/fiasco/lib/dither.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/error.c | 403 | ||||
-rw-r--r-- | converter/other/fiasco/lib/error.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/image.c | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/image.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/list.c | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/list.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/macros.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/misc.c | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/misc.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/rpf.c | 296 | ||||
-rw-r--r-- | converter/other/fiasco/lib/rpf.h | 4 | ||||
-rw-r--r-- | converter/other/fiasco/lib/types.h | 4 |
18 files changed, 373 insertions, 403 deletions
diff --git a/converter/other/fiasco/lib/arith.c b/converter/other/fiasco/lib/arith.c index dc35d1d1..825d4757 100644 --- a/converter/other/fiasco/lib/arith.c +++ b/converter/other/fiasco/lib/arith.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/arith.h b/converter/other/fiasco/lib/arith.h index 744eb9d7..04297eb5 100644 --- a/converter/other/fiasco/lib/arith.h +++ b/converter/other/fiasco/lib/arith.h @@ -1,8 +1,8 @@ /* * arith.h * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/bit-io.c b/converter/other/fiasco/lib/bit-io.c index 1bfef598..f69343e6 100644 --- a/converter/other/fiasco/lib/bit-io.c +++ b/converter/other/fiasco/lib/bit-io.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* @@ -14,6 +14,7 @@ * $State: Exp $ */ +#define _DEFAULT_SOURCE 1 /* New name for SVID & BSD source defines */ #define _BSD_SOURCE 1 /* Make sure strdup() is in string.h */ #define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ diff --git a/converter/other/fiasco/lib/bit-io.h b/converter/other/fiasco/lib/bit-io.h index d37cc47c..08029824 100644 --- a/converter/other/fiasco/lib/bit-io.h +++ b/converter/other/fiasco/lib/bit-io.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/dither.c b/converter/other/fiasco/lib/dither.c index accd9dd6..669bb16c 100644 --- a/converter/other/fiasco/lib/dither.c +++ b/converter/other/fiasco/lib/dither.c @@ -3,8 +3,8 @@ * * Adapted by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* @@ -713,15 +713,11 @@ display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, word_t *cbptr, *crptr; /* pointer to chroma bands */ word_t *yptr; /* pointers to lumincance band */ int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; - unsigned int *r_table, *g_table, *b_table; Cr_g_tab = private->Cr_g_tab; Cr_r_tab = private->Cr_r_tab; Cb_b_tab = private->Cb_b_tab; Cb_g_tab = private->Cb_g_tab; - r_table = private->r_table; - g_table = private->g_table; - b_table = private->b_table; yptr = image->pixels [Y]; cbptr = image->pixels [Cb]; crptr = image->pixels [Cr]; @@ -1044,9 +1040,7 @@ display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, { unsigned int *dst; /* pointer to dithered pixels */ word_t *src; /* current pixel of frame */ - unsigned int *y_table; - y_table = private->y_table; dst = (unsigned int *) out; src = image->pixels [GRAY]; @@ -1164,15 +1158,11 @@ display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, word_t *cbptr, *crptr; /* pointer to chroma bands */ word_t *yptr; /* pointers to lumincance band */ int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; - unsigned int *r_table, *g_table, *b_table; Cr_g_tab = private->Cr_g_tab; Cr_r_tab = private->Cr_r_tab; Cb_b_tab = private->Cb_b_tab; Cb_g_tab = private->Cb_g_tab; - r_table = private->r_table; - g_table = private->g_table; - b_table = private->b_table; yptr = image->pixels [Y]; cbptr = image->pixels [Cb]; crptr = image->pixels [Cr]; @@ -1495,9 +1485,7 @@ display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, { unsigned int *dst; /* pointer to dithered pixels */ word_t *src; /* current pixel of frame */ - unsigned int *y_table; - y_table = private->y_table; dst = (unsigned int *) out; src = image->pixels [GRAY]; diff --git a/converter/other/fiasco/lib/dither.h b/converter/other/fiasco/lib/dither.h index 71f9d3c3..767bca28 100644 --- a/converter/other/fiasco/lib/dither.h +++ b/converter/other/fiasco/lib/dither.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/error.c b/converter/other/fiasco/lib/error.c index ee3afe1f..394f896f 100644 --- a/converter/other/fiasco/lib/error.c +++ b/converter/other/fiasco/lib/error.c @@ -3,29 +3,19 @@ * * Written by: Stefan Frank * Ullrich Hafner - * + * * Credits: Modelled after variable argument routines from Jef - * Poskanzer's pbmplus package. + * Poskanzer's pbmplus package. * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> - - "int dummy = " change to int dummy; dummy =" for Netpbm to avoid - unused variable warning. - - */ - -/* - * $Date: 2000/06/14 20:49:37 $ - * $Author: hafner $ - * $Revision: 5.1 $ - * $State: Exp $ + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ #define _ERROR_C #include "config.h" +#include <stdbool.h> #include <stdio.h> #include <errno.h> @@ -47,7 +37,7 @@ /***************************************************************************** local variables - + *****************************************************************************/ static fiasco_verbosity_e verboselevel = FIASCO_SOME_VERBOSITY; @@ -60,234 +50,237 @@ jmp_buf env; /***************************************************************************** public code - + *****************************************************************************/ void -set_error (const char *format, ...) -/* - * Set error text to given string. - */ -{ - va_list args; - unsigned len = 0; - const char *str = format; - - VA_START (args, format); - - len = strlen (format); - while ((str = strchr (str, '%'))) - { - str++; - if (*str == 's') - { - char *vstring = va_arg (args, char *); - len += strlen (vstring); - } - else if (*str == 'd') - { - int dummy; - dummy = va_arg (args, int); - len += 10; - } - else if (*str == 'c') - { - int dummy; - dummy = va_arg (args, int); - len += 1; - } - else - return; - str++; - } - va_end(args); - - VA_START (args, format); - - if (error_message) - Free (error_message); - error_message = Calloc (len, sizeof (char)); - - vsprintf (error_message, format, args); - - va_end (args); +set_error(const char * const format, ...) { +/*---------------------------------------------------------------------------- + Set error text to given string. +-----------------------------------------------------------------------------*/ + va_list args; + unsigned len; + bool error; + const char * str; + + VA_START (args, format); + + /* Compute how long the error text will be: 'len' */ + + for (len = strlen(format), str = &format[0], error = false; + *str && !error; ) { + + str = strchr(str, '%'); + + if (*str) { + ++str; /* Move past % */ + if (*str == 's') { + char * const vstring = va_arg (args, char *); + len += strlen(vstring); + } else if (*str == 'd') { + (void)va_arg(args, int); + len += 10; + } else if (*str == 'c') { + (void)va_arg(args, int); + len += 1; + } else + error = true; + if (!error) + ++str; + } + } + va_end(args); + + if (!error) { + VA_START(args, format); + + if (error_message) + Free(error_message); + error_message = Calloc(len, sizeof (char)); + + vsprintf(error_message, format, args); + + va_end(args); + } } + + void -error (const char *format, ...) -/* - * Set error text to given string. - */ -{ - va_list args; - unsigned len = 0; - const char *str = format; - - VA_START (args, format); - - len = strlen (format); - while ((str = strchr (str, '%'))) - { - str++; - if (*str == 's') - { - char *vstring = va_arg (args, char *); - len += strlen (vstring); - } - else if (*str == 'd') - { - int dummy; - dummy = va_arg (args, int); - len += 10; - } - else if (*str == 'c') - { - int dummy; - dummy = va_arg (args, int); - len += 1; - } - else - { +error(const char * const format, ...) { +/*---------------------------------------------------------------------------- + Set error text to given string. +-----------------------------------------------------------------------------*/ + va_list args; + unsigned len; + const char * str; + + len = 0; /* initial value */ + str = &format[0]; /* initial value */ + + VA_START (args, format); + + len = strlen (format); + while ((str = strchr (str, '%'))) { + ++str; + if (*str == 's') { + char * const vstring = va_arg (args, char *); + len += strlen(vstring); + } else if (*str == 'd') { + (void)va_arg(args, int); + len += 10; + } else if (*str == 'c') { + (void)va_arg(args, int); + len += 1; + } else { #if HAVE_SETJMP_H - longjmp (env, 1); -#else /* not HAVE_SETJMP_H */ - exit (1); -#endif /* HAVE_SETJMP_H */ - }; - - str++; - } - va_end(args); - - VA_START (args, format); - - if (error_message) - Free (error_message); - error_message = Calloc (len, sizeof (char)); - - vsprintf (error_message, format, args); - - va_end (args); - + longjmp(env, 1); +#else + exit(1); +#endif + }; + + ++str; + } + va_end(args); + + VA_START(args, format); + + if (error_message) + Free(error_message); + error_message = Calloc(len, sizeof (char)); + + vsprintf(error_message, format, args); + + va_end(args); + #if HAVE_SETJMP_H - longjmp (env, 1); -#else /* not HAVE_SETJMP_H */ - exit (1); -#endif /* HAVE_SETJMP_H */ + longjmp(env, 1); +#else + exit(1); +#endif } + + const char * -fiasco_get_error_message (void) -/* - * Return value: - * Last error message of FIASCO library. - */ -{ - return error_message ? error_message : ""; +fiasco_get_error_message(void) { +/*---------------------------------------------------------------------------- + Last error message of FIASCO library. +-----------------------------------------------------------------------------*/ + return error_message ? error_message : ""; } + + const char * -get_system_error (void) -{ - return strerror (errno); +get_system_error(void) { + return strerror(errno); } + + void -file_error (const char *filename) -/* - * Print file error message and exit. - * - * No return value. - */ -{ - error ("File `%s': I/O Error - %s.", filename, get_system_error ()); +file_error(const char * const filename) { +/*---------------------------------------------------------------------------- + Print file error message and exit. +-----------------------------------------------------------------------------*/ + error("File `%s': I/O Error - %s.", filename, get_system_error ()); } -void -warning (const char *format, ...) -/* - * Issue a warning and continue execution. - * - * No return value. - */ -{ - va_list args; - - VA_START (args, format); - if (verboselevel == FIASCO_NO_VERBOSITY) - return; - - fprintf (stderr, "Warning: "); - vfprintf (stderr, format, args); - fputc ('\n', stderr); - va_end (args); +void +warning(const char * const format, ...) { +/*---------------------------------------------------------------------------- + Issue a warning. +-----------------------------------------------------------------------------*/ + va_list args; + + VA_START (args, format); + + if (verboselevel == FIASCO_NO_VERBOSITY) { + /* User doesn't want warnings */ + } else { + fprintf (stderr, "Warning: "); + vfprintf (stderr, format, args); + fputc ('\n', stderr); + } + va_end (args); } -void -message (const char *format, ...) -/* - * Print a message to stderr. - */ -{ - va_list args; - - VA_START (args, format); - if (verboselevel == FIASCO_NO_VERBOSITY) - return; - vfprintf (stderr, format, args); - fputc ('\n', stderr); - va_end (args); +void +message(const char * const format, ...) { +/*---------------------------------------------------------------------------- + Print a message to Standard Error +-----------------------------------------------------------------------------*/ + va_list args; + + VA_START (args, format); + + if (verboselevel == FIASCO_NO_VERBOSITY) { + /* User doesn't want messages */ + } else { + vfprintf (stderr, format, args); + fputc ('\n', stderr); + } + va_end (args); } -void -debug_message (const char *format, ...) -/* - * Print a message to stderr. - */ -{ - va_list args; - VA_START (args, format); - - if (verboselevel < FIASCO_ULTIMATE_VERBOSITY) - return; - - fprintf (stderr, "*** "); - vfprintf (stderr, format, args); - fputc ('\n', stderr); - va_end (args); -} void -info (const char *format, ...) -/* - * Print a message to stderr. Do not append a newline. - */ -{ - va_list args; +debug_message(const char * const format, ...) { +/*---------------------------------------------------------------------------- + Print a message to Standard Error if debug messages are enabled. +-----------------------------------------------------------------------------*/ + va_list args; + + VA_START (args, format); + + if (verboselevel >= FIASCO_ULTIMATE_VERBOSITY) { + fprintf (stderr, "*** "); + vfprintf (stderr, format, args); + fputc ('\n', stderr); + } + va_end (args); +} - VA_START (args, format); - if (verboselevel == FIASCO_NO_VERBOSITY) - return; - vfprintf (stderr, format, args); - fflush (stderr); - va_end (args); +void +info(const char * const format, ...) { +/*---------------------------------------------------------------------------- + Print a message to stderr. Do not append a newline. +-----------------------------------------------------------------------------*/ + va_list args; + + VA_START (args, format); + + if (verboselevel == FIASCO_NO_VERBOSITY) { + /* User doesn't want informational messages */ + } else { + vfprintf (stderr, format, args); + fflush (stderr); + } + va_end (args); } + + void -fiasco_set_verbosity (fiasco_verbosity_e level) -{ +fiasco_set_verbosity(fiasco_verbosity_e const level) { verboselevel = level; } + + fiasco_verbosity_e -fiasco_get_verbosity (void) -{ +fiasco_get_verbosity(void) { return verboselevel; } + + + diff --git a/converter/other/fiasco/lib/error.h b/converter/other/fiasco/lib/error.h index 288b25f4..4159ccd2 100644 --- a/converter/other/fiasco/lib/error.h +++ b/converter/other/fiasco/lib/error.h @@ -4,8 +4,8 @@ * Written by: Stefan Frank * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ #ifndef ERROR_H_INCLUDED diff --git a/converter/other/fiasco/lib/image.c b/converter/other/fiasco/lib/image.c index fa3b2db5..a700fe88 100644 --- a/converter/other/fiasco/lib/image.c +++ b/converter/other/fiasco/lib/image.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/image.h b/converter/other/fiasco/lib/image.h index 00978526..a87a3c05 100644 --- a/converter/other/fiasco/lib/image.h +++ b/converter/other/fiasco/lib/image.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/list.c b/converter/other/fiasco/lib/list.c index bb4efae1..b67ff4b8 100644 --- a/converter/other/fiasco/lib/list.c +++ b/converter/other/fiasco/lib/list.c @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/list.h b/converter/other/fiasco/lib/list.h index db7c08b2..68577dfd 100644 --- a/converter/other/fiasco/lib/list.h +++ b/converter/other/fiasco/lib/list.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/macros.h b/converter/other/fiasco/lib/macros.h index 9968110a..0bc80e7c 100644 --- a/converter/other/fiasco/lib/macros.h +++ b/converter/other/fiasco/lib/macros.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/misc.c b/converter/other/fiasco/lib/misc.c index 782ed1e9..c5629c5c 100644 --- a/converter/other/fiasco/lib/misc.c +++ b/converter/other/fiasco/lib/misc.c @@ -6,8 +6,8 @@ * Written by: Stefan Frank * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/misc.h b/converter/other/fiasco/lib/misc.h index 28fd8b5a..6f643b7a 100644 --- a/converter/other/fiasco/lib/misc.h +++ b/converter/other/fiasco/lib/misc.h @@ -4,8 +4,8 @@ * Written by: Stefan Frank * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/rpf.c b/converter/other/fiasco/lib/rpf.c index 84c1f9b6..e6ff6e09 100644 --- a/converter/other/fiasco/lib/rpf.c +++ b/converter/other/fiasco/lib/rpf.c @@ -1,10 +1,10 @@ /* - * rpf.c: Conversion of float to reduced precision format values + * rpf.c: Conversion of float to reduced precision format values * - * Written by: Stefan Frank - * Richard Krampfl - * Ullrich Hafner - * + * Written by: Stefan Frank + * Richard Krampfl + * Ullrich Hafner + * * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> */ @@ -18,6 +18,7 @@ #include "pm_config.h" #include "config.h" +#include "mallocvar.h" #include "types.h" #include "macros.h" @@ -26,39 +27,37 @@ #include "misc.h" #include "rpf.h" -/* - * CAUTION: The IEEE float format must be used by your compiler, - * or all following code is void! - */ +int const RPF_ZERO = -1; -#if BYTE_ORDER == BIG_ENDIAN -/* - * Big-Endian Architecture (e.g. SUN, Motorola) - * Memory representation of integer 0x00112233 is 00,11,22,33 - */ +/***************************************************************************** -enum real_bytes {BYTE_0, BYTE_1, BYTE_2, BYTE_3}; + private code + +*****************************************************************************/ -#else -/* - * Little-Endian Architecture (e.g. Intel, VAX, Alpha) - * Memory representation of integer 0x00112233 is 33,22,11,00 - */ -enum real_bytes {BYTE_3, BYTE_2, BYTE_1, BYTE_0}; +typedef struct { + double fraction; + int exponent; +} FracExp; -#endif -const int RPF_ZERO = -1; -/***************************************************************************** +static FracExp +fracExpFromDouble(double const x) { + + FracExp retval; + + retval.fraction = frexp(x, &retval.exponent); + + return retval; +} + - private code - -*****************************************************************************/ int -rtob (real_t f, const rpf_t *rpf) +rtob (real_t const f, + const rpf_t * const rpfP) /* * Convert real number 'f' into fixed point format. * The real number in [-'range'; +'range'] is scaled to [-1 ; +1]. @@ -66,111 +65,98 @@ rtob (real_t f, const rpf_t *rpf) * packed into one integer. * * Return value: - * real value in reduced precision format + * real value in reduced precision format */ { - unsigned int mantissa; - int exponent, sign; - union - { - float f; - unsigned char c[4]; - } v; /* conversion dummy */ - - f /= rpf->range; /* scale f to [-1,+1] */ - v.f = f; - - /* - * Extract mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) - */ - - mantissa = ((((v.c[BYTE_1] & 127) << 8 ) | v.c[BYTE_2]) << 8) | v.c[BYTE_3]; - exponent = (((v.c[BYTE_0] & 127) << 1) | (v.c[BYTE_1] & 128 ? 1 : 0)) - 126; - sign = v.c[BYTE_0] & 128 ? 1 : 0; - - /* - * Generate reduced precision mantissa. - */ - mantissa >>= 1; /* shift 1 into from left */ - mantissa |= (1 << 22); - if (exponent > 0) - mantissa <<= exponent; - else - mantissa >>= -exponent; + /* + * Extract mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) + */ + + double const normalized = f / rpfP->range; + /* 'f' scaled to [-1,+1] */ + FracExp const fracExp = fracExpFromDouble(normalized); + unsigned int const signedMantissa = + (unsigned int) (fracExp.fraction * (1<<23)); + + unsigned int mantissa; + unsigned int sign; /* 0 for positive; 1 for negative */ + + if (signedMantissa < 0) { + mantissa = -signedMantissa; + sign = 1; + } else { + mantissa = +signedMantissa; + sign = 0; + } + + /* + * Generate reduced precision mantissa. + */ + if (fracExp.exponent > 0) + mantissa <<= fracExp.exponent; + else + mantissa >>= -fracExp.exponent; + + mantissa >>= (23 - rpfP->mantissa_bits - 1); + + mantissa += 1; /* Round last bit. */ + mantissa >>= 1; - mantissa >>= (23 - rpf->mantissa_bits - 1); - - mantissa += 1; /* Round last bit. */ - mantissa >>= 1; - - if (mantissa == 0) /* close to zero */ - return RPF_ZERO; - else if (mantissa >= (1U << rpf->mantissa_bits)) /* overflow */ - return sign; - else - return ((mantissa & ((1U << rpf->mantissa_bits) - 1)) << 1) | sign; + if (mantissa == 0) /* close to zero */ + return RPF_ZERO; + else if (mantissa >= (1U << rpfP->mantissa_bits)) /* overflow */ + return sign; + else + return ((mantissa & ((1U << rpfP->mantissa_bits) - 1)) << 1) | sign; } + + float -btor (int binary, const rpf_t *rpf) +btor (int const binary, + const rpf_t * const rpfP) /* * Convert value 'binary' in reduced precision format to a real value. - * For more information refer to function lin_rtob() above. + * For more information refer to function rtob() above. * * Return value: - * converted value + * converted value */ { - unsigned int mantissa; - int sign, exponent; - union - { - float f; - unsigned char c[4]; - } value; - - if (binary == RPF_ZERO) - return 0; - - if (binary < 0 || binary >= 1 << (rpf->mantissa_bits + 1)) - error ("Reduced precision format: value %d out of range.", binary); - - /* - * Restore IEEE float format: - * mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) - */ + unsigned int mantissa; + float sign; + float f; + + if (binary == RPF_ZERO) + return 0; + + if (binary < 0 || binary >= 1 << (rpfP->mantissa_bits + 1)) + error ("Reduced precision format: value %d out of range.", binary); + + /* + * Restore IEEE float format: + * mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) + */ - sign = binary & 1; - mantissa = (binary & ((1 << (rpf->mantissa_bits + 1)) - 1)) >> 1; - mantissa <<= (23 - rpf->mantissa_bits); - exponent = 0; - - if (mantissa == 0) - { - value.f = (sign ? -1.0 : 1.0); - } - else - { - while (!(mantissa & (1 << 22))) /* normalize mantissa */ - { - exponent--; - mantissa <<= 1; - } - mantissa <<= 1; - - value.c[BYTE_0] = (sign << 7) | ((exponent + 126) >> 1); - value.c[BYTE_1] = (((exponent + 126) & 1) << 7) - | ((mantissa >> 16) & 127); - value.c[BYTE_2] = (mantissa >> 8) & 255; - value.c[BYTE_3] = mantissa & 255; - } + sign = (binary & 0x1) == 0 ? 1.0 : -1.0; + mantissa = (binary & ((0x1 << (rpfP->mantissa_bits + 1)) - 1)) >> 1; + mantissa <<= (23 - rpfP->mantissa_bits); + + if (mantissa == 0) + f = sign; + else + f = sign * (float) mantissa / 8388608; - return value.f * rpf->range; /* expand [ -1 ; +1 ] to - [ -range ; +range ] */ + return f * rpfP->range; /* expand [ -1 ; +1 ] to + [ -range ; +range ] */ } + + + rpf_t * -alloc_rpf (unsigned mantissa, fiasco_rpf_range_e range) +alloc_rpf (unsigned const mantissa, + fiasco_rpf_range_e const range) /* * Reduced precision format constructor. * Allocate memory for the rpf_t structure. @@ -180,45 +166,47 @@ alloc_rpf (unsigned mantissa, fiasco_rpf_range_e range) * returned. * * Return value - * pointer to the new rpf structure + * pointer to the new rpf structure */ { - rpf_t *rpf = Calloc (1, sizeof (rpf_t)); + rpf_t * rpfP; + + MALLOCVAR(rpfP); - if (mantissa < 2) - { - warning (_("Size of RPF mantissa has to be in the interval [2,8]. " - "Using minimum value 2.\n")); - mantissa = 2; - } - else if (mantissa > 8) - { - warning (_("Size of RPF mantissa has to be in the interval [2,8]. " - "Using maximum value 8.\n")); - mantissa = 2; - } - - rpf->mantissa_bits = mantissa; - rpf->range_e = range; - switch (range) - { - case FIASCO_RPF_RANGE_0_75: - rpf->range = 0.75; - break; - case FIASCO_RPF_RANGE_1_50: - rpf->range = 1.50; - break; - case FIASCO_RPF_RANGE_2_00: - rpf->range = 2.00; - break; - case FIASCO_RPF_RANGE_1_00: - rpf->range = 1.00; - break; - default: - warning (_("Invalid RPF range specified. Using default value 1.0.")); - rpf->range = 1.00; - rpf->range_e = FIASCO_RPF_RANGE_1_00; - break; - } - return rpf; + if (mantissa < 2) { + warning (_("Size of RPF mantissa has to be in the interval [2,8]. " + "Using minimum value 2.\n")); + rpfP->mantissa_bits = 2; + } else if (mantissa > 8) { + warning (_("Size of RPF mantissa has to be in the interval [2,8]. " + "Using maximum value 8.\n")); + rpfP->mantissa_bits = 2; + } else + rpfP->mantissa_bits = mantissa; + + switch (range) { + case FIASCO_RPF_RANGE_0_75: + rpfP->range = 0.75; + rpfP->range_e = range; + break; + case FIASCO_RPF_RANGE_1_50: + rpfP->range = 1.50; + rpfP->range_e = range; + break; + case FIASCO_RPF_RANGE_2_00: + rpfP->range = 2.00; + rpfP->range_e = range; + break; + case FIASCO_RPF_RANGE_1_00: + rpfP->range = 1.00; + rpfP->range_e = range; + break; + default: + warning (_("Invalid RPF range specified. Using default value 1.0.")); + rpfP->range = 1.00; + rpfP->range_e = FIASCO_RPF_RANGE_1_00; + break; + } + return rpfP; } + diff --git a/converter/other/fiasco/lib/rpf.h b/converter/other/fiasco/lib/rpf.h index ba3ff6be..e543f855 100644 --- a/converter/other/fiasco/lib/rpf.h +++ b/converter/other/fiasco/lib/rpf.h @@ -5,8 +5,8 @@ * Richard Krampfl * Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* diff --git a/converter/other/fiasco/lib/types.h b/converter/other/fiasco/lib/types.h index 16d8028c..02e40a90 100644 --- a/converter/other/fiasco/lib/types.h +++ b/converter/other/fiasco/lib/types.h @@ -3,8 +3,8 @@ * * Written by: Ullrich Hafner * - * This file is part of FIASCO («F»ractal «I»mage «A»nd «S»equence «CO»dec) - * Copyright (C) 1994-2000 Ullrich Hafner <hafner@bigfoot.de> + * This file is part of FIASCO (Fractal Image And Sequence COdec) + * Copyright (C) 1994-2000 Ullrich Hafner */ /* |