diff options
Diffstat (limited to 'converter/other/fiasco')
88 files changed, 6831 insertions, 6831 deletions
diff --git a/converter/other/fiasco/binerror.c b/converter/other/fiasco/binerror.c index 9820d853..dd40dc9b 100644 --- a/converter/other/fiasco/binerror.c +++ b/converter/other/fiasco/binerror.c @@ -1,11 +1,11 @@ /* - * error.c: Error handling + * error.c: Error handling * - * Written by: Stefan Frank - * Ullrich Hafner - * - * Credits: Modelled after variable argument routines from Jef - * Poskanzer's pbmplus package. + * Written by: Stefan Frank + * Ullrich Hafner + * + * Credits: Modelled after variable argument routines from Jef + * Poskanzer's pbmplus package. * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -29,16 +29,16 @@ #include <stdio.h> #if STDC_HEADERS -# include <stdarg.h> -# define VA_START(args, lastarg) va_start(args, lastarg) +# include <stdarg.h> +# define VA_START(args, lastarg) va_start(args, lastarg) #else /* not STDC_HEADERS */ -# include <varargs.h> -# define VA_START(args, lastarg) va_start(args) +# include <varargs.h> +# define VA_START(args, lastarg) va_start(args) #endif /* not STDC_HEADERS */ #include <string.h> #if HAVE_SETJMP_H -# include <setjmp.h> +# include <setjmp.h> #endif /* HAVE_SETJMP_H */ #include "fiasco.h" @@ -46,8 +46,8 @@ /***************************************************************************** - global variables - + global variables + *****************************************************************************/ int error_line = 0; @@ -55,16 +55,16 @@ const char *error_file = NULL; /***************************************************************************** - local variables - + local variables + *****************************************************************************/ static const char *executable = "(name not initialized)"; /***************************************************************************** - public code - + public code + *****************************************************************************/ void @@ -87,12 +87,12 @@ _error (const char *format, ...) * No return value. */ { - va_list args; + va_list args; VA_START (args, format); fprintf (stderr, "%s: %s: line %d:\nError: ", - executable, error_file, error_line); + executable, error_file, error_line); vfprintf (stderr, format, args); fputc ('\n', stderr); va_end(args); @@ -109,13 +109,13 @@ _file_error (const char *filename) */ { fprintf (stderr, "%s: %s: line %d:\nError: ", - executable, error_file, error_line); + executable, error_file, error_line); perror (filename); exit (2); } -void +void _warning (const char *format, ...) /* * Issue a warning and continue execution. @@ -128,7 +128,7 @@ _warning (const char *format, ...) VA_START (args, format); fprintf (stderr, "%s: %s: line %d:\nWarning: ", - executable, error_file, error_line); + executable, error_file, error_line); vfprintf (stderr, format, args); fputc ('\n', stderr); diff --git a/converter/other/fiasco/binerror.h b/converter/other/fiasco/binerror.h index 4f313aca..b30f53e0 100644 --- a/converter/other/fiasco/binerror.h +++ b/converter/other/fiasco/binerror.h @@ -1,8 +1,8 @@ /* * error.h - * - * Written by: Stefan Frank - * Ullrich Hafner + * + * Written by: Stefan Frank + * Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -25,7 +25,7 @@ #ifdef _ERROR_C #define _EXTERN_TYPE #else -#define _EXTERN_TYPE extern +#define _EXTERN_TYPE extern #endif _EXTERN_TYPE int error_line; @@ -41,9 +41,9 @@ void _file_error (const char *filename); #if HAVE_ASSERT_H -# include <assert.h> +# include <assert.h> #else /* not HAVE_ASSERT_H */ -# define assert(exp) {if (!(exp)) error ("Assertion `" #exp " != NULL' failed.");} +# define assert(exp) {if (!(exp)) error ("Assertion `" #exp " != NULL' failed.");} #endif /* not HAVE_ASSERT_H */ #endif /* not _ERROR_H */ diff --git a/converter/other/fiasco/buttons.c b/converter/other/fiasco/buttons.c index fc54d84a..7a6c77a3 100644 --- a/converter/other/fiasco/buttons.c +++ b/converter/other/fiasco/buttons.c @@ -1,8 +1,8 @@ /* - * buttons.c: Draw MWFA player buttons in X11 window + * buttons.c: Draw MWFA player buttons in X11 window + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -23,7 +23,7 @@ #include <X11/StringDefs.h> #if STDC_HEADERS -# include <stdlib.h> +# include <stdlib.h> #endif /* not STDC_HEADERS */ #include "types.h" @@ -35,38 +35,38 @@ /***************************************************************************** - local variables - + local variables + *****************************************************************************/ static const int EVENT_MASK = (KeyPressMask | ButtonPressMask | - ButtonReleaseMask | ExposureMask); + ButtonReleaseMask | ExposureMask); /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ static void draw_progress_bar (x11_info_t *xinfo, binfo_t *binfo, unsigned n, - unsigned n_frames); + unsigned n_frames); static void draw_button (x11_info_t *xinfo, binfo_t *binfo, - buttons_t button, bool_t pressed); + buttons_t button, bool_t pressed); static void draw_control_panel (x11_info_t *xinfo, binfo_t *binfo, - unsigned n, unsigned n_frames); + unsigned n, unsigned n_frames); /***************************************************************************** - public code - + public code + *****************************************************************************/ -binfo_t * +binfo_t * init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, - unsigned buttons_height, unsigned progbar_height) + unsigned buttons_height, unsigned progbar_height) /* * Initialize a toolbar with the typical collection of video player * buttons (pause, play, record, next, etc.) in the window given by 'xinfo'. @@ -76,7 +76,7 @@ init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, * the size of the progressbar is given by 'progbar_height'. * * Return value: - * struct managing the toolbar and progressbar information + * struct managing the toolbar and progressbar information */ { XGCValues values; @@ -84,12 +84,12 @@ init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, Colormap cmap; XColor gray, dgray, lgray, red; XColor graye, dgraye, lgraye, rede; - buttons_t button; /* counter */ + buttons_t button; /* counter */ binfo_t *binfo = calloc (1, sizeof (binfo_t)); if (!binfo) error ("Out of memory."); - + binfo->width = xinfo->ximage->width; binfo->height = buttons_height; binfo->progbar_height = progbar_height; @@ -99,12 +99,12 @@ init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, * Generate sub-window for control panel */ binfo->window = XCreateSimpleWindow (xinfo->display, xinfo->window, - 0, xinfo->ximage->height, - binfo->width, binfo->height, 0, - BlackPixel (xinfo->display, - xinfo->screen), - WhitePixel (xinfo->display, - xinfo->screen)); + 0, xinfo->ximage->height, + binfo->width, binfo->height, 0, + BlackPixel (xinfo->display, + xinfo->screen), + WhitePixel (xinfo->display, + xinfo->screen)); XSelectInput(xinfo->display, binfo->window, StructureNotifyMask); XMapWindow (xinfo->display, binfo->window); do @@ -122,47 +122,47 @@ init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, XAllocNamedColor (xinfo->display, cmap, "white", &lgray, &lgraye); XAllocNamedColor (xinfo->display, cmap, "#a8a8a8", &gray, &graye); XAllocNamedColor (xinfo->display, cmap, "red", &red, &rede); - + values.foreground = BlackPixel (xinfo->display, xinfo->screen); values.background = WhitePixel (xinfo->display, xinfo->screen); binfo->gc [BLACK] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, xinfo->screen), - (GCForeground | GCBackground), &values); + RootWindow (xinfo->display, xinfo->screen), + (GCForeground | GCBackground), &values); values.foreground = BlackPixel (xinfo->display, xinfo->screen); values.background = WhitePixel (xinfo->display, xinfo->screen); values.line_width = 3; values.join_style = JoinRound; binfo->gc [THICKBLACK] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, - xinfo->screen), - (GCForeground | GCBackground - | GCLineWidth | GCJoinStyle), &values); + RootWindow (xinfo->display, + xinfo->screen), + (GCForeground | GCBackground + | GCLineWidth | GCJoinStyle), &values); values.foreground = gray.pixel; values.background = WhitePixel (xinfo->display, xinfo->screen); binfo->gc [NGRAY] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, xinfo->screen), - (GCForeground | GCBackground), &values); + RootWindow (xinfo->display, xinfo->screen), + (GCForeground | GCBackground), &values); values.foreground = lgray.pixel; values.background = WhitePixel (xinfo->display, xinfo->screen); binfo->gc [LGRAY] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, xinfo->screen), - (GCForeground | GCBackground), &values); + RootWindow (xinfo->display, xinfo->screen), + (GCForeground | GCBackground), &values); values.foreground = dgray.pixel; values.background = WhitePixel (xinfo->display, xinfo->screen); binfo->gc [DGRAY] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, xinfo->screen), - (GCForeground | GCBackground), &values); + RootWindow (xinfo->display, xinfo->screen), + (GCForeground | GCBackground), &values); values.foreground = red.pixel; values.background = WhitePixel (xinfo->display, xinfo->screen); binfo->gc [RED] = XCreateGC (xinfo->display, - RootWindow (xinfo->display, xinfo->screen), - (GCForeground | GCBackground), &values); + RootWindow (xinfo->display, xinfo->screen), + (GCForeground | GCBackground), &values); for (button = 0; button < NO_BUTTON; button++) binfo->pressed [button] = NO; - draw_control_panel (xinfo, binfo, n, n_frames); - + draw_control_panel (xinfo, binfo, n, n_frames); + return binfo; } @@ -176,11 +176,11 @@ wait_for_input (x11_info_t *xinfo) * No return value. * * Side effect: - * program is terminated after key press or mouse click. + * program is terminated after key press or mouse click. */ { bool_t leave_loop = NO; - + XSelectInput (xinfo->display, xinfo->window, EVENT_MASK); while (!leave_loop) @@ -190,13 +190,13 @@ wait_for_input (x11_info_t *xinfo) XMaskEvent (xinfo->display, EVENT_MASK, &event); switch (event.type) { - case ButtonPress: - case KeyPress: - leave_loop = YES; - break; - default: - display_image (0, 0, xinfo); - break; + case ButtonPress: + case KeyPress: + leave_loop = YES; + break; + default: + display_image (0, 0, xinfo); + break; } } } @@ -214,17 +214,17 @@ check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n, unsigned n_frames) * No return values. * * Side effects: - * status of buttons (binfo->pressed [button]) is changed accordingly. + * status of buttons (binfo->pressed [button]) is changed accordingly. */ { bool_t leave_eventloop; leave_eventloop = (!binfo->pressed [PAUSE_BUTTON] - && binfo->pressed [PLAY_BUTTON]) - || (!binfo->pressed [PAUSE_BUTTON] - && binfo->record_is_rewind - && binfo->pressed [RECORD_BUTTON]) - || binfo->pressed [RECORD_BUTTON]; + && binfo->pressed [PLAY_BUTTON]) + || (!binfo->pressed [PAUSE_BUTTON] + && binfo->record_is_rewind + && binfo->pressed [RECORD_BUTTON]) + || binfo->pressed [RECORD_BUTTON]; draw_progress_bar (xinfo, binfo, n, n_frames); if (binfo->pressed [PAUSE_BUTTON] && binfo->pressed [PLAY_BUTTON]) @@ -253,48 +253,48 @@ check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n, unsigned n_frames) XEvent event; int button; bool_t wait_release = NO; - - + + if (XCheckMaskEvent (xinfo->display, EVENT_MASK, &event)) { - switch (event.type) - { - case ButtonPress: - wait_release = NO; - if (!(binfo->pressed [RECORD_BUTTON] && - !binfo->record_is_rewind)) - for (button = 0; button < NO_BUTTON; button++) - { - int x0, y0, x1, y1; /* button coordinates */ - - x0 = button * (binfo->width / NO_BUTTON); - y0 = binfo->progbar_height; - x1 = x0 + binfo->width / NO_BUTTON; - y1 = y0 + binfo->height - binfo->progbar_height - 1; - if (event.xbutton.x > x0 && event.xbutton.x < x1 - && event.xbutton.y > y0 && event.xbutton.y < y1) - { - draw_button (xinfo, binfo, button, - !binfo->pressed [button]); - wait_release = YES; - break; - } - } - break; - case ButtonRelease: - wait_release = NO; - break; - default: - wait_release = NO; - draw_control_panel (xinfo, binfo, n, n_frames); - display_image (0, 0, xinfo); - break; - } - leave_eventloop = !wait_release - && (binfo->pressed [PLAY_BUTTON] - || binfo->pressed [STOP_BUTTON] - || binfo->pressed [RECORD_BUTTON] - || binfo->pressed [QUIT_BUTTON]); + switch (event.type) + { + case ButtonPress: + wait_release = NO; + if (!(binfo->pressed [RECORD_BUTTON] && + !binfo->record_is_rewind)) + for (button = 0; button < NO_BUTTON; button++) + { + int x0, y0, x1, y1; /* button coordinates */ + + x0 = button * (binfo->width / NO_BUTTON); + y0 = binfo->progbar_height; + x1 = x0 + binfo->width / NO_BUTTON; + y1 = y0 + binfo->height - binfo->progbar_height - 1; + if (event.xbutton.x > x0 && event.xbutton.x < x1 + && event.xbutton.y > y0 && event.xbutton.y < y1) + { + draw_button (xinfo, binfo, button, + !binfo->pressed [button]); + wait_release = YES; + break; + } + } + break; + case ButtonRelease: + wait_release = NO; + break; + default: + wait_release = NO; + draw_control_panel (xinfo, binfo, n, n_frames); + display_image (0, 0, xinfo); + break; + } + leave_eventloop = !wait_release + && (binfo->pressed [PLAY_BUTTON] + || binfo->pressed [STOP_BUTTON] + || binfo->pressed [RECORD_BUTTON] + || binfo->pressed [QUIT_BUTTON]); } } while (!leave_eventloop); @@ -308,13 +308,13 @@ check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n, unsigned n_frames) /***************************************************************************** - private code - + private code + *****************************************************************************/ static void draw_control_panel (x11_info_t *xinfo, binfo_t *binfo, - unsigned n, unsigned n_frames) + unsigned n, unsigned n_frames) /* * Draw control panel 'binfo' with all buttons and progressbar in * the given 'window'. @@ -325,9 +325,9 @@ draw_control_panel (x11_info_t *xinfo, binfo_t *binfo, */ { buttons_t button; - + XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY], - 0, 0, binfo->width, binfo->height); + 0, 0, binfo->width, binfo->height); draw_progress_bar (xinfo, binfo, n, n_frames); for (button = 0; button < NO_BUTTON; button++) draw_button (xinfo, binfo, button, binfo->pressed [button]); @@ -335,7 +335,7 @@ draw_control_panel (x11_info_t *xinfo, binfo_t *binfo, static void draw_progress_bar (x11_info_t *xinfo, binfo_t *binfo, unsigned n, - unsigned n_frames) + unsigned n_frames) /* * Draw progressbar of control panel 'binfo' in the given 'window'. * 'n' gives the current frame, whereas 'n_frames' is the total number of @@ -346,32 +346,32 @@ draw_progress_bar (x11_info_t *xinfo, binfo_t *binfo, unsigned n, { unsigned x, y, width, height; - x = 2; - y = 1; + x = 2; + y = 1; width = binfo->width - 5; height = binfo->progbar_height - 3; - + XDrawLine (xinfo->display, binfo->window, binfo->gc [DGRAY], - x, y, x + width, y); + x, y, x + width, y); XDrawLine (xinfo->display, binfo->window, binfo->gc [DGRAY], - x, y, x, y + height - 1); + x, y, x, y + height - 1); XDrawLine (xinfo->display, binfo->window, binfo->gc [LGRAY], - x + width, y + 1, x + width, y + height); + x + width, y + 1, x + width, y + height); XDrawLine (xinfo->display, binfo->window, binfo->gc [LGRAY], - x, y + height, x + width, y + height); + x, y + height, x + width, y + height); x++; y++; width -= 2; height -= 2; XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY], - x, y, width, height); + x, y, width, height); XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], - x + n * max (1, width / n_frames), y, - max (1, width / n_frames), height); + x + n * max (1, width / n_frames), y, + max (1, width / n_frames), height); } static void draw_button (x11_info_t *xinfo, binfo_t *binfo, - buttons_t button, bool_t pressed) + buttons_t button, bool_t pressed) /* * Draw 'button' of control panel 'binfo' in the given 'window'. * 'pressed' indicates whether the button is pressed or not. @@ -379,17 +379,17 @@ draw_button (x11_info_t *xinfo, binfo_t *binfo, * No return value. */ { - grayscale_t top, bottom; /* index of GC */ - unsigned x, y, width, height; /* coordinates of button */ - - x = button * (binfo->width / NO_BUTTON); - y = binfo->progbar_height; + grayscale_t top, bottom; /* index of GC */ + unsigned x, y, width, height; /* coordinates of button */ + + x = button * (binfo->width / NO_BUTTON); + y = binfo->progbar_height; width = binfo->width / NO_BUTTON; height = binfo->height - binfo->progbar_height - 1; - + if (width < 4 || height < 4) return; - + if (pressed) { top = DGRAY; @@ -401,108 +401,108 @@ draw_button (x11_info_t *xinfo, binfo_t *binfo, bottom = DGRAY; } - x += 2; + x += 2; width -= 4; - + XDrawLine (xinfo->display, binfo->window, binfo->gc [top], - x, y, x + width, y); + x, y, x + width, y); XDrawLine (xinfo->display, binfo->window, binfo->gc [top], - x, y, x, y + height - 1); + x, y, x, y + height - 1); XDrawLine (xinfo->display, binfo->window, binfo->gc [bottom], - x + width, y + 1, x + width, y + height); + x + width, y + 1, x + width, y + height); XDrawLine (xinfo->display, binfo->window, binfo->gc [bottom], - x, y + height, x + width, y + height); + x, y + height, x + width, y + height); x++; y++; width -= 2; height -= 2; XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY], - x, y, width, height); + x, y, width, height); switch (button) { case STOP_BUTTON: - XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], - x + width / 2 - 6, y + height / 2 - 4, 11, 11); - if (pressed && !binfo->pressed [STOP_BUTTON]) - { - draw_button (xinfo, binfo, PLAY_BUTTON, NO); - draw_button (xinfo, binfo, PAUSE_BUTTON, NO); - draw_button (xinfo, binfo, RECORD_BUTTON, NO); - } - break; + XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], + x + width / 2 - 6, y + height / 2 - 4, 11, 11); + if (pressed && !binfo->pressed [STOP_BUTTON]) + { + draw_button (xinfo, binfo, PLAY_BUTTON, NO); + draw_button (xinfo, binfo, PAUSE_BUTTON, NO); + draw_button (xinfo, binfo, RECORD_BUTTON, NO); + } + break; case PAUSE_BUTTON: - XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], - x + width / 2 - 6, y + height / 2 - 4, 5, 11); - XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], - x + width / 2 + 1, y + height / 2 - 4, 5, 11); - break; + XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], + x + width / 2 - 6, y + height / 2 - 4, 5, 11); + XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], + x + width / 2 + 1, y + height / 2 - 4, 5, 11); + break; case PLAY_BUTTON: - { - XPoint triangle [3]; - - triangle [0].x = x + width / 2 - 5; - triangle [0].y = y + height / 2 - 5; - triangle [1].x = 10; - triangle [1].y = 6; - triangle [2].x = -10; - triangle [2].y = 6; - - XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], - triangle, 3, Convex, CoordModePrevious); - if (pressed && !binfo->pressed [PLAY_BUTTON] - && binfo->pressed [RECORD_BUTTON]) - draw_button (xinfo, binfo, RECORD_BUTTON, NO); - } - break; + { + XPoint triangle [3]; + + triangle [0].x = x + width / 2 - 5; + triangle [0].y = y + height / 2 - 5; + triangle [1].x = 10; + triangle [1].y = 6; + triangle [2].x = -10; + triangle [2].y = 6; + + XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], + triangle, 3, Convex, CoordModePrevious); + if (pressed && !binfo->pressed [PLAY_BUTTON] + && binfo->pressed [RECORD_BUTTON]) + draw_button (xinfo, binfo, RECORD_BUTTON, NO); + } + break; case RECORD_BUTTON: - if (!binfo->record_is_rewind) - { - XFillArc (xinfo->display, binfo->window, binfo->gc [RED], - x + width / 2 - 5, y + height / 2 - 5, 11, 11, 0, - 360 * 64); - if (pressed && !binfo->pressed [RECORD_BUTTON]) - { - draw_button (xinfo, binfo, STOP_BUTTON, YES); - draw_button (xinfo, binfo, PLAY_BUTTON, NO); - draw_button (xinfo, binfo, PAUSE_BUTTON, NO); - } - } - else - { - XPoint triangle [3]; - - triangle [0].x = x + width / 2 + 5; - triangle [0].y = y + height / 2 - 5; - triangle [1].x = -10; - triangle [1].y = 6; - triangle [2].x = 10; - triangle [2].y = 6; - - XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], - triangle, 3, Convex, CoordModePrevious); - if (pressed && !binfo->pressed [RECORD_BUTTON] - && binfo->pressed [PLAY_BUTTON]) - draw_button (xinfo, binfo, PLAY_BUTTON, NO); - } - break; + if (!binfo->record_is_rewind) + { + XFillArc (xinfo->display, binfo->window, binfo->gc [RED], + x + width / 2 - 5, y + height / 2 - 5, 11, 11, 0, + 360 * 64); + if (pressed && !binfo->pressed [RECORD_BUTTON]) + { + draw_button (xinfo, binfo, STOP_BUTTON, YES); + draw_button (xinfo, binfo, PLAY_BUTTON, NO); + draw_button (xinfo, binfo, PAUSE_BUTTON, NO); + } + } + else + { + XPoint triangle [3]; + + triangle [0].x = x + width / 2 + 5; + triangle [0].y = y + height / 2 - 5; + triangle [1].x = -10; + triangle [1].y = 6; + triangle [2].x = 10; + triangle [2].y = 6; + + XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], + triangle, 3, Convex, CoordModePrevious); + if (pressed && !binfo->pressed [RECORD_BUTTON] + && binfo->pressed [PLAY_BUTTON]) + draw_button (xinfo, binfo, PLAY_BUTTON, NO); + } + break; case QUIT_BUTTON: - { - XPoint triangle [3]; - - triangle [0].x = x + width / 2 - 6; - triangle [0].y = y + height / 2 + 2; - triangle [1].x = 6; - triangle [1].y = -7; - triangle [2].x = 6; - triangle [2].y = 7; - - XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], - triangle, 3, Convex, CoordModePrevious); - XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], - x + width / 2 - 5, y + height / 2 + 4, 11, 3); - } - break; + { + XPoint triangle [3]; + + triangle [0].x = x + width / 2 - 6; + triangle [0].y = y + height / 2 + 2; + triangle [1].x = 6; + triangle [1].y = -7; + triangle [2].x = 6; + triangle [2].y = 7; + + XFillPolygon (xinfo->display, binfo->window, binfo->gc [BLACK], + triangle, 3, Convex, CoordModePrevious); + XFillRectangle (xinfo->display, binfo->window, binfo->gc [BLACK], + x + width / 2 - 5, y + height / 2 + 4, 11, 3); + } + break; default: - break; + break; } binfo->pressed [button] = pressed; } diff --git a/converter/other/fiasco/buttons.h b/converter/other/fiasco/buttons.h index 079715f5..19c4935e 100644 --- a/converter/other/fiasco/buttons.h +++ b/converter/other/fiasco/buttons.h @@ -1,8 +1,8 @@ /* * buttons.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -20,15 +20,15 @@ #ifndef X_DISPLAY_MISSING typedef enum grayscale_e {BLACK, NGRAY, LGRAY, DGRAY, RED, - THICKBLACK, NO_GC} grayscale_t; + THICKBLACK, NO_GC} grayscale_t; typedef enum buttons_e {STOP_BUTTON, PLAY_BUTTON, PAUSE_BUTTON, RECORD_BUTTON, - QUIT_BUTTON, NO_BUTTON} buttons_t; + QUIT_BUTTON, NO_BUTTON} buttons_t; typedef struct buttoninfo { Window window; bool_t pressed [NO_BUTTON]; - GC gc [NO_GC]; + GC gc [NO_GC]; unsigned width; unsigned height; unsigned progbar_height; @@ -37,12 +37,12 @@ typedef struct buttoninfo void check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n, - unsigned n_frames); + unsigned n_frames); void wait_for_input (x11_info_t *xinfo); -binfo_t * +binfo_t * init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, - unsigned buttons_height, unsigned progbar_height); + unsigned buttons_height, unsigned progbar_height); #endif /* not X_DISPLAY_MISSING */ diff --git a/converter/other/fiasco/codec/approx.c b/converter/other/fiasco/codec/approx.c index d8fefcaa..a3f6523d 100644 --- a/converter/other/fiasco/codec/approx.c +++ b/converter/other/fiasco/codec/approx.c @@ -2,7 +2,7 @@ * approx.c: Approximation of range images with matching pursuit * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -35,7 +35,7 @@ /***************************************************************************** local variables - + *****************************************************************************/ typedef struct mp @@ -53,13 +53,13 @@ typedef struct mp /***************************************************************************** prototypes - + *****************************************************************************/ static void orthogonalize (unsigned index, unsigned n, unsigned level, real_t min_norm, const word_t *domain_blocks, const coding_t *c); -static void +static void matching_pursuit (mp_t *mp, bool_t full_search, real_t price, unsigned max_edges, int y_state, const range_t *range, const domain_pool_t *domain_pool, const coeff_t *coeff, @@ -68,14 +68,14 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, /***************************************************************************** public code - + *****************************************************************************/ -real_t +real_t approximate_range (real_t max_costs, real_t price, int max_edges, int y_state, range_t *range, domain_pool_t *domain_pool, coeff_t *coeff, const wfa_t *wfa, const coding_t *c) { -/*---------------------------------------------------------------------------- +/*---------------------------------------------------------------------------- Approximate image block 'range' by matching pursuit. This functions calls the matching pursuit algorithm several times (with different parameters) in order to find the best approximation. Refer to function @@ -99,15 +99,15 @@ approximate_range (real_t max_costs, real_t price, int max_edges, */ if (c->options.second_domain_block) { mp_t tmp_mp; - + tmp_mp = mp; /* initial value */ tmp_mp.exclude[0] = tmp_mp.indices [0]; tmp_mp.exclude[1] = NO_EDGE; - + matching_pursuit(&tmp_mp, c->options.full_search, price, max_edges, y_state, range, domain_pool, coeff, wfa, c); - if (tmp_mp.costs < mp.costs) /* success */ + if (tmp_mp.costs < mp.costs) /* success */ mp = tmp_mp; } @@ -123,23 +123,23 @@ approximate_range (real_t max_costs, real_t price, int max_edges, tmp_mp = mp; /* initial value */ iteration = -1; /* initial value */ - + do { int i; - + ++iteration; tmp_mp.exclude[iteration] = NO_EDGE; - + for (i = 0; isdomain(tmp_mp.indices[i]); ++i) { if (tmp_mp.weight [i] == 0) { tmp_mp.exclude[iteration] = tmp_mp.indices [i]; break; } - } + } if (isdomain (tmp_mp.exclude [iteration])) { /* try again */ tmp_mp.exclude [iteration + 1] = NO_EDGE; - + matching_pursuit(&tmp_mp, c->options.full_search, price, max_edges, y_state, range, domain_pool, coeff, wfa, c); @@ -165,25 +165,25 @@ approximate_range (real_t max_costs, real_t price, int max_edges, do { int i; - + ++iteration; tmp_mp.exclude[iteration] = NO_EDGE; - + for (i = 0; isdomain (tmp_mp.indices [i]); ++i) { rpf_t * const rpf = tmp_mp.indices [i] ? coeff->rpf : coeff->dc_rpf; - + if (tmp_mp.weight [i] == btor (rtob (200, rpf), rpf) || tmp_mp.weight [i] == btor (rtob (-200, rpf), rpf)) { tmp_mp.exclude [iteration] = tmp_mp.indices [i]; break; } } - + if (isdomain(tmp_mp.exclude[iteration])) { /* try again */ tmp_mp.exclude[iteration + 1] = NO_EDGE; - + matching_pursuit(&tmp_mp, c->options.full_search, price, max_edges, y_state, range, domain_pool, coeff, wfa, c); @@ -226,10 +226,10 @@ approximate_range (real_t max_costs, real_t price, int max_edges, range->level, y_state, wfa, domain_pool->model); coeff->update (mp.weight, mp.into, range->level, coeff); - + Free(domain_blocks); } - + for (edge = 0; isedge (mp.indices [edge]); ++edge) { range->into [edge] = mp.into [edge]; range->weight [edge] = mp.weight [edge]; @@ -242,7 +242,7 @@ approximate_range (real_t max_costs, real_t price, int max_edges, range->into [0] = NO_EDGE; mp.costs = MAXCOSTS; } - + return mp.costs; } @@ -251,25 +251,25 @@ approximate_range (real_t max_costs, real_t price, int max_edges, /***************************************************************************** local variables - + *****************************************************************************/ -static real_t norm_ortho_vector [MAXSTATES]; +static real_t norm_ortho_vector [MAXSTATES]; /* * Square-norm of the i-th vector of the orthogonal basis (OB) * ||o_i||^2; i = 0, ... ,n */ static real_t ip_image_ortho_vector [MAXEDGES]; -/* - * Inner product between the i-th vector of the OB and the given range: - * <b, o_i>; i = 0, ... ,n +/* + * Inner product between the i-th vector of the OB and the given range: + * <b, o_i>; i = 0, ... ,n */ static real_t ip_domain_ortho_vector [MAXSTATES][MAXEDGES]; -/* - * Inner product between the i-th vector of the OB and the image of domain j: - * <s_j, o_i>; j = 0, ... , wfa->states; i = 0, ... ,n, +/* + * Inner product between the i-th vector of the OB and the image of domain j: + * <s_j, o_i>; j = 0, ... , wfa->states; i = 0, ... ,n, */ -static real_t rem_denominator [MAXSTATES]; +static real_t rem_denominator [MAXSTATES]; static real_t rem_numerator [MAXSTATES]; /* * At step n of the orthogonalization the comparative value @@ -280,7 +280,7 @@ static real_t rem_numerator [MAXSTATES]; * the constant (remaining) parts of every domain are * stored in 'rem_numerator' and 'rem_denominator' separately */ -static bool_t used [MAXSTATES]; +static bool_t used [MAXSTATES]; /* * Shows whether a domain image was already used in a * linear combination (YES) or not (NO) @@ -289,10 +289,10 @@ static bool_t used [MAXSTATES]; /***************************************************************************** private code - + *****************************************************************************/ -static void +static void matching_pursuit (mp_t *mp, bool_t full_search, real_t price, unsigned max_edges, int y_state, const range_t *range, const domain_pool_t *domain_pool, const coeff_t *coeff, @@ -313,7 +313,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, * elements in the linear combination is limited by 'max_edges'. In * 'mp', vectors may be specified which should be excluded during the * approximation. - * + * * No return value. * * Side effects: @@ -329,7 +329,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, const real_t min_norm = 2e-3; /* lower bound of norm */ unsigned best_n = 0; unsigned size = size_of_level (range->level); - + /* * Initialize domain pool and inner product arrays */ @@ -378,7 +378,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, + additional_bits) * price + mp->err; n = 0; - do + do { /* * Current approximation is: b = d_0 o_0 + ... + d_(n-1) o_(n-1) @@ -390,15 +390,15 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, * which has minimal costs: s_index. * (No progress is indicated by index == -1) */ - + real_t min_matrix_bits = 0; real_t min_weights_bits = 0; real_t min_error = 0; real_t min_weight [MAXEDGES]; real_t min_costs = full_search ? MAXCOSTS : mp->costs; - - for (index = -1, domain = 0; domain_blocks [domain] >= 0; domain++) - if (!used [domain]) + + for (index = -1, domain = 0; domain_blocks [domain] >= 0; domain++) + if (!used [domain]) { real_t matrix_bits, weights_bits; /* @@ -413,7 +413,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, word_t states [MAXEDGES + 1]; real_t weights [MAXEDGES + 1]; unsigned i, k; - + for (i = 0, k = 0; k < n; k++) if (mp->weight [k] != 0) { @@ -477,7 +477,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, f[k] = ip_image_ortho_vector[k] / norm_ortho_vector[k]; v [k] = mp->indices [k]; } - + for (l = n; l >= 0; --l) { rpf_t * const rpf = domain_blocks[v[l]] ? coeff->rpf : coeff->dc_rpf; @@ -488,13 +488,13 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, { real_t const fl = f[l]; - + for (k = 0; k < l; ++k) { f[k] -= fl * ip_domain_ortho_vector[v[l]][k] / norm_ortho_vector[k]; } } - } + } /* * Compute the number of output bits of the linear @@ -507,7 +507,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, word_t states [MAXEDGES + 1]; real_t weights [MAXEDGES + 1]; int i; - + for (i = 0, k = 0; k <= n; k++) if (f [k] != 0) { @@ -525,10 +525,10 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, range->level, y_state, wfa, domain_pool->model); } - + /* * To compute the approximation error, the corresponding - * linear factors of the linear combination + * linear factors of the linear combination * b = r_0 o_0 + ... + r_(n-1) o_(n-1) + r_n o_'domain' * with orthogonal vectors must be computed with following * formula: @@ -546,7 +546,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, a = get_ip_state_state (domain_blocks [v [l]], domain_blocks [domain], range->level, c); - for (k = 0; k < n; k++) + for (k = 0; k < n; k++) a -= ip_domain_ortho_vector [v [l]][k] / norm_ortho_vector [k] * ip_domain_ortho_vector [domain][k]; @@ -554,7 +554,7 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, } norm_ortho_vector [n] = rem_denominator [domain]; ip_image_ortho_vector [n] = rem_numerator [domain]; - + for (k = 0; k <= n; k++) for (l = k + 1; (unsigned) l <= n; l++) r [k] += ip_domain_ortho_vector [v [l]][k] * r [l] @@ -586,40 +586,40 @@ matching_pursuit (mp_t *mp, bool_t full_search, real_t price, } } } - + if (index >= 0) /* found a better approximation */ { if (min_costs < mp->costs) { unsigned k; - + mp->costs = min_costs; mp->err = min_error; mp->matrix_bits = min_matrix_bits; mp->weights_bits = min_weights_bits; - + for (k = 0; k <= n; k++) mp->weight [k] = min_weight [k]; best_n = n + 1; } - + mp->indices [n] = index; mp->into [n] = domain_blocks [index]; used [index] = YES; - /* - * Gram-Schmidt orthogonalization step n + /* + * Gram-Schmidt orthogonalization step n */ orthogonalize (index, n, range->level, min_norm, domain_blocks, c); n++; - } - } + } + } while (n < max_edges && index >= 0); mp->indices [best_n] = NO_EDGE; - + mp->costs = (mp->matrix_bits + mp->weights_bits + additional_bits) * price + mp->err; @@ -641,31 +641,31 @@ orthogonalize (unsigned index, unsigned n, unsigned level, real_t min_norm, * * Side effects: * The remainder values (numerator and denominator) of - * all 'domain_blocks' are updated. + * all 'domain_blocks' are updated. */ { unsigned domain; - + ip_image_ortho_vector [n] = rem_numerator [index]; norm_ortho_vector [n] = rem_denominator [index]; /* - * Compute inner products between all domain images and + * Compute inner products between all domain images and * vector n of the orthogonal basis: - * for (i = 0, ... , wfa->states) + * for (i = 0, ... , wfa->states) * <s_i, o_n> := <s_i, v_n> - * \sum (k = 0, ... , n - 1){ <v_n, o_k> <s_i, o_k> / ||o_k||^2} * Moreover the denominator and numerator parts of the comparative * value are updated. */ - for (domain = 0; domain_blocks [domain] >= 0; domain++) - if (!used [domain]) + for (domain = 0; domain_blocks [domain] >= 0; domain++) + if (!used [domain]) { unsigned k; real_t tmp = get_ip_state_state (domain_blocks [index], domain_blocks [domain], level, c); - - for (k = 0; k < n; k++) + + for (k = 0; k < n; k++) tmp -= ip_domain_ortho_vector [domain][k] / norm_ortho_vector [k] * ip_domain_ortho_vector [index][k]; ip_domain_ortho_vector [domain][n] = tmp; @@ -677,8 +677,8 @@ orthogonalize (unsigned index, unsigned n, unsigned level, real_t min_norm, /* * Exclude vectors with small denominator */ - if (!used [domain]) - if (rem_denominator [domain] / size_of_level (level) < min_norm) + if (!used [domain]) + if (rem_denominator [domain] / size_of_level (level) < min_norm) used [domain] = YES; } } diff --git a/converter/other/fiasco/codec/approx.h b/converter/other/fiasco/codec/approx.h index 42f1458a..cce27eb6 100644 --- a/converter/other/fiasco/codec/approx.h +++ b/converter/other/fiasco/codec/approx.h @@ -1,8 +1,8 @@ /* * approx.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -21,10 +21,10 @@ #include "cwfa.h" #include "domain-pool.h" -real_t +real_t approximate_range (real_t max_costs, real_t price, int max_edges, - int y_state, range_t *range, domain_pool_t *domain_pool, - coeff_t *coeff, const wfa_t *wfa, const coding_t *c); + int y_state, range_t *range, domain_pool_t *domain_pool, + coeff_t *coeff, const wfa_t *wfa, const coding_t *c); #endif /* not _APPROX_H */ diff --git a/converter/other/fiasco/codec/bintree.c b/converter/other/fiasco/codec/bintree.c index b050ab63..ca828fb2 100644 --- a/converter/other/fiasco/codec/bintree.c +++ b/converter/other/fiasco/codec/bintree.c @@ -1,8 +1,8 @@ /* - * bintree.c: Bintree model of WFA tree + * bintree.c: Bintree model of WFA tree + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -28,8 +28,8 @@ /***************************************************************************** - public code - + public code + *****************************************************************************/ void @@ -40,7 +40,7 @@ tree_update (bool_t child, unsigned level, tree_t *model) * No return value. * * Side effects: - * tree model is changed. + * tree model is changed. */ { if (!child) @@ -59,7 +59,7 @@ tree_bits (bool_t child, unsigned level, const tree_t *model) * For each 'level' a different context is used. * * Return value: - * # bits + * # bits */ { real_t prob = model->counts [level] / (real_t) model->total [level]; @@ -80,13 +80,13 @@ init_tree_model (tree_t *tree_model) { unsigned level; unsigned counts_0 [MAXLEVEL] = {20, 17, 15, 10, 5, 4, 3, - 2, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1 , 1, 1, 1}; + 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1 , 1, 1, 1}; unsigned counts_1 [MAXLEVEL] = {1 , 1, 1, 1, 1, 1, 1, - 1, 1, 2, 3, 5, 10, 15, 20, - 25, 30, 35, 60, 60, 60, 60}; - - for (level = 0; level < MAXLEVEL ; level++) + 1, 1, 2, 3, 5, 10, 15, 20, + 25, 30, 35, 60, 60, 60, 60}; + + for (level = 0; level < MAXLEVEL ; level++) { tree_model->counts [level] = counts_1 [level]; tree_model->total [level] = counts_0 [level] + counts_1 [level]; diff --git a/converter/other/fiasco/codec/bintree.h b/converter/other/fiasco/codec/bintree.h index 3dc88ac1..c68b2e7b 100644 --- a/converter/other/fiasco/codec/bintree.h +++ b/converter/other/fiasco/codec/bintree.h @@ -1,8 +1,8 @@ /* * bintree.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -28,8 +28,8 @@ typedef struct tree * which indicate whether there exists a tree edge or not. */ { - unsigned counts [MAXLEVEL]; /* # NO_RANGE symbols at given level */ - unsigned total [MAXLEVEL]; /* total number of symbols at '' */ + unsigned counts [MAXLEVEL]; /* # NO_RANGE symbols at given level */ + unsigned total [MAXLEVEL]; /* total number of symbols at '' */ } tree_t; real_t diff --git a/converter/other/fiasco/codec/coder.h b/converter/other/fiasco/codec/coder.h index 2fe81d81..4e8e400d 100644 --- a/converter/other/fiasco/codec/coder.h +++ b/converter/other/fiasco/codec/coder.h @@ -1,8 +1,8 @@ /* * coder.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/codec/coeff.c b/converter/other/fiasco/codec/coeff.c index 6d33bad5..3a5a6a0a 100644 --- a/converter/other/fiasco/codec/coeff.c +++ b/converter/other/fiasco/codec/coeff.c @@ -1,8 +1,8 @@ /* - * coeff.c: Matching pursuit coefficients probability model + * coeff.c: Matching pursuit coefficients probability model + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -28,9 +28,9 @@ /* * Coefficient model interface: * Implementing the coefficients model interface requires the - * following steps: + * following steps: * - Add a constructor that initializes the coeff_t structure - * - Allocate new model with default_alloc() + * - Allocate new model with default_alloc() * - Fill the c_array_t coeff_models[] array with constructor and name * - Write code for methods bits() and update() * - Either use default functions for remaining methods or override them @@ -38,21 +38,21 @@ */ /***************************************************************************** - uniform distribution coefficients model + uniform distribution coefficients model *****************************************************************************/ static coeff_t * alloc_uniform_coeff_model (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level); + unsigned min_level, unsigned max_level); static void uniform_update (const real_t *used_coeff, const word_t *used_states, - unsigned level, coeff_t *coeff); + unsigned level, coeff_t *coeff); static real_t uniform_bits (const real_t *used_coeff, const word_t *used_states, - unsigned level, const coeff_t *coeff); + unsigned level, const coeff_t *coeff); /***************************************************************************** - default functions + default functions *****************************************************************************/ static void @@ -63,15 +63,15 @@ static void default_free (coeff_t *coeff); static coeff_t * default_alloc (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level); + unsigned min_level, unsigned max_level); /***************************************************************************** - adaptive arithmetic coding model + adaptive arithmetic coding model *****************************************************************************/ static coeff_t * alloc_aac_coeff_model (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level); + unsigned min_level, unsigned max_level); static void aac_model_free (void *model); static void * @@ -80,70 +80,70 @@ static void * aac_model_duplicate (const coeff_t *coeff, const void *model); static void aac_update (const real_t *used_coeff, const word_t *used_states, - unsigned level, coeff_t *coeff); + unsigned level, coeff_t *coeff); static real_t aac_bits (const real_t *used_coeff, const word_t *used_states, - unsigned level, const coeff_t *coeff); + unsigned level, const coeff_t *coeff); /***************************************************************************** - public code - + public code + *****************************************************************************/ typedef struct c_array { const char *identifier; coeff_t *(*function) (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level); + unsigned min_level, unsigned max_level); } c_array_t; c_array_t coeff_models[] = {{"adaptive", alloc_aac_coeff_model}, - {"uniform", alloc_uniform_coeff_model}, - {NULL, NULL}}; + {"uniform", alloc_uniform_coeff_model}, + {NULL, NULL}}; coeff_t * alloc_coeff_model (const char *coeff_model_name, rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level) + unsigned min_level, unsigned max_level) /* * Allocate a new coefficients model which is identified by the string * 'coeff_model_name'. 'rpf' and 'dc_rpf' define the reduced * precision formats the should be used to quantize normal and DC * components, respectively. 'min_level' and 'max_level' define the * range of range approximations. - * + * * Return value: - * pointer to the allocated coefficients model + * pointer to the allocated coefficients model * * Note: * Refer to 'coeff.h' for a short description of the member functions. */ { unsigned n; - + for (n = 0; coeff_models [n].identifier; n++) /* step through all id's */ - if (strcaseeq (coeff_models [n].identifier, coeff_model_name)) - return coeff_models [n].function (rpf, dc_rpf, min_level, max_level); + if (strcaseeq (coeff_models [n].identifier, coeff_model_name)) + return coeff_models [n].function (rpf, dc_rpf, min_level, max_level); warning ("Can't initialize coefficients model '%s'. " - "Using default value '%s'.", - coeff_model_name, coeff_models [0].identifier); + "Using default value '%s'.", + coeff_model_name, coeff_models [0].identifier); return coeff_models [0].function (rpf, dc_rpf, min_level, max_level); } /***************************************************************************** - private code - + private code + *****************************************************************************/ /***************************************************************************** - uniform distribution coefficients model + uniform distribution coefficients model *****************************************************************************/ static coeff_t * alloc_uniform_coeff_model (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level) + unsigned min_level, unsigned max_level) /* * Underlying probability model: uniform distribution. * I.e. each coefficient is written as such with @@ -154,21 +154,21 @@ alloc_uniform_coeff_model (rpf_t *rpf, rpf_t *dc_rpf, coeff->bits = uniform_bits; coeff->update = uniform_update; - + return coeff; } static real_t uniform_bits (const real_t *used_coeff, const word_t *used_states, - unsigned level, const coeff_t *coeff) + unsigned level, const coeff_t *coeff) { unsigned edge; - real_t bits = 0; /* #bits to store coefficients */ - + real_t bits = 0; /* #bits to store coefficients */ + for (edge = 0; isedge (used_states [edge]); edge++) { rpf_t *rpf = used_states [edge] ? coeff->rpf : coeff->dc_rpf; - + bits += rpf->mantissa_bits + 1; } @@ -177,13 +177,13 @@ uniform_bits (const real_t *used_coeff, const word_t *used_states, static void uniform_update (const real_t *used_coeff, const word_t *used_states, - unsigned level, coeff_t *coeff) + unsigned level, coeff_t *coeff) { - return; /* nothing to do */ + return; /* nothing to do */ } /***************************************************************************** - adaptive arithmetic coding model + adaptive arithmetic coding model *****************************************************************************/ typedef struct aac_model @@ -194,74 +194,74 @@ typedef struct aac_model static coeff_t * alloc_aac_coeff_model (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level) + unsigned min_level, unsigned max_level) /* * Underlying probability model: adaptive arithmetic coding using * the level of a range as context. */ { coeff_t *coeff = default_alloc (rpf, dc_rpf, min_level, max_level); - + coeff->bits = aac_bits; coeff->update = aac_update; coeff->model_free = aac_model_free; coeff->model_duplicate = aac_model_duplicate; - coeff->model = aac_model_alloc (coeff); - + coeff->model = aac_model_alloc (coeff); + return coeff; } static real_t aac_bits (const real_t *used_coeff, const word_t *used_states, - unsigned level, const coeff_t *coeff) + unsigned level, const coeff_t *coeff) { - real_t bits = 0; /* # bits to store coefficients */ - unsigned edge; - int state; + real_t bits = 0; /* # bits to store coefficients */ + unsigned edge; + int state; word_t *counts; aac_model_t *model = (aac_model_t *) coeff->model; counts = model->counts - + (1 << (1 + coeff->dc_rpf->mantissa_bits)) - + ((level - coeff->min_level) - * (1 << (1 + coeff->rpf->mantissa_bits))); - + + (1 << (1 + coeff->dc_rpf->mantissa_bits)) + + ((level - coeff->min_level) + * (1 << (1 + coeff->rpf->mantissa_bits))); + for (edge = 0; isedge (state = used_states [edge]); edge++) if (state) - bits -= log2 (counts [rtob (used_coeff [edge], coeff->rpf)] - / (real_t) model->totals [level - - coeff->min_level + 1]); + bits -= log2 (counts [rtob (used_coeff [edge], coeff->rpf)] + / (real_t) model->totals [level + - coeff->min_level + 1]); else - bits -= log2 (model->counts [rtob (used_coeff [edge], coeff->dc_rpf)] - / (real_t) model->totals [0]); - + bits -= log2 (model->counts [rtob (used_coeff [edge], coeff->dc_rpf)] + / (real_t) model->totals [0]); + return bits; } static void aac_update (const real_t *used_coeff, const word_t *used_states, - unsigned level, coeff_t *coeff) + unsigned level, coeff_t *coeff) { - unsigned edge; - int state; + unsigned edge; + int state; word_t *counts; aac_model_t *model = (aac_model_t *) coeff->model; counts = model->counts - + (1 << (1 + coeff->dc_rpf->mantissa_bits)) - + ((level - coeff->min_level) - * (1 << (1 + coeff->rpf->mantissa_bits))); + + (1 << (1 + coeff->dc_rpf->mantissa_bits)) + + ((level - coeff->min_level) + * (1 << (1 + coeff->rpf->mantissa_bits))); for (edge = 0; isedge (state = used_states [edge]); edge++) if (state) { - counts [rtob (used_coeff [edge], coeff->rpf)]++; - model->totals [level - coeff->min_level + 1]++; + counts [rtob (used_coeff [edge], coeff->rpf)]++; + model->totals [level - coeff->min_level + 1]++; } else { - model->counts [rtob (used_coeff [edge], coeff->dc_rpf)]++; - model->totals [0]++; + model->counts [rtob (used_coeff [edge], coeff->dc_rpf)]++; + model->totals [0]++; } } @@ -272,12 +272,12 @@ aac_model_duplicate (const coeff_t *coeff, const void *model) aac_model_t *dst = aac_model_alloc (coeff); memcpy (dst->counts, src->counts, - sizeof (word_t) * ((coeff->max_level - coeff->min_level + 1) - * (1 << (1 + coeff->rpf->mantissa_bits)) - + (1 << (1 + coeff->dc_rpf->mantissa_bits)))); + sizeof (word_t) * ((coeff->max_level - coeff->min_level + 1) + * (1 << (1 + coeff->rpf->mantissa_bits)) + + (1 << (1 + coeff->dc_rpf->mantissa_bits)))); memcpy (dst->totals, src->totals, - sizeof (word_t) * (coeff->max_level - coeff->min_level + 1 + 1)); - + sizeof (word_t) * (coeff->max_level - coeff->min_level + 1 + 1)); + return dst; } @@ -285,36 +285,36 @@ static void * aac_model_alloc (const coeff_t *coeff) { aac_model_t *model; - unsigned size = (coeff->max_level - coeff->min_level + 1) - * (1 << (1 + coeff->rpf->mantissa_bits)) - + (1 << (1 + coeff->dc_rpf->mantissa_bits)); - - model = Calloc (1, sizeof (aac_model_t)); + unsigned size = (coeff->max_level - coeff->min_level + 1) + * (1 << (1 + coeff->rpf->mantissa_bits)) + + (1 << (1 + coeff->dc_rpf->mantissa_bits)); + + model = Calloc (1, sizeof (aac_model_t)); model->counts = Calloc (size, sizeof (word_t)); model->totals = Calloc (coeff->max_level - coeff->min_level + 1 + 1, - sizeof (word_t)); + sizeof (word_t)); /* * Initialize model */ { unsigned n; word_t *ptr = model->counts; - + for (n = size; n; n--) - *ptr++ = 1; + *ptr++ = 1; model->totals [0] = 1 << (1 + coeff->dc_rpf->mantissa_bits); for (n = coeff->min_level; n <= coeff->max_level; n++) - model->totals [n - coeff->min_level + 1] - = 1 << (1 + coeff->rpf->mantissa_bits); + model->totals [n - coeff->min_level + 1] + = 1 << (1 + coeff->rpf->mantissa_bits); } - + return (void *) model; } static void aac_model_free (void *model) { - aac_model_t *aac_model = (aac_model_t *) model; + aac_model_t *aac_model = (aac_model_t *) model; if (aac_model) { @@ -325,26 +325,26 @@ aac_model_free (void *model) } /***************************************************************************** - default functions + default functions *****************************************************************************/ static coeff_t * default_alloc (rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level) + unsigned min_level, unsigned max_level) { coeff_t *coeff = Calloc (1, sizeof (coeff_t)); - coeff->rpf = rpf; - coeff->dc_rpf = dc_rpf; - coeff->min_level = min_level; - coeff->max_level = max_level; - coeff->model = NULL; - coeff->bits = NULL; - coeff->update = NULL; - coeff->free = default_free; - coeff->model_free = default_model_free; + coeff->rpf = rpf; + coeff->dc_rpf = dc_rpf; + coeff->min_level = min_level; + coeff->max_level = max_level; + coeff->model = NULL; + coeff->bits = NULL; + coeff->update = NULL; + coeff->free = default_free; + coeff->model_free = default_model_free; coeff->model_duplicate = default_model_duplicate; - + return coeff; } diff --git a/converter/other/fiasco/codec/coeff.h b/converter/other/fiasco/codec/coeff.h index 6193e2ee..f22de2d7 100644 --- a/converter/other/fiasco/codec/coeff.h +++ b/converter/other/fiasco/codec/coeff.h @@ -1,8 +1,8 @@ /* * coeff.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -23,23 +23,23 @@ typedef struct coeff { - rpf_t *rpf; /* reduced precision format */ - rpf_t *dc_rpf; /* RPF of DC (state 0) component */ - unsigned min_level, max_level; /* allocate memory for [min,..,max] */ - void *model; /* generic pointer to prob. model */ + rpf_t *rpf; /* reduced precision format */ + rpf_t *dc_rpf; /* RPF of DC (state 0) component */ + unsigned min_level, max_level; /* allocate memory for [min,..,max] */ + void *model; /* generic pointer to prob. model */ real_t (*bits) (const real_t *used_coeff, const word_t *used_domains, - unsigned level, const struct coeff *coeff); + unsigned level, const struct coeff *coeff); /* * Compute bit-rate of a range approximation with coefficients given by * -1 terminated list 'used_domains'. */ void (*update) (const real_t *used_coeff, const word_t *used_domains, - unsigned level, struct coeff *coeff); + unsigned level, struct coeff *coeff); /* * Update the probability model according to the chosen approximation. * (given by the -1 terminated list 'used_domains'). */ - void (*free) (struct coeff *coeff); + void (*free) (struct coeff *coeff); /* * Discard the given coefficients struct. */ @@ -55,7 +55,7 @@ typedef struct coeff coeff_t * alloc_coeff_model (const char *coeff_model_name, rpf_t *rpf, rpf_t *dc_rpf, - unsigned min_level, unsigned max_level); + unsigned min_level, unsigned max_level); #endif /* not _COEFF_H */ diff --git a/converter/other/fiasco/codec/control.c b/converter/other/fiasco/codec/control.c index 2ea06052..0588623f 100644 --- a/converter/other/fiasco/codec/control.c +++ b/converter/other/fiasco/codec/control.c @@ -1,8 +1,8 @@ /* - * control.c: Control unit of WFA structure + * control.c: Control unit of WFA structure + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -17,7 +17,7 @@ #include "config.h" #include <string.h> - + #include "types.h" #include "macros.h" #include "error.h" @@ -30,24 +30,24 @@ /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ -static void +static void clear_or_alloc (real_t **ptr, size_t size); -static void +static void compute_images (unsigned from, unsigned to, const wfa_t *wfa, coding_t *c); /***************************************************************************** - public code - + public code + *****************************************************************************/ -void +void append_state (bool_t auxiliary_state, real_t final, unsigned level_of_state, - wfa_t *wfa, coding_t *c) + wfa_t *wfa, coding_t *c) /* * Append a 'wfa' state. If 'auxiliary_state' == YES then * allocate memory for inner products and state images. 'final' is @@ -57,13 +57,13 @@ append_state (bool_t auxiliary_state, real_t final, unsigned level_of_state, * No return value. * * Side effects: - * The WFA information are updated in structure 'wfa' - * State images are computed and inner products are cleared (in 'c') + * The WFA information are updated in structure 'wfa' + * State images are computed and inner products are cleared (in 'c') */ { wfa->final_distribution [wfa->states] = final; wfa->level_of_state [wfa->states] = level_of_state; - + if (!auxiliary_state) { unsigned level; @@ -74,63 +74,63 @@ append_state (bool_t auxiliary_state, real_t final, unsigned level_of_state, * Allocate memory for inner products and for state images */ clear_or_alloc (&c->images_of_state [wfa->states], - size_of_tree (c->options.images_level)); - + size_of_tree (c->options.images_level)); + for (level = c->options.images_level + 1; - level <= c->options.lc_max_level; level++) - clear_or_alloc (&c->ip_states_state [wfa->states][level], - wfa->states + 1); + level <= c->options.lc_max_level; level++) + clear_or_alloc (&c->ip_states_state [wfa->states][level], + wfa->states + 1); clear_or_alloc (&c->ip_images_state [wfa->states], - size_of_tree (c->products_level)); + size_of_tree (c->products_level)); /* * Compute the images of the current state at level 0,..,'imageslevel' */ - + c->images_of_state [wfa->states][0] = final; - compute_images (wfa->states, wfa->states, wfa, c); + compute_images (wfa->states, wfa->states, wfa, c); /* * Compute the inner products between the current state and the * old states 0,...,'states'-1 - */ - + */ + compute_ip_states_state (wfa->states, wfa->states, wfa, c); } else { unsigned level; - + wfa->domain_type [wfa->states] = 0; - + /* * Free the allocated memory */ if (c->images_of_state [wfa->states] != NULL) { - Free (c->images_of_state [wfa->states]); - c->images_of_state [wfa->states] = NULL; + Free (c->images_of_state [wfa->states]); + c->images_of_state [wfa->states] = NULL; } for (level = 0; level <= c->options.lc_max_level; level++) - if (c->ip_states_state [wfa->states][level]) - { - Free (c->ip_states_state [wfa->states][level]); - c->ip_states_state [wfa->states][level] = NULL; - } + if (c->ip_states_state [wfa->states][level]) + { + Free (c->ip_states_state [wfa->states][level]); + c->ip_states_state [wfa->states][level] = NULL; + } if (c->ip_images_state [wfa->states]) { - Free (c->ip_images_state [wfa->states]); - c->ip_images_state [wfa->states] = NULL; + Free (c->ip_images_state [wfa->states]); + c->ip_images_state [wfa->states] = NULL; } } - + wfa->states++; - if (wfa->states >= MAXSTATES) + if (wfa->states >= MAXSTATES) error ("Maximum number of states reached!"); -} - -void +} + +void append_basis_states (unsigned basis_states, wfa_t *wfa, coding_t *c) /* * Append the WFA basis states 0, ... , ('basis_states' - 1). @@ -138,8 +138,8 @@ append_basis_states (unsigned basis_states, wfa_t *wfa, coding_t *c) * No return value. * * Side effects: - * The WFA information are updated in structure 'wfa' - * State images and inner products are computed (in 'c') + * The WFA information are updated in structure 'wfa' + * State images and inner products are computed (in 'c') */ { unsigned level, state; @@ -151,30 +151,30 @@ append_basis_states (unsigned basis_states, wfa_t *wfa, coding_t *c) for (state = 0; state < basis_states; state++) { clear_or_alloc (&c->images_of_state [state], - size_of_tree (c->options.images_level)); + size_of_tree (c->options.images_level)); for (level = c->options.images_level + 1; - level <= c->options.lc_max_level; level++) - clear_or_alloc (&c->ip_states_state [state][level], state + 1); + level <= c->options.lc_max_level; level++) + clear_or_alloc (&c->ip_states_state [state][level], state + 1); clear_or_alloc (&c->ip_images_state [state], - size_of_tree (c->products_level)); + size_of_tree (c->products_level)); c->images_of_state [state][0] = wfa->final_distribution [state]; wfa->level_of_state [state] = -1; } - - compute_images (0, basis_states - 1, wfa, c); + + compute_images (0, basis_states - 1, wfa, c); compute_ip_states_state (0, basis_states - 1, wfa, c); wfa->states = basis_states; - - if (wfa->states >= MAXSTATES) + + if (wfa->states >= MAXSTATES) error ("Maximum number of states reached!"); -} - -void +} + +void append_transitions (unsigned state, unsigned label, const real_t *weight, - const word_t *into, wfa_t *wfa) + const word_t *into, wfa_t *wfa) /* * Append the 'wfa' transitions (given by the arrays 'weight' and 'into') * of the range ('state','label'). @@ -182,7 +182,7 @@ append_transitions (unsigned state, unsigned label, const real_t *weight, * No return value. * * Side effects: - * new 'wfa' edges are appended + * new 'wfa' edges are appended */ { unsigned edge; @@ -192,81 +192,81 @@ append_transitions (unsigned state, unsigned label, const real_t *weight, { append_edge (state, into [edge], weight [edge], label, wfa); if (into [edge] == wfa->y_state [state][label]) - wfa->y_column [state][label] = 1; + wfa->y_column [state][label] = 1; } } /***************************************************************************** - private code - + private code + *****************************************************************************/ -static void +static void compute_images (unsigned from, unsigned to, const wfa_t *wfa, coding_t *c) /* - * Computes the images of the given states 'from', ... , 'to' + * Computes the images of the given states 'from', ... , 'to' * at level 0,...,'c->imagelevel'. * Uses the fact that each state image is a linear combination of state * images, i.e. s_i := c_0 s_0 + ... + c_i s_i. */ { unsigned label, level, state; - + /* * Compute the images Phi(state) - * # level = 0 - * ## level = 1 - * #### level = 2 - * ######## level = 3 + * # level = 0 + * ## level = 1 + * #### level = 2 + * ######## level = 3 * ... * ########...## level = imageslevel */ - + for (level = 1; level <= c->options.images_level; level++) for (state = from; state <= to; state++) - for (label = 0; label < MAXLABELS; label++) - { - real_t *dst, *src; - unsigned edge; - int domain; /* current domain */ - - if (ischild (domain = wfa->tree[state][label])) - { - dst = c->images_of_state [state] + address_of_level (level) + - label * size_of_level (level - 1); - src = c->images_of_state [domain] - + address_of_level (level - 1); - memcpy (dst, src, size_of_level (level - 1) * sizeof (real_t)); - } - for (edge = 0; isedge (domain = wfa->into[state][label][edge]); - edge++) - { - unsigned n; - real_t weight = wfa->weight [state][label][edge]; - - dst = c->images_of_state [state] + address_of_level (level) + - label * size_of_level (level - 1); - src = c->images_of_state [domain] - + address_of_level (level - 1); - - for (n = size_of_level (level - 1); n; n--) - *dst++ += *src++ * weight; - } - } + for (label = 0; label < MAXLABELS; label++) + { + real_t *dst, *src; + unsigned edge; + int domain; /* current domain */ + + if (ischild (domain = wfa->tree[state][label])) + { + dst = c->images_of_state [state] + address_of_level (level) + + label * size_of_level (level - 1); + src = c->images_of_state [domain] + + address_of_level (level - 1); + memcpy (dst, src, size_of_level (level - 1) * sizeof (real_t)); + } + for (edge = 0; isedge (domain = wfa->into[state][label][edge]); + edge++) + { + unsigned n; + real_t weight = wfa->weight [state][label][edge]; + + dst = c->images_of_state [state] + address_of_level (level) + + label * size_of_level (level - 1); + src = c->images_of_state [domain] + + address_of_level (level - 1); + + for (n = size_of_level (level - 1); n; n--) + *dst++ += *src++ * weight; + } + } } -static void +static void clear_or_alloc (real_t **ptr, size_t size) /* - * if *ptr == NULL allocate memory with Calloc - * otherwise fill the real_t-array ptr[] with 0 + * if *ptr == NULL allocate memory with Calloc + * otherwise fill the real_t-array ptr[] with 0 */ { - if (*ptr == NULL) + if (*ptr == NULL) *ptr = Calloc (size, sizeof (real_t)); - else + else memset (*ptr, 0, size * sizeof (real_t)); - + } diff --git a/converter/other/fiasco/codec/control.h b/converter/other/fiasco/codec/control.h index 6c0834a1..9bfc9b50 100644 --- a/converter/other/fiasco/codec/control.h +++ b/converter/other/fiasco/codec/control.h @@ -1,8 +1,8 @@ /* * control.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -20,14 +20,14 @@ #include "cwfa.h" #include "types.h" -void +void append_transitions (unsigned state, unsigned label, const real_t *weight, - const word_t *into, wfa_t *wfa); -void + const word_t *into, wfa_t *wfa); +void append_basis_states (unsigned basis_states, wfa_t *wfa, coding_t *c); -void +void append_state (bool_t auxiliary_state, real_t final, unsigned level_of_state, - wfa_t *wfa, coding_t *c); + wfa_t *wfa, coding_t *c); #endif /* not _CONTROL_H */ diff --git a/converter/other/fiasco/codec/cwfa.h b/converter/other/fiasco/codec/cwfa.h index e8e2d474..4fed343c 100644 --- a/converter/other/fiasco/codec/cwfa.h +++ b/converter/other/fiasco/codec/cwfa.h @@ -1,8 +1,8 @@ /* * cwfa.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -32,15 +32,15 @@ extern const real_t MAXCOSTS; typedef struct motion { - image_t *original; /* Current image */ - image_t *past; /* Preceding image */ - image_t *future; /* Succeeding image */ - frame_type_e frame_type; /* frame type: B_, P_ I_FRAME */ - unsigned number; /* display number of frame */ - real_t *xbits; /* # bits for mv x-component */ - real_t *ybits; /* # bits for mv y-component */ - real_t **mc_forward_norms; /* norms of mcpe */ - real_t **mc_backward_norms; /* norms of mcpe */ + image_t *original; /* Current image */ + image_t *past; /* Preceding image */ + image_t *future; /* Succeeding image */ + frame_type_e frame_type; /* frame type: B_, P_ I_FRAME */ + unsigned number; /* display number of frame */ + real_t *xbits; /* # bits for mv x-component */ + real_t *ybits; /* # bits for mv y-component */ + real_t **mc_forward_norms; /* norms of mcpe */ + real_t **mc_backward_norms; /* norms of mcpe */ } motion_t; typedef struct range @@ -48,30 +48,30 @@ typedef struct range * Information about current range in the original image. * Approximation data (error, encoding bits, approximation type and factors * of the linear combination) are also saved. - */ + */ { unsigned global_address; /* We need absolute image addresses - for distance calculations. */ - unsigned x, y; /* Coordinates of upper left corner */ - unsigned image; /* Position in the tree */ - unsigned address; /* Address of the pixel data */ - unsigned level; /* Level of the range */ - real_t weight [MAXEDGES + 1]; /* coeff. of the approximation */ - word_t into [MAXEDGES + 1]; /* used domains of the approximation */ - int tree; /* == domain : range is approximated - with new state 'domain' - == RANGE : - with a linear comb. */ - real_t err; /* approximation error */ - real_t tree_bits; /* # bits to encode tree */ - real_t matrix_bits; /* # bits to encode matrices */ - real_t weights_bits; /* # bits to encode weights */ - mv_t mv; /* motion vector */ - real_t mv_tree_bits; /* # bits to encode mv tree */ - real_t mv_coord_bits; /* # bits to encode mv coordinates */ - real_t nd_tree_bits; /* # bits to encode nd tree */ - real_t nd_weights_bits; /* # bits to encode nd factors */ - bool_t prediction; /* range is predicted? */ + for distance calculations. */ + unsigned x, y; /* Coordinates of upper left corner */ + unsigned image; /* Position in the tree */ + unsigned address; /* Address of the pixel data */ + unsigned level; /* Level of the range */ + real_t weight [MAXEDGES + 1]; /* coeff. of the approximation */ + word_t into [MAXEDGES + 1]; /* used domains of the approximation */ + int tree; /* == domain : range is approximated + with new state 'domain' + == RANGE : + with a linear comb. */ + real_t err; /* approximation error */ + real_t tree_bits; /* # bits to encode tree */ + real_t matrix_bits; /* # bits to encode matrices */ + real_t weights_bits; /* # bits to encode weights */ + mv_t mv; /* motion vector */ + real_t mv_tree_bits; /* # bits to encode mv tree */ + real_t mv_coord_bits; /* # bits to encode mv coordinates */ + real_t nd_tree_bits; /* # bits to encode nd tree */ + real_t nd_weights_bits; /* # bits to encode nd factors */ + bool_t prediction; /* range is predicted? */ } range_t; typedef struct coding @@ -80,27 +80,27 @@ typedef struct coding * process. */ { - real_t price; /* determines quality of approx. */ - real_t **images_of_state; /* image of state i at level - 0, ... , imageslevel */ + real_t price; /* determines quality of approx. */ + real_t **images_of_state; /* image of state i at level + 0, ... , imageslevel */ real_t *(*ip_states_state)[MAXLEVEL]; /* inner products between state i - and states 0, ... , i - at all image levels */ - real_t **ip_images_state; /* inner products between all - ranges and state i */ - real_t *pixels; /* current image pixels stored in tree - order (only leaves are stored) */ - unsigned products_level; /* inner products are stored up to - this level */ - tiling_t *tiling; /* tiling of the entire image */ - tree_t tree; /* probability model */ - tree_t p_tree; /* prediction probability model */ - motion_t *mt; /* motion compensation information */ - coeff_t *coeff; - coeff_t *d_coeff; + and states 0, ... , i + at all image levels */ + real_t **ip_images_state; /* inner products between all + ranges and state i */ + real_t *pixels; /* current image pixels stored in tree + order (only leaves are stored) */ + unsigned products_level; /* inner products are stored up to + this level */ + tiling_t *tiling; /* tiling of the entire image */ + tree_t tree; /* probability model */ + tree_t p_tree; /* prediction probability model */ + motion_t *mt; /* motion compensation information */ + coeff_t *coeff; + coeff_t *d_coeff; domain_pool_t *domain_pool; domain_pool_t *d_domain_pool; - c_options_t options; /* global options */ + c_options_t options; /* global options */ } coding_t; #endif /* not _CWFA_H */ diff --git a/converter/other/fiasco/codec/decoder.h b/converter/other/fiasco/codec/decoder.h index 7823ab91..d11ccefd 100644 --- a/converter/other/fiasco/codec/decoder.h +++ b/converter/other/fiasco/codec/decoder.h @@ -1,8 +1,8 @@ /* * decode.h - * - * Written by: Ullrich Hafner - * + * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -23,41 +23,41 @@ typedef struct video { - unsigned future_display; /* number of a future frame */ - unsigned display; /* current display number */ - image_t *frame; /* current frame */ - image_t *sframe; /* current smoothed frame */ - image_t *future; /* future reference */ - image_t *sfuture; /* future (smmothed) reference */ - image_t *past ; /* past reference */ - wfa_t *wfa; /* current wfa */ - wfa_t *wfa_future; /* future wfa */ - wfa_t *wfa_past; /* past wfa */ + unsigned future_display; /* number of a future frame */ + unsigned display; /* current display number */ + image_t *frame; /* current frame */ + image_t *sframe; /* current smoothed frame */ + image_t *future; /* future reference */ + image_t *sfuture; /* future (smmothed) reference */ + image_t *past ; /* past reference */ + wfa_t *wfa; /* current wfa */ + wfa_t *wfa_future; /* future wfa */ + wfa_t *wfa_past; /* past wfa */ } video_t; typedef struct dectimer { - unsigned int input [3]; - unsigned int preprocessing [3]; - unsigned int decoder [3]; - unsigned int cleanup [3]; - unsigned int motion [3]; - unsigned int smooth [3]; - unsigned int display [3]; - unsigned int frames [3]; + unsigned int input [3]; + unsigned int preprocessing [3]; + unsigned int decoder [3]; + unsigned int cleanup [3]; + unsigned int motion [3]; + unsigned int smooth [3]; + unsigned int display [3]; + unsigned int frames [3]; } dectimer_t; image_t * get_next_frame (bool_t store_wfa, int enlarge_factor, - int smoothing, const char *reference_frame, - format_e format, video_t *video, dectimer_t *timer, - wfa_t *orig_wfa, bitfile_t *input); + int smoothing, const char *reference_frame, + format_e format, video_t *video, dectimer_t *timer, + wfa_t *orig_wfa, bitfile_t *input); image_t * decode_image (unsigned orig_width, unsigned orig_height, format_e format, - unsigned *dec_timer, const wfa_t *wfa); + unsigned *dec_timer, const wfa_t *wfa); word_t * decode_range (unsigned range_state, unsigned range_label, unsigned range_level, - word_t **domain, wfa_t *wfa); + word_t **domain, wfa_t *wfa); image_t * decode_state (unsigned state, unsigned level, wfa_t *wfa); void diff --git a/converter/other/fiasco/codec/dfiasco.c b/converter/other/fiasco/codec/dfiasco.c index ce25654a..3f5d3fcc 100644 --- a/converter/other/fiasco/codec/dfiasco.c +++ b/converter/other/fiasco/codec/dfiasco.c @@ -1,7 +1,7 @@ /* - * dfiasco.c: Decoder public interface + * dfiasco.c: Decoder public interface * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -37,7 +37,7 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -47,11 +47,11 @@ static void free_dfiasco (dfiasco_t *dfiasco); static dfiasco_t * alloc_dfiasco (wfa_t *wfa, video_t *video, bitfile_t *input, - int enlarge_factor, int smoothing, format_e image_format); + int enlarge_factor, int smoothing, format_e image_format); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -60,24 +60,24 @@ fiasco_decoder_new (const char *filename, const fiasco_d_options_t *options) { try { - bitfile_t *input; /* pointer to WFA FIASCO stream */ - wfa_t *wfa; /* wfa structure */ - video_t *video; /* information about decoder state */ - const d_options_t *dop; /* decoder additional options */ - dfiasco_t *dfiasco; /* decoder internal state */ - fiasco_decoder_t *decoder; /* public interface to decoder */ + bitfile_t *input; /* pointer to WFA FIASCO stream */ + wfa_t *wfa; /* wfa structure */ + video_t *video; /* information about decoder state */ + const d_options_t *dop; /* decoder additional options */ + dfiasco_t *dfiasco; /* decoder internal state */ + fiasco_decoder_t *decoder; /* public interface to decoder */ fiasco_d_options_t *default_options = NULL; if (options) { - dop = cast_d_options ((fiasco_d_options_t *) options); - if (!dop) - return NULL; + dop = cast_d_options ((fiasco_d_options_t *) options); + if (!dop) + return NULL; } else { - default_options = fiasco_d_options_new (); - dop = cast_d_options (default_options); + default_options = fiasco_d_options_new (); + dop = cast_d_options (default_options); } wfa = alloc_wfa (NO); @@ -85,8 +85,8 @@ fiasco_decoder_new (const char *filename, const fiasco_d_options_t *options) input = open_wfa (filename, wfa->wfainfo); read_basis (wfa->wfainfo->basis_name, wfa); - decoder = Calloc (1, sizeof (fiasco_decoder_t)); - decoder->delete = fiasco_decoder_delete; + decoder = Calloc (1, sizeof (fiasco_decoder_t)); + decoder->delete = fiasco_decoder_delete; decoder->write_frame = fiasco_decoder_write_frame; decoder->get_frame = fiasco_decoder_get_frame; decoder->get_length = fiasco_decoder_get_length; @@ -98,46 +98,46 @@ fiasco_decoder_new (const char *filename, const fiasco_d_options_t *options) decoder->is_color = fiasco_decoder_is_color; decoder->private = dfiasco - = alloc_dfiasco (wfa, video, input, - dop->magnification, - dop->smoothing, - dop->image_format); + = alloc_dfiasco (wfa, video, input, + dop->magnification, + dop->smoothing, + dop->image_format); if (default_options) - fiasco_d_options_delete (default_options); + fiasco_d_options_delete (default_options); if (dfiasco->enlarge_factor >= 0) { - int n; - unsigned long pixels = wfa->wfainfo->width * wfa->wfainfo->height; - - for (n = 1; n <= (int) dfiasco->enlarge_factor; n++) - { - if (pixels << (n << 1) > 2048 * 2048) - { - set_error (_("Magnifaction factor `%d' is too large. " - "Maximum value is %d."), - dfiasco->enlarge_factor, MAX(0, n - 1)); - fiasco_decoder_delete (decoder); - return NULL; - } - } + int n; + unsigned long pixels = wfa->wfainfo->width * wfa->wfainfo->height; + + for (n = 1; n <= (int) dfiasco->enlarge_factor; n++) + { + if (pixels << (n << 1) > 2048 * 2048) + { + set_error (_("Magnifaction factor `%d' is too large. " + "Maximum value is %d."), + dfiasco->enlarge_factor, MAX(0, n - 1)); + fiasco_decoder_delete (decoder); + return NULL; + } + } } else { - int n; - - for (n = 0; n <= (int) - dfiasco->enlarge_factor; n++) - { - if (wfa->wfainfo->width >> n < 32 - || wfa->wfainfo->height >> n < 32) - { - set_error (_("Magnifaction factor `%d' is too small. " - "Minimum value is %d."), - dfiasco->enlarge_factor, - MAX(0, n - 1)); - fiasco_decoder_delete (decoder); - return NULL; - } - } + int n; + + for (n = 0; n <= (int) - dfiasco->enlarge_factor; n++) + { + if (wfa->wfainfo->width >> n < 32 + || wfa->wfainfo->height >> n < 32) + { + set_error (_("Magnifaction factor `%d' is too small. " + "Minimum value is %d."), + dfiasco->enlarge_factor, - MAX(0, n - 1)); + fiasco_decoder_delete (decoder); + return NULL; + } + } } return (fiasco_decoder_t *) decoder; } @@ -149,7 +149,7 @@ fiasco_decoder_new (const char *filename, const fiasco_d_options_t *options) int fiasco_decoder_write_frame (fiasco_decoder_t *decoder, - const char *filename) + const char *filename) { dfiasco_t *dfiasco = cast_dfiasco (decoder); @@ -159,15 +159,15 @@ fiasco_decoder_write_frame (fiasco_decoder_t *decoder, { try { - image_t *frame = get_next_frame (NO, dfiasco->enlarge_factor, - dfiasco->smoothing, NULL, - FORMAT_4_4_4, dfiasco->video, NULL, - dfiasco->wfa, dfiasco->input); - write_image (filename, frame); + image_t *frame = get_next_frame (NO, dfiasco->enlarge_factor, + dfiasco->smoothing, NULL, + FORMAT_4_4_4, dfiasco->video, NULL, + dfiasco->wfa, dfiasco->input); + write_image (filename, frame); } catch { - return 0; + return 0; } return 1; } @@ -184,25 +184,25 @@ fiasco_decoder_get_frame (fiasco_decoder_t *decoder) { try { - fiasco_image_t *image = Calloc (1, sizeof (fiasco_image_t)); - image_t *frame = get_next_frame (NO, dfiasco->enlarge_factor, - dfiasco->smoothing, NULL, - dfiasco->image_format, - dfiasco->video, NULL, - dfiasco->wfa, dfiasco->input); - - frame->reference_count++; /* for motion compensation */ - image->private = frame; - image->delete = fiasco_image_delete; - image->get_width = fiasco_image_get_width; - image->get_height = fiasco_image_get_height; - image->is_color = fiasco_image_is_color; - - return image; + fiasco_image_t *image = Calloc (1, sizeof (fiasco_image_t)); + image_t *frame = get_next_frame (NO, dfiasco->enlarge_factor, + dfiasco->smoothing, NULL, + dfiasco->image_format, + dfiasco->video, NULL, + dfiasco->wfa, dfiasco->input); + + frame->reference_count++; /* for motion compensation */ + image->private = frame; + image->delete = fiasco_image_delete; + image->get_width = fiasco_image_get_width; + image->get_height = fiasco_image_get_height; + image->is_color = fiasco_image_is_color; + + return image; } catch { - return NULL; + return NULL; } } } @@ -241,9 +241,9 @@ fiasco_decoder_get_width (fiasco_decoder_t *decoder) unsigned width; if (dfiasco->enlarge_factor >= 0) - width = dfiasco->wfa->wfainfo->width << dfiasco->enlarge_factor; + width = dfiasco->wfa->wfainfo->width << dfiasco->enlarge_factor; else - width = dfiasco->wfa->wfainfo->width >> - dfiasco->enlarge_factor; + width = dfiasco->wfa->wfainfo->width >> - dfiasco->enlarge_factor; return width & 1 ? width + 1 : width; } @@ -261,9 +261,9 @@ fiasco_decoder_get_height (fiasco_decoder_t *decoder) unsigned height; if (dfiasco->enlarge_factor >= 0) - height = dfiasco->wfa->wfainfo->height << dfiasco->enlarge_factor; + height = dfiasco->wfa->wfainfo->height << dfiasco->enlarge_factor; else - height = dfiasco->wfa->wfainfo->height >> - dfiasco->enlarge_factor; + height = dfiasco->wfa->wfainfo->height >> - dfiasco->enlarge_factor; return height & 1 ? height + 1 : height; } @@ -329,30 +329,30 @@ fiasco_decoder_delete (fiasco_decoder_t *decoder) /***************************************************************************** - private code + private code *****************************************************************************/ static dfiasco_t * alloc_dfiasco (wfa_t *wfa, video_t *video, bitfile_t *input, - int enlarge_factor, int smoothing, format_e image_format) + int enlarge_factor, int smoothing, format_e image_format) /* * FIASCO decoder constructor: * Initialize decoder structure. * * Return value: - * pointer to the new decoder structure + * pointer to the new decoder structure */ { dfiasco_t *dfiasco = Calloc (1, sizeof (dfiasco_t)); strcpy (dfiasco->id, "DFIASCO"); - dfiasco->wfa = wfa; - dfiasco->video = video; - dfiasco->input = input; + dfiasco->wfa = wfa; + dfiasco->video = video; + dfiasco->input = input; dfiasco->enlarge_factor = enlarge_factor; - dfiasco->smoothing = smoothing; + dfiasco->smoothing = smoothing; dfiasco->image_format = image_format; return dfiasco; @@ -367,7 +367,7 @@ free_dfiasco (dfiasco_t *dfiasco) * No return value. * * Side effects: - * 'video' struct is discarded. + * 'video' struct is discarded. */ { Free (dfiasco); @@ -380,7 +380,7 @@ cast_dfiasco (fiasco_decoder_t *dfiasco) * Check whether `dfiasco' is a valid object of type dfiasco_t. * * Return value: - * pointer to dfiasco_t struct on success + * pointer to dfiasco_t struct on success * NULL otherwise */ { @@ -389,8 +389,8 @@ cast_dfiasco (fiasco_decoder_t *dfiasco) { if (!streq (this->id, "DFIASCO")) { - set_error (_("Parameter `dfiasco' doesn't match required type.")); - return NULL; + set_error (_("Parameter `dfiasco' doesn't match required type.")); + return NULL; } } else diff --git a/converter/other/fiasco/codec/dfiasco.h b/converter/other/fiasco/codec/dfiasco.h index eed12b6b..765a09d4 100644 --- a/converter/other/fiasco/codec/dfiasco.h +++ b/converter/other/fiasco/codec/dfiasco.h @@ -1,8 +1,8 @@ /* * dfiasco.h - * - * Written by: Ullrich Hafner - * + * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -29,7 +29,7 @@ typedef struct dfiasco wfa_t *wfa; video_t *video; bitfile_t *input; - int enlarge_factor; + int enlarge_factor; int smoothing; format_e image_format; } dfiasco_t; diff --git a/converter/other/fiasco/codec/domain-pool.c b/converter/other/fiasco/codec/domain-pool.c index 1c14a30c..e9986269 100644 --- a/converter/other/fiasco/codec/domain-pool.c +++ b/converter/other/fiasco/codec/domain-pool.c @@ -2,7 +2,7 @@ * domain-pool.c: Domain pool management (probability model) * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -34,9 +34,9 @@ /* * Domain pool model interface: * Implementing the domain pool model interface requires the - * following steps: + * following steps: * - Add a constructor that initializes the domain_pool_t structure - * - Allocate new model with default_alloc() + * - Allocate new model with default_alloc() * - Fill the dp_array_t domain_pools array with constructor and name * - Write code for methods bits() and generate() * - Either use default functions for remaining methods or override them @@ -44,9 +44,9 @@ */ /***************************************************************************** - + local variables - + *****************************************************************************/ static real_t *matrix_0 = NULL; @@ -174,7 +174,7 @@ default_alloc (void); /***************************************************************************** public code - + *****************************************************************************/ typedef struct dp_array @@ -185,7 +185,7 @@ typedef struct dp_array } dp_array_t; dp_array_t const domain_pools[] = {{"adaptive", alloc_qac_domain_pool}, - {"constant", alloc_const_domain_pool}, + {"constant", alloc_const_domain_pool}, {"basis", alloc_basis_domain_pool}, {"uniform", alloc_uniform_domain_pool}, {"rle", alloc_rle_domain_pool}, @@ -199,8 +199,8 @@ alloc_domain_pool (const char *domain_pool_name, unsigned max_domains, * Allocate a new domain pool identified by the string * 'domain_pool_name'. Maximum number of domain images (each one * represented by one state of the given 'wfa') is specified by - * 'max_domains'. - * + * 'max_domains'. + * * Return value: * pointer to the allocated domain pool * @@ -209,16 +209,16 @@ alloc_domain_pool (const char *domain_pool_name, unsigned max_domains, */ { unsigned n; - + if (!max_domains) { warning ("Can't generate empty domain pool. " "Using at least DC component."); max_domains = 1; } - + for (n = 0; domain_pools [n].identifier; n++) /* step through all id's */ - if (strcaseeq (domain_pools [n].identifier, domain_pool_name)) + if (strcaseeq (domain_pools [n].identifier, domain_pool_name)) return domain_pools [n].function (max_domains, max_edges, wfa); warning ("Can't initialize domain pool '%s'. Using default value '%s'.", @@ -230,7 +230,7 @@ alloc_domain_pool (const char *domain_pool_name, unsigned max_domains, /***************************************************************************** private code - + *****************************************************************************/ /***************************************************************************** @@ -256,7 +256,7 @@ alloc_qac_domain_pool (unsigned max_domains, unsigned max_edges, { domain_pool_t *pool; unsigned state; - + pool = default_alloc (); pool->model = qac_model_alloc (max_domains); pool->generate = qac_generate; @@ -266,7 +266,7 @@ alloc_qac_domain_pool (unsigned max_domains, unsigned max_edges, pool->chroma = qac_chroma; pool->model_free = qac_model_free; pool->model_duplicate = qac_model_duplicate; - + for (state = 0; state < wfa->basis_states; state++) if (usedomain (state, wfa)) qac_append (state, -1, wfa, pool->model); @@ -308,7 +308,7 @@ qac_model_duplicate (const void *src) qdst = qac_model_alloc (qsrc->max_domains); qdst->y_index = qsrc->y_index; qdst->n = qsrc->n; - + memcpy (qdst->index, qsrc->index, qsrc->n * sizeof (word_t)); memcpy (qdst->states, qsrc->states, qsrc->n * sizeof (word_t)); @@ -325,14 +325,14 @@ qac_generate (unsigned level, int y_state, const wfa_t *wfa, const void *model) if (y_state >= 0 && !usedomain (y_state, wfa)) /* don't use y-state */ y_state = -1; - + domains = Calloc (qac_model->n + 2, sizeof (word_t)); memcpy (domains, qac_model->states, qac_model->n * sizeof (word_t)); for (n = 0; n < qac_model->n; n++) if (domains [n] == y_state) /* match */ - y_state_is_domain = YES; + y_state_is_domain = YES; if (y_state_is_domain) domains [qac_model->n] = -1; /* end marker */ @@ -361,11 +361,11 @@ qac_bits (const word_t *domains, const word_t *used_domains, bits += matrix_0 [qac_model->index [domain]]; if (y_state >= 0) bits += matrix_0 [qac_model->y_index]; - + if (used_domains != NULL) { unsigned edge; - + for (edge = 0; isedge (domain = used_domains [edge]); edge++) if (domains [domain] == y_state) { @@ -377,8 +377,8 @@ qac_bits (const word_t *domains, const word_t *used_domains, bits -= matrix_0 [qac_model->index [domain]]; bits += matrix_1 [qac_model->index [domain]]; } - } - + } + return bits; } @@ -391,7 +391,7 @@ qac_update (const word_t *domains, const word_t *used_domains, bool_t used_y_state = NO; qac_model_t *qac_model = (qac_model_t *) model; bool_t y_state_is_domain = NO; - + if (y_state >= 0 && !usedomain (y_state, wfa)) /* don't use y-state */ y_state = -1; @@ -399,9 +399,9 @@ qac_update (const word_t *domains, const word_t *used_domains, { qac_model->index [domain]++; /* mark domains unused. */ if (qac_model->states [domain] == y_state) /* match */ - y_state_is_domain = YES; + y_state_is_domain = YES; } - + for (edge = 0; isedge (domain = used_domains [edge]); edge++) if (domains [domain] == y_state) /* chroma coding */ { @@ -413,24 +413,24 @@ qac_update (const word_t *domains, const word_t *used_domains, else /* luminance coding */ { qac_model->index [used_domains [edge]]--; /* undo */ - qac_model->index [used_domains [edge]] >>= 1; + qac_model->index [used_domains [edge]] >>= 1; } if (y_state >= 0 && !used_y_state) qac_model->y_index++; /* update y-state model */ - + for (domain = 0; domain < qac_model->n; domain++) if (qac_model->index [domain] > 1020) /* check for overflow */ - qac_model->index [domain] = 1020; + qac_model->index [domain] = 1020; if (qac_model->y_index > 1020) /* check for overflow */ - qac_model->y_index = 1020; + qac_model->y_index = 1020; } static bool_t qac_append (unsigned new_state, unsigned level, const wfa_t *wfa, void *model) { qac_model_t *qac_model = (qac_model_t *) model; /* probability model */ - + if (qac_model->n >= qac_model->max_domains) return NO; /* don't use state in domain pool */ else @@ -448,14 +448,14 @@ static void qac_chroma (unsigned max_domains, const wfa_t *wfa, void *model) { qac_model_t *qac_model = (qac_model_t *) model; /* probability model */ - + if (max_domains < qac_model->n) /* choose most probable domains */ { word_t *domains; unsigned n, new, old; word_t *states = Calloc (max_domains, sizeof (word_t)); word_t *index = Calloc (max_domains, sizeof (word_t)); - + domains = compute_hits (wfa->basis_states, wfa->states - 1, max_domains, wfa); for (n = 0; n < max_domains && domains [n] >= 0; n++) @@ -491,11 +491,11 @@ alloc_const_domain_pool (unsigned max_domains, unsigned max_edges, */ { domain_pool_t *pool; - - pool = default_alloc (); + + pool = default_alloc (); pool->generate = const_generate; pool->bits = const_bits; - + return pool; } @@ -504,10 +504,10 @@ const_generate (unsigned level, int y_state, const wfa_t *wfa, const void *model) { word_t *domains = Calloc (2, sizeof (word_t)); - + domains [0] = 0; domains [1] = -1; - + return domains; } @@ -548,11 +548,11 @@ alloc_uniform_domain_pool (unsigned max_domains, unsigned max_edges, */ { domain_pool_t *pool; - - pool = default_alloc (); + + pool = default_alloc (); pool->generate = uniform_generate; pool->bits = uniform_bits; - + return pool; } @@ -567,17 +567,17 @@ uniform_generate (unsigned level, int y_state, const wfa_t *wfa, if (usedomain (state, wfa)) domains [n++] = state; domains [n] = -1; - + return domains; } - + static real_t uniform_bits (const word_t *domains, const word_t *used_domains, unsigned level, int y_state, const wfa_t *wfa, const void *model) { unsigned state, n; real_t bits = 0; - + for (state = 0, n = 0; state < wfa->states; state++) if (usedomain (state, wfa)) n++; @@ -587,7 +587,7 @@ uniform_bits (const word_t *domains, const word_t *used_domains, if (used_domains != NULL) { int edge; - + for (edge = 0; isedge (used_domains [edge]); edge++) bits -= log2 (1.0 / n); } @@ -615,13 +615,13 @@ alloc_rle_domain_pool (unsigned max_domains, unsigned max_edges, const wfa_t *wfa) /* * Domain pool with state images {0, ..., 'max_domains'). - * Underlying probability model: rle + * Underlying probability model: rle */ { domain_pool_t *pool; unsigned state; - - pool = default_alloc (); + + pool = default_alloc (); pool->model = rle_model_alloc (max_domains); pool->model_free = rle_model_free; pool->model_duplicate = rle_model_duplicate; @@ -643,7 +643,7 @@ rle_model_alloc (unsigned max_domains) { unsigned m; rle_model_t *model = Calloc (1, sizeof (rle_model_t)); - + for (m = model->total = 0; m < MAXEDGES + 1; m++, model->total++) model->count [m] = 1; @@ -652,7 +652,7 @@ rle_model_alloc (unsigned max_domains) model->n = 0; model->y_index = 0; model->max_domains = max_domains; - + return model; } @@ -676,12 +676,12 @@ rle_model_duplicate (const void *src) model->states = Calloc (model->max_domains, sizeof (word_t)); model->total = rle_src->total; model->y_index = rle_src->y_index; - + memcpy (model->states, rle_src->states, model->max_domains * sizeof (word_t)); memcpy (model->count, rle_src->count, (MAXEDGES + 1) * sizeof (word_t)); - + return model; } @@ -692,17 +692,17 @@ rle_generate (unsigned level, int y_state, const wfa_t *wfa, const void *model) unsigned n; rle_model_t *rle_model = (rle_model_t *) model; bool_t y_state_is_domain = NO; - + if (y_state >= 0 && !usedomain (y_state, wfa)) /* don't use y-state */ y_state = -1; - + domains = Calloc (rle_model->n + 2, sizeof (word_t)); memcpy (domains, rle_model->states, rle_model->n * sizeof (word_t)); for (n = 0; n < rle_model->n; n++) if (domains [n] == y_state) /* match */ - y_state_is_domain = YES; + y_state_is_domain = YES; if (y_state_is_domain) domains [rle_model->n] = -1; /* end marker */ @@ -726,17 +726,17 @@ rle_bits (const word_t *domains, const word_t *used_domains, rle_model_t *rle_model = (rle_model_t *) model; unsigned last; int into; - + if (y_state >= 0 && !usedomain (y_state, wfa)) /* don't use y-state */ y_state = -1; if (used_domains) { word_t domain; - + if (y_state >= 0) bits += matrix_0 [rle_model->y_index]; - + for (edge = n = 0; isedge (domain = used_domains [edge]); edge++) if (domains [domain] != y_state) sorted [n++] = used_domains [edge]; @@ -745,7 +745,7 @@ rle_bits (const word_t *domains, const word_t *used_domains, bits -= matrix_0 [rle_model->y_index]; bits += matrix_1 [rle_model->y_index]; } - + if (n > 1) qsort (sorted, n, sizeof (word_t), sort_asc_word); } @@ -761,7 +761,7 @@ rle_bits (const word_t *domains, const word_t *used_domains, word_t array0 [2] = {NO_EDGE}; bits += qac_bits (array0, array0, level, y_state, wfa, rle_model->domain_0); } - + last = 1; for (edge = 0; edge < n; edge++) if ((into = sorted [edge]) && rle_model->n - 1 - last) @@ -769,7 +769,7 @@ rle_bits (const word_t *domains, const word_t *used_domains, bits += bits_bin_code (into - last, rle_model->n - 1 - last); last = into + 1; } - + return bits; } @@ -781,21 +781,21 @@ rle_update (const word_t *domains, const word_t *used_domains, bool_t state_0 = NO, state_y = NO; word_t array0 [2] = {0, NO_EDGE}; unsigned edge = 0; - + if (y_state >= 0 && !usedomain (y_state, wfa)) /* don't use y-state */ y_state = -1; if (used_domains) { word_t domain; - + for (edge = 0; isedge (domain = used_domains [edge]); edge++) if (domains [domain] == 0) state_0 = YES; else if (domains [domain] == y_state) state_y = YES; } - + rle_model->count [edge]++; rle_model->total++; @@ -807,14 +807,14 @@ rle_update (const word_t *domains, const word_t *used_domains, else rle_model->y_index++; if (rle_model->y_index > 1020) /* check for overflow */ - rle_model->y_index = 1020; + rle_model->y_index = 1020; } static bool_t rle_append (unsigned new_state, unsigned level, const wfa_t *wfa, void *model) { rle_model_t *rle_model = (rle_model_t *) model; /* probability model */ - + if (rle_model->n >= rle_model->max_domains) return NO; /* don't use state in domain pool */ else @@ -827,7 +827,7 @@ rle_append (unsigned new_state, unsigned level, const wfa_t *wfa, void *model) assert (rle_model->n == 1); qac_append (0, -1, wfa, rle_model->domain_0); } - + return YES; /* state will be used in domain pool */ } } @@ -836,14 +836,14 @@ static void rle_chroma (unsigned max_domains, const wfa_t *wfa, void *model) { rle_model_t *rle_model = (rle_model_t *) model; /* probability model */ - + if (max_domains < rle_model->n) /* choose most probable domains */ { unsigned n; word_t *states = Calloc (max_domains, sizeof (word_t)); word_t *domains = compute_hits (wfa->basis_states, wfa->states - 1, max_domains, wfa); - + for (n = 0; n < max_domains && domains [n] >= 0; n++) states [n] = domains [n]; @@ -868,12 +868,12 @@ alloc_rle_no_chroma_domain_pool (unsigned max_domains, unsigned max_edges, const wfa_t *wfa) /* * Domain pool with state images {0, ..., 'max_domains'). - * Underlying probability model: rle + * Underlying probability model: rle * Domain pool is not changed for chroma bands */ { domain_pool_t *pool = alloc_rle_domain_pool (max_domains, max_edges, wfa); - + pool->chroma = default_chroma; return pool; @@ -898,7 +898,7 @@ default_alloc (void) pool->free = default_free; pool->model_free = default_model_free; pool->model_duplicate = default_model_duplicate; - + return pool; } @@ -964,12 +964,12 @@ init_matrix_probabilities (void) { if (matrix_0 == NULL || matrix_1 == NULL) { - unsigned index; + unsigned index; unsigned n, exp; - + matrix_0 = Calloc (1 << (MAX_PROB + 1), sizeof (real_t)); matrix_1 = Calloc (1 << (MAX_PROB + 1), sizeof (real_t)); - + for (index = 0, n = MIN_PROB; n <= MAX_PROB; n++) for (exp = 0; exp < (unsigned) 1 << n; exp++, index++) { diff --git a/converter/other/fiasco/codec/domain-pool.h b/converter/other/fiasco/codec/domain-pool.h index a2c46141..b3258b67 100644 --- a/converter/other/fiasco/codec/domain-pool.h +++ b/converter/other/fiasco/codec/domain-pool.h @@ -1,8 +1,8 @@ /* * domain-pool.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -22,42 +22,42 @@ typedef struct domain_pool { - void *model; /* probability model */ + void *model; /* probability model */ word_t *(*generate) (unsigned level, int y_state, const wfa_t *wfa, - const void *model); + const void *model); /* * Generate set of domain images which may be used for an approximation. * Use parameters 'level', 'y_state' and 'wfa' to make the decision. */ real_t (*bits) (const word_t *domains, const word_t *used_domains, - unsigned level, int y_state, const wfa_t *wfa, - const void *model); + unsigned level, int y_state, const wfa_t *wfa, + const void *model); /* * Compute bit-rate of a range approximation with domains given by * the -1 terminated list 'used_domains'. */ - void (*update) (const word_t *domains, const word_t *used_domains, - unsigned level, int y_state, const wfa_t *wfa, - void *model); + void (*update) (const word_t *domains, const word_t *used_domains, + unsigned level, int y_state, const wfa_t *wfa, + void *model); /* * Update the probability model according to the chosen approximation. * (given by the -1 terminated list 'used_domains'). */ bool_t (*append) (unsigned state, unsigned level, const wfa_t *wfa, - void *model); + void *model); /* * Try to append a new state to the domain pool. */ - void (*chroma) (unsigned max_domains, const wfa_t *wfa, void *model); + void (*chroma) (unsigned max_domains, const wfa_t *wfa, void *model); /* * Derive a new domain pool that will be used for chroma channel - * coding + * coding */ void (*free) (struct domain_pool *pool); /* * Discard the given domain pool struct. */ - void (*model_free) (void *model); + void (*model_free) (void *model); /* * Free given probability model. */ @@ -69,7 +69,7 @@ typedef struct domain_pool domain_pool_t * alloc_domain_pool (const char *domain_pool_name, unsigned max_domains, - unsigned max_edges, const wfa_t *wfa); + unsigned max_edges, const wfa_t *wfa); #endif /* not _DOMAIN_POOL_H */ diff --git a/converter/other/fiasco/codec/ip.c b/converter/other/fiasco/codec/ip.c index 18257a06..4209ab21 100644 --- a/converter/other/fiasco/codec/ip.c +++ b/converter/other/fiasco/codec/ip.c @@ -1,7 +1,7 @@ /* - * ip.c: Computation of inner products + * ip.c: Computation of inner products * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -26,29 +26,29 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static real_t standard_ip_image_state (unsigned address, unsigned level, unsigned domain, - const coding_t *c); + const coding_t *c); static real_t standard_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, - const coding_t *c); + const coding_t *c); /***************************************************************************** - public code + public code *****************************************************************************/ real_t get_ip_image_state (unsigned image, unsigned address, unsigned level, - unsigned domain, const coding_t *c) + unsigned domain, const coding_t *c) /* * Return value: - * Inner product between 'image' ('address') and + * Inner product between 'image' ('address') and * 'domain' at given 'level' */ { @@ -71,8 +71,8 @@ get_ip_image_state (unsigned image, unsigned address, unsigned level, void compute_ip_images_state (unsigned image, unsigned address, unsigned level, - unsigned n, unsigned from, - const wfa_t *wfa, coding_t *c) + unsigned n, unsigned from, + const wfa_t *wfa, coding_t *c) /* * Compute the inner products between all states * 'from', ... , 'wfa->max_states' and the range images 'image' @@ -81,84 +81,84 @@ compute_ip_images_state (unsigned image, unsigned address, unsigned level, * No return value. * * Side effects: - * inner product tables 'c->ip_images_states' are updated + * inner product tables 'c->ip_images_states' are updated */ { if (level > c->options.images_level) { unsigned state, label; - if (level > c->options.images_level + 1) /* recursive computation */ - compute_ip_images_state (MAXLABELS * image + 1, address * MAXLABELS, - level - 1, MAXLABELS * n, from, wfa, c); + if (level > c->options.images_level + 1) /* recursive computation */ + compute_ip_images_state (MAXLABELS * image + 1, address * MAXLABELS, + level - 1, MAXLABELS * n, from, wfa, c); /* * Compute inner product <f, Phi_i> */ for (label = 0; label < MAXLABELS; label++) - for (state = from; state < wfa->states; state++) - if (need_image (state, wfa)) - { - unsigned edge, count; - int domain; - real_t *dst, *src; - - if (ischild (domain = wfa->tree [state][label])) - { - if (level > c->options.images_level + 1) - { - dst = c->ip_images_state [state] + image; - src = c->ip_images_state [domain] - + image * MAXLABELS + label + 1; - for (count = n; count; count--, src += MAXLABELS) - *dst++ += *src; - } - else - { - unsigned newadr = address * MAXLABELS + label; - - dst = c->ip_images_state [state] + image; - - for (count = n; count; count--, newadr += MAXLABELS) - *dst++ += standard_ip_image_state (newadr, level - 1, - domain, c); - } - } - for (edge = 0; isedge (domain = wfa->into [state][label][edge]); - edge++) - { - real_t weight = wfa->weight [state][label][edge]; - - if (level > c->options.images_level + 1) - { - dst = c->ip_images_state [state] + image; - src = c->ip_images_state [domain] - + image * MAXLABELS + label + 1; - for (count = n; count; count--, src += MAXLABELS) - *dst++ += *src * weight; - } - else - { - unsigned newadr = address * MAXLABELS + label; - - dst = c->ip_images_state [state] + image; - - for (count = n; count; count--, newadr += MAXLABELS) - *dst++ += weight * - standard_ip_image_state (newadr, level - 1, - domain, c); - } - } - } + for (state = from; state < wfa->states; state++) + if (need_image (state, wfa)) + { + unsigned edge, count; + int domain; + real_t *dst, *src; + + if (ischild (domain = wfa->tree [state][label])) + { + if (level > c->options.images_level + 1) + { + dst = c->ip_images_state [state] + image; + src = c->ip_images_state [domain] + + image * MAXLABELS + label + 1; + for (count = n; count; count--, src += MAXLABELS) + *dst++ += *src; + } + else + { + unsigned newadr = address * MAXLABELS + label; + + dst = c->ip_images_state [state] + image; + + for (count = n; count; count--, newadr += MAXLABELS) + *dst++ += standard_ip_image_state (newadr, level - 1, + domain, c); + } + } + for (edge = 0; isedge (domain = wfa->into [state][label][edge]); + edge++) + { + real_t weight = wfa->weight [state][label][edge]; + + if (level > c->options.images_level + 1) + { + dst = c->ip_images_state [state] + image; + src = c->ip_images_state [domain] + + image * MAXLABELS + label + 1; + for (count = n; count; count--, src += MAXLABELS) + *dst++ += *src * weight; + } + else + { + unsigned newadr = address * MAXLABELS + label; + + dst = c->ip_images_state [state] + image; + + for (count = n; count; count--, newadr += MAXLABELS) + *dst++ += weight * + standard_ip_image_state (newadr, level - 1, + domain, c); + } + } + } } } real_t get_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, - const coding_t *c) + const coding_t *c) /* * Return value: - * Inner product between 'domain1' and 'domain2' at given 'level'. + * Inner product between 'domain1' and 'domain2' at given 'level'. */ { if (level <= c->options.images_level) @@ -175,15 +175,15 @@ get_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, * Use already computed inner products stored in 'ip_images_states' */ if (domain2 < domain1) - return c->ip_states_state [domain1][level][domain2]; + return c->ip_states_state [domain1][level][domain2]; else - return c->ip_states_state [domain2][level][domain1]; + return c->ip_states_state [domain2][level][domain1]; } } void compute_ip_states_state (unsigned from, unsigned to, - const wfa_t *wfa, coding_t *c) + const wfa_t *wfa, coding_t *c) /* * Computes the inner products between the current state 'state1' and the * old states 0,...,'state1'-1 @@ -191,7 +191,7 @@ compute_ip_states_state (unsigned from, unsigned to, * No return value. * * Side effects: - * inner product tables 'c->ip_states_state' are computed. + * inner product tables 'c->ip_states_state' are computed. */ { unsigned level; @@ -202,72 +202,72 @@ compute_ip_states_state (unsigned from, unsigned to, */ for (level = c->options.images_level + 1; - level <= c->options.lc_max_level; level++) + level <= c->options.lc_max_level; level++) for (state1 = from; state1 <= to; state1++) - for (state2 = 0; state2 <= state1; state2++) - if (need_image (state2, wfa)) - { - unsigned label; - real_t ip = 0; - - for (label = 0; label < MAXLABELS; label++) - { - int domain1, domain2; - unsigned edge1, edge2; - real_t sum, weight2; - - if (ischild (domain1 = wfa->tree [state1][label])) - { - sum = 0; - if (ischild (domain2 = wfa->tree [state2][label])) - sum = get_ip_state_state (domain1, domain2, - level - 1, c); - - for (edge2 = 0; - isedge (domain2 = wfa->into [state2][label][edge2]); - edge2++) - { - weight2 = wfa->weight [state2][label][edge2]; - sum += weight2 * get_ip_state_state (domain1, domain2, - level - 1, c); - } - ip += sum; - } - for (edge1 = 0; - isedge (domain1 = wfa->into [state1][label][edge1]); - edge1++) - { - real_t weight1 = wfa->weight [state1][label][edge1]; - - sum = 0; - if (ischild (domain2 = wfa->tree [state2][label])) - sum = get_ip_state_state (domain1, domain2, - level - 1, c); - - for (edge2 = 0; - isedge (domain2 = wfa->into [state2][label][edge2]); - edge2++) - { - weight2 = wfa->weight [state2][label][edge2]; - sum += weight2 * get_ip_state_state (domain1, domain2, - level - 1, c); - } - ip += weight1 * sum; - } - } - c->ip_states_state [state1][level][state2] = ip; - } + for (state2 = 0; state2 <= state1; state2++) + if (need_image (state2, wfa)) + { + unsigned label; + real_t ip = 0; + + for (label = 0; label < MAXLABELS; label++) + { + int domain1, domain2; + unsigned edge1, edge2; + real_t sum, weight2; + + if (ischild (domain1 = wfa->tree [state1][label])) + { + sum = 0; + if (ischild (domain2 = wfa->tree [state2][label])) + sum = get_ip_state_state (domain1, domain2, + level - 1, c); + + for (edge2 = 0; + isedge (domain2 = wfa->into [state2][label][edge2]); + edge2++) + { + weight2 = wfa->weight [state2][label][edge2]; + sum += weight2 * get_ip_state_state (domain1, domain2, + level - 1, c); + } + ip += sum; + } + for (edge1 = 0; + isedge (domain1 = wfa->into [state1][label][edge1]); + edge1++) + { + real_t weight1 = wfa->weight [state1][label][edge1]; + + sum = 0; + if (ischild (domain2 = wfa->tree [state2][label])) + sum = get_ip_state_state (domain1, domain2, + level - 1, c); + + for (edge2 = 0; + isedge (domain2 = wfa->into [state2][label][edge2]); + edge2++) + { + weight2 = wfa->weight [state2][label][edge2]; + sum += weight2 * get_ip_state_state (domain1, domain2, + level - 1, c); + } + ip += weight1 * sum; + } + } + c->ip_states_state [state1][level][state2] = ip; + } } /***************************************************************************** - private code + private code *****************************************************************************/ static real_t standard_ip_image_state (unsigned address, unsigned level, unsigned domain, - const coding_t *c) + const coding_t *c) /* * Returns the inner product between the subimage 'address' and the * state image 'domain' at given 'level'. The stored state images @@ -275,7 +275,7 @@ standard_ip_image_state (unsigned address, unsigned level, unsigned domain, * standard way by multiplying the corresponding pixel values. * * Return value: - * computed inner product + * computed inner product */ { unsigned i; @@ -296,7 +296,7 @@ standard_ip_image_state (unsigned address, unsigned level, unsigned domain, static real_t standard_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, - const coding_t *c) + const coding_t *c) /* * Returns the inner product between the subimage 'address' and the * state image 'state' at given 'level'. The stored state images are @@ -304,7 +304,7 @@ standard_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, * multiplying the corresponding pixel values. * * Return value: - * computed inner product + * computed inner product */ { unsigned i; diff --git a/converter/other/fiasco/codec/ip.h b/converter/other/fiasco/codec/ip.h index 0c693826..f7d7efac 100644 --- a/converter/other/fiasco/codec/ip.h +++ b/converter/other/fiasco/codec/ip.h @@ -1,8 +1,8 @@ /* * ip.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -19,19 +19,19 @@ #include "cwfa.h" -void +void compute_ip_states_state (unsigned from, unsigned to, - const wfa_t *wfa, coding_t *c); -real_t + const wfa_t *wfa, coding_t *c); +real_t get_ip_state_state (unsigned domain1, unsigned domain2, unsigned level, - const coding_t *c); -void + const coding_t *c); +void compute_ip_images_state (unsigned image, unsigned address, unsigned level, - unsigned n, unsigned from, - const wfa_t *wfa, coding_t *c); -real_t + unsigned n, unsigned from, + const wfa_t *wfa, coding_t *c); +real_t get_ip_image_state (unsigned image, unsigned address, unsigned level, - unsigned domain, const coding_t *c); + unsigned domain, const coding_t *c); #endif /* not _IP_H */ diff --git a/converter/other/fiasco/codec/motion.c b/converter/other/fiasco/codec/motion.c index 0d1fa099..18d3bdd3 100644 --- a/converter/other/fiasco/codec/motion.c +++ b/converter/other/fiasco/codec/motion.c @@ -1,9 +1,9 @@ /* - * motion.c: Motion compensation code + * motion.c: Motion compensation code + * + * Written by: Ullrich Hafner + * Michael Unger * - * Written by: Ullrich Hafner - * Michael Unger - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -31,13 +31,13 @@ /***************************************************************************** - public code - + public code + *****************************************************************************/ void restore_mc (int enlarge_factor, image_t *image, const image_t *past, - const image_t *future, const wfa_t *wfa) + const image_t *future, const wfa_t *wfa) /* * Restore motion compensated prediction of 'image' represented by 'wfa'. * If 'enlarge_factor' != 0 then enlarge image by given amount. @@ -48,193 +48,193 @@ restore_mc (int enlarge_factor, image_t *image, const image_t *past, { unsigned state, label; unsigned root_state; - word_t *mcblock1, *mcblock2; /* MC blocks */ + word_t *mcblock1, *mcblock2; /* MC blocks */ #define FX(v) ((image->format == FORMAT_4_2_0) && band != Y ? ((v) / 2) : v) - + mcblock1 = Calloc (size_of_level (MAX((int) wfa->wfainfo->p_max_level - + 2 * enlarge_factor, 0)), - sizeof (word_t)); + + 2 * enlarge_factor, 0)), + sizeof (word_t)); mcblock2 = Calloc (size_of_level (MAX((int) wfa->wfainfo->p_max_level - + 2 * enlarge_factor, 0)), - sizeof (word_t)); + + 2 * enlarge_factor, 0)), + sizeof (word_t)); if (!image->color) root_state = wfa->root_state; else root_state = wfa->tree [wfa->tree [wfa->root_state][0]][0]; - + for (state = wfa->basis_states; state <= root_state; state++) for (label = 0; label < MAXLABELS; label++) - if (wfa->mv_tree[state][label].type != NONE) - { - color_e band; - unsigned level = wfa->level_of_state [state] - 1; - unsigned width = width_of_level (level); - unsigned height = height_of_level (level); - unsigned offset = image->width - width; - - switch (wfa->mv_tree [state][label].type) - { - case FORWARD: - for (band = first_band (image->color); - band <= last_band (image->color); band++) - { - extract_mc_block (mcblock1, FX (width), FX (height), - past->pixels [band], FX (past->width), - wfa->wfainfo->half_pixel, - FX (wfa->x [state][label]), - FX (wfa->y [state][label]), - FX (wfa->mv_tree [state][label].fx), - FX (wfa->mv_tree [state][label].fy)); - { - word_t *mc1; /* current pixel in MC block */ - word_t *orig; /* current pixel in original image */ - unsigned x, y; /* pixel coordinates */ - - mc1 = mcblock1; - orig = (word_t *) image->pixels [band] - + FX (wfa->x[state][label]) - + FX (wfa->y[state][label]) * FX (image->width); - - for (y = FX (height); y; y--) - { - for (x = FX (width); x; x--) - *orig++ += *mc1++; - - orig += FX (offset); - } - } - } - break; - case BACKWARD: - for (band = first_band (image->color); - band <= last_band (image->color); band++) - { - extract_mc_block (mcblock1, FX (width), FX (height), - future->pixels [band], - FX (future->width), - wfa->wfainfo->half_pixel, - FX (wfa->x [state][label]), - FX (wfa->y [state][label]), - FX (wfa->mv_tree [state][label].bx), - FX (wfa->mv_tree [state][label].by)); - { - word_t *mc1; /* current pixel in MC block 1 */ - word_t *orig; /* current pixel in original image */ - unsigned x, y; /* pixel coordinates */ - - mc1 = mcblock1; - orig = (word_t *) image->pixels [band] - + FX (wfa->x[state][label]) - + FX (wfa->y[state][label]) * FX (image->width); - - for (y = FX (height); y; y--) - { - for (x = FX (width); x; x--) - *orig++ += *mc1++; - - orig += FX (offset); - } - } - } - break; - case INTERPOLATED: - for (band = first_band (image->color); - band <= last_band (image->color); band++) - { - extract_mc_block (mcblock1, FX (width), FX (height), - past->pixels [band], FX (past->width), - wfa->wfainfo->half_pixel, - FX (wfa->x[state][label]), - FX (wfa->y[state][label]), - FX (wfa->mv_tree[state][label].fx), - FX (wfa->mv_tree[state][label].fy)); - extract_mc_block (mcblock2, FX (width), FX (height), - future->pixels [band], - FX (future->width), - wfa->wfainfo->half_pixel, - FX (wfa->x[state][label]), - FX (wfa->y[state][label]), - FX (wfa->mv_tree[state][label].bx), - FX (wfa->mv_tree[state][label].by)); - { - word_t *mc1; /* current pixel in MC block 1 */ - word_t *mc2; /* current pixel in MC block 1 */ - word_t *orig; /* current pixel in original image */ - unsigned x, y; /* pixel coordinates */ - - mc1 = mcblock1; - mc2 = mcblock2; - orig = (word_t *) image->pixels [band] - + FX (wfa->x[state][label]) - + FX (wfa->y[state][label]) * FX (image->width); - - for (y = FX (height); y; y--) - { - for (x = FX (width); x; x--) + if (wfa->mv_tree[state][label].type != NONE) + { + color_e band; + unsigned level = wfa->level_of_state [state] - 1; + unsigned width = width_of_level (level); + unsigned height = height_of_level (level); + unsigned offset = image->width - width; + + switch (wfa->mv_tree [state][label].type) + { + case FORWARD: + for (band = first_band (image->color); + band <= last_band (image->color); band++) + { + extract_mc_block (mcblock1, FX (width), FX (height), + past->pixels [band], FX (past->width), + wfa->wfainfo->half_pixel, + FX (wfa->x [state][label]), + FX (wfa->y [state][label]), + FX (wfa->mv_tree [state][label].fx), + FX (wfa->mv_tree [state][label].fy)); + { + word_t *mc1; /* current pixel in MC block */ + word_t *orig; /* current pixel in original image */ + unsigned x, y; /* pixel coordinates */ + + mc1 = mcblock1; + orig = (word_t *) image->pixels [band] + + FX (wfa->x[state][label]) + + FX (wfa->y[state][label]) * FX (image->width); + + for (y = FX (height); y; y--) + { + for (x = FX (width); x; x--) + *orig++ += *mc1++; + + orig += FX (offset); + } + } + } + break; + case BACKWARD: + for (band = first_band (image->color); + band <= last_band (image->color); band++) + { + extract_mc_block (mcblock1, FX (width), FX (height), + future->pixels [band], + FX (future->width), + wfa->wfainfo->half_pixel, + FX (wfa->x [state][label]), + FX (wfa->y [state][label]), + FX (wfa->mv_tree [state][label].bx), + FX (wfa->mv_tree [state][label].by)); + { + word_t *mc1; /* current pixel in MC block 1 */ + word_t *orig; /* current pixel in original image */ + unsigned x, y; /* pixel coordinates */ + + mc1 = mcblock1; + orig = (word_t *) image->pixels [band] + + FX (wfa->x[state][label]) + + FX (wfa->y[state][label]) * FX (image->width); + + for (y = FX (height); y; y--) + { + for (x = FX (width); x; x--) + *orig++ += *mc1++; + + orig += FX (offset); + } + } + } + break; + case INTERPOLATED: + for (band = first_band (image->color); + band <= last_band (image->color); band++) + { + extract_mc_block (mcblock1, FX (width), FX (height), + past->pixels [band], FX (past->width), + wfa->wfainfo->half_pixel, + FX (wfa->x[state][label]), + FX (wfa->y[state][label]), + FX (wfa->mv_tree[state][label].fx), + FX (wfa->mv_tree[state][label].fy)); + extract_mc_block (mcblock2, FX (width), FX (height), + future->pixels [band], + FX (future->width), + wfa->wfainfo->half_pixel, + FX (wfa->x[state][label]), + FX (wfa->y[state][label]), + FX (wfa->mv_tree[state][label].bx), + FX (wfa->mv_tree[state][label].by)); + { + word_t *mc1; /* current pixel in MC block 1 */ + word_t *mc2; /* current pixel in MC block 1 */ + word_t *orig; /* current pixel in original image */ + unsigned x, y; /* pixel coordinates */ + + mc1 = mcblock1; + mc2 = mcblock2; + orig = (word_t *) image->pixels [band] + + FX (wfa->x[state][label]) + + FX (wfa->y[state][label]) * FX (image->width); + + for (y = FX (height); y; y--) + { + for (x = FX (width); x; x--) #ifdef HAVE_SIGNED_SHIFT - *orig++ += (*mc1++ + *mc2++) >> 1; + *orig++ += (*mc1++ + *mc2++) >> 1; #else /* not HAVE_SIGNED_SHIFT */ - *orig++ += (*mc1++ + *mc2++) / 2; + *orig++ += (*mc1++ + *mc2++) / 2; #endif /* not HAVE_SIGNED_SHIFT */ - orig += FX (offset); - } - } - } - break; - default: - break; - } - } + orig += FX (offset); + } + } + } + break; + default: + break; + } + } if (image->color) { - unsigned n; - word_t *ptr; + unsigned n; + word_t *ptr; static int *clipping = NULL; - unsigned shift = image->format == FORMAT_4_2_0 ? 2 : 0; + unsigned shift = image->format == FORMAT_4_2_0 ? 2 : 0; - if (!clipping) /* initialize clipping table */ + if (!clipping) /* initialize clipping table */ { - int i; - - clipping = Calloc (256 * 3, sizeof (int)); - for (i = -128; i < 128; i++) - clipping [256 + i + 128] = i; - for (i = 0; i < 256; i++) - clipping [i] = clipping [256]; - for (i = 512; i < 512 + 256; i++) - clipping [i] = clipping [511]; - clipping += 256 + 128; + int i; + + clipping = Calloc (256 * 3, sizeof (int)); + for (i = -128; i < 128; i++) + clipping [256 + i + 128] = i; + for (i = 0; i < 256; i++) + clipping [i] = clipping [256]; + for (i = 512; i < 512 + 256; i++) + clipping [i] = clipping [511]; + clipping += 256 + 128; } - + ptr = image->pixels [Cb]; for (n = (image->width * image->height) >> shift; n; n--, ptr++) #ifdef HAVE_SIGNED_SHIFT - *ptr = clipping [*ptr >> 4] << 4; + *ptr = clipping [*ptr >> 4] << 4; #else /* not HAVE_SIGNED_SHIFT */ - *ptr = clipping [*ptr / 16] * 16; + *ptr = clipping [*ptr / 16] * 16; #endif /* not HAVE_SIGNED_SHIFT */ ptr = image->pixels [Cr]; for (n = (image->width * image->height) >> shift; n; n--, ptr++) #ifdef HAVE_SIGNED_SHIFT - *ptr = clipping [*ptr >> 4] << 4; + *ptr = clipping [*ptr >> 4] << 4; #else /* not HAVE_SIGNED_SHIFT */ *ptr = clipping [*ptr / 16] * 16; #endif /* not HAVE_SIGNED_SHIFT */ } - + Free (mcblock1); Free (mcblock2); } void extract_mc_block (word_t *mcblock, unsigned width, unsigned height, - const word_t *reference, unsigned ref_width, - bool_t half_pixel, unsigned xo, unsigned yo, - unsigned mx, unsigned my) + const word_t *reference, unsigned ref_width, + bool_t half_pixel, unsigned xo, unsigned yo, + unsigned mx, unsigned my) /* * Extract motion compensation image 'mcblock' of size 'width'x'height' * from 'reference' image (width is given by 'ref_width'). @@ -244,93 +244,93 @@ extract_mc_block (word_t *mcblock, unsigned width, unsigned height, * No return value. * * Side effects: - * 'mcblock[]' MCPE block is filled with reference pixels + * 'mcblock[]' MCPE block is filled with reference pixels */ { - if (!half_pixel) /* Fullpixel precision */ + if (!half_pixel) /* Fullpixel precision */ { - const word_t *rblock; /* pointer to reference image */ - unsigned y; /* current row */ - + const word_t *rblock; /* pointer to reference image */ + unsigned y; /* current row */ + rblock = reference + (yo + my) * ref_width + (xo + mx); - for (y = height; y; y--) + for (y = height; y; y--) { - memcpy (mcblock, rblock, width * sizeof (word_t)); + memcpy (mcblock, rblock, width * sizeof (word_t)); - mcblock += width; - rblock += ref_width; + mcblock += width; + rblock += ref_width; } } - else /* Halfpixel precision */ + else /* Halfpixel precision */ { - unsigned x, y; /* current coordinates */ - unsigned offset; /* remaining pixels in row */ - const word_t *rblock; /* pointer to reference image */ - const word_t *ryblock; /* pointer to next line */ - const word_t *rxblock; /* pointer to next column */ - const word_t *rxyblock; /* pointer to next column & row */ - + unsigned x, y; /* current coordinates */ + unsigned offset; /* remaining pixels in row */ + const word_t *rblock; /* pointer to reference image */ + const word_t *ryblock; /* pointer to next line */ + const word_t *rxblock; /* pointer to next column */ + const word_t *rxyblock; /* pointer to next column & row */ + rblock = reference + (yo + my / 2) * ref_width + (xo + mx / 2); - ryblock = rblock + ref_width; /* pixel in next row */ - rxblock = rblock + 1; /* pixel in next column */ - rxyblock = ryblock + 1; /* pixel in next row & column */ + ryblock = rblock + ref_width; /* pixel in next row */ + rxblock = rblock + 1; /* pixel in next column */ + rxyblock = ryblock + 1; /* pixel in next row & column */ offset = ref_width - width; - + if ((mx & 1) == 0) { - if ((my & 1) == 0) /* Don't use halfpixel refinement */ - for (y = height; y; y--) - { - memcpy (mcblock, rblock, width * sizeof (word_t)); - - mcblock += width; - rblock += ref_width; - } - else /* Halfpixel in y direction */ - for (y = height; y; y--) - { - for (x = width; x; x--) + if ((my & 1) == 0) /* Don't use halfpixel refinement */ + for (y = height; y; y--) + { + memcpy (mcblock, rblock, width * sizeof (word_t)); + + mcblock += width; + rblock += ref_width; + } + else /* Halfpixel in y direction */ + for (y = height; y; y--) + { + for (x = width; x; x--) #ifdef HAVE_SIGNED_SHIFT - *mcblock++ = (*rblock++ + *ryblock++) >> 1; + *mcblock++ = (*rblock++ + *ryblock++) >> 1; #else /* not HAVE_SIGNED_SHIFT */ - *mcblock++ = (*rblock++ + *ryblock++) / 2; + *mcblock++ = (*rblock++ + *ryblock++) / 2; #endif /* not HAVE_SIGNED_SHIFT */ - rblock += offset; - ryblock += offset; - } + rblock += offset; + ryblock += offset; + } } else { - if ((my & 1) == 0) /* Halfpixel in x direction */ - for (y = height; y; y--) - { - for (x = width; x; x--) + if ((my & 1) == 0) /* Halfpixel in x direction */ + for (y = height; y; y--) + { + for (x = width; x; x--) #ifdef HAVE_SIGNED_SHIFT - *mcblock++ = (*rblock++ + *rxblock++) >> 1; + *mcblock++ = (*rblock++ + *rxblock++) >> 1; #else /* not HAVE_SIGNED_SHIFT */ - *mcblock++ = (*rblock++ + *rxblock++) / 2; + *mcblock++ = (*rblock++ + *rxblock++) / 2; #endif /* not HAVE_SIGNED_SHIFT */ - rblock += offset; - rxblock += offset; - } - else /* Halfpixel in xy direction */ - for (y = height; y; y--) - { - for (x = width; x; x--) + rblock += offset; + rxblock += offset; + } + else /* Halfpixel in xy direction */ + for (y = height; y; y--) + { + for (x = width; x; x--) #ifdef HAVE_SIGNED_SHIFT - *mcblock++ = (*rblock++ + *rxblock++ - + *ryblock++ + *rxyblock++) >> 2; + *mcblock++ = (*rblock++ + *rxblock++ + + *ryblock++ + *rxyblock++) >> 2; #else /* not HAVE_SIGNED_SHIFT */ - *mcblock++ = (*rblock++ + *rxblock++ - + *ryblock++ + *rxyblock++) / 4; + *mcblock++ = (*rblock++ + *rxblock++ + + *ryblock++ + *rxyblock++) / 4; #endif /* not HAVE_SIGNED_SHIFT */ - rblock += offset; - ryblock += offset; - rxblock += offset; - rxyblock += offset; - } + rblock += offset; + ryblock += offset; + rxblock += offset; + rxyblock += offset; + } } } } diff --git a/converter/other/fiasco/codec/motion.h b/converter/other/fiasco/codec/motion.h index 82d1f1ec..f913c65d 100644 --- a/converter/other/fiasco/codec/motion.h +++ b/converter/other/fiasco/codec/motion.h @@ -1,9 +1,9 @@ /* * motion.h * - * Written by: Ullrich Hafner - * Michael Unger - * + * Written by: Ullrich Hafner + * Michael Unger + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -24,12 +24,12 @@ void restore_mc (int enlarge_factor, image_t *image, const image_t *past, - const image_t *future, const wfa_t *wfa); + const image_t *future, const wfa_t *wfa); void extract_mc_block (word_t *mcblock, unsigned width, unsigned height, - const word_t *reference, unsigned ref_width, - bool_t half_pixel, unsigned xo, unsigned yo, - unsigned mx, unsigned my); + const word_t *reference, unsigned ref_width, + bool_t half_pixel, unsigned xo, unsigned yo, + unsigned mx, unsigned my); #endif /* not _MOTION_H */ diff --git a/converter/other/fiasco/codec/mwfa.c b/converter/other/fiasco/codec/mwfa.c index 0be08a4f..f83f2d00 100644 --- a/converter/other/fiasco/codec/mwfa.c +++ b/converter/other/fiasco/codec/mwfa.c @@ -1,9 +1,9 @@ /* - * mwfa.c: Initialization of MWFA coder + * mwfa.c: Initialization of MWFA coder + * + * Written by: Michael Unger + * Ullrich Hafner * - * Written by: Michael Unger - * Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -38,33 +38,33 @@ static const unsigned local_range = 6; /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ static void get_mcpe (word_t *mcpe, const image_t *original, - unsigned x0, unsigned y0, unsigned width, unsigned height, - const word_t *mcblock1, const word_t *mcblock2); + unsigned x0, unsigned y0, unsigned width, unsigned height, + const word_t *mcblock1, const word_t *mcblock2); static real_t mcpe_norm (const image_t *original, unsigned x0, unsigned y0, unsigned width, - unsigned height, const word_t *mcblock1, const word_t *mcblock2); -static real_t + unsigned height, const word_t *mcblock1, const word_t *mcblock2); +static real_t find_best_mv (real_t price, const image_t *original, const image_t *reference, - unsigned x0, unsigned y0, unsigned width, unsigned height, - real_t *bits, int *mx, int *my, const real_t *mc_norms, - const wfa_info_t *wi, const motion_t *mt); + unsigned x0, unsigned y0, unsigned width, unsigned height, + real_t *bits, int *mx, int *my, const real_t *mc_norms, + const wfa_info_t *wi, const motion_t *mt); static real_t find_second_mv (real_t price, const image_t *original, - const image_t *reference, const word_t *mcblock1, - unsigned xr, unsigned yr, unsigned width, unsigned height, - real_t *bits, int *mx, int *my, const wfa_info_t *wi, - const motion_t *mt); + const image_t *reference, const word_t *mcblock1, + unsigned xr, unsigned yr, unsigned width, unsigned height, + real_t *bits, int *mx, int *my, const wfa_info_t *wi, + const motion_t *mt); /***************************************************************************** - public code - + public code + *****************************************************************************/ motion_t * @@ -75,32 +75,32 @@ alloc_motion (const wfa_info_t *wi) * fill in default values specified by 'wi'. * * Return value: - * pointer to the new option structure or NULL on error + * pointer to the new option structure or NULL on error */ { - int dx; /* motion vector coordinate */ + int dx; /* motion vector coordinate */ unsigned level; unsigned range_size = wi->half_pixel - ? square (wi->search_range) - : square (2 * wi->search_range); + ? square (wi->search_range) + : square (2 * wi->search_range); motion_t *mt = Calloc (1, sizeof (motion_t)); - + mt->original = NULL; mt->past = NULL; mt->future = NULL; - mt->xbits = Calloc (2 * wi->search_range, sizeof (real_t)); - mt->ybits = Calloc (2 * wi->search_range, sizeof (real_t)); + mt->xbits = Calloc (2 * wi->search_range, sizeof (real_t)); + mt->ybits = Calloc (2 * wi->search_range, sizeof (real_t)); for (dx = -wi->search_range; dx < (int) wi->search_range; dx++) { mt->xbits [dx + wi->search_range] - = mt->ybits [dx + wi->search_range] - = mv_code_table [dx + wi->search_range][1]; + = mt->ybits [dx + wi->search_range] + = mv_code_table [dx + wi->search_range][1]; } - + mt->mc_forward_norms = Calloc (MAXLEVEL, sizeof (real_t *)); mt->mc_backward_norms = Calloc (MAXLEVEL, sizeof (real_t *)); - + for (level = wi->p_min_level; level <= wi->p_max_level; level++) { mt->mc_forward_norms [level] = Calloc (range_size, sizeof (real_t)); @@ -119,7 +119,7 @@ free_motion (motion_t *mt) * No return value. * * Side effects: - * structure 'motion' is discarded. + * structure 'motion' is discarded. */ { unsigned level; @@ -129,9 +129,9 @@ free_motion (motion_t *mt) for (level = 0; level < MAXLEVEL; level++) { if (mt->mc_forward_norms [level]) - Free (mt->mc_forward_norms [level]); + Free (mt->mc_forward_norms [level]); if (mt->mc_backward_norms [level]) - Free (mt->mc_backward_norms [level]); + Free (mt->mc_backward_norms [level]); } Free (mt->mc_forward_norms); Free (mt->mc_backward_norms); @@ -140,7 +140,7 @@ free_motion (motion_t *mt) void subtract_mc (image_t *image, const image_t *past, const image_t *future, - const wfa_t *wfa) + const wfa_t *wfa) /* * Subtract motion compensation from chrom channels of 'image'. * Reference frames are given by 'past' and 'future'. @@ -150,135 +150,135 @@ subtract_mc (image_t *image, const image_t *past, const image_t *future, { unsigned state, label; word_t *mcblock1 = Calloc (size_of_level (wfa->wfainfo->p_max_level), - sizeof (word_t)); + sizeof (word_t)); word_t *mcblock2 = Calloc (size_of_level (wfa->wfainfo->p_max_level), - sizeof (word_t)); + sizeof (word_t)); for (state = wfa->basis_states; state < wfa->states; state++) for (label = 0; label < MAXLABELS; label++) - if (wfa->mv_tree [state][label].type != NONE) - { - color_e band; /* current color band */ - unsigned width, height; /* size of mcblock */ - unsigned offset; /* remaining pixels in original */ - - width = width_of_level (wfa->level_of_state [state] - 1); - height = height_of_level (wfa->level_of_state [state] - 1); - offset = image->width - width; - - switch (wfa->mv_tree [state][label].type) - { - case FORWARD: - for (band = first_band (image->color) + 1; - band <= last_band (image->color); band++) - { - unsigned y; /* row of block */ - word_t *mc1; /* pixel in MC block 1 */ - word_t *orig; /* pixel in original image */ - - extract_mc_block (mcblock1, width, height, - past->pixels [band], past->width, - wfa->wfainfo->half_pixel, - wfa->x [state][label], - wfa->y [state][label], - (wfa->mv_tree [state][label].fx / 2) - * 2, - (wfa->mv_tree [state][label].fy / 2) - * 2); - mc1 = mcblock1; - orig = image->pixels [band] + wfa->x [state][label] - + wfa->y [state][label] * image->width; - - for (y = height; y; y--) - { - unsigned x; /* column of block */ - - for (x = width; x; x--) - *orig++ -= *mc1++; - - orig += offset; - } - } - break; - case BACKWARD: - for (band = first_band (image->color) + 1; - band <= last_band (image->color); band++) - { - unsigned y; /* row of block */ - word_t *mc1; /* pixel in MC block 1 */ - word_t *orig; /* pixel in original image */ - - extract_mc_block (mcblock1, width, height, - future->pixels [band], future->width, - wfa->wfainfo->half_pixel, - wfa->x [state][label], - wfa->y [state][label], - (wfa->mv_tree [state][label].bx / 2) - * 2, - (wfa->mv_tree [state][label].by / 2) - * 2); - mc1 = mcblock1; - orig = image->pixels [band] + wfa->x [state][label] - + wfa->y [state][label] * image->width; - - for (y = height; y; y--) - { - unsigned x; /* column of block */ - - for (x = width; x; x--) - *orig++ -= *mc1++; - - orig += offset; - } - } - break; - case INTERPOLATED: - for (band = first_band (image->color) + 1; - band <= last_band (image->color); band++) - { - unsigned y; /* row of block */ - word_t *mc1; /* pixel in MC block 1 */ - word_t *mc2; /* pixel in MC block 2 */ - word_t *orig; /* pixel in original image */ - - extract_mc_block (mcblock1, width, height, - past->pixels [band], past->width, - wfa->wfainfo->half_pixel, - wfa->x [state][label], - wfa->y [state][label], - (wfa->mv_tree[state][label].fx / 2) - * 2, - (wfa->mv_tree[state][label].fy / 2) - * 2); - extract_mc_block (mcblock2, width, height, - future->pixels [band], future->width, - wfa->wfainfo->half_pixel, - wfa->x [state][label], - wfa->y [state][label], - (wfa->mv_tree[state][label].bx / 2) - * 2, - (wfa->mv_tree[state][label].by / 2) - * 2); - mc1 = mcblock1; - mc2 = mcblock2; - orig = image->pixels [band] + wfa->x [state][label] - + wfa->y [state][label] * image->width; - - for (y = height; y; y--) - { - unsigned x; /* column of block */ - - for (x = width; x; x--) - *orig++ -= (*mc1++ + *mc2++) / 2; - - orig += offset; - } - } - break; - default: - break; - } - } + if (wfa->mv_tree [state][label].type != NONE) + { + color_e band; /* current color band */ + unsigned width, height; /* size of mcblock */ + unsigned offset; /* remaining pixels in original */ + + width = width_of_level (wfa->level_of_state [state] - 1); + height = height_of_level (wfa->level_of_state [state] - 1); + offset = image->width - width; + + switch (wfa->mv_tree [state][label].type) + { + case FORWARD: + for (band = first_band (image->color) + 1; + band <= last_band (image->color); band++) + { + unsigned y; /* row of block */ + word_t *mc1; /* pixel in MC block 1 */ + word_t *orig; /* pixel in original image */ + + extract_mc_block (mcblock1, width, height, + past->pixels [band], past->width, + wfa->wfainfo->half_pixel, + wfa->x [state][label], + wfa->y [state][label], + (wfa->mv_tree [state][label].fx / 2) + * 2, + (wfa->mv_tree [state][label].fy / 2) + * 2); + mc1 = mcblock1; + orig = image->pixels [band] + wfa->x [state][label] + + wfa->y [state][label] * image->width; + + for (y = height; y; y--) + { + unsigned x; /* column of block */ + + for (x = width; x; x--) + *orig++ -= *mc1++; + + orig += offset; + } + } + break; + case BACKWARD: + for (band = first_band (image->color) + 1; + band <= last_band (image->color); band++) + { + unsigned y; /* row of block */ + word_t *mc1; /* pixel in MC block 1 */ + word_t *orig; /* pixel in original image */ + + extract_mc_block (mcblock1, width, height, + future->pixels [band], future->width, + wfa->wfainfo->half_pixel, + wfa->x [state][label], + wfa->y [state][label], + (wfa->mv_tree [state][label].bx / 2) + * 2, + (wfa->mv_tree [state][label].by / 2) + * 2); + mc1 = mcblock1; + orig = image->pixels [band] + wfa->x [state][label] + + wfa->y [state][label] * image->width; + + for (y = height; y; y--) + { + unsigned x; /* column of block */ + + for (x = width; x; x--) + *orig++ -= *mc1++; + + orig += offset; + } + } + break; + case INTERPOLATED: + for (band = first_band (image->color) + 1; + band <= last_band (image->color); band++) + { + unsigned y; /* row of block */ + word_t *mc1; /* pixel in MC block 1 */ + word_t *mc2; /* pixel in MC block 2 */ + word_t *orig; /* pixel in original image */ + + extract_mc_block (mcblock1, width, height, + past->pixels [band], past->width, + wfa->wfainfo->half_pixel, + wfa->x [state][label], + wfa->y [state][label], + (wfa->mv_tree[state][label].fx / 2) + * 2, + (wfa->mv_tree[state][label].fy / 2) + * 2); + extract_mc_block (mcblock2, width, height, + future->pixels [band], future->width, + wfa->wfainfo->half_pixel, + wfa->x [state][label], + wfa->y [state][label], + (wfa->mv_tree[state][label].bx / 2) + * 2, + (wfa->mv_tree[state][label].by / 2) + * 2); + mc1 = mcblock1; + mc2 = mcblock2; + orig = image->pixels [band] + wfa->x [state][label] + + wfa->y [state][label] * image->width; + + for (y = height; y; y--) + { + unsigned x; /* column of block */ + + for (x = width; x; x--) + *orig++ -= (*mc1++ + *mc2++) / 2; + + orig += offset; + } + } + break; + default: + break; + } + } Free (mcblock1); Free (mcblock2); @@ -286,7 +286,7 @@ subtract_mc (image_t *image, const image_t *past, const image_t *future, void find_P_frame_mc (word_t *mcpe, real_t price, range_t *range, - const wfa_info_t *wi, const motion_t *mt) + const wfa_info_t *wi, const motion_t *mt) /* * Determine best motion vector for P-frame. * @@ -301,7 +301,7 @@ find_P_frame_mc (word_t *mcpe, real_t price, range_t *range, unsigned width = width_of_level (range->level); unsigned height = height_of_level (range->level); word_t *mcblock = Calloc (width * height, sizeof (word_t)); - + range->mv_tree_bits = 1; range->mv.type = FORWARD; @@ -309,24 +309,24 @@ find_P_frame_mc (word_t *mcpe, real_t price, range_t *range, * Find best matching forward prediction */ find_best_mv (price, mt->original, mt->past, range->x, range->y, - width, height, &range->mv_coord_bits, &range->mv.fx, - &range->mv.fy, mt->mc_forward_norms [range->level], wi, mt); + width, height, &range->mv_coord_bits, &range->mv.fx, + &range->mv.fy, mt->mc_forward_norms [range->level], wi, mt); /* * Compute MCPE */ extract_mc_block (mcblock, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, range->x, range->y, - range->mv.fx, range->mv.fy); + mt->past->width, wi->half_pixel, range->x, range->y, + range->mv.fx, range->mv.fy); get_mcpe (mcpe, mt->original, range->x, range->y, width, height, - mcblock, NULL); + mcblock, NULL); Free (mcblock); } void find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, - const wfa_info_t *wi, const motion_t *mt) + const wfa_info_t *wi, const motion_t *mt) /* * Determines best motion compensation for B-frame. * Steps: @@ -338,104 +338,104 @@ find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, * FORWARD 000 * BACKWARD 001 * INTERPOLATED 01 - * + * * Return values: * range->mvt_bits (# of mv-tree bits) * range->mvxybits (# of bits for vector components) * mt->mcpe (MCPE in scan-order) */ { - mc_type_e mctype; /* type of motion compensation */ - real_t forward_costs; /* costs of FORWARD mc */ - real_t backward_costs; /* costs of BACKWARD mc */ - real_t interp_costs; /* costs of INTERPOLATED mc */ - real_t forward_bits; /* bits for FORWARD mc */ - real_t backward_bits; /* bits for BACKWARD mc */ - real_t interp_bits; /* bits for INTERPOLATED mc */ - int fx, fy; /* coordinates FORWARD mc */ - int bx, by; /* coordinates BACKWARD mc */ - int ifx, ify; /* coordinates forw. INTERPOLATED mc */ - int ibx, iby; /* coordinates back. INTERPOLATED mc */ + mc_type_e mctype; /* type of motion compensation */ + real_t forward_costs; /* costs of FORWARD mc */ + real_t backward_costs; /* costs of BACKWARD mc */ + real_t interp_costs; /* costs of INTERPOLATED mc */ + real_t forward_bits; /* bits for FORWARD mc */ + real_t backward_bits; /* bits for BACKWARD mc */ + real_t interp_bits; /* bits for INTERPOLATED mc */ + int fx, fy; /* coordinates FORWARD mc */ + int bx, by; /* coordinates BACKWARD mc */ + int ifx, ify; /* coordinates forw. INTERPOLATED mc */ + int ibx, iby; /* coordinates back. INTERPOLATED mc */ unsigned width = width_of_level (range->level); unsigned height = height_of_level (range->level); word_t *mcblock1 = Calloc (width * height, sizeof (word_t)); word_t *mcblock2 = Calloc (width * height, sizeof (word_t)); - + /* * Forward interpolation: use past frame as reference */ forward_costs = find_best_mv (price, mt->original, mt->past, - range->x, range->y, width, height, - &forward_bits, &fx, &fy, - mt->mc_forward_norms [range->level], wi, mt) - + 3 * price; /* code 000 */ + range->x, range->y, width, height, + &forward_bits, &fx, &fy, + mt->mc_forward_norms [range->level], wi, mt) + + 3 * price; /* code 000 */ /* * Backward interpolation: use future frame as reference */ backward_costs = find_best_mv (price, mt->original, mt->future, - range->x, range->y, width, height, - &backward_bits, &bx, &by, - mt->mc_backward_norms [range->level], wi, mt) - + 3 * price; /* code 001 */ + range->x, range->y, width, height, + &backward_bits, &bx, &by, + mt->mc_backward_norms [range->level], wi, mt) + + 3 * price; /* code 001 */ /* * Bidirectional interpolation: use both past and future frame as reference */ - if (wi->cross_B_search) + if (wi->cross_B_search) { - real_t icosts1; /* costs interpolation alternative 1 */ - real_t icosts2; /* costs interpolation alternative 2 */ - real_t ibackward_bits; /* additional bits alternative 1 */ - real_t iforward_bits; /* additional bits alternative 1 */ - + real_t icosts1; /* costs interpolation alternative 1 */ + real_t icosts2; /* costs interpolation alternative 2 */ + real_t ibackward_bits; /* additional bits alternative 1 */ + real_t iforward_bits; /* additional bits alternative 1 */ + /* * Alternative 1: keep forward mv and vary backward mv locally */ extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, - range->x, range->y, fx, fy); + mt->past->width, wi->half_pixel, + range->x, range->y, fx, fy); - ibx = bx; /* start with backward coordinates */ + ibx = bx; /* start with backward coordinates */ iby = by; icosts1 = find_second_mv (price, mt->original, mt->future, - mcblock1, range->x, range->y, width, height, - &ibackward_bits, &ibx, &iby, wi, mt) - + (forward_bits + 2) * price; /* code 01 */ + mcblock1, range->x, range->y, width, height, + &ibackward_bits, &ibx, &iby, wi, mt) + + (forward_bits + 2) * price; /* code 01 */ /* * Alternative 2: Keep backward mv and vary forward mv locally */ extract_mc_block (mcblock1, width, height, mt->future->pixels [GRAY], - mt->future->width, wi->half_pixel, - range->x, range->y, bx, by); + mt->future->width, wi->half_pixel, + range->x, range->y, bx, by); ifx = fx; ify = fy; icosts2 = find_second_mv (price, mt->original, mt->past, - mcblock1, range->x, range->y, width, height, - &iforward_bits, &ifx, &ify, wi, mt) - + (backward_bits + 2) * price; /* code 01 */ - + mcblock1, range->x, range->y, width, height, + &iforward_bits, &ifx, &ify, wi, mt) + + (backward_bits + 2) * price; /* code 01 */ + /* * Choose best alternative */ if (icosts1 < icosts2) { - ifx = fx; - ify = fy; - interp_bits = forward_bits + ibackward_bits; - interp_costs = icosts1; + ifx = fx; + ify = fy; + interp_bits = forward_bits + ibackward_bits; + interp_costs = icosts1; } else { - ibx = bx; - iby = by; - interp_bits = iforward_bits + backward_bits; - interp_costs = icosts2; + ibx = bx; + iby = by; + interp_bits = iforward_bits + backward_bits; + interp_costs = icosts2; } } - else /* local exhaustive search */ + else /* local exhaustive search */ { /* * Keep forward and backward mv because of time constraints @@ -448,14 +448,14 @@ find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, interp_bits = forward_bits + backward_bits; extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, - range->x, range->y, fx, fy); + mt->past->width, wi->half_pixel, + range->x, range->y, fx, fy); extract_mc_block (mcblock2, width, height, mt->future->pixels [GRAY], - mt->future->width, wi->half_pixel, - range->x, range->y, bx, by); + mt->future->width, wi->half_pixel, + range->x, range->y, bx, by); interp_costs = mcpe_norm (mt->original, range->x, range->y, - width, height, mcblock1, mcblock2) - + (interp_bits + 2) * price; /* code 01 */ + width, height, mcblock1, mcblock2) + + (interp_bits + 2) * price; /* code 01 */ } /* @@ -464,63 +464,63 @@ find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, if (forward_costs <= interp_costs) { if (forward_costs <= backward_costs) - mctype = FORWARD; + mctype = FORWARD; else - mctype = BACKWARD; + mctype = BACKWARD; } else { if (backward_costs <= interp_costs) - mctype = BACKWARD; + mctype = BACKWARD; else - mctype = INTERPOLATED; + mctype = INTERPOLATED; } switch (mctype) { case FORWARD: - range->mv_tree_bits = 3; - range->mv_coord_bits = forward_bits; - range->mv.type = FORWARD; - range->mv.fx = fx; - range->mv.fy = fy; - extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, - range->x, range->y, range->mv.fx, range->mv.fy); - get_mcpe (mcpe, mt->original, range->x, range->y, width, height, - mcblock1, NULL); - break; + range->mv_tree_bits = 3; + range->mv_coord_bits = forward_bits; + range->mv.type = FORWARD; + range->mv.fx = fx; + range->mv.fy = fy; + extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], + mt->past->width, wi->half_pixel, + range->x, range->y, range->mv.fx, range->mv.fy); + get_mcpe (mcpe, mt->original, range->x, range->y, width, height, + mcblock1, NULL); + break; case BACKWARD: - range->mv_tree_bits = 3; - range->mv_coord_bits = backward_bits; - range->mv.type = BACKWARD; - range->mv.bx = bx; - range->mv.by = by; - extract_mc_block (mcblock1, width, height, mt->future->pixels [GRAY], - mt->future->width, wi->half_pixel, - range->x, range->y, range->mv.bx, range->mv.by); - get_mcpe (mcpe, mt->original, range->x, range->y, width, height, - mcblock1, NULL); - break; + range->mv_tree_bits = 3; + range->mv_coord_bits = backward_bits; + range->mv.type = BACKWARD; + range->mv.bx = bx; + range->mv.by = by; + extract_mc_block (mcblock1, width, height, mt->future->pixels [GRAY], + mt->future->width, wi->half_pixel, + range->x, range->y, range->mv.bx, range->mv.by); + get_mcpe (mcpe, mt->original, range->x, range->y, width, height, + mcblock1, NULL); + break; case INTERPOLATED: - range->mv_tree_bits = 2; - range->mv_coord_bits = interp_bits; - range->mv.type = INTERPOLATED; - range->mv.fx = ifx; - range->mv.fy = ify; - range->mv.bx = ibx; - range->mv.by = iby; - extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, - range->x, range->y, range->mv.fx, range->mv.fy); - extract_mc_block (mcblock2, width, height, mt->future->pixels [GRAY], - mt->future->width, wi->half_pixel, - range->x, range->y, range->mv.bx, range->mv.by); - get_mcpe (mcpe, mt->original, range->x, range->y, width, height, - mcblock1, mcblock2); - break; + range->mv_tree_bits = 2; + range->mv_coord_bits = interp_bits; + range->mv.type = INTERPOLATED; + range->mv.fx = ifx; + range->mv.fy = ify; + range->mv.bx = ibx; + range->mv.by = iby; + extract_mc_block (mcblock1, width, height, mt->past->pixels [GRAY], + mt->past->width, wi->half_pixel, + range->x, range->y, range->mv.fx, range->mv.fy); + extract_mc_block (mcblock2, width, height, mt->future->pixels [GRAY], + mt->future->width, wi->half_pixel, + range->x, range->y, range->mv.bx, range->mv.by); + get_mcpe (mcpe, mt->original, range->x, range->y, width, height, + mcblock1, mcblock2); + break; default: - break; + break; } Free (mcblock1); @@ -529,7 +529,7 @@ find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, void fill_norms_table (unsigned x0, unsigned y0, unsigned level, - const wfa_info_t *wi, motion_t *mt) + const wfa_info_t *wi, motion_t *mt) /* * Compute norms of difference images for all possible displacements * in 'mc_forward_norm' and 'mc_backward_norm'. @@ -537,50 +537,50 @@ fill_norms_table (unsigned x0, unsigned y0, unsigned level, * No return value. * * Side effects: - * 'mt->mc_backward_norms' are computed - * 'mt->mc_forward_norms' are computed + * 'mt->mc_backward_norms' are computed + * 'mt->mc_forward_norms' are computed */ { - int mx, my; /* coordinates of motion vector */ - unsigned sr; /* mv search range +-'sr' pixels */ - unsigned index = 0; /* index of motion vector */ + int mx, my; /* coordinates of motion vector */ + unsigned sr; /* mv search range +-'sr' pixels */ + unsigned index = 0; /* index of motion vector */ unsigned width = width_of_level (level); unsigned height = height_of_level (level); word_t *mcblock = Calloc (width * height, sizeof (word_t)); sr = wi->half_pixel ? wi->search_range / 2 : wi->search_range; - + for (my = -sr; my < (int) sr; my++) for (mx = -sr; mx < (int) sr; mx++, index++) { - if ((int) x0 + mx < 0 || /* block outside visible area */ - x0 + mx + width > mt->original->width || - (int) y0 + my < 0 || - y0 + my + height > mt->original->height) - { - mt->mc_forward_norms [level][index] = 0.0; - mt->mc_backward_norms [level][index] = 0.0; - } - else - { - extract_mc_block (mcblock, width, height, mt->past->pixels [GRAY], - mt->past->width, wi->half_pixel, - x0, y0, mx, my); - mt->mc_forward_norms [level][index] - = mcpe_norm (mt->original, x0, y0, width, height, - mcblock, NULL); - - if (mt->frame_type == B_FRAME) - { - extract_mc_block (mcblock, width, height, - mt->future->pixels [GRAY], - mt->future->width, wi->half_pixel, - x0, y0, mx, my); - mt->mc_backward_norms[level][index] - = mcpe_norm (mt->original, x0, y0, width, height, - mcblock, NULL); - } - } + if ((int) x0 + mx < 0 || /* block outside visible area */ + x0 + mx + width > mt->original->width || + (int) y0 + my < 0 || + y0 + my + height > mt->original->height) + { + mt->mc_forward_norms [level][index] = 0.0; + mt->mc_backward_norms [level][index] = 0.0; + } + else + { + extract_mc_block (mcblock, width, height, mt->past->pixels [GRAY], + mt->past->width, wi->half_pixel, + x0, y0, mx, my); + mt->mc_forward_norms [level][index] + = mcpe_norm (mt->original, x0, y0, width, height, + mcblock, NULL); + + if (mt->frame_type == B_FRAME) + { + extract_mc_block (mcblock, width, height, + mt->future->pixels [GRAY], + mt->future->width, wi->half_pixel, + x0, y0, mx, my); + mt->mc_backward_norms[level][index] + = mcpe_norm (mt->original, x0, y0, width, height, + mcblock, NULL); + } + } } Free (mcblock); @@ -588,14 +588,14 @@ fill_norms_table (unsigned x0, unsigned y0, unsigned level, /***************************************************************************** - private code - + private code + *****************************************************************************/ static void get_mcpe (word_t *mcpe, const image_t *original, unsigned x0, unsigned y0, - unsigned width, unsigned height, const word_t *mcblock1, - const word_t *mcblock2) + unsigned width, unsigned height, const word_t *mcblock1, + const word_t *mcblock2) /* * Compute MCPE image 'original' - reference. The reference is either * composed of 'mcblock1' or of ('mcblock1' + 'mcblock2') / 2 (if @@ -605,44 +605,44 @@ get_mcpe (word_t *mcpe, const image_t *original, unsigned x0, unsigned y0, * No return value. * * Side effects: - * 'mcpe []' is filled with the delta image + * 'mcpe []' is filled with the delta image */ { - const word_t *oblock; /* pointer to original image */ + const word_t *oblock; /* pointer to original image */ assert (mcpe); - + oblock = original->pixels [GRAY] + y0 * original->width + x0; - if (mcblock2 != NULL) /* interpolated prediction */ + if (mcblock2 != NULL) /* interpolated prediction */ { - unsigned x, y; /* current coordinates */ - - for (y = height; y; y--) + unsigned x, y; /* current coordinates */ + + for (y = height; y; y--) { - for (x = width; x; x--) - *mcpe++ = *oblock++ - (*mcblock1++ + *mcblock2++) / 2; + for (x = width; x; x--) + *mcpe++ = *oblock++ - (*mcblock1++ + *mcblock2++) / 2; - oblock += original->width - width; + oblock += original->width - width; } } - else /* forward or backward prediction */ + else /* forward or backward prediction */ { - unsigned x, y; /* current coordinates */ - - for (y = height; y; y--) + unsigned x, y; /* current coordinates */ + + for (y = height; y; y--) { - for (x = width; x; x--) - *mcpe++ = *oblock++ - *mcblock1++; - - oblock += original->width - width; + for (x = width; x; x--) + *mcpe++ = *oblock++ - *mcblock1++; + + oblock += original->width - width; } } } static real_t mcpe_norm (const image_t *original, unsigned x0, unsigned y0, unsigned width, - unsigned height, const word_t *mcblock1, const word_t *mcblock2) + unsigned height, const word_t *mcblock1, const word_t *mcblock2) /* * Compute norm of motion compensation prediction error. * Coordinates of 'original' block are given by ('x0', 'y0') @@ -650,79 +650,79 @@ mcpe_norm (const image_t *original, unsigned x0, unsigned y0, unsigned width, * Reference blocks are stored in 'mcimage1' and 'mcimage2'. * * Return value: - * square of norm of difference image + * square of norm of difference image */ { unsigned n; real_t norm = 0; word_t *mcpe = Calloc (width * height, sizeof (word_t)); word_t *ptr = mcpe; - + get_mcpe (mcpe, original, x0, y0, width, height, mcblock1, mcblock2); - for (n = height * width; n; n--, ptr++) + for (n = height * width; n; n--, ptr++) norm += square (*ptr / 16); - + Free (mcpe); - + return norm; } -static real_t +static real_t find_best_mv (real_t price, const image_t *original, const image_t *reference, - unsigned x0, unsigned y0, unsigned width, unsigned height, - real_t *bits, int *mx, int *my, const real_t *mc_norms, - const wfa_info_t *wi, const motion_t *mt) + unsigned x0, unsigned y0, unsigned width, unsigned height, + real_t *bits, int *mx, int *my, const real_t *mc_norms, + const wfa_info_t *wi, const motion_t *mt) /* * Find best matching motion vector in image 'reference' to predict * the block ('x0', 'y0') of size 'width'x'height in image 'original'. * * Return values: - * prediction costs + * prediction costs * * Side effects: - * 'mx', 'my' coordinates of motion vector - * 'bits' number of bits to encode mv + * 'mx', 'my' coordinates of motion vector + * 'bits' number of bits to encode mv */ { - unsigned sr; /* mv search range +/- 'sr' pixels */ - unsigned index; /* index of motion vector */ - int x, y; /* coordinates of motion vector */ - real_t costs; /* costs arising if mv is chosen */ - real_t mincosts = MAXCOSTS; /* best costs so far */ - unsigned bitshift; /* half_pixel coordinates multiplier */ - + unsigned sr; /* mv search range +/- 'sr' pixels */ + unsigned index; /* index of motion vector */ + int x, y; /* coordinates of motion vector */ + real_t costs; /* costs arising if mv is chosen */ + real_t mincosts = MAXCOSTS; /* best costs so far */ + unsigned bitshift; /* half_pixel coordinates multiplier */ + *mx = *my = 0; /* * Find best fitting motion vector: * Use exhaustive search in the interval x,y +- sr (no halfpixel accuracy) - * or x,y +- sr/2 (halfpixel accuracy) + * or x,y +- sr/2 (halfpixel accuracy) */ - sr = wi->half_pixel ? wi->search_range / 2 : wi->search_range; - bitshift = (wi->half_pixel ? 2 : 1); /* bit0 reserved for halfpixel pred. */ - + sr = wi->half_pixel ? wi->search_range / 2 : wi->search_range; + bitshift = (wi->half_pixel ? 2 : 1); /* bit0 reserved for halfpixel pred. */ + for (index = 0, y = -sr; y < (int) sr; y++) for (x = -sr; x < (int) sr; x++, index++) - if ((int) x0 + x >= 0 && (int) y0 + y >= 0 && - x0 + x + width <= original->width && - y0 + y + height <= original->height) - { - /* - * Block is inside visible area. - * Compare current costs with 'mincosts' - */ - costs = mc_norms [index] - + (mt->xbits [(x + sr) * bitshift] - + mt->ybits [(y + sr) * bitshift]) * price; - - if (costs < mincosts) - { - mincosts = costs; - *mx = x * bitshift; - *my = y * bitshift; - } - } + if ((int) x0 + x >= 0 && (int) y0 + y >= 0 && + x0 + x + width <= original->width && + y0 + y + height <= original->height) + { + /* + * Block is inside visible area. + * Compare current costs with 'mincosts' + */ + costs = mc_norms [index] + + (mt->xbits [(x + sr) * bitshift] + + mt->ybits [(y + sr) * bitshift]) * price; + + if (costs < mincosts) + { + mincosts = costs; + *mx = x * bitshift; + *my = y * bitshift; + } + } /* * Halfpixel prediction: @@ -730,53 +730,53 @@ find_best_mv (real_t price, const image_t *original, const image_t *reference, */ if (wi->half_pixel) { - int rx, ry; /* halfpixel refinement */ - unsigned bestrx, bestry; /* coordinates of best mv */ + int rx, ry; /* halfpixel refinement */ + unsigned bestrx, bestry; /* coordinates of best mv */ word_t *mcblock = Calloc (width * height, sizeof (word_t)); - + bestrx = bestry = 0; for (rx = -1; rx <= 1; rx++) - for (ry = -1; ry <= 1; ry++) - { - /* - * Check if the new motion vector is in allowed area - */ - if (rx == 0 && ry == 0) /* already tested */ - continue; - if ((int) x0 + (*mx / 2) + rx < 0 || /* outside visible area */ - x0 + (*mx / 2) + rx + width > original->width || - (int) y0 + (*my / 2) + ry < 0 || - y0 + (*my / 2) + ry + height > original->height) - continue; - if (*mx + rx < (int) -sr || *mx + rx >= (int) sr || - *my + ry < (int) -sr || *my + ry >= (int) sr) - continue; /* out of bounds */ - - /* - * Compute costs of new motion compensation - */ - extract_mc_block (mcblock, width, height, - reference->pixels [GRAY], - reference->width, wi->half_pixel, - x0, y0, *mx + rx, *my + ry); - costs = mcpe_norm (mt->original, x0, y0, width, height, mcblock, - NULL) - + (mt->xbits [*mx + rx + sr * bitshift] - + mt->ybits [*my + ry + sr * bitshift]) * price; - if (costs < mincosts) - { - bestrx = rx; - bestry = ry; - mincosts = costs; - } - } + for (ry = -1; ry <= 1; ry++) + { + /* + * Check if the new motion vector is in allowed area + */ + if (rx == 0 && ry == 0) /* already tested */ + continue; + if ((int) x0 + (*mx / 2) + rx < 0 || /* outside visible area */ + x0 + (*mx / 2) + rx + width > original->width || + (int) y0 + (*my / 2) + ry < 0 || + y0 + (*my / 2) + ry + height > original->height) + continue; + if (*mx + rx < (int) -sr || *mx + rx >= (int) sr || + *my + ry < (int) -sr || *my + ry >= (int) sr) + continue; /* out of bounds */ + + /* + * Compute costs of new motion compensation + */ + extract_mc_block (mcblock, width, height, + reference->pixels [GRAY], + reference->width, wi->half_pixel, + x0, y0, *mx + rx, *my + ry); + costs = mcpe_norm (mt->original, x0, y0, width, height, mcblock, + NULL) + + (mt->xbits [*mx + rx + sr * bitshift] + + mt->ybits [*my + ry + sr * bitshift]) * price; + if (costs < mincosts) + { + bestrx = rx; + bestry = ry; + mincosts = costs; + } + } *mx += bestrx; *my += bestry; Free (mcblock); } /* halfpixel */ - + *bits = mt->xbits [*mx + sr * bitshift] + mt->ybits [*my + sr * bitshift]; return mincosts; @@ -784,28 +784,28 @@ find_best_mv (real_t price, const image_t *original, const image_t *reference, static real_t find_second_mv (real_t price, const image_t *original, - const image_t *reference, const word_t *mcblock1, - unsigned xr, unsigned yr, unsigned width, unsigned height, - real_t *bits, int *mx, int *my, const wfa_info_t *wi, - const motion_t *mt) + const image_t *reference, const word_t *mcblock1, + unsigned xr, unsigned yr, unsigned width, unsigned height, + real_t *bits, int *mx, int *my, const wfa_info_t *wi, + const motion_t *mt) /* * Search local area (*mx,*my) for best additional mv. * Overwrite mt->tmpblock. * TODO check sr = search_range * * Return values: - * prediction costs + * prediction costs * * Side effects: - * 'mx','my' coordinates of mv - * 'bits' number of bits to encode mv + * 'mx','my' coordinates of mv + * 'bits' number of bits to encode mv */ { - real_t mincosts = MAXCOSTS; /* best costs so far */ - unsigned sr; /* MV search range +/- 'sr' pixels */ - int x, y; /* coordinates of motion vector */ - int y0, y1, x0, x1; /* start/end coord. of search range */ - unsigned bitshift; /* half_pixel coordinates multiplier */ + real_t mincosts = MAXCOSTS; /* best costs so far */ + unsigned sr; /* MV search range +/- 'sr' pixels */ + int x, y; /* coordinates of motion vector */ + int y0, y1, x0, x1; /* start/end coord. of search range */ + unsigned bitshift; /* half_pixel coordinates multiplier */ word_t *mcblock2 = Calloc (width * height, sizeof (word_t)); sr = wi->search_range; @@ -817,40 +817,40 @@ find_second_mv (real_t price, const image_t *original, *mx = *my = 0; - bitshift = (wi->half_pixel ? 2 : 1); /* bit0 reserved for halfpixel pred. */ + bitshift = (wi->half_pixel ? 2 : 1); /* bit0 reserved for halfpixel pred. */ + - for (y = y0; y < y1; y++) for (x = x0; x < x1; x++) { - real_t costs; /* costs arising if mv is chosen */ - - /* - * Test each mv ('x', 'y') in the given search range: - * Get the new motion compensation image from 'reference' and compute - * the norm of the motion compensation prediction error - * 'original' - 0.5 * ('firstmc' + 'reference') - */ - if ((int) (xr * bitshift) + x < 0 || /* outside visible area */ - xr * bitshift + x > (original->width - width) * bitshift || - (int) (yr * bitshift) + y < 0 || - yr * bitshift + y > (original->height - height) * bitshift) - continue; - - extract_mc_block (mcblock2, width, height, - reference->pixels [GRAY], reference->width, - wi->half_pixel, x0, y0, x, y); - - costs = mcpe_norm (mt->original, x0, y0, width, height, - mcblock1, mcblock2) - + (mt->xbits [x + sr] + mt->ybits [y + sr]) * price; - - if (costs < mincosts) - { - mincosts = costs; - *mx = x; - *my = y; - } + real_t costs; /* costs arising if mv is chosen */ + + /* + * Test each mv ('x', 'y') in the given search range: + * Get the new motion compensation image from 'reference' and compute + * the norm of the motion compensation prediction error + * 'original' - 0.5 * ('firstmc' + 'reference') + */ + if ((int) (xr * bitshift) + x < 0 || /* outside visible area */ + xr * bitshift + x > (original->width - width) * bitshift || + (int) (yr * bitshift) + y < 0 || + yr * bitshift + y > (original->height - height) * bitshift) + continue; + + extract_mc_block (mcblock2, width, height, + reference->pixels [GRAY], reference->width, + wi->half_pixel, x0, y0, x, y); + + costs = mcpe_norm (mt->original, x0, y0, width, height, + mcblock1, mcblock2) + + (mt->xbits [x + sr] + mt->ybits [y + sr]) * price; + + if (costs < mincosts) + { + mincosts = costs; + *mx = x; + *my = y; + } } *bits = mt->xbits [*mx + sr] + mt->ybits [*my + sr]; diff --git a/converter/other/fiasco/codec/mwfa.h b/converter/other/fiasco/codec/mwfa.h index 2c1e7c9f..1e35eef2 100644 --- a/converter/other/fiasco/codec/mwfa.h +++ b/converter/other/fiasco/codec/mwfa.h @@ -1,9 +1,9 @@ /* * mwfa.h * - * Written by: Michael Unger - * Ullrich Hafner - * + * Written by: Michael Unger + * Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -25,16 +25,16 @@ void fill_norms_table (unsigned x0, unsigned y0, unsigned level, - const wfa_info_t *wi, motion_t *mt); + const wfa_info_t *wi, motion_t *mt); void find_B_frame_mc (word_t *mcpe, real_t price, range_t *range, - const wfa_info_t *wi, const motion_t *mt); + const wfa_info_t *wi, const motion_t *mt); void find_P_frame_mc (word_t *mcpe, real_t price, range_t *range, - const wfa_info_t *wi, const motion_t *mt); + const wfa_info_t *wi, const motion_t *mt); void subtract_mc (image_t *image, const image_t *past, const image_t *future, - const wfa_t *wfa); + const wfa_t *wfa); void free_motion (motion_t *mt); motion_t * diff --git a/converter/other/fiasco/codec/options.c b/converter/other/fiasco/codec/options.c index b9c64efd..8029a48e 100644 --- a/converter/other/fiasco/codec/options.c +++ b/converter/other/fiasco/codec/options.c @@ -1,8 +1,8 @@ /* - * options.c: FIASCO options handling + * options.c: FIASCO options handling + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -44,10 +44,10 @@ fiasco_c_options_new (void) * fill in default values. * * Return value: - * pointer to the new option structure + * pointer to the new option structure */ { - c_options_t *options = calloc (1, sizeof (c_options_t)); + c_options_t *options = calloc (1, sizeof (c_options_t)); fiasco_c_options_t *public = calloc (1, sizeof (fiasco_c_options_t)); if (!options || !public) @@ -55,9 +55,9 @@ fiasco_c_options_new (void) set_error (_("Out of memory.")); return NULL; } - public->private = options; - public->delete = fiasco_c_options_delete; - public->set_tiling = fiasco_c_options_set_tiling; + public->private = options; + public->delete = fiasco_c_options_delete; + public->set_tiling = fiasco_c_options_set_tiling; public->set_frame_pattern = fiasco_c_options_set_frame_pattern; public->set_basisfile = fiasco_c_options_set_basisfile; public->set_chroma_quality = fiasco_c_options_set_chroma_quality; @@ -66,57 +66,57 @@ fiasco_c_options_new (void) public->set_quantization = fiasco_c_options_set_quantization; public->set_progress_meter = fiasco_c_options_set_progress_meter; public->set_smoothing = fiasco_c_options_set_smoothing; - public->set_title = fiasco_c_options_set_title; + public->set_title = fiasco_c_options_set_title; public->set_comment = fiasco_c_options_set_comment; - + strcpy (options->id, "COFIASCO"); /* * Set default value of fiasco options */ - options->basis_name = strdup ("small.fco"); - options->lc_min_level = 4; - options->lc_max_level = 12; - options->p_min_level = 8; - options->p_max_level = 10; - options->images_level = 5; - options->max_states = MAXSTATES; - options->chroma_max_states = 40; - options->max_elements = MAXEDGES; - options->tiling_exponent = 4; - options->tiling_method = FIASCO_TILING_VARIANCE_DSC; - options->id_domain_pool = strdup ("rle"); - options->id_d_domain_pool = strdup ("rle"); - options->id_rpf_model = strdup ("adaptive"); - options->id_d_rpf_model = strdup ("adaptive"); - options->rpf_mantissa = 3; - options->rpf_range = FIASCO_RPF_RANGE_1_50; - options->dc_rpf_mantissa = 5; - options->dc_rpf_range = FIASCO_RPF_RANGE_1_00; - options->d_rpf_mantissa = 3; - options->d_rpf_range = FIASCO_RPF_RANGE_1_50; - options->d_dc_rpf_mantissa = 5; - options->d_dc_rpf_range = FIASCO_RPF_RANGE_1_00; - options->chroma_decrease = 2.0; - options->prediction = NO; - options->delta_domains = YES; - options->normal_domains = YES; - options->search_range = 16; - options->fps = 25; - options->pattern = strdup ("IPPPPPPPPP"); - options->reference_filename = NULL; + options->basis_name = strdup ("small.fco"); + options->lc_min_level = 4; + options->lc_max_level = 12; + options->p_min_level = 8; + options->p_max_level = 10; + options->images_level = 5; + options->max_states = MAXSTATES; + options->chroma_max_states = 40; + options->max_elements = MAXEDGES; + options->tiling_exponent = 4; + options->tiling_method = FIASCO_TILING_VARIANCE_DSC; + options->id_domain_pool = strdup ("rle"); + options->id_d_domain_pool = strdup ("rle"); + options->id_rpf_model = strdup ("adaptive"); + options->id_d_rpf_model = strdup ("adaptive"); + options->rpf_mantissa = 3; + options->rpf_range = FIASCO_RPF_RANGE_1_50; + options->dc_rpf_mantissa = 5; + options->dc_rpf_range = FIASCO_RPF_RANGE_1_00; + options->d_rpf_mantissa = 3; + options->d_rpf_range = FIASCO_RPF_RANGE_1_50; + options->d_dc_rpf_mantissa = 5; + options->d_dc_rpf_range = FIASCO_RPF_RANGE_1_00; + options->chroma_decrease = 2.0; + options->prediction = NO; + options->delta_domains = YES; + options->normal_domains = YES; + options->search_range = 16; + options->fps = 25; + options->pattern = strdup ("IPPPPPPPPP"); + options->reference_filename = NULL; options->half_pixel_prediction = NO; - options->cross_B_search = YES; - options->B_as_past_ref = YES; + options->cross_B_search = YES; + options->B_as_past_ref = YES; options->check_for_underflow = NO; - options->check_for_overflow = NO; + options->check_for_overflow = NO; options->second_domain_block = NO; - options->full_search = NO; - options->progress_meter = FIASCO_PROGRESS_NONE; - options->smoothing = 70; - options->comment = strdup (""); - options->title = strdup (""); - + options->full_search = NO; + options->progress_meter = FIASCO_PROGRESS_NONE; + options->smoothing = 70; + options->comment = strdup (""); + options->title = strdup (""); + return public; } @@ -129,14 +129,14 @@ fiasco_c_options_delete (fiasco_c_options_t *options) * No return value. * * Side effects: - * structure 'options' is discarded. + * structure 'options' is discarded. */ { c_options_t *this = cast_c_options (options); if (!this) return; - + Free (this->id_domain_pool); Free (this->id_d_domain_pool); Free (this->id_rpf_model); @@ -144,7 +144,7 @@ fiasco_c_options_delete (fiasco_c_options_t *options) Free (this->pattern); Free (this->comment); Free (this->title); - + Free (this); return; @@ -152,15 +152,15 @@ fiasco_c_options_delete (fiasco_c_options_t *options) int fiasco_c_options_set_tiling (fiasco_c_options_t *options, - fiasco_tiling_e method, unsigned exponent) + fiasco_tiling_e method, unsigned exponent) /* * Set tiling `method' and `exponent'. * See type `fiasco_tiling_e' for a list of valid tiling `methods'. * The image is subdivied into 2^`exponent' tiles * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -175,21 +175,21 @@ fiasco_c_options_set_tiling (fiasco_c_options_t *options, case FIASCO_TILING_SPIRAL_DSC: case FIASCO_TILING_VARIANCE_ASC: case FIASCO_TILING_VARIANCE_DSC: - this->tiling_method = method; - break; + this->tiling_method = method; + break; default: - set_error (_("Invalid tiling method `%d' specified " - "(valid methods are 0, 1, 2, or 3)."), method); - return 0; + set_error (_("Invalid tiling method `%d' specified " + "(valid methods are 0, 1, 2, or 3)."), method); + return 0; } this->tiling_exponent = exponent; - + return 1; } int fiasco_c_options_set_frame_pattern (fiasco_c_options_t *options, - const char *pattern) + const char *pattern) /* * Set `pattern' of input frames. * `pattern' has to be a sequence of the following @@ -201,10 +201,10 @@ fiasco_c_options_set_frame_pattern (fiasco_c_options_t *options, * * When coding video frames the prediction type of input frame N is determined * by reading `pattern' [N] (`pattern' is periodically extended). - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -226,49 +226,49 @@ fiasco_c_options_set_frame_pattern (fiasco_c_options_t *options, else { const char *str; - bool_t parse_error = NO; - int c = 0; - + bool_t parse_error = NO; + int c = 0; + for (str = pattern; *str && !parse_error; str++) - switch (*str) - { - case 'i': - case 'I': - case 'b': - case 'B': - case 'p': - case 'P': - break; - default: - c = *str; - parse_error = YES; - } + switch (*str) + { + case 'i': + case 'I': + case 'b': + case 'B': + case 'p': + case 'P': + break; + default: + c = *str; + parse_error = YES; + } if (parse_error) { - set_error (_("Frame type pattern contains invalid character `%c' " - "(choose I, B or P)."), c); - return 0; + set_error (_("Frame type pattern contains invalid character `%c' " + "(choose I, B or P)."), c); + return 0; } else { - Free (this->pattern); - this->pattern = strdup (pattern); + Free (this->pattern); + this->pattern = strdup (pattern); - return 1; + return 1; } } } int fiasco_c_options_set_basisfile (fiasco_c_options_t *options, - const char *filename) + const char *filename) /* * Set `filename' of FIASCO initial basis. - * + * * Return value: - * 1 on success (if the file is readable) - * 0 otherwise + * 1 on success (if the file is readable) + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -289,14 +289,14 @@ fiasco_c_options_set_basisfile (fiasco_c_options_t *options, FILE *file = open_file (filename, "FIASCO_DATA", READ_ACCESS); if (file) { - fclose (file); - return 1; + fclose (file); + return 1; } else { - set_error (_("Can't read basis file `%s'.\n%s."), filename, - get_system_error ()); - return 0; + set_error (_("Can't read basis file `%s'.\n%s."), filename, + get_system_error ()); + return 0; } */ return 1; } @@ -304,20 +304,20 @@ fiasco_c_options_set_basisfile (fiasco_c_options_t *options, int fiasco_c_options_set_chroma_quality (fiasco_c_options_t *options, - float quality_factor, - unsigned dictionary_size) + float quality_factor, + unsigned dictionary_size) /* * Set color compression parameters. * When coding chroma channels (Cb and Cr) * - approximation quality is given by `quality_factor' * `Y quality' and * - `dictionary_size' gives the number of dictionary elements. - * + * * If 'quality' <= 0 then the luminancy coding quality is also during * chroma channel coding. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -329,13 +329,13 @@ fiasco_c_options_set_chroma_quality (fiasco_c_options_t *options, else if (!dictionary_size) { set_error (_("Size of chroma compression dictionary has to be " - "a positive number.")); + "a positive number.")); return 0; } else if (quality_factor <= 0) { set_error (_("Quality of chroma channel compression has to be " - "positive value.")); + "positive value.")); return 0; } else @@ -349,32 +349,32 @@ fiasco_c_options_set_chroma_quality (fiasco_c_options_t *options, int fiasco_c_options_set_optimizations (fiasco_c_options_t *options, - unsigned min_block_level, - unsigned max_block_level, - unsigned max_elements, - unsigned dictionary_size, - unsigned optimization_level) + unsigned min_block_level, + unsigned max_block_level, + unsigned max_elements, + unsigned dictionary_size, + unsigned optimization_level) /* * Set various optimization parameters. * - During compression only image blocks of size * {`min_block_level', ... ,`max_block_level'} are considered. * The smaller this set of blocks is the faster the coder runs - * and the worse the image quality will be. + * and the worse the image quality will be. * - An individual approximation may use at most `max_elements' * elements of the dictionary which itself contains at most * `dictionary_size' elements. The smaller these values are - * the faster the coder runs and the worse the image quality will be. + * the faster the coder runs and the worse the image quality will be. * - `optimization_level' enables some additional low level optimizations. * 0: standard approximation method * 1: significantly increases the approximation quality, * running time is twice as high as with the standard method - * 2: hardly increases the approximation quality of method 1, + * 2: hardly increases the approximation quality of method 1, * running time is twice as high as with method 1 * (this method just remains for completeness) * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -391,7 +391,7 @@ fiasco_c_options_set_optimizations (fiasco_c_options_t *options, else if (!max_elements) { set_error (_("At least one dictionary element has to be used " - "in an approximation.")); + "in an approximation.")); return 0; } else if (max_block_level < 4) @@ -407,19 +407,19 @@ fiasco_c_options_set_optimizations (fiasco_c_options_t *options, else if (max_block_level < min_block_level) { set_error (_("Maximum block size has to be larger or " - "equal minimum block size.")); + "equal minimum block size.")); return 0; } else { - this->lc_min_level = min_block_level; - this->lc_max_level = max_block_level; - this->max_states = dictionary_size; - this->max_elements = max_elements; + this->lc_min_level = min_block_level; + this->lc_max_level = max_block_level; + this->max_states = dictionary_size; + this->max_elements = max_elements; this->second_domain_block = optimization_level > 0 ? YES : NO; this->check_for_overflow = optimization_level > 1 ? YES : NO; this->check_for_underflow = optimization_level > 1 ? YES : NO; - this->full_search = optimization_level > 1 ? YES : NO; + this->full_search = optimization_level > 1 ? YES : NO; return 1; } @@ -427,9 +427,9 @@ fiasco_c_options_set_optimizations (fiasco_c_options_t *options, int fiasco_c_options_set_prediction (fiasco_c_options_t *options, - int intra_prediction, - unsigned min_block_level, - unsigned max_block_level) + int intra_prediction, + unsigned min_block_level, + unsigned max_block_level) /* * Set minimum and maximum size of image block prediction to * `min_block_level' and `max_block_level'. @@ -438,8 +438,8 @@ fiasco_c_options_set_prediction (fiasco_c_options_t *options, * Prediction of intra frames is only used if `intra_prediction' != 0. * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -451,19 +451,19 @@ fiasco_c_options_set_prediction (fiasco_c_options_t *options, else if (max_block_level < 6) { set_error (_("Maximum prediction block size has to be " - "at least level 6")); + "at least level 6")); return 0; } else if (min_block_level < 6) { set_error (_("Minimum prediction block size has to be " - "at least level 6")); + "at least level 6")); return 0; } else if (max_block_level < min_block_level) { set_error (_("Maximum prediction block size has to be larger or " - "equal minimum block size.")); + "equal minimum block size.")); return 0; } else @@ -471,17 +471,17 @@ fiasco_c_options_set_prediction (fiasco_c_options_t *options, this->p_min_level = min_block_level; this->p_max_level = max_block_level; this->prediction = intra_prediction; - + return 1; } } int fiasco_c_options_set_video_param (fiasco_c_options_t *options, - unsigned frames_per_second, - int half_pixel_prediction, - int cross_B_search, - int B_as_past_ref) + unsigned frames_per_second, + int half_pixel_prediction, + int cross_B_search, + int B_as_past_ref) /* * Set various parameters used for video compensation. * 'frames_per_second' defines the frame rate which should be @@ -494,10 +494,10 @@ fiasco_c_options_set_video_param (fiasco_c_options_t *options, * exhaustive search (in the given search range) is used. * If 'B_as_past_ref' is not 0 then B frames are allowed to be used * for B frame predicion. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -508,10 +508,10 @@ fiasco_c_options_set_video_param (fiasco_c_options_t *options, } else { - this->fps = frames_per_second; + this->fps = frames_per_second; this->half_pixel_prediction = half_pixel_prediction; - this->cross_B_search = cross_B_search; - this->B_as_past_ref = B_as_past_ref; + this->cross_B_search = cross_B_search; + this->B_as_past_ref = B_as_past_ref; return 1; } @@ -519,20 +519,20 @@ fiasco_c_options_set_video_param (fiasco_c_options_t *options, int fiasco_c_options_set_quantization (fiasco_c_options_t *options, - unsigned mantissa, - fiasco_rpf_range_e range, - unsigned dc_mantissa, - fiasco_rpf_range_e dc_range) + unsigned mantissa, + fiasco_rpf_range_e range, + unsigned dc_mantissa, + fiasco_rpf_range_e dc_range) /* * Set accuracy of coefficients quantization. * DC coefficients (of the constant dictionary vector f(x,y) = 1) * are quantized to values of the interval [-`dc_range', `dc_range'] using * #`dc_mantissa' bits. All other quantized coefficients are quantized in * an analogous way using the parameters `range' and `mantissa'. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -544,46 +544,46 @@ fiasco_c_options_set_quantization (fiasco_c_options_t *options, else if (mantissa < 2 || mantissa > 8 || dc_mantissa < 2 || dc_mantissa > 8) { set_error (_("Number of RPF mantissa bits `%d', `%d' have to be in " - "the interval [2,8]."), mantissa, dc_mantissa); + "the interval [2,8]."), mantissa, dc_mantissa); return 0; } else { if ((range == FIASCO_RPF_RANGE_0_75 - || range == FIASCO_RPF_RANGE_1_00 - || range == FIASCO_RPF_RANGE_1_50 - || range == FIASCO_RPF_RANGE_2_00) - && - (dc_range == FIASCO_RPF_RANGE_0_75 - || dc_range == FIASCO_RPF_RANGE_1_00 - || dc_range == FIASCO_RPF_RANGE_1_50 - || dc_range == FIASCO_RPF_RANGE_2_00)) + || range == FIASCO_RPF_RANGE_1_00 + || range == FIASCO_RPF_RANGE_1_50 + || range == FIASCO_RPF_RANGE_2_00) + && + (dc_range == FIASCO_RPF_RANGE_0_75 + || dc_range == FIASCO_RPF_RANGE_1_00 + || dc_range == FIASCO_RPF_RANGE_1_50 + || dc_range == FIASCO_RPF_RANGE_2_00)) { - this->rpf_range = range; - this->dc_rpf_range = dc_range; - this->rpf_mantissa = mantissa; - this->dc_rpf_mantissa = dc_mantissa; + this->rpf_range = range; + this->dc_rpf_range = dc_range; + this->rpf_mantissa = mantissa; + this->dc_rpf_mantissa = dc_mantissa; - return 1; + return 1; } else { - set_error (_("Invalid RPF ranges `%d', `%d' specified."), - range, dc_range); - return 0; + set_error (_("Invalid RPF ranges `%d', `%d' specified."), + range, dc_range); + return 0; } } } int fiasco_c_options_set_progress_meter (fiasco_c_options_t *options, - fiasco_progress_e type) + fiasco_progress_e type) /* * Set type of progress meter. * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -597,12 +597,12 @@ fiasco_c_options_set_progress_meter (fiasco_c_options_t *options, case FIASCO_PROGRESS_BAR: case FIASCO_PROGRESS_PERCENT: case FIASCO_PROGRESS_NONE: - this->progress_meter = type; - break; + this->progress_meter = type; + break; default: - set_error (_("Invalid progress meter `%d' specified " - "(valid values are 0, 1, or 2)."), type); - return 0; + set_error (_("Invalid progress meter `%d' specified " + "(valid values are 0, 1, or 2)."), type); + return 0; } return 1; } @@ -611,10 +611,10 @@ int fiasco_c_options_set_smoothing (fiasco_c_options_t *options, int smoothing) /* * Define `smoothing'-percentage along partitioning borders. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -639,10 +639,10 @@ int fiasco_c_options_set_comment (fiasco_c_options_t *options, const char *comment) /* * Define `comment' of FIASCO stream. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -667,10 +667,10 @@ int fiasco_c_options_set_title (fiasco_c_options_t *options, const char *title) /* * Define `title' of FIASCO stream. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { c_options_t *this = (c_options_t *) cast_c_options (options); @@ -698,7 +698,7 @@ cast_c_options (fiasco_c_options_t *options) * Check whether `options' is a valid object of type c_options_t. * * Return value: - * pointer to options struct on success + * pointer to options struct on success * NULL otherwise */ { @@ -707,8 +707,8 @@ cast_c_options (fiasco_c_options_t *options) { if (!streq (this->id, "COFIASCO")) { - set_error (_("Parameter `options' doesn't match required type.")); - return NULL; + set_error (_("Parameter `options' doesn't match required type.")); + return NULL; } } else @@ -721,7 +721,7 @@ cast_c_options (fiasco_c_options_t *options) /************************************************************************** *************************************************************************** - DECODER + DECODER *************************************************************************** **************************************************************************/ @@ -733,10 +733,10 @@ fiasco_d_options_new (void) * fill in default values. * * Return value: - * pointer to the new option structure + * pointer to the new option structure */ { - d_options_t *options = calloc (1, sizeof (d_options_t)); + d_options_t *options = calloc (1, sizeof (d_options_t)); fiasco_d_options_t *public = calloc (1, sizeof (fiasco_d_options_t)); if (!options || !public) @@ -744,21 +744,21 @@ fiasco_d_options_new (void) set_error (_("Out of memory.")); return NULL; } - public->private = options; - public->delete = fiasco_d_options_delete; + public->private = options; + public->delete = fiasco_d_options_delete; public->set_smoothing = fiasco_d_options_set_smoothing; public->set_magnification = fiasco_d_options_set_magnification; public->set_4_2_0_format = fiasco_d_options_set_4_2_0_format; - + strcpy (options->id, "DOFIASCO"); /* * Set default value of fiasco decoder options */ - options->smoothing = 70; + options->smoothing = 70; options->magnification = 0; options->image_format = FORMAT_4_4_4; - + return public; } @@ -771,14 +771,14 @@ fiasco_d_options_delete (fiasco_d_options_t *options) * No return value. * * Side effects: - * structure 'options' is discarded. + * structure 'options' is discarded. */ { d_options_t *this = cast_d_options (options); if (!this) return; - + Free (this); return; @@ -788,10 +788,10 @@ int fiasco_d_options_set_smoothing (fiasco_d_options_t *options, int smoothing) /* * Define `smoothing'-percentage along partitioning borders. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { d_options_t *this = (d_options_t *) cast_d_options (options); @@ -822,8 +822,8 @@ fiasco_d_options_set_magnification (fiasco_d_options_t *options, int level) * etc. * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { d_options_t *this = (d_options_t *) cast_d_options (options); @@ -843,10 +843,10 @@ int fiasco_d_options_set_4_2_0_format (fiasco_d_options_t *options, int format) /* * Set image format to 4:2:0 or 4:4:4. - * + * * Return value: - * 1 on success - * 0 otherwise + * 1 on success + * 0 otherwise */ { d_options_t *this = (d_options_t *) cast_d_options (options); @@ -869,18 +869,18 @@ cast_d_options (fiasco_d_options_t *options) * Check whether `options' is a valid object of type d_options_t. * * Return value: - * pointer to options struct on success + * pointer to options struct on success * NULL otherwise */ { d_options_t *this = (d_options_t *) options->private; - + if (this) { if (!streq (this->id, "DOFIASCO")) { - set_error (_("Parameter `options' doesn't match required type.")); - return NULL; + set_error (_("Parameter `options' doesn't match required type.")); + return NULL; } } else diff --git a/converter/other/fiasco/codec/options.h b/converter/other/fiasco/codec/options.h index 783c41ef..e39550f6 100644 --- a/converter/other/fiasco/codec/options.h +++ b/converter/other/fiasco/codec/options.h @@ -1,8 +1,8 @@ /* * options.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -19,49 +19,49 @@ typedef struct c_options { - char id [9]; - char *basis_name; - unsigned lc_min_level; - unsigned lc_max_level; - unsigned p_min_level; - unsigned p_max_level; - unsigned images_level; - unsigned max_states; - unsigned chroma_max_states; - unsigned max_elements; - unsigned tiling_exponent; + char id [9]; + char *basis_name; + unsigned lc_min_level; + unsigned lc_max_level; + unsigned p_min_level; + unsigned p_max_level; + unsigned images_level; + unsigned max_states; + unsigned chroma_max_states; + unsigned max_elements; + unsigned tiling_exponent; fiasco_tiling_e tiling_method; - char *id_domain_pool; - char *id_d_domain_pool; - char *id_rpf_model; - char *id_d_rpf_model; - unsigned rpf_mantissa; - real_t rpf_range; - unsigned dc_rpf_mantissa; + char *id_domain_pool; + char *id_d_domain_pool; + char *id_rpf_model; + char *id_d_rpf_model; + unsigned rpf_mantissa; + real_t rpf_range; + unsigned dc_rpf_mantissa; fiasco_rpf_range_e dc_rpf_range; - unsigned d_rpf_mantissa; + unsigned d_rpf_mantissa; fiasco_rpf_range_e d_rpf_range; - unsigned d_dc_rpf_mantissa; + unsigned d_dc_rpf_mantissa; fiasco_rpf_range_e d_dc_rpf_range; - real_t chroma_decrease; - bool_t prediction; - bool_t delta_domains; - bool_t normal_domains; - unsigned search_range; - unsigned fps; - char *pattern; - char *reference_filename; - bool_t half_pixel_prediction; - bool_t cross_B_search; - bool_t B_as_past_ref; - bool_t check_for_underflow; - bool_t check_for_overflow; - bool_t second_domain_block; - bool_t full_search; + real_t chroma_decrease; + bool_t prediction; + bool_t delta_domains; + bool_t normal_domains; + unsigned search_range; + unsigned fps; + char *pattern; + char *reference_filename; + bool_t half_pixel_prediction; + bool_t cross_B_search; + bool_t B_as_past_ref; + bool_t check_for_underflow; + bool_t check_for_overflow; + bool_t second_domain_block; + bool_t full_search; fiasco_progress_e progress_meter; - char *title; - char *comment; - unsigned smoothing; + char *title; + char *comment; + unsigned smoothing; } c_options_t; typedef struct d_options diff --git a/converter/other/fiasco/codec/prediction.c b/converter/other/fiasco/codec/prediction.c index c592baa5..c321391a 100644 --- a/converter/other/fiasco/codec/prediction.c +++ b/converter/other/fiasco/codec/prediction.c @@ -1,8 +1,8 @@ /* - * prediction.c: Range image prediction with MC or ND + * prediction.c: Range image prediction with MC or ND * - * Written by: Ullrich Hafner - * Michael Unger + * Written by: Ullrich Hafner + * Michael Unger * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -40,7 +40,7 @@ /***************************************************************************** - local variables + local variables *****************************************************************************/ @@ -55,7 +55,7 @@ typedef struct state_data real_t *ip_states_state [MAXLEVEL]; word_t tree [MAXLABELS]; - mv_t mv_tree [MAXLABELS]; + mv_t mv_tree [MAXLABELS]; word_t y_state [MAXLABELS]; byte_t y_column [MAXLABELS]; byte_t prediction [MAXLABELS]; @@ -70,49 +70,49 @@ typedef struct state_data /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static real_t nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, - range_t *range, wfa_t *wfa, coding_t *c); + range_t *range, wfa_t *wfa, coding_t *c); static real_t mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, - range_t *range, wfa_t *wfa, coding_t *c); + range_t *range, wfa_t *wfa, coding_t *c); static state_data_t * store_state_data (unsigned from, unsigned to, unsigned max_level, - wfa_t *wfa, coding_t *c); + wfa_t *wfa, coding_t *c); static void restore_state_data (unsigned from, unsigned to, unsigned max_level, - state_data_t *data, wfa_t *wfa, coding_t *c); + state_data_t *data, wfa_t *wfa, coding_t *c); /***************************************************************************** - public code + public code *****************************************************************************/ real_t predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, - coding_t *c, unsigned band, int y_state, unsigned states, - const tree_t *tree_model, const tree_t *p_tree_model, - const void *domain_model, const void *d_domain_model, - const void *coeff_model, const void *d_coeff_model) + coding_t *c, unsigned band, int y_state, unsigned states, + const tree_t *tree_model, const tree_t *p_tree_model, + const void *domain_model, const void *d_domain_model, + const void *coeff_model, const void *d_coeff_model) { - unsigned state; /* counter */ - void *rec_domain_model; /* domain model after recursion */ - void *rec_d_domain_model; /* p domain model after recursion */ - void *rec_coeff_model; /* coeff model after recursion */ - void *rec_d_coeff_model; /* d coeff model after recursion */ - tree_t rec_tree_model; /* tree_model after '' */ - tree_t rec_p_tree_model; /* p_tree_model after '' */ - unsigned rec_states; /* wfa->states after '' */ - real_t *rec_pixels; /* c->pixels after '' */ - state_data_t *rec_state_data; /* state_data struct after '' */ - real_t costs; /* current approximation costs */ - unsigned level; /* counter */ - state_data_t *sd; /* pointer to state_data field */ + unsigned state; /* counter */ + void *rec_domain_model; /* domain model after recursion */ + void *rec_d_domain_model; /* p domain model after recursion */ + void *rec_coeff_model; /* coeff model after recursion */ + void *rec_d_coeff_model; /* d coeff model after recursion */ + tree_t rec_tree_model; /* tree_model after '' */ + tree_t rec_p_tree_model; /* p_tree_model after '' */ + unsigned rec_states; /* wfa->states after '' */ + real_t *rec_pixels; /* c->pixels after '' */ + state_data_t *rec_state_data; /* state_data struct after '' */ + real_t costs; /* current approximation costs */ + unsigned level; /* counter */ + state_data_t *sd; /* pointer to state_data field */ /* * Store WFA data from state 'lc_states' to 'wfa->states' - 1 and @@ -127,7 +127,7 @@ predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, rec_states = wfa->states; rec_pixels = c->pixels; rec_state_data = store_state_data (states, rec_states - 1, - c->options.lc_max_level, wfa, c); + c->options.lc_max_level, wfa, c); /* * Restore probability models to the state before the recursive subdivision @@ -138,9 +138,9 @@ predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, c->p_tree = *p_tree_model; c->domain_pool->model = c->domain_pool->model_duplicate (domain_model); c->d_domain_pool->model = c->d_domain_pool->model_duplicate (d_domain_model); - c->coeff->model = c->coeff->model_duplicate (c->coeff, coeff_model); - c->d_coeff->model = c->d_coeff->model_duplicate (c->d_coeff, - d_coeff_model); + c->coeff->model = c->coeff->model_duplicate (c->coeff, coeff_model); + c->d_coeff->model = c->d_coeff->model_duplicate (c->d_coeff, + d_coeff_model); if (c->mt->frame_type == I_FRAME) costs = nd_prediction (max_costs, price, band, y_state, range, wfa, c); @@ -156,27 +156,27 @@ predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, */ for (state = states; state < rec_states; state++) { - sd = &rec_state_data [state - states]; - for (level = c->options.images_level + 1; - level <= c->options.lc_max_level; level++) - if (sd->ip_states_state [level] != NULL) - Free (sd->ip_states_state [level]); - if (sd->images_of_state != NULL) - Free (sd->images_of_state); - if (sd->inner_products != NULL) - Free (sd->inner_products); + sd = &rec_state_data [state - states]; + for (level = c->options.images_level + 1; + level <= c->options.lc_max_level; level++) + if (sd->ip_states_state [level] != NULL) + Free (sd->ip_states_state [level]); + if (sd->images_of_state != NULL) + Free (sd->images_of_state); + if (sd->inner_products != NULL) + Free (sd->inner_products); } if (states < rec_states) - Free (rec_state_data); + Free (rec_state_data); c->domain_pool->model_free (rec_domain_model); c->d_domain_pool->model_free (rec_d_domain_model); c->coeff->model_free (rec_coeff_model); c->d_coeff->model_free (rec_d_coeff_model); costs = (range->tree_bits + range->matrix_bits + range->weights_bits - + range->mv_tree_bits + range->mv_coord_bits - + range->nd_tree_bits + range->nd_weights_bits) * price - + range->err; + + range->mv_tree_bits + range->mv_coord_bits + + range->nd_tree_bits + range->nd_weights_bits) * price + + range->err; } else { @@ -198,9 +198,9 @@ predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, range->prediction = NO; if (wfa->states != states) - remove_states (states, wfa); + remove_states (states, wfa); restore_state_data (states, rec_states - 1, c->options.lc_max_level, - rec_state_data, wfa, c); + rec_state_data, wfa, c); costs = MAXCOSTS; } @@ -216,8 +216,8 @@ clear_norms_table (unsigned level, const wfa_info_t *wi, motion_t *mt) */ { unsigned range_size = wi->half_pixel - ? square (wi->search_range) - : square (2 * wi->search_range); + ? square (wi->search_range) + : square (2 * wi->search_range); if (level > wi->p_min_level) { @@ -236,34 +236,34 @@ update_norms_table (unsigned level, const wfa_info_t *wi, motion_t *mt) */ { unsigned range_size = wi->half_pixel - ? square (wi->search_range) - : square (2 * wi->search_range); + ? square (wi->search_range) + : square (2 * wi->search_range); if (level > wi->p_min_level) { - unsigned index; /* index of motion vector */ + unsigned index; /* index of motion vector */ for (index = 0; index < range_size; index++) - mt->mc_forward_norms [level][index] - += mt->mc_forward_norms [level - 1][index]; + mt->mc_forward_norms [level][index] + += mt->mc_forward_norms [level - 1][index]; if (mt->frame_type == B_FRAME) - for (index = 0; index < range_size; index++) - mt->mc_backward_norms [level][index] - += mt->mc_backward_norms [level - 1][index]; + for (index = 0; index < range_size; index++) + mt->mc_backward_norms [level][index] + += mt->mc_backward_norms [level - 1][index]; } } /***************************************************************************** - private code + private code *****************************************************************************/ static real_t mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, - range_t *range, wfa_t *wfa, coding_t *c) + range_t *range, wfa_t *wfa, coding_t *c) { - real_t costs; /* current approximation costs */ + real_t costs; /* current approximation costs */ range_t prange = *range; unsigned width = width_of_level (range->level); unsigned height = height_of_level (range->level); @@ -286,12 +286,12 @@ mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, costs = (prange.mv_tree_bits + prange.mv_coord_bits) * price; - if (costs < max_costs) /* motion vector not too expensive */ + if (costs < max_costs) /* motion vector not too expensive */ { - unsigned last_state; /* last WFA state before recursion */ - real_t *ipi [MAXSTATES]; /* inner products pointers */ + unsigned last_state; /* last WFA state before recursion */ + real_t *ipi [MAXSTATES]; /* inner products pointers */ unsigned state; - real_t mvt, mvc; + real_t mvt, mvc; c->pixels = Calloc (width * height, sizeof (real_t)); cut_to_bintree (c->pixels, mcpe, width, height, 0, 0, width, height); @@ -301,12 +301,12 @@ mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, */ last_state = wfa->states - 1; for (state = 0; state <= last_state; state++) - if (need_image (state, wfa)) - { - ipi [state] = c->ip_images_state[state]; - c->ip_images_state[state] - = Calloc (size_of_tree (c->products_level), sizeof (real_t)); - } + if (need_image (state, wfa)) + { + ipi [state] = c->ip_images_state[state]; + c->ip_images_state[state] + = Calloc (size_of_tree (c->products_level), sizeof (real_t)); + } mvc = prange.mv_coord_bits; mvt = prange.mv_tree_bits; @@ -322,42 +322,42 @@ mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, prange.nd_tree_bits = 0; compute_ip_images_state (prange.image, prange.address, prange.level, - 1, 0, wfa, c); + 1, 0, wfa, c); costs += subdivide (max_costs - costs, band, y_state, &prange, - wfa, c, NO, YES); + wfa, c, NO, YES); - if (costs < max_costs) /* use motion compensation */ + if (costs < max_costs) /* use motion compensation */ { - unsigned img, adr; /* temp. values */ - - img = range->image; - adr = range->address; - *range = prange; - range->image = img; - range->address = adr; - range->mv_coord_bits = mvc; - range->mv_tree_bits = mvt; - range->prediction = YES; - - for (state = last_state + 1; state < wfa->states; state++) - if (need_image (state, wfa)) - memset (c->ip_images_state [state], 0, - size_of_tree (c->products_level) * sizeof (real_t)); - - costs = (range->tree_bits + range->matrix_bits + range->weights_bits - + range->mv_tree_bits + range->mv_coord_bits - + range->nd_tree_bits + range->nd_weights_bits) * price - + range->err; + unsigned img, adr; /* temp. values */ + + img = range->image; + adr = range->address; + *range = prange; + range->image = img; + range->address = adr; + range->mv_coord_bits = mvc; + range->mv_tree_bits = mvt; + range->prediction = YES; + + for (state = last_state + 1; state < wfa->states; state++) + if (need_image (state, wfa)) + memset (c->ip_images_state [state], 0, + size_of_tree (c->products_level) * sizeof (real_t)); + + costs = (range->tree_bits + range->matrix_bits + range->weights_bits + + range->mv_tree_bits + range->mv_coord_bits + + range->nd_tree_bits + range->nd_weights_bits) * price + + range->err; } else - costs = MAXCOSTS; + costs = MAXCOSTS; for (state = 0; state <= last_state; state++) - if (need_image (state, wfa)) - { - Free (c->ip_images_state[state]); - c->ip_images_state[state] = ipi [state]; - } + if (need_image (state, wfa)) + { + Free (c->ip_images_state[state]); + c->ip_images_state[state] = ipi [state]; + } Free (c->pixels); } else @@ -370,9 +370,9 @@ mc_prediction (real_t max_costs, real_t price, unsigned band, int y_state, static real_t nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, - range_t *range, wfa_t *wfa, coding_t *c) + range_t *range, wfa_t *wfa, coding_t *c) { - real_t costs; /* current approximation costs */ + real_t costs; /* current approximation costs */ range_t lrange = *range; /* @@ -380,13 +380,13 @@ nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, */ { real_t x = get_ip_image_state (range->image, range->address, - range->level, 0, c); + range->level, 0, c); real_t y = get_ip_state_state (0, 0, range->level, c); real_t w = btor (rtob (x / y, c->coeff->dc_rpf), c->coeff->dc_rpf); word_t s [2] = {0, -1}; - lrange.into [0] = 0; - lrange.into [1] = NO_EDGE; + lrange.into [0] = 0; + lrange.into [1] = NO_EDGE; lrange.weight [0] = w; lrange.mv_coord_bits = 0; lrange.mv_tree_bits = 0; @@ -404,10 +404,10 @@ nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, if (costs < max_costs) { unsigned state; - range_t rrange; /* range: recursive subdivision */ - unsigned last_state; /* last WFA state before recursion */ - real_t *ipi [MAXSTATES]; /* inner products pointers */ - unsigned width = width_of_level (range->level); + range_t rrange; /* range: recursive subdivision */ + unsigned last_state; /* last WFA state before recursion */ + real_t *ipi [MAXSTATES]; /* inner products pointers */ + unsigned width = width_of_level (range->level); unsigned height = height_of_level (range->level); real_t *pixels; @@ -415,15 +415,15 @@ nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, * Generate difference image original - approximation */ { - unsigned n; - real_t *src, *dst; /* pointers to image data */ - real_t w = - lrange.weight [0] * c->images_of_state [0][0]; + unsigned n; + real_t *src, *dst; /* pointers to image data */ + real_t w = - lrange.weight [0] * c->images_of_state [0][0]; - src = c->pixels + range->address * size_of_level (range->level); - dst = c->pixels = pixels = Calloc (width * height, sizeof (real_t)); + src = c->pixels + range->address * size_of_level (range->level); + dst = c->pixels = pixels = Calloc (width * height, sizeof (real_t)); - for (n = width * height; n; n--) - *dst++ = *src++ + w; + for (n = width * height; n; n--) + *dst++ = *src++ + w; } /* @@ -442,56 +442,56 @@ nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, last_state = wfa->states - 1; for (state = 0; state <= last_state; state++) - if (need_image (state, wfa)) - { - ipi [state] = c->ip_images_state[state]; - c->ip_images_state[state] - = Calloc (size_of_tree (c->products_level), sizeof (real_t)); - } + if (need_image (state, wfa)) + { + ipi [state] = c->ip_images_state[state]; + c->ip_images_state[state] + = Calloc (size_of_tree (c->products_level), sizeof (real_t)); + } compute_ip_images_state (rrange.image, rrange.address, rrange.level, - 1, 0, wfa, c); + 1, 0, wfa, c); costs += subdivide (max_costs - costs, band, y_state, &rrange, wfa, c, - NO, YES); + NO, YES); Free (pixels); if (costs < max_costs && ischild (rrange.tree)) /* use prediction */ { - unsigned img, adr; - unsigned edge; - - img = range->image; - adr = range->address; - *range = rrange; - range->image = img; - range->address = adr; - range->nd_tree_bits += lrange.nd_tree_bits; - range->nd_weights_bits += lrange.weights_bits; - - for (edge = 0; isedge (lrange.into [edge]); edge++) - { - range->into [edge] = lrange.into [edge]; - range->weight [edge] = lrange.weight [edge]; - } - range->into [edge] = NO_EDGE; - range->prediction = edge; - - for (state = last_state + 1; state < wfa->states; state++) - if (need_image (state, wfa)) - memset (c->ip_images_state [state], 0, - size_of_tree (c->products_level) * sizeof (real_t)); + unsigned img, adr; + unsigned edge; + + img = range->image; + adr = range->address; + *range = rrange; + range->image = img; + range->address = adr; + range->nd_tree_bits += lrange.nd_tree_bits; + range->nd_weights_bits += lrange.weights_bits; + + for (edge = 0; isedge (lrange.into [edge]); edge++) + { + range->into [edge] = lrange.into [edge]; + range->weight [edge] = lrange.weight [edge]; + } + range->into [edge] = NO_EDGE; + range->prediction = edge; + + for (state = last_state + 1; state < wfa->states; state++) + if (need_image (state, wfa)) + memset (c->ip_images_state [state], 0, + size_of_tree (c->products_level) * sizeof (real_t)); } else - costs = MAXCOSTS; + costs = MAXCOSTS; for (state = 0; state <= last_state; state++) - if (need_image (state, wfa)) - { - Free (c->ip_images_state [state]); - c->ip_images_state [state] = ipi [state]; - } + if (need_image (state, wfa)) + { + Free (c->ip_images_state [state]); + c->ip_images_state [state] = ipi [state]; + } } else costs = MAXCOSTS; @@ -501,20 +501,20 @@ nd_prediction (real_t max_costs, real_t price, unsigned band, int y_state, static state_data_t * store_state_data (unsigned from, unsigned to, unsigned max_level, - wfa_t *wfa, coding_t *c) + wfa_t *wfa, coding_t *c) /* * Save and remove all states starting from state 'from'. * * Return value: - * pointer to array of state_data structs + * pointer to array of state_data structs */ { - state_data_t *data; /* array of savestates */ - state_data_t *sd; /* pointer to current savestates */ - unsigned state, label, level; + state_data_t *data; /* array of savestates */ + state_data_t *sd; /* pointer to current savestates */ + unsigned state, label, level; if (to < from) - return NULL; /* nothing to do */ + return NULL; /* nothing to do */ data = Calloc (to - from + 1, sizeof (state_data_t)); @@ -534,30 +534,30 @@ store_state_data (unsigned from, unsigned to, unsigned max_level, for (label = 0; label < MAXLABELS; label++) { - sd->tree [label] = wfa->tree [state][label]; - sd->y_state [label] = wfa->y_state [state][label]; - sd->y_column [label] = wfa->y_column [state][label]; - sd->mv_tree [label] = wfa->mv_tree [state][label]; - sd->x [label] = wfa->x [state][label]; - sd->y [label] = wfa->y [state][label]; - sd->prediction [label] = wfa->prediction [state][label]; - - memcpy (sd->weight [label], wfa->weight [state][label], - sizeof (real_t) * (MAXEDGES + 1)); - memcpy (sd->int_weight [label], wfa->int_weight [state][label], - sizeof (word_t) * (MAXEDGES + 1)); - memcpy (sd->into [label], wfa->into [state][label], - sizeof (word_t) * (MAXEDGES + 1)); - - wfa->into [state][label][0] = NO_EDGE; - wfa->tree [state][label] = RANGE; - wfa->y_state [state][label] = RANGE; + sd->tree [label] = wfa->tree [state][label]; + sd->y_state [label] = wfa->y_state [state][label]; + sd->y_column [label] = wfa->y_column [state][label]; + sd->mv_tree [label] = wfa->mv_tree [state][label]; + sd->x [label] = wfa->x [state][label]; + sd->y [label] = wfa->y [state][label]; + sd->prediction [label] = wfa->prediction [state][label]; + + memcpy (sd->weight [label], wfa->weight [state][label], + sizeof (real_t) * (MAXEDGES + 1)); + memcpy (sd->int_weight [label], wfa->int_weight [state][label], + sizeof (word_t) * (MAXEDGES + 1)); + memcpy (sd->into [label], wfa->into [state][label], + sizeof (word_t) * (MAXEDGES + 1)); + + wfa->into [state][label][0] = NO_EDGE; + wfa->tree [state][label] = RANGE; + wfa->y_state [state][label] = RANGE; } for (level = c->options.images_level + 1; level <= max_level; - level++) + level++) { - sd->ip_states_state [level] = c->ip_states_state [state][level]; - c->ip_states_state [state][level] = NULL; + sd->ip_states_state [level] = c->ip_states_state [state][level]; + c->ip_states_state [state][level] = NULL; } } @@ -566,18 +566,18 @@ store_state_data (unsigned from, unsigned to, unsigned max_level, static void restore_state_data (unsigned from, unsigned to, unsigned max_level, - state_data_t *data, wfa_t *wfa, coding_t *c) + state_data_t *data, wfa_t *wfa, coding_t *c) /* * Restore all state data starting from state 'from'. * * No return value. */ { - state_data_t *sd; /* pointer to state_data item */ - unsigned state, label, level; + state_data_t *sd; /* pointer to state_data item */ + unsigned state, label, level; if (to < from) - return; /* nothing to do */ + return; /* nothing to do */ for (state = from; state <= to; state++) { @@ -588,35 +588,35 @@ restore_state_data (unsigned from, unsigned to, unsigned max_level, wfa->domain_type [state] = sd->domain_type; if (c->images_of_state [state] != NULL) - Free (c->images_of_state [state]); + Free (c->images_of_state [state]); c->images_of_state [state] = sd->images_of_state; if (c->ip_images_state [state] != NULL) - Free (c->ip_images_state [state]); + Free (c->ip_images_state [state]); c->ip_images_state [state] = sd->inner_products; for (label = 0; label < MAXLABELS; label++) { - wfa->tree [state][label] = sd->tree [label]; - wfa->y_state [state][label] = sd->y_state [label]; - wfa->y_column [state][label] = sd->y_column [label]; - wfa->mv_tree [state][label] = sd->mv_tree [label]; - wfa->x [state][label] = sd->x [label]; - wfa->y [state][label] = sd->y [label]; - wfa->prediction [state][label] = sd->prediction [label]; - - memcpy (wfa->weight [state][label], sd->weight [label], - sizeof(real_t) * (MAXEDGES + 1)); - memcpy (wfa->int_weight [state][label], sd->int_weight [label], - sizeof(word_t) * (MAXEDGES + 1)); - memcpy (wfa->into [state][label], sd->into [label], - sizeof(word_t) * (MAXEDGES + 1)); + wfa->tree [state][label] = sd->tree [label]; + wfa->y_state [state][label] = sd->y_state [label]; + wfa->y_column [state][label] = sd->y_column [label]; + wfa->mv_tree [state][label] = sd->mv_tree [label]; + wfa->x [state][label] = sd->x [label]; + wfa->y [state][label] = sd->y [label]; + wfa->prediction [state][label] = sd->prediction [label]; + + memcpy (wfa->weight [state][label], sd->weight [label], + sizeof(real_t) * (MAXEDGES + 1)); + memcpy (wfa->int_weight [state][label], sd->int_weight [label], + sizeof(word_t) * (MAXEDGES + 1)); + memcpy (wfa->into [state][label], sd->into [label], + sizeof(word_t) * (MAXEDGES + 1)); } for (level = c->options.images_level + 1; level <= max_level; - level++) + level++) { - if (c->ip_states_state [state][level] != NULL) - Free (c->ip_states_state [state][level]); - c->ip_states_state [state][level] = sd->ip_states_state [level]; + if (c->ip_states_state [state][level] != NULL) + Free (c->ip_states_state [state][level]); + c->ip_states_state [state][level] = sd->ip_states_state [level]; } } diff --git a/converter/other/fiasco/codec/prediction.h b/converter/other/fiasco/codec/prediction.h index 0646dfd8..10b432b3 100644 --- a/converter/other/fiasco/codec/prediction.h +++ b/converter/other/fiasco/codec/prediction.h @@ -1,9 +1,9 @@ /* * prediction.h * - * Written by: Ullrich Hafner - * Michael Unger - * + * Written by: Ullrich Hafner + * Michael Unger + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -23,10 +23,10 @@ real_t predict_range (real_t max_costs, real_t price, range_t *range, wfa_t *wfa, - coding_t *c, unsigned band, int y_state, unsigned states, - const tree_t *tree_model, const tree_t *p_tree_model, - const void *domain_model, const void *d_domain_model, - const void *coeff_model, const void *d_coeff_model); + coding_t *c, unsigned band, int y_state, unsigned states, + const tree_t *tree_model, const tree_t *p_tree_model, + const void *domain_model, const void *d_domain_model, + const void *coeff_model, const void *d_coeff_model); void update_norms_table (unsigned level, const wfa_info_t *wi, motion_t *mt); void diff --git a/converter/other/fiasco/codec/subdivide.c b/converter/other/fiasco/codec/subdivide.c index 3ddf1ffc..7eb951c0 100644 --- a/converter/other/fiasco/codec/subdivide.c +++ b/converter/other/fiasco/codec/subdivide.c @@ -1,7 +1,7 @@ /* - * subdivide.c: Recursive subdivision of range images + * subdivide.c: Recursive subdivision of range images * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -41,27 +41,27 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, - const range_t *child, const int *y_state, - wfa_t *wfa, coding_t *c); + const range_t *child, const int *y_state, + wfa_t *wfa, coding_t *c); static void init_range (range_t *range, const image_t *image, unsigned band, - const wfa_t *wfa, coding_t *c); + const wfa_t *wfa, coding_t *c); /***************************************************************************** - public code + public code *****************************************************************************/ real_t subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, - wfa_t *wfa, coding_t *c, bool_t prediction, bool_t delta) + wfa_t *wfa, coding_t *c, bool_t prediction, bool_t delta) /* * Subdivide the current 'range' recursively and decide whether * a linear combination, a recursive subdivision, or a prediction is @@ -73,46 +73,46 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, * If 'delta' is TRUE then current range is already predicted. * * Return value: - * costs of the best approximation or MAXCOSTS if costs exceed 'max_costs' + * costs of the best approximation or MAXCOSTS if costs exceed 'max_costs' * * Side effects: - * 'range' factors and costs of linear combination are modified - * 'wfa' new transitions and prediction coefficients are added - * 'c' pixels and inner products are updated + * 'range' factors and costs of linear combination are modified + * 'wfa' new transitions and prediction coefficients are added + * 'c' pixels and inner products are updated */ { real_t subdivide_costs; /* Costs arising from approx. the current - range with two children */ + range with two children */ real_t lincomb_costs; /* Costs arising from approx. the current - range with a linear combination */ - int new_y_state [MAXLABELS]; /* Corresponding state of Y */ - real_t price; /* Approximation costs multiplier */ - bool_t try_mc; /* YES: try MC prediction */ - bool_t try_nd; /* YES: try ND prediction */ - unsigned states; /* Number of states before the - recursive subdivision starts */ - void *domain_model; /* copy of domain pool model */ - void *d_domain_model; /* copy of delta domain pool model */ - void *lc_domain_model; /* copy of domain pool model */ - void *lc_d_domain_model; /* copy of delta domain pool model */ - void *coeff_model; /* copy of coefficients model */ - void *d_coeff_model; /* copy of delta coefficients model */ - void *lc_coeff_model; /* copy of coefficients model */ - void *lc_d_coeff_model; /* copy of delta coefficients model */ - tree_t tree_model; /* copy of tree model */ - tree_t p_tree_model; /* copy of pred. tree model */ - range_t lrange; /* range of lin. comb. approx. */ - range_t rrange; /* range of recursive approx. */ - range_t child [MAXLABELS]; /* new children of the current range */ - static unsigned percent = 0; /* status of progress meter */ + range with a linear combination */ + int new_y_state [MAXLABELS]; /* Corresponding state of Y */ + real_t price; /* Approximation costs multiplier */ + bool_t try_mc; /* YES: try MC prediction */ + bool_t try_nd; /* YES: try ND prediction */ + unsigned states; /* Number of states before the + recursive subdivision starts */ + void *domain_model; /* copy of domain pool model */ + void *d_domain_model; /* copy of delta domain pool model */ + void *lc_domain_model; /* copy of domain pool model */ + void *lc_d_domain_model; /* copy of delta domain pool model */ + void *coeff_model; /* copy of coefficients model */ + void *d_coeff_model; /* copy of delta coefficients model */ + void *lc_coeff_model; /* copy of coefficients model */ + void *lc_d_coeff_model; /* copy of delta coefficients model */ + tree_t tree_model; /* copy of tree model */ + tree_t p_tree_model; /* copy of pred. tree model */ + range_t lrange; /* range of lin. comb. approx. */ + range_t rrange; /* range of recursive approx. */ + range_t child [MAXLABELS]; /* new children of the current range */ + static unsigned percent = 0; /* status of progress meter */ if (wfa->wfainfo->level == range->level) percent = 0; - range->into [0] = NO_EDGE; /* default approximation: empty */ + range->into [0] = NO_EDGE; /* default approximation: empty */ range->tree = RANGE; - if (range->level < 3) /* Don't process small ranges */ + if (range->level < 3) /* Don't process small ranges */ return MAXCOSTS; /* @@ -122,35 +122,35 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, if (c->tiling->exponent && range->level == wfa->wfainfo->level - c->tiling->exponent) { - unsigned width, height; /* size of range (dummies)*/ + unsigned width, height; /* size of range (dummies)*/ if (c->tiling->vorder [range->global_address] < 0) - return 0; /* nothing to do */ + return 0; /* nothing to do */ else - locate_subimage (wfa->wfainfo->level, range->level, - c->tiling->vorder [range->global_address], - &range->x, &range->y, &width, &height); + locate_subimage (wfa->wfainfo->level, range->level, + c->tiling->vorder [range->global_address], + &range->x, &range->y, &width, &height); } if (range->x >= c->mt->original->width || range->y >= c->mt->original->height) - return 0; /* range is not visible */ + return 0; /* range is not visible */ /* * Check whether prediction is allowed or not * mc == motion compensation, nd == nondeterminism */ try_mc = (prediction && c->mt->frame_type != I_FRAME - && range->level >= wfa->wfainfo->p_min_level - && range->level <= wfa->wfainfo->p_max_level - && (range->x + width_of_level (range->level) - <= c->mt->original->width) - && (range->y + height_of_level (range->level) - <= c->mt->original->height)); + && range->level >= wfa->wfainfo->p_min_level + && range->level <= wfa->wfainfo->p_max_level + && (range->x + width_of_level (range->level) + <= c->mt->original->width) + && (range->y + height_of_level (range->level) + <= c->mt->original->height)); try_nd = (prediction && c->mt->frame_type == I_FRAME - && range->level >= wfa->wfainfo->p_min_level - && range->level <= wfa->wfainfo->p_max_level); + && range->level >= wfa->wfainfo->p_min_level + && range->level <= wfa->wfainfo->p_max_level); if (try_mc) clear_norms_table (range->level, wfa->wfainfo, c->mt); @@ -171,15 +171,15 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, /* * Compute children of corresponding state in Y band */ - if (band != Y) /* Cb and Cr bands only */ + if (band != Y) /* Cb and Cr bands only */ { unsigned label; for (label = 0; label < MAXLABELS; label++) - if (ischild (y_state)) - new_y_state [label] = wfa->tree [y_state][label]; - else - new_y_state [label] = RANGE; + if (ischild (y_state)) + new_y_state [label] = wfa->tree [y_state][label]; + else + new_y_state [label] = RANGE; } else new_y_state [0] = new_y_state [1] = RANGE; @@ -210,13 +210,13 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, lrange.mv_coord_bits = 0; lrange.nd_tree_bits = 0; lrange.nd_weights_bits = 0; - lrange.prediction = NO; + lrange.prediction = NO; lincomb_costs - = approximate_range (max_costs, price, c->options.max_elements, - y_state, &lrange, - (delta ? c->d_domain_pool : c->domain_pool), - (delta ? c->d_coeff : c->coeff), wfa, c); + = approximate_range (max_costs, price, c->options.max_elements, + y_state, &lrange, + (delta ? c->d_domain_pool : c->domain_pool), + (delta ? c->d_coeff : c->coeff), wfa, c); } else lincomb_costs = MAXCOSTS; @@ -236,7 +236,7 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, c->d_domain_pool->model = c->d_domain_pool->model_duplicate (d_domain_model); c->coeff->model = c->coeff->model_duplicate (c->coeff, coeff_model); c->d_coeff->model = c->d_coeff->model_duplicate (c->d_coeff, - d_coeff_model); + d_coeff_model); /* * Second alternative of range approximation: @@ -256,122 +256,122 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, rrange.matrix_bits = 0; rrange.weights_bits = 0; rrange.err = 0; - rrange.mv_tree_bits = try_mc ? 1 : 0; /* mc allowed but not used */ + rrange.mv_tree_bits = try_mc ? 1 : 0; /* mc allowed but not used */ rrange.mv_coord_bits = 0; rrange.nd_tree_bits = try_nd ? - tree_bits (CHILD, lrange.level, &c->p_tree): 0; + tree_bits (CHILD, lrange.level, &c->p_tree): 0; rrange.nd_weights_bits = 0; - rrange.prediction = NO; + rrange.prediction = NO; /* * Initialize the cost function and subdivide the current range. * Every child is approximated by a recursive call of subdivide() */ subdivide_costs = (rrange.tree_bits + rrange.weights_bits - + rrange.matrix_bits + rrange.mv_tree_bits - + rrange.mv_coord_bits + rrange.nd_tree_bits - + rrange.nd_weights_bits) * price; + + rrange.matrix_bits + rrange.mv_tree_bits + + rrange.mv_coord_bits + rrange.nd_tree_bits + + rrange.nd_weights_bits) * price; for (label = 0; label < MAXLABELS; label++) { - real_t remaining_costs; /* upper limit for next recursion */ - - child[label].image = rrange.image * MAXLABELS + label + 1; - child[label].address = rrange.address * MAXLABELS + label; - child[label].global_address = rrange.global_address * MAXLABELS - + label; - child[label].level = rrange.level - 1; - child[label].x = rrange.level & 1 - ? rrange.x - : (rrange.x - + label * width_of_level (rrange.level - 1)); - child[label].y = rrange.level & 1 - ? (rrange.y - + label * height_of_level (rrange.level - 1)) - : rrange.y; - - /* - * If necessary compute the inner products of the new states - * (generated during the recursive approximation of child [0]) - */ - if (label && rrange.level <= c->options.lc_max_level) - compute_ip_images_state (child[label].image, child[label].address, - child[label].level, 1, states, wfa, c); - /* - * Call subdivide() for both children. - * Abort the recursion if 'subdivide_costs' exceed 'lincomb_costs' - * or 'max_costs'. - */ - remaining_costs = MIN(lincomb_costs, max_costs) - subdivide_costs; - - if (remaining_costs > 0) /* still a way for improvement */ - { - subdivide_costs += subdivide (remaining_costs, band, - new_y_state [label], &child [label], - wfa, c, prediction, delta); - } - else if (try_mc && child[label].level >= wfa->wfainfo->p_min_level) - { - fill_norms_table (child[label].x, child[label].y, - child[label].level, wfa->wfainfo, c->mt); - } - - if (try_mc) - update_norms_table (rrange.level, wfa->wfainfo, c->mt); - - /* - * Update of progress meter - */ - if (c->options.progress_meter != FIASCO_PROGRESS_NONE) - { - if (c->options.progress_meter == FIASCO_PROGRESS_PERCENT) - { - unsigned new_percent; /* new status of progress meter */ - - new_percent = (child[label].global_address + 1) * 100.0 - / (1 << (wfa->wfainfo->level - child[label].level)); - if (new_percent > percent) - { - percent = new_percent; - info ("%3d%% \r", percent); - } - } - else if (c->options.progress_meter == FIASCO_PROGRESS_BAR) - { - unsigned new_percent; /* new status of progress meter */ - - new_percent = (child[label].global_address + 1) * 50.0 - / (1 << (wfa->wfainfo->level - - child[label].level)); - for (; new_percent > percent; percent++) - { - info ("#"); - } - } - } - - /* - * If costs of subdivision exceed costs of linear combination - * then abort recursion. - */ - if (subdivide_costs >= MIN(lincomb_costs, max_costs)) - { - subdivide_costs = MAXCOSTS; - break; - } - rrange.err += child [label].err; - rrange.tree_bits += child [label].tree_bits; - rrange.matrix_bits += child [label].matrix_bits; - rrange.weights_bits += child [label].weights_bits; - rrange.mv_tree_bits += child [label].mv_tree_bits; - rrange.mv_coord_bits += child [label].mv_coord_bits; - rrange.nd_weights_bits += child [label].nd_weights_bits; - rrange.nd_tree_bits += child [label].nd_tree_bits; - - tree_update (ischild (child [label].tree) ? CHILD : LEAF, - child [label].level, &c->tree); - tree_update (child [label].prediction ? LEAF : CHILD, - child [label].level, &c->p_tree); + real_t remaining_costs; /* upper limit for next recursion */ + + child[label].image = rrange.image * MAXLABELS + label + 1; + child[label].address = rrange.address * MAXLABELS + label; + child[label].global_address = rrange.global_address * MAXLABELS + + label; + child[label].level = rrange.level - 1; + child[label].x = rrange.level & 1 + ? rrange.x + : (rrange.x + + label * width_of_level (rrange.level - 1)); + child[label].y = rrange.level & 1 + ? (rrange.y + + label * height_of_level (rrange.level - 1)) + : rrange.y; + + /* + * If necessary compute the inner products of the new states + * (generated during the recursive approximation of child [0]) + */ + if (label && rrange.level <= c->options.lc_max_level) + compute_ip_images_state (child[label].image, child[label].address, + child[label].level, 1, states, wfa, c); + /* + * Call subdivide() for both children. + * Abort the recursion if 'subdivide_costs' exceed 'lincomb_costs' + * or 'max_costs'. + */ + remaining_costs = MIN(lincomb_costs, max_costs) - subdivide_costs; + + if (remaining_costs > 0) /* still a way for improvement */ + { + subdivide_costs += subdivide (remaining_costs, band, + new_y_state [label], &child [label], + wfa, c, prediction, delta); + } + else if (try_mc && child[label].level >= wfa->wfainfo->p_min_level) + { + fill_norms_table (child[label].x, child[label].y, + child[label].level, wfa->wfainfo, c->mt); + } + + if (try_mc) + update_norms_table (rrange.level, wfa->wfainfo, c->mt); + + /* + * Update of progress meter + */ + if (c->options.progress_meter != FIASCO_PROGRESS_NONE) + { + if (c->options.progress_meter == FIASCO_PROGRESS_PERCENT) + { + unsigned new_percent; /* new status of progress meter */ + + new_percent = (child[label].global_address + 1) * 100.0 + / (1 << (wfa->wfainfo->level - child[label].level)); + if (new_percent > percent) + { + percent = new_percent; + info ("%3d%% \r", percent); + } + } + else if (c->options.progress_meter == FIASCO_PROGRESS_BAR) + { + unsigned new_percent; /* new status of progress meter */ + + new_percent = (child[label].global_address + 1) * 50.0 + / (1 << (wfa->wfainfo->level + - child[label].level)); + for (; new_percent > percent; percent++) + { + info ("#"); + } + } + } + + /* + * If costs of subdivision exceed costs of linear combination + * then abort recursion. + */ + if (subdivide_costs >= MIN(lincomb_costs, max_costs)) + { + subdivide_costs = MAXCOSTS; + break; + } + rrange.err += child [label].err; + rrange.tree_bits += child [label].tree_bits; + rrange.matrix_bits += child [label].matrix_bits; + rrange.weights_bits += child [label].weights_bits; + rrange.mv_tree_bits += child [label].mv_tree_bits; + rrange.mv_coord_bits += child [label].mv_coord_bits; + rrange.nd_weights_bits += child [label].nd_weights_bits; + rrange.nd_tree_bits += child [label].nd_tree_bits; + + tree_update (ischild (child [label].tree) ? CHILD : LEAF, + child [label].level, &c->tree); + tree_update (child [label].prediction ? LEAF : CHILD, + child [label].level, &c->p_tree); } } else @@ -382,9 +382,9 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, * Predict range via motion compensation or nondeterminism and * approximate delta image. */ - if (try_mc || try_nd) /* try prediction */ + if (try_mc || try_nd) /* try prediction */ { - real_t prediction_costs; /* Costs arising from approx. the current + real_t prediction_costs; /* Costs arising from approx. the current range with prediction */ prediction_costs @@ -393,7 +393,7 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, price, range, wfa, c, band, y_state, states, &tree_model, &p_tree_model, domain_model, d_domain_model, coeff_model, d_coeff_model); - if (prediction_costs < MAXCOSTS) /* prediction has smallest costs */ + if (prediction_costs < MAXCOSTS) /* prediction has smallest costs */ { c->domain_pool->model_free (domain_model); c->d_domain_pool->model_free (d_domain_model); @@ -426,13 +426,13 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, c->domain_pool->model = domain_model; c->d_domain_pool->model = d_domain_model; - c->coeff->model = coeff_model; - c->d_coeff->model = d_coeff_model; + c->coeff->model = coeff_model; + c->d_coeff->model = d_coeff_model; c->tree = tree_model; c->p_tree = p_tree_model; if (wfa->states != states) - remove_states (states, wfa); + remove_states (states, wfa); return MAXCOSTS; } @@ -455,15 +455,15 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, c->domain_pool->model = lc_domain_model; c->d_domain_pool->model = lc_d_domain_model; - c->coeff->model = lc_coeff_model; - c->d_coeff->model = lc_d_coeff_model; + c->coeff->model = lc_coeff_model; + c->d_coeff->model = lc_d_coeff_model; c->tree = tree_model; c->p_tree = p_tree_model; *range = lrange; if (wfa->states != states) - remove_states (states, wfa); + remove_states (states, wfa); return lincomb_costs; } @@ -478,15 +478,15 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, * - if state is (partially) outside image geometry */ if (band > Y - || (c->tiling->exponent - && rrange.level > wfa->wfainfo->level - c->tiling->exponent) - || (range->x + width_of_level (range->level) - > c->mt->original->width) - || (range->y + height_of_level (range->level) - > c->mt->original->height)) - init_new_state (YES, delta, &rrange, child, new_y_state, wfa, c); + || (c->tiling->exponent + && rrange.level > wfa->wfainfo->level - c->tiling->exponent) + || (range->x + width_of_level (range->level) + > c->mt->original->width) + || (range->y + height_of_level (range->level) + > c->mt->original->height)) + init_new_state (YES, delta, &rrange, child, new_y_state, wfa, c); else - init_new_state (NO, delta, &rrange, child, new_y_state, wfa, c); + init_new_state (NO, delta, &rrange, child, new_y_state, wfa, c); *range = rrange; @@ -505,8 +505,8 @@ subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, void cut_to_bintree (real_t *dst, const word_t *src, - unsigned src_width, unsigned src_height, - unsigned x0, unsigned y0, unsigned width, unsigned height) + unsigned src_width, unsigned src_height, + unsigned x0, unsigned y0, unsigned width, unsigned height) /* * Cut region ('x0', 'y0', 'width', 'height') of the pixel array 'src'. * Size of image is given by 'src_width' x 'src_height'. @@ -515,15 +515,15 @@ cut_to_bintree (real_t *dst, const word_t *src, * No return value. * * Side effects: - * 'dst []' is filled with corresponding region. + * 'dst []' is filled with corresponding region. */ { const unsigned mask01 = 0x555555; /* binary ...010101010101 */ const unsigned mask10 = 0xaaaaaa; /* binary ...101010101010 */ const unsigned mask01plus1 = mask01 + 1; /* binary ...010101010110 */ const unsigned mask10plus1 = mask10 + 1; /* binary ...101010101011 */ - unsigned x, y; /* pixel coordinates */ - unsigned xmask, ymask; /* address conversion */ + unsigned x, y; /* pixel coordinates */ + unsigned xmask, ymask; /* address conversion */ if (width != height && width != (height >> 1)) error ("Bintree cutting requires special type of images."); @@ -534,24 +534,24 @@ cut_to_bintree (real_t *dst, const word_t *src, xmask = 0; for (x = x0; x < x0 + width; x++, xmask = (xmask + mask01plus1) & mask10) { - if (y >= src_height || x >= src_width) - dst [xmask | ymask] = 0; - else - dst [xmask | ymask] = src [y * src_width + x] / 16; + if (y >= src_height || x >= src_width) + dst [xmask | ymask] = 0; + else + dst [xmask | ymask] = src [y * src_width + x] / 16; } } } /***************************************************************************** - private code + private code *****************************************************************************/ static void init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, - const range_t *child, const int *y_state, - wfa_t *wfa, coding_t *c) + const range_t *child, const int *y_state, + wfa_t *wfa, coding_t *c) /* * Initializes a new state with all parameters needed for the encoding step. * If flag 'auxiliary_state' is set then don't insert state into domain pools. @@ -563,7 +563,7 @@ init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, * No return value. * * Side effects: - * New state is appended to 'wfa' (and also its inner products and images + * New state is appended to 'wfa' (and also its inner products and images * are computed and stored in 'c') */ { @@ -573,13 +573,13 @@ init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, if (!auxiliary_state) { if (!delta || c->options.delta_domains) - state_is_domain = c->domain_pool->append (wfa->states, range->level, - wfa, c->domain_pool->model); + state_is_domain = c->domain_pool->append (wfa->states, range->level, + wfa, c->domain_pool->model); if (delta || c->options.normal_domains) - state_is_domain = c->d_domain_pool->append (wfa->states, range->level, - wfa, - c->d_domain_pool->model) - || state_is_domain; + state_is_domain = c->d_domain_pool->append (wfa->states, range->level, + wfa, + c->d_domain_pool->model) + || state_is_domain; } else state_is_domain = NO; @@ -597,7 +597,7 @@ init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, wfa->prediction [wfa->states][label] = child [label].prediction; append_transitions (wfa->states, label, child [label].weight, - child [label].into, wfa); + child [label].into, wfa); } wfa->delta_state [wfa->states] = delta; @@ -607,13 +607,13 @@ init_new_state (bool_t auxiliary_state, bool_t delta, range_t *range, /* state_is_domain = YES; */ append_state (!state_is_domain, - compute_final_distribution (wfa->states, wfa), - range->level, wfa, c); + compute_final_distribution (wfa->states, wfa), + range->level, wfa, c); } static void init_range (range_t *range, const image_t *image, unsigned band, - const wfa_t *wfa, coding_t *c) + const wfa_t *wfa, coding_t *c) /* * Read a new 'range' of the image 'image_name' (current color component * is 'band') and compute the new inner product arrays. @@ -621,9 +621,9 @@ init_range (range_t *range, const image_t *image, unsigned band, * No return value. * * Side effects: - * 'c->pixels' are filled with pixel values of image block - * 'c->ip_images_state' are computed with respect to new image block - * 'range->address' and 'range->image' are initialized with zero + * 'c->pixels' are filled with pixel values of image block + * 'c->ip_images_state' are computed with respect to new image block + * 'range->address' and 'range->image' are initialized with zero */ { unsigned state; @@ -633,13 +633,13 @@ init_range (range_t *range, const image_t *image, unsigned band, */ for (state = 0; state < wfa->states; state++) if (need_image (state, wfa)) - memset (c->ip_images_state[state], 0, - size_of_tree (c->products_level) * sizeof(real_t)); + memset (c->ip_images_state[state], 0, + size_of_tree (c->products_level) * sizeof(real_t)); cut_to_bintree (c->pixels, image->pixels [band], - image->width, image->height, - range->x, range->y, width_of_level (range->level), - height_of_level (range->level)); + image->width, image->height, + range->x, range->y, width_of_level (range->level), + height_of_level (range->level)); range->address = range->image = 0; compute_ip_images_state (0, 0, range->level, 1, 0, wfa, c); diff --git a/converter/other/fiasco/codec/subdivide.h b/converter/other/fiasco/codec/subdivide.h index bd9cd10e..dbd5620a 100644 --- a/converter/other/fiasco/codec/subdivide.h +++ b/converter/other/fiasco/codec/subdivide.h @@ -1,8 +1,8 @@ /* * subdivide.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -20,13 +20,13 @@ #include "types.h" #include "cwfa.h" -real_t +real_t subdivide (real_t max_costs, unsigned band, int y_state, range_t *range, - wfa_t *wfa, coding_t *c, bool_t prediction, bool_t delta); + wfa_t *wfa, coding_t *c, bool_t prediction, bool_t delta); void cut_to_bintree (real_t *dst, const word_t *src, - unsigned src_width, unsigned src_height, - unsigned x0, unsigned y0, unsigned width, unsigned height); + unsigned src_width, unsigned src_height, + unsigned x0, unsigned y0, unsigned width, unsigned height); #endif /* not _SUBDIVIDE_H */ diff --git a/converter/other/fiasco/codec/tiling.c b/converter/other/fiasco/codec/tiling.c index 9af43da0..08423b24 100644 --- a/converter/other/fiasco/codec/tiling.c +++ b/converter/other/fiasco/codec/tiling.c @@ -1,8 +1,8 @@ /* - * tiling.c: Subimage permutation + * tiling.c: Subimage permutation + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -33,8 +33,8 @@ typedef struct var_list { - int address; /* bintree address */ - real_t variance; /* variance of tile */ + int address; /* bintree address */ + real_t variance; /* variance of tile */ } var_list_t; #ifndef LITERAL_FN_DEF_MATCH @@ -71,17 +71,17 @@ cmpdecvar(const void * const value1, tiling_t * alloc_tiling (fiasco_tiling_e method, unsigned tiling_exponent, - unsigned image_level) + unsigned image_level) /* * Image tiling constructor. * Allocate memory for the tiling_t structure. * `method' defines the tiling method (spiral or variance, * ascending or descending). * In case of invalid parameters, a structure with tiling.exponent == 0 is - * returned. + * returned. * * Return value - * pointer to the new tiling structure on success + * pointer to the new tiling structure on success */ { tiling_t *tiling = Calloc (1, sizeof (tiling_t)); @@ -90,21 +90,21 @@ alloc_tiling (fiasco_tiling_e method, unsigned tiling_exponent, { tiling_exponent = 6; warning (_("Image tiles must be at least 8x8 pixels large.\n" - "Setting tiling size to 8x8 pixels.")); + "Setting tiling size to 8x8 pixels.")); } - + switch (method) { case FIASCO_TILING_SPIRAL_ASC: case FIASCO_TILING_SPIRAL_DSC: case FIASCO_TILING_VARIANCE_ASC: case FIASCO_TILING_VARIANCE_DSC: - tiling_exponent = tiling_exponent; - break; + tiling_exponent = tiling_exponent; + break; default: - warning (_("Invalid tiling method specified. Disabling tiling.")); - tiling_exponent = 0; - break; + warning (_("Invalid tiling method specified. Disabling tiling.")); + tiling_exponent = 0; + break; } return tiling; @@ -119,7 +119,7 @@ free_tiling (tiling_t *tiling) * No return value. * * Side effects: - * structure 'tiling' is discarded. + * structure 'tiling' is discarded. */ { if (tiling->vorder) @@ -145,88 +145,88 @@ perform_tiling (const image_t *image, tiling_t *tiling) * No return value. * * Side effects: - * The tiling permutation is stored in 'tiling->vorder'. + * The tiling permutation is stored in 'tiling->vorder'. */ { if (tiling->exponent) { - unsigned tiles = 1 << tiling->exponent; /* number of image tiles */ - bool_t *tile_valid; /* tile i is in valid range ? */ - + unsigned tiles = 1 << tiling->exponent; /* number of image tiles */ + bool_t *tile_valid; /* tile i is in valid range ? */ + tiling->vorder = Calloc (tiles, sizeof (int)); tile_valid = Calloc (tiles, sizeof (bool_t)); if (tiling->method == FIASCO_TILING_VARIANCE_ASC - || tiling->method == FIASCO_TILING_VARIANCE_DSC) + || tiling->method == FIASCO_TILING_VARIANCE_DSC) { - unsigned address; /* bintree address of tile */ - unsigned number; /* number of image tiles */ - unsigned lx = log2 (image->width - 1) + 1; /* x level */ - unsigned ly = log2 (image->height - 1) + 1; /* y level */ - unsigned level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0); - var_list_t *var_list = Calloc (tiles, sizeof (var_list_t)); - - /* - * Compute variances of image tiles - */ - for (number = 0, address = 0; address < tiles; address++) - { - unsigned width, height; /* size of image tile */ - unsigned x0, y0; /* NW corner of image tile */ - - locate_subimage (level, level - tiling->exponent, address, - &x0, &y0, &width, &height); - if (x0 < image->width && y0 < image->height) /* valid range */ - { - if (x0 + width > image->width) /* outside image area */ - width = image->width - x0; - if (y0 + height > image->height) /* outside image area */ - height = image->height - y0; - - var_list [number].variance - = variance (image->pixels [GRAY], x0, y0, - width, height, image->width); - var_list [number].address = address; - number++; - tile_valid [address] = YES; - } - else - tile_valid [address] = NO; - } - - /* - * Sort image tiles according to sign of 'tiling->exp' - */ - if (tiling->method == FIASCO_TILING_VARIANCE_DSC) - qsort (var_list, number, sizeof (var_list_t), cmpdecvar); - else - qsort (var_list, number, sizeof (var_list_t), cmpincvar); - - for (number = 0, address = 0; address < tiles; address++) - if (tile_valid [address]) - { - tiling->vorder [address] = var_list [number].address; - number++; - debug_message ("tile number %d has original address %d", - number, tiling->vorder [address]); - } - else - tiling->vorder [address] = -1; - - Free (var_list); + unsigned address; /* bintree address of tile */ + unsigned number; /* number of image tiles */ + unsigned lx = log2 (image->width - 1) + 1; /* x level */ + unsigned ly = log2 (image->height - 1) + 1; /* y level */ + unsigned level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0); + var_list_t *var_list = Calloc (tiles, sizeof (var_list_t)); + + /* + * Compute variances of image tiles + */ + for (number = 0, address = 0; address < tiles; address++) + { + unsigned width, height; /* size of image tile */ + unsigned x0, y0; /* NW corner of image tile */ + + locate_subimage (level, level - tiling->exponent, address, + &x0, &y0, &width, &height); + if (x0 < image->width && y0 < image->height) /* valid range */ + { + if (x0 + width > image->width) /* outside image area */ + width = image->width - x0; + if (y0 + height > image->height) /* outside image area */ + height = image->height - y0; + + var_list [number].variance + = variance (image->pixels [GRAY], x0, y0, + width, height, image->width); + var_list [number].address = address; + number++; + tile_valid [address] = YES; + } + else + tile_valid [address] = NO; + } + + /* + * Sort image tiles according to sign of 'tiling->exp' + */ + if (tiling->method == FIASCO_TILING_VARIANCE_DSC) + qsort (var_list, number, sizeof (var_list_t), cmpdecvar); + else + qsort (var_list, number, sizeof (var_list_t), cmpincvar); + + for (number = 0, address = 0; address < tiles; address++) + if (tile_valid [address]) + { + tiling->vorder [address] = var_list [number].address; + number++; + debug_message ("tile number %d has original address %d", + number, tiling->vorder [address]); + } + else + tiling->vorder [address] = -1; + + Free (var_list); } else if (tiling->method == FIASCO_TILING_SPIRAL_DSC - || tiling->method == FIASCO_TILING_SPIRAL_ASC) + || tiling->method == FIASCO_TILING_SPIRAL_ASC) { - compute_spiral (tiling->vorder, image->width, image->height, - tiling->exponent, - tiling->method == FIASCO_TILING_SPIRAL_ASC); + compute_spiral (tiling->vorder, image->width, image->height, + tiling->exponent, + tiling->method == FIASCO_TILING_SPIRAL_ASC); } else { - warning ("We do not know the tiling method.\n" - "Skipping image tiling step."); - tiling->exponent = 0; + warning ("We do not know the tiling method.\n" + "Skipping image tiling step."); + tiling->exponent = 0; } } } diff --git a/converter/other/fiasco/codec/tiling.h b/converter/other/fiasco/codec/tiling.h index 6668ad8b..ef6d426d 100644 --- a/converter/other/fiasco/codec/tiling.h +++ b/converter/other/fiasco/codec/tiling.h @@ -1,8 +1,8 @@ /* * tiling.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -22,17 +22,17 @@ typedef struct tiling { - unsigned exponent; /* Image is split in 2^exp tiles */ - fiasco_tiling_e method; /* Method of Image tiling */ - int *vorder; /* Block permutation (size = 2^exp) - -1 indicates empty block */ + unsigned exponent; /* Image is split in 2^exp tiles */ + fiasco_tiling_e method; /* Method of Image tiling */ + int *vorder; /* Block permutation (size = 2^exp) + -1 indicates empty block */ } tiling_t; void perform_tiling (const image_t *image, tiling_t *tiling); tiling_t * alloc_tiling (fiasco_tiling_e method, unsigned tiling_exponent, - unsigned image_level); + unsigned image_level); void free_tiling (tiling_t *tiling); diff --git a/converter/other/fiasco/codec/wfa.h b/converter/other/fiasco/codec/wfa.h index 4e66ccbd..ae86d216 100644 --- a/converter/other/fiasco/codec/wfa.h +++ b/converter/other/fiasco/codec/wfa.h @@ -1,7 +1,7 @@ /* * wfa.h * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -19,38 +19,38 @@ #define MAXEDGES 5 #define MAXSTATES 6000 -#define MAXLABELS 2 /* only bintree possible anymore */ +#define MAXLABELS 2 /* only bintree possible anymore */ #define MAXLEVEL 22 #define FIASCO_BINFILE_RELEASE 2 -#define FIASCO_MAGIC "FIASCO" /* FIASCO magic number */ +#define FIASCO_MAGIC "FIASCO" /* FIASCO magic number */ #define FIASCO_BASIS_MAGIC "Fiasco" /* FIASCO initial basis */ -#define NO_EDGE -1 -#define RANGE -1 -#define NO_RANGE 0 +#define NO_EDGE -1 +#define RANGE -1 +#define NO_RANGE 0 -#define CHILD 1 -#define LEAF 0 +#define CHILD 1 +#define LEAF 0 -#define MAX_PROB 9 -#define MIN_PROB 1 +#define MAX_PROB 9 +#define MIN_PROB 1 /* * WFA state types: - * 0: state is not allowed to be used in an - * approximation and it's image is not needed - * for ip computations. - * AUXILIARY_MASK: state is required for computation of ip's but is not - * allowed to be used in an approximation. - * USE_DOMAIN_MASK: state is allowed to be used in an approximation. + * 0: state is not allowed to be used in an + * approximation and it's image is not needed + * for ip computations. + * AUXILIARY_MASK: state is required for computation of ip's but is not + * allowed to be used in an approximation. + * USE_DOMAIN_MASK: state is allowed to be used in an approximation. */ enum state_types {AUXILIARY_MASK = 1 << 0, USE_DOMAIN_MASK = 1 << 1}; -#define isedge(x) ((x) != NO_EDGE) -#define isdomain(x) ((x) != NO_EDGE) -#define isrange(x) ((x) == RANGE) -#define ischild(x) ((x) != RANGE) +#define isedge(x) ((x) != NO_EDGE) +#define isdomain(x) ((x) != NO_EDGE) +#define isrange(x) ((x) == RANGE) +#define ischild(x) ((x) != RANGE) #define isauxiliary(d,wfa) ((wfa)->domain_type[d] & AUXILIARY_MASK) #define usedomain(d, wfa) ((wfa)->domain_type[d] & USE_DOMAIN_MASK) #define need_image(d,wfa) (isauxiliary ((d), (wfa)) || usedomain ((d), (wfa))) @@ -64,15 +64,15 @@ typedef struct mv * Motion vector components */ { - mc_type_e type; /* motion compensation type */ - int fx, fy; /* forward vector coordinates */ - int bx, by; /* backward vector coordinates */ + mc_type_e type; /* motion compensation type */ + int fx, fy; /* forward vector coordinates */ + int bx, by; /* backward vector coordinates */ } mv_t; typedef struct range_info { - unsigned x, y; /* coordinates of upper left corner */ - unsigned level; /* bintree level of range */ + unsigned x, y; /* coordinates of upper left corner */ + unsigned level; /* bintree level of range */ } range_info_t; #include "image.h" @@ -81,32 +81,32 @@ typedef struct range_info typedef struct wfa_info { - char *wfa_name; /* filename of the WFA */ - char *basis_name; /* filename of the initial basis */ - char *title; /* title of FIASCO stream */ - char *comment; /* comment for FIASCO stream */ - - unsigned max_states; /* max. cardinality of domain pool */ - unsigned chroma_max_states; /* max. cardinality of domain pool for - chroma band coding */ - bool_t color; /* color image */ - unsigned width; /* image width */ - unsigned height; /* image height */ - unsigned level; /* image level */ - rpf_t *rpf; /* Standard reduced precision format */ - rpf_t *dc_rpf; /* DC reduced precision format */ - rpf_t *d_rpf; /* Delta reduced precision format */ - rpf_t *d_dc_rpf; /* Delta DC reduced precision format */ - unsigned frames; /* number of frames in the video */ - unsigned fps; /* number of frames per second */ - unsigned p_min_level; /* min. level of prediction */ - unsigned p_max_level; /* max. level of prediction */ - unsigned search_range; /* motion vector interval */ - bool_t half_pixel; /* usage of half pixel precision */ - bool_t cross_B_search; /* usage of Cross-B-Search */ - bool_t B_as_past_ref; /* usage of B frames as ref's */ - unsigned smoothing; /* smoothing of image along borders */ - unsigned release; /* FIASCO file format release */ + char *wfa_name; /* filename of the WFA */ + char *basis_name; /* filename of the initial basis */ + char *title; /* title of FIASCO stream */ + char *comment; /* comment for FIASCO stream */ + + unsigned max_states; /* max. cardinality of domain pool */ + unsigned chroma_max_states; /* max. cardinality of domain pool for + chroma band coding */ + bool_t color; /* color image */ + unsigned width; /* image width */ + unsigned height; /* image height */ + unsigned level; /* image level */ + rpf_t *rpf; /* Standard reduced precision format */ + rpf_t *dc_rpf; /* DC reduced precision format */ + rpf_t *d_rpf; /* Delta reduced precision format */ + rpf_t *d_dc_rpf; /* Delta DC reduced precision format */ + unsigned frames; /* number of frames in the video */ + unsigned fps; /* number of frames per second */ + unsigned p_min_level; /* min. level of prediction */ + unsigned p_max_level; /* max. level of prediction */ + unsigned search_range; /* motion vector interval */ + bool_t half_pixel; /* usage of half pixel precision */ + bool_t cross_B_search; /* usage of Cross-B-Search */ + bool_t B_as_past_ref; /* usage of B frames as ref's */ + unsigned smoothing; /* smoothing of image along borders */ + unsigned release; /* FIASCO file format release */ } wfa_info_t; typedef struct wfa @@ -114,27 +114,27 @@ typedef struct wfa * Used to store all information and data structures of a WFA */ { - wfa_info_t *wfainfo; /* misc. information about the WFA */ - frame_type_e frame_type; /* intra, predicted, bi-directional */ - unsigned states; /* number of states */ - unsigned basis_states; /* number of states in the basis */ - unsigned root_state; /* root of the tree */ - real_t *final_distribution; /* one pixel images */ - byte_t *level_of_state; /* level of the image part which is - represented by the current state */ - byte_t *domain_type; /* Bit_0==1: auxiliary state - Bit_1==1: used for Y compr */ - mv_t (*mv_tree)[MAXLABELS]; /* motion vectors */ - word_t (*tree)[MAXLABELS]; /* bintree partitioning */ - u_word_t (*x)[MAXLABELS]; /* range coordinate */ - u_word_t (*y)[MAXLABELS]; /* range coordinate */ - word_t (*into)[MAXLABELS][MAXEDGES + 1]; /* domain references */ - real_t (*weight)[MAXLABELS][MAXEDGES + 1]; /* lin.comb. coefficients */ - word_t (*int_weight)[MAXLABELS][MAXEDGES + 1]; /* bin. representation */ - word_t (*y_state)[MAXLABELS]; /* bintree of Y component */ - byte_t (*y_column)[MAXLABELS]; /* array for Y component references */ - byte_t (*prediction)[MAXLABELS]; /* DC prediction */ - bool_t (*delta_state); /* delta state */ + wfa_info_t *wfainfo; /* misc. information about the WFA */ + frame_type_e frame_type; /* intra, predicted, bi-directional */ + unsigned states; /* number of states */ + unsigned basis_states; /* number of states in the basis */ + unsigned root_state; /* root of the tree */ + real_t *final_distribution; /* one pixel images */ + byte_t *level_of_state; /* level of the image part which is + represented by the current state */ + byte_t *domain_type; /* Bit_0==1: auxiliary state + Bit_1==1: used for Y compr */ + mv_t (*mv_tree)[MAXLABELS]; /* motion vectors */ + word_t (*tree)[MAXLABELS]; /* bintree partitioning */ + u_word_t (*x)[MAXLABELS]; /* range coordinate */ + u_word_t (*y)[MAXLABELS]; /* range coordinate */ + word_t (*into)[MAXLABELS][MAXEDGES + 1]; /* domain references */ + real_t (*weight)[MAXLABELS][MAXEDGES + 1]; /* lin.comb. coefficients */ + word_t (*int_weight)[MAXLABELS][MAXEDGES + 1]; /* bin. representation */ + word_t (*y_state)[MAXLABELS]; /* bintree of Y component */ + byte_t (*y_column)[MAXLABELS]; /* array for Y component references */ + byte_t (*prediction)[MAXLABELS]; /* DC prediction */ + bool_t (*delta_state); /* delta state */ } wfa_t; #endif /* not _WFA_H */ diff --git a/converter/other/fiasco/codec/wfalib.c b/converter/other/fiasco/codec/wfalib.c index 90420d6f..fd73092f 100644 --- a/converter/other/fiasco/codec/wfalib.c +++ b/converter/other/fiasco/codec/wfalib.c @@ -1,8 +1,8 @@ /* - * wfalib.c: Library functions both for encoding and decoding + * wfalib.c: Library functions both for encoding and decoding + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -35,8 +35,8 @@ /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ static unsigned @@ -44,8 +44,8 @@ xy_to_address (unsigned x, unsigned y, unsigned level, unsigned n); /***************************************************************************** - public code - + public code + *****************************************************************************/ wfa_t * @@ -56,11 +56,11 @@ alloc_wfa (bool_t coding) * Flag 'coding' indicates whether WFA is used for coding or decoding. * * Return value: - * pointer to the new WFA structure + * pointer to the new WFA structure */ { wfa_t *wfa = Calloc (1, sizeof (wfa_t)); - + /* * Allocate memory */ @@ -74,17 +74,17 @@ alloc_wfa (bool_t coding) wfa->mv_tree = Calloc (MAXSTATES * MAXLABELS, sizeof (mv_t)); wfa->y_state = Calloc (MAXSTATES * MAXLABELS, sizeof (word_t)); wfa->into = Calloc (MAXSTATES * MAXLABELS * (MAXEDGES + 1), - sizeof (word_t)); + sizeof (word_t)); wfa->weight = Calloc (MAXSTATES * MAXLABELS * (MAXEDGES + 1), - sizeof (real_t)); + sizeof (real_t)); wfa->int_weight = Calloc (MAXSTATES * MAXLABELS * (MAXEDGES + 1), - sizeof (word_t)); + sizeof (word_t)); wfa->wfainfo = Calloc (1, sizeof (wfa_info_t));; wfa->prediction = Calloc (MAXSTATES * MAXLABELS, sizeof (byte_t)); wfa->wfainfo->wfa_name = NULL; wfa->wfainfo->basis_name = NULL; - wfa->wfainfo->title = strdup (""); + wfa->wfainfo->title = strdup (""); wfa->wfainfo->comment = strdup (""); /* @@ -96,24 +96,24 @@ alloc_wfa (bool_t coding) wfa->states = 0; wfa->basis_states = 0; wfa->root_state = 0; - for (state = 0; state < MAXSTATES; state++) + for (state = 0; state < MAXSTATES; state++) { - wfa->final_distribution [state] = 0; - wfa->domain_type [state] = 0; - for (label = 0; label < MAXLABELS; label++) - { - wfa->into [state][label][0] = NO_EDGE; - wfa->tree [state][label] = RANGE; - wfa->y_state [state][label] = RANGE; - } + wfa->final_distribution [state] = 0; + wfa->domain_type [state] = 0; + for (label = 0; label < MAXLABELS; label++) + { + wfa->into [state][label][0] = NO_EDGE; + wfa->tree [state][label] = RANGE; + wfa->y_state [state][label] = RANGE; + } } } - if (coding) /* initialize additional variables */ + if (coding) /* initialize additional variables */ wfa->y_column = Calloc (MAXSTATES * MAXLABELS, sizeof (byte_t)); else wfa->y_column = NULL; - + return wfa; } @@ -126,7 +126,7 @@ free_wfa (wfa_t *wfa) * No return value. * * Side effects: - * 'wfa' struct is discarded. + * 'wfa' struct is discarded. */ { if (wfa->wfainfo->wfa_name) @@ -157,14 +157,14 @@ free_wfa (wfa_t *wfa) Free (wfa); } -real_t +real_t compute_final_distribution (unsigned state, const wfa_t *wfa) /* * Compute the final distribution of the given 'state'. * Uses the fact that the generated 'wfa' is average preserving. * * Return value: - * final distribution + * final distribution */ { unsigned label; @@ -174,14 +174,14 @@ compute_final_distribution (unsigned state, const wfa_t *wfa) { unsigned edge; int domain; - + if (ischild (domain = wfa->tree [state][label])) - final += wfa->final_distribution [domain]; + final += wfa->final_distribution [domain]; for (edge = 0; isedge (domain = wfa->into [state][label][edge]); edge++) - final += wfa->weight [state][label][edge] - * wfa->final_distribution [domain]; + final += wfa->weight [state][label][edge] + * wfa->final_distribution [domain]; } - + return final / MAXLABELS; } @@ -193,10 +193,10 @@ compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa) * {i | 'from' <= i <= 'to'}. I.e. domains are in {i | from <= i < 'to'} * Always ensure that state 0 is among selected states even though from * may be > 0. - * + * * Return value: - * pointer to array of the most popular state images - * sorted by increasing state numbers and terminated by -1 + * pointer to array of the most popular state images + * sorted by increasing state numbers and terminated by -1 */ { word_t *domains; @@ -209,12 +209,12 @@ compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa) hits [domain].value = domain; hits [domain].key = 0; } - + for (state = from; state <= to; state++) for (label = 0; label < MAXLABELS; label++) - for (edge = 0; isedge (domain = wfa->into [state][label][edge]); - edge++) - hits [domain].key++; + for (edge = 0; isedge (domain = wfa->into [state][label][edge]); + edge++) + hits [domain].key++; qsort (hits + 1, to - 1, sizeof (pair_t), sort_desc_pair); @@ -222,23 +222,23 @@ compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa) domains = Calloc (n + 1, sizeof (word_t)); for (domain = 0; domain < (int) n && (!domain || hits [domain].key); - domain++) + domain++) domains [domain] = hits [domain].value; if (n != domain) debug_message ("Only %d domains have been used in the luminance.", - domain); + domain); n = domain; qsort (domains, n, sizeof (word_t), sort_asc_word); domains [n] = -1; - + Free (hits); - + return domains; } void append_edge (unsigned from, unsigned into, real_t weight, - unsigned label, wfa_t *wfa) + unsigned label, wfa_t *wfa) /* * Append an edge from state 'from' to state 'into' with * the given 'label' and 'weight' to the 'wfa'. @@ -246,10 +246,10 @@ append_edge (unsigned from, unsigned into, real_t weight, * No return value. * * Side effects: - * 'wfa' structure is changed. + * 'wfa' structure is changed. */ { - unsigned new; /* position of the new edge */ + unsigned new; /* position of the new edge */ unsigned edge; /* @@ -257,7 +257,7 @@ append_edge (unsigned from, unsigned into, real_t weight, * edges are sorted by increasing 'into' values */ for (new = 0; (isedge (wfa->into [from][label][new]) - && wfa->into [from][label][new] < (int) into); new++) + && wfa->into [from][label][new] < (int) into); new++) ; /* * Move the edges 'n' to position 'n+1', for n = max, ..., 'new' @@ -269,7 +269,7 @@ append_edge (unsigned from, unsigned into, real_t weight, wfa->into [from][label][edge] = wfa->into [from][label][edge - 1]; wfa->weight [from][label][edge] = wfa->weight [from][label][edge - 1]; wfa->int_weight [from][label][edge] - = wfa->int_weight [from][label][edge - 1]; + = wfa->int_weight [from][label][edge - 1]; } /* * Insert the new edge @@ -279,15 +279,15 @@ append_edge (unsigned from, unsigned into, real_t weight, wfa->int_weight [from][label][edge] = weight * 512 + 0.5; } -void +void remove_states (unsigned from, wfa_t *wfa) -/* +/* * Remove 'wfa' states 'wfa->basis_states',...,'wfa->states' - 1. * * No return value. * * Side effects: - * 'wfa' structure is cleared for the given states. + * 'wfa' structure is cleared for the given states. */ { unsigned state; @@ -295,18 +295,18 @@ remove_states (unsigned from, wfa_t *wfa) for (state = from; state < wfa->states; state++) { unsigned label; - - for (label = 0; label < MAXLABELS; label++) + + for (label = 0; label < MAXLABELS; label++) { - wfa->into [state][label][0] = NO_EDGE; - wfa->tree [state][label] = RANGE; - wfa->prediction [state][label] = FALSE; - wfa->y_state [state][label] = RANGE; - wfa->mv_tree [state][label].type = NONE; - wfa->mv_tree [state][label].fx = 0; - wfa->mv_tree [state][label].fy = 0; - wfa->mv_tree [state][label].bx = 0; - wfa->mv_tree [state][label].by = 0; + wfa->into [state][label][0] = NO_EDGE; + wfa->tree [state][label] = RANGE; + wfa->prediction [state][label] = FALSE; + wfa->y_state [state][label] = RANGE; + wfa->mv_tree [state][label].type = NONE; + wfa->mv_tree [state][label].fx = 0; + wfa->mv_tree [state][label].fy = 0; + wfa->mv_tree [state][label].bx = 0; + wfa->mv_tree [state][label].by = 0; } wfa->domain_type [state] = 0; wfa->delta_state [state] = FALSE; @@ -323,7 +323,7 @@ copy_wfa (wfa_t *dst, const wfa_t *src) * No return value. * * Side effects: - * 'dst' is filled with same data as 'src' + * 'dst' is filled with same data as 'src' * * NOTE: size of WFA 'dst' must be at least size of WFA 'src' */ @@ -339,11 +339,11 @@ copy_wfa (wfa_t *dst, const wfa_t *src) memset (dst->y, 0, MAXSTATES * MAXLABELS * sizeof (word_t)); memset (dst->y_state, 0, MAXSTATES * MAXLABELS * sizeof (word_t)); memset (dst->into, NO_EDGE, - MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); + MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); memset (dst->weight, 0, - MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (real_t)); + MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (real_t)); memset (dst->int_weight, 0, - MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); + MAXSTATES * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); memset (dst->prediction, 0, MAXSTATES * MAXLABELS * sizeof (byte_t)); memset (dst->delta_state, 0, MAXSTATES * sizeof (bool_t)); if (dst->y_column) @@ -352,62 +352,62 @@ copy_wfa (wfa_t *dst, const wfa_t *src) for (state = 0; state < MAXSTATES; state++) /* clear WFA struct */ { unsigned label; - + for (label = 0; label < MAXLABELS; label++) { - dst->into [state][label][0] = NO_EDGE; - dst->tree [state][label] = RANGE; - dst->mv_tree [state][label].type = NONE; - dst->y_state[state][label] = RANGE; + dst->into [state][label][0] = NO_EDGE; + dst->tree [state][label] = RANGE; + dst->mv_tree [state][label].type = NONE; + dst->y_state[state][label] = RANGE; } dst->delta_state [state] = NO; dst->domain_type [state] = 0; } - + dst->frame_type = src->frame_type; - dst->states = src->states; + dst->states = src->states; dst->basis_states = src->basis_states; dst->root_state = src->root_state; memcpy (dst->wfainfo, src->wfainfo, sizeof (wfa_info_t)); - if (dst->states == 0) /* nothing to do */ + if (dst->states == 0) /* nothing to do */ return; memcpy (dst->final_distribution, src->final_distribution, - src->states * sizeof (real_t)); + src->states * sizeof (real_t)); memcpy (dst->level_of_state, src->level_of_state, - src->states * sizeof (byte_t)); + src->states * sizeof (byte_t)); memcpy (dst->domain_type, src->domain_type, - src->states * sizeof (byte_t)); + src->states * sizeof (byte_t)); memcpy (dst->delta_state, src->delta_state, - src->states * sizeof (bool_t)); + src->states * sizeof (bool_t)); memcpy (dst->mv_tree, src->mv_tree, - src->states * MAXLABELS * sizeof (mv_t)); + src->states * MAXLABELS * sizeof (mv_t)); memcpy (dst->tree, src->tree, - src->states * MAXLABELS * sizeof (word_t)); + src->states * MAXLABELS * sizeof (word_t)); memcpy (dst->x, src->x, - src->states * MAXLABELS * sizeof (word_t)); + src->states * MAXLABELS * sizeof (word_t)); memcpy (dst->y, src->y, - src->states * MAXLABELS * sizeof (word_t)); + src->states * MAXLABELS * sizeof (word_t)); memcpy (dst->y_state, src->y_state, - src->states * MAXLABELS * sizeof (word_t)); + src->states * MAXLABELS * sizeof (word_t)); memcpy (dst->into, src->into, - src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); + src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); memcpy (dst->weight, src->weight, - src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (real_t)); + src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (real_t)); memcpy (dst->int_weight, src->int_weight, - src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); + src->states * MAXLABELS * (MAXEDGES + 1) * sizeof (word_t)); memcpy (dst->prediction, src->prediction, - src->states * MAXLABELS * sizeof (byte_t)); + src->states * MAXLABELS * sizeof (byte_t)); if (dst->y_column) memcpy (dst->y_column, src->y_column, - src->states * MAXLABELS * sizeof (byte_t)); + src->states * MAXLABELS * sizeof (byte_t)); } void locate_subimage (unsigned orig_level, unsigned level, unsigned bintree, - unsigned *x, unsigned *y, unsigned *width, unsigned *height) + unsigned *x, unsigned *y, unsigned *width, unsigned *height) /* * Compute pixel coordinates of the subimage which 'bintree' address is given. * The level of the original image is 'orig_level' and the level of the @@ -416,14 +416,14 @@ locate_subimage (unsigned orig_level, unsigned level, unsigned bintree, * No return value. * * Side effects: - * '*x', '*y' coordinates of the upper left corner - * '*width', '*height' size of image + * '*x', '*y' coordinates of the upper left corner + * '*width', '*height' size of image */ { /* * Compute coordinates of the subimage */ - *x = *y = 0; /* start at NW corner */ + *x = *y = 0; /* start at NW corner */ *width = width_of_level (level); *height = height_of_level (level); @@ -439,31 +439,31 @@ locate_subimage (unsigned orig_level, unsigned level, unsigned bintree, } else if (level < orig_level) { - unsigned mask; /* mask for bintree -> xy conversion */ - bool_t hor; /* 1 next subdivision is horizontal - 0 next subdivision is vertical */ - unsigned l = orig_level - 1; /* current level */ - - hor = orig_level % 2; /* start with vertival subdivision - for square image and vice versa */ - + unsigned mask; /* mask for bintree -> xy conversion */ + bool_t hor; /* 1 next subdivision is horizontal + 0 next subdivision is vertical */ + unsigned l = orig_level - 1; /* current level */ + + hor = orig_level % 2; /* start with vertival subdivision + for square image and vice versa */ + for (mask = 1 << (orig_level - level - 1); mask; mask >>= 1, hor = !hor) { - if (bintree & mask) /* change coordinates */ - { - if (hor) /* horizontal subdivision */ - *y += height_of_level (l); - else /* vertical subdivision */ - *x += width_of_level (l); - } - l--; + if (bintree & mask) /* change coordinates */ + { + if (hor) /* horizontal subdivision */ + *y += height_of_level (l); + else /* vertical subdivision */ + *x += width_of_level (l); + } + l--; } } } void compute_spiral (int *vorder, unsigned image_width, unsigned image_height, - unsigned tiling_exp, bool_t inc_spiral) + unsigned tiling_exp, bool_t inc_spiral) /* * Compute image tiling with spiral order. * 'inc_spiral' specifies whether the spiral starts in the middle @@ -474,28 +474,28 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height, * No return value. * * Side effects: - * vorder[] is filled with tiling permutation + * vorder[] is filled with tiling permutation */ { - unsigned x, y; /* current position */ - unsigned xmin, xmax, ymin, ymax; /* boundaries for current line */ - unsigned width, height; /* offset for each tile */ - unsigned lx, ly, level; /* level x and y */ - unsigned tiles; /* total number of tiles */ - unsigned address; /* bintree address */ - + unsigned x, y; /* current position */ + unsigned xmin, xmax, ymin, ymax; /* boundaries for current line */ + unsigned width, height; /* offset for each tile */ + unsigned lx, ly, level; /* level x and y */ + unsigned tiles; /* total number of tiles */ + unsigned address; /* bintree address */ + lx = log2 (image_width - 1) + 1; ly = log2 (image_height - 1) + 1; level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0); - tiles = 1 << tiling_exp; /* Number of image tiles */ + tiles = 1 << tiling_exp; /* Number of image tiles */ width = width_of_level (level - tiling_exp); height = height_of_level (level - tiling_exp); for (address = 0; address < tiles; address++) { unsigned x0, y0, width, height; - + locate_subimage (level, level - tiling_exp, address, - &x0, &y0, &width, &height); + &x0, &y0, &width, &height); vorder [address] = (x0 < image_width && y0 < image_height) ? 0 : -1; } @@ -507,7 +507,7 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height, /* * 1234 - * CDE5 Traverse image in spiral order + * CDE5 Traverse image in spiral order * BGF6 starting at the top left corner * A987 */ @@ -515,59 +515,59 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height, { for (x = xmin, y = ymin; x < xmax; x += width) /* W>E */ { - while (vorder [address] == -1) - address++; - if (x < image_width && y < image_height) /* valid range */ - vorder [address++] = xy_to_address (x, y, level, tiling_exp); - while (address < tiles && vorder [address] == -1) - address++; + while (vorder [address] == -1) + address++; + if (x < image_width && y < image_height) /* valid range */ + vorder [address++] = xy_to_address (x, y, level, tiling_exp); + while (address < tiles && vorder [address] == -1) + address++; } ymin += height; if (address >= tiles) - break; - + break; + for (x = xmax - width, y = ymin; y < ymax; y += height) /* N>S */ { - while (vorder [address] == -1) - address++; - if (x <= image_width && y <= image_height) /* valid range */ - vorder [address++] = xy_to_address (x, y, level, tiling_exp); - while (address < tiles && vorder [address] == -1) - address++; + while (vorder [address] == -1) + address++; + if (x <= image_width && y <= image_height) /* valid range */ + vorder [address++] = xy_to_address (x, y, level, tiling_exp); + while (address < tiles && vorder [address] == -1) + address++; } xmax -= width; if (address >= tiles) - break; + break; for (x = xmax - width, y = ymax - width; x >= xmin; x -= width) /* E<W */ { - while (vorder [address] == -1) - address++; - if (x <= image_width && y <= image_height) /* valid range */ - vorder [address++] = xy_to_address (x, y, level, tiling_exp); - while (address < tiles && vorder [address] == -1) - address++; + while (vorder [address] == -1) + address++; + if (x <= image_width && y <= image_height) /* valid range */ + vorder [address++] = xy_to_address (x, y, level, tiling_exp); + while (address < tiles && vorder [address] == -1) + address++; } ymax -= height; if (address >= tiles) - break; + break; - for (x = xmin, y = ymax - height; y >= ymin; y -= height) /* S>N */ + for (x = xmin, y = ymax - height; y >= ymin; y -= height) /* S>N */ { - while (vorder [address] == -1) - address++; - if (x <= image_width && y <= image_height) /* valid range */ - vorder [address++] = xy_to_address (x, y, level, tiling_exp); - while (address < tiles && vorder [address] == -1) - address++; + while (vorder [address] == -1) + address++; + if (x <= image_width && y <= image_height) /* valid range */ + vorder [address++] = xy_to_address (x, y, level, tiling_exp); + while (address < tiles && vorder [address] == -1) + address++; } xmin += width; - + if (address >= tiles) - break; + break; } if (inc_spiral) @@ -576,18 +576,18 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height, while (i < j) { - int tmp; - - while (vorder [i] == -1) - i++; - while (vorder [j] == -1) - j--; - - tmp = vorder [i]; - vorder [i] = vorder [j]; - vorder [j] = tmp; - i++; - j--; + int tmp; + + while (vorder [i] == -1) + i++; + while (vorder [j] == -1) + j--; + + tmp = vorder [i]; + vorder [i] = vorder [j]; + vorder [j] = tmp; + i++; + j--; } } /* @@ -595,109 +595,109 @@ compute_spiral (int *vorder, unsigned image_width, unsigned image_height, */ { unsigned number; - + for (number = 0, address = 0; address < tiles; address++) - if (vorder [address] != -1) - debug_message ("number %d: address %d", - number++, vorder [address]); + if (vorder [address] != -1) + debug_message ("number %d: address %d", + number++, vorder [address]); } } bool_t find_range (unsigned x, unsigned y, unsigned band, - const wfa_t *wfa, unsigned *range_state, unsigned *range_label) + const wfa_t *wfa, unsigned *range_state, unsigned *range_label) /* * Find a range ('*range_state', '*range_label') that contains * pixel ('x', 'y') in the iven color 'band'. * * Return value: - * TRUE on success, or FALSE if there is no such range + * TRUE on success, or FALSE if there is no such range * * Side effects: - * '*range_state' and '*range_label' are modified on success. + * '*range_state' and '*range_label' are modified on success. */ { unsigned state, label; unsigned first_state, last_state; bool_t success = NO; - + first_state = wfa->basis_states; last_state = wfa->states; if (wfa->wfainfo->color) switch (band) { - case Y: - first_state = wfa->basis_states; - last_state = wfa->tree [wfa->tree [wfa->root_state][0]][0]; - break; - case Cb: - first_state = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; - last_state = wfa->tree [wfa->tree [wfa->root_state][0]][1]; - break; - case Cr: - first_state = wfa->tree [wfa->tree [wfa->root_state][0]][1] + 1; - last_state = wfa->states; - break; - default: - error ("unknown color component."); + case Y: + first_state = wfa->basis_states; + last_state = wfa->tree [wfa->tree [wfa->root_state][0]][0]; + break; + case Cb: + first_state = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; + last_state = wfa->tree [wfa->tree [wfa->root_state][0]][1]; + break; + case Cr: + first_state = wfa->tree [wfa->tree [wfa->root_state][0]][1] + 1; + last_state = wfa->states; + break; + default: + error ("unknown color component."); } for (state = first_state; state < last_state; state++) for (label = 0; label < MAXLABELS; label++) - if (isrange (wfa->tree [state][label])) - if (x >= wfa->x [state][label] && y >= wfa->y [state][label] - && x < (unsigned) (wfa->x [state][label] - + width_of_level (wfa->level_of_state [state] - 1)) - && y < (unsigned) (wfa->y [state][label] - + height_of_level (wfa->level_of_state [state] - 1))) - { - success = YES; - *range_state = state; - *range_label = label; - - return success; - } + if (isrange (wfa->tree [state][label])) + if (x >= wfa->x [state][label] && y >= wfa->y [state][label] + && x < (unsigned) (wfa->x [state][label] + + width_of_level (wfa->level_of_state [state] - 1)) + && y < (unsigned) (wfa->y [state][label] + + height_of_level (wfa->level_of_state [state] - 1))) + { + success = YES; + *range_state = state; + *range_label = label; + + return success; + } return success; } void sort_ranges (unsigned state, unsigned *domain, - range_sort_t *rs, const wfa_t *wfa) + range_sort_t *rs, const wfa_t *wfa) /* * Generate list of ranges in coder order. * 'state' is the current state of the call tree while 'domain' is the * index of the last added WFA state. * * Side effects: - * 'domain' is incremented after recursion returns - * 'rs' is filled accordingly + * 'domain' is incremented after recursion returns + * 'rs' is filled accordingly * * No return value. */ { unsigned label; - + for (label = 0; label < MAXLABELS; label++) { if (isrange (wfa->tree [state][label])) - rs->range_subdivided [rs->range_no] = NO; + rs->range_subdivided [rs->range_no] = NO; else { - sort_ranges (wfa->tree [state][label], domain, rs, wfa); - rs->range_subdivided [rs->range_no] = YES; + sort_ranges (wfa->tree [state][label], domain, rs, wfa); + rs->range_subdivided [rs->range_no] = YES; } rs->range_state [rs->range_no] = state; rs->range_label [rs->range_no] = label; rs->range_max_domain [rs->range_no] = *domain; while (!usedomain (rs->range_max_domain [rs->range_no], wfa)) - rs->range_max_domain [rs->range_no]--; + rs->range_max_domain [rs->range_no]--; if (label == 1 || !rs->range_subdivided [rs->range_no]) - rs->range_no++; + rs->range_no++; } - + (*domain)++; } @@ -709,11 +709,11 @@ locate_delta_images (wfa_t *wfa) * via MC or ND. * * Return value: - * TRUE at least one state is part of a delta approximation - * FALSE no delta approximations in this WFA + * TRUE at least one state is part of a delta approximation + * FALSE no delta approximations in this WFA * * Side effects: - * 'wfa->delta [state][label]' is set accordingly. + * 'wfa->delta [state][label]' is set accordingly. */ { unsigned state, label; @@ -724,22 +724,22 @@ locate_delta_images (wfa_t *wfa) for (state = wfa->root_state; state >= wfa->basis_states; state--) for (label = 0; label < MAXLABELS; label++) - if (ischild (wfa->tree [state][label])) - if (wfa->mv_tree [state][label].type != NONE - || isedge (wfa->into [state][label][0]) - || wfa->delta_state [state]) - { - delta = YES; - wfa->delta_state [wfa->tree [state][label]] = YES; - } + if (ischild (wfa->tree [state][label])) + if (wfa->mv_tree [state][label].type != NONE + || isedge (wfa->into [state][label][0]) + || wfa->delta_state [state]) + { + delta = YES; + wfa->delta_state [wfa->tree [state][label]] = YES; + } return delta; } /***************************************************************************** - private code - + private code + ******************************************************************************/ static unsigned @@ -750,25 +750,25 @@ xy_to_address (unsigned x, unsigned y, unsigned level, unsigned n) * 'n' specifies number of iterations. * * Return value: - * address of subimage - */ -{ + * address of subimage + */ +{ unsigned address = 0; while (n--) { address <<= 1; - if (--level % 2) + if (--level % 2) { - if (x & width_of_level (level)) - address++; + if (x & width_of_level (level)) + address++; } else { - if (y & height_of_level (level)) - address++; + if (y & height_of_level (level)) + address++; } } - + return address; } diff --git a/converter/other/fiasco/codec/wfalib.h b/converter/other/fiasco/codec/wfalib.h index 5c1e0907..63723f30 100644 --- a/converter/other/fiasco/codec/wfalib.h +++ b/converter/other/fiasco/codec/wfalib.h @@ -1,8 +1,8 @@ /* * wfalib.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -34,26 +34,26 @@ bool_t locate_delta_images (wfa_t *wfa); void sort_ranges (unsigned state, unsigned *domain, - range_sort_t *rs, const wfa_t *wfa); + range_sort_t *rs, const wfa_t *wfa); bool_t find_range (unsigned x, unsigned y, unsigned band, - const wfa_t *wfa, unsigned *range_state, unsigned *range_label); + const wfa_t *wfa, unsigned *range_state, unsigned *range_label); void compute_spiral (int *vorder, unsigned image_width, unsigned image_height, - unsigned tiling_exp, bool_t inc_spiral); + unsigned tiling_exp, bool_t inc_spiral); void locate_subimage (unsigned orig_level, unsigned level, unsigned bintree, - unsigned *x, unsigned *y, unsigned *width, unsigned *height); + unsigned *x, unsigned *y, unsigned *width, unsigned *height); void copy_wfa (wfa_t *dst, const wfa_t *src); -void +void remove_states (unsigned from, wfa_t *wfa); void append_edge (unsigned from, unsigned into, real_t weight, - unsigned label, wfa_t *wfa); + unsigned label, wfa_t *wfa); word_t * compute_hits (unsigned from, unsigned to, unsigned n, const wfa_t *wfa); -real_t +real_t compute_final_distribution (unsigned state, const wfa_t *wfa); wfa_t * alloc_wfa (bool_t coding); diff --git a/converter/other/fiasco/display.c b/converter/other/fiasco/display.c index d8d32fa6..5eed6aeb 100644 --- a/converter/other/fiasco/display.c +++ b/converter/other/fiasco/display.c @@ -1,11 +1,11 @@ /* - * display.c: X11 display of frames + * display.c: X11 display of frames + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner - * + * * Based on mpeg2decode, (C) 1994, MPEG Software Simulation Group * and mpeg2play, (C) 1994 Stefan Eckart * <stefan@lis.e-technik.tu-muenchen.de> @@ -37,8 +37,8 @@ /***************************************************************************** - shared memory functions (if USE_SHM is defined) - + shared memory functions (if USE_SHM is defined) + *****************************************************************************/ #ifdef USE_SHM @@ -64,16 +64,16 @@ InstallXErrorHandler (x11_info_t *xinfo); static void DeInstallXErrorHandler (x11_info_t *xinfo); -static int shmem_flag; -static XShmSegmentInfo shminfo1, shminfo2; -static int gXErrorFlag; -static int CompletionType = -1; +static int shmem_flag; +static XShmSegmentInfo shminfo1, shminfo2; +static int gXErrorFlag; +static int CompletionType = -1; static int HandleXError (Display *dpy, XErrorEvent *event) { gXErrorFlag = 1; - + return 0; } @@ -95,21 +95,21 @@ DeInstallXErrorHandler (x11_info_t *xinfo) /***************************************************************************** - public code - + public code + *****************************************************************************/ void display_image (unsigned x0, unsigned y0, x11_info_t *xinfo) /* * Display 'image' at pos ('x0', 'y0') in the current window - * (given by 'xinfo->window'). + * (given by 'xinfo->window'). * * No return value. */ { int byte_order_check = 1; - + /* * Always work in native bit and byte order. This tells Xlib to * reverse bit and byte order if necessary when crossing a @@ -125,28 +125,28 @@ display_image (unsigned x0, unsigned y0, x11_info_t *xinfo) { xinfo->ximage->byte_order = MSBFirst; xinfo->ximage->bitmap_bit_order = MSBFirst; - } + } /* Display dithered image */ #ifdef USE_SHM if (shmem_flag) { XEvent xev; - + XShmPutImage (xinfo->display, xinfo->window, xinfo->gc, xinfo->ximage, - 0, 0, x0, y0, xinfo->ximage->width, xinfo->ximage->height, - True); + 0, 0, x0, y0, xinfo->ximage->width, xinfo->ximage->height, + True); XFlush (xinfo->display); - + while (!XCheckTypedEvent (xinfo->display, CompletionType, &xev)) - ; + ; } - else + else #endif /* USE_SHM */ { - xinfo->ximage->data = (char *) xinfo->pixels; + xinfo->ximage->data = (char *) xinfo->pixels; XPutImage (xinfo->display, xinfo->window, xinfo->gc, xinfo->ximage, 0, 0, - x0, y0, xinfo->ximage->width, xinfo->ximage->height); + x0, y0, xinfo->ximage->width, xinfo->ximage->height); } } @@ -177,7 +177,7 @@ close_window (x11_info_t *xinfo) x11_info_t * open_window (const char *titlename, const char *iconname, - unsigned width, unsigned height) + unsigned width, unsigned height) /* * Open a X11 window of size 'width'x'height'. * If 'color' is false then allocate a colormap with grayscales. @@ -185,20 +185,20 @@ open_window (const char *titlename, const char *iconname, * respectively. * * Return value: - * X11 info struct containing display, gc, window ID and colormap. + * X11 info struct containing display, gc, window ID and colormap. */ { - XVisualInfo visual_template; /* template for XGetVisualInfo() */ - XVisualInfo visual_info; /* return value of XGetVisualInfo() */ - int visual_n; /* # of matches of XGetVisualInfo */ - XEvent xev; - XSizeHints hint; - XSetWindowAttributes xswa; - unsigned int fg, bg; /* foreground and background color */ - unsigned int mask; /* event mask */ - x11_info_t *xinfo = calloc (1, sizeof (x11_info_t)); + XVisualInfo visual_template; /* template for XGetVisualInfo() */ + XVisualInfo visual_info; /* return value of XGetVisualInfo() */ + int visual_n; /* # of matches of XGetVisualInfo */ + XEvent xev; + XSizeHints hint; + XSetWindowAttributes xswa; + unsigned int fg, bg; /* foreground and background color */ + unsigned int mask; /* event mask */ + x11_info_t *xinfo = calloc (1, sizeof (x11_info_t)); long visual_mask; - + if (!xinfo) error ("Out of memory"); /* @@ -207,32 +207,32 @@ open_window (const char *titlename, const char *iconname, xinfo->display = XOpenDisplay (NULL); if (xinfo->display == NULL) error ("Can't open display.\n" - "Make sure that your environment variable DISPLAY " - "is set correctly."); + "Make sure that your environment variable DISPLAY " + "is set correctly."); xinfo->screen = DefaultScreen (xinfo->display); xinfo->gc = DefaultGC (xinfo->display, xinfo->screen); { - unsigned depth [] = {32, 24, 16}; - int class [] = {TrueColor, PseudoColor}; + unsigned depth [] = {32, 24, 16}; + int class [] = {TrueColor, PseudoColor}; const char *class_text [] = {"TrueColor", "PseudoColor"}; - Status found = 0; + Status found = 0; unsigned d, c; for (d = 0; !found && d < sizeof (depth) / sizeof (unsigned); d++) - for (c = 0; !found && c < sizeof (class) / sizeof (int); c++) - { - found = XMatchVisualInfo (xinfo->display, xinfo->screen, - depth [d], class [c], &visual_info); - if (found) - fprintf (stderr, "%s : %d bit colordepth.\n", - class_text [c], depth [d]); - } + for (c = 0; !found && c < sizeof (class) / sizeof (int); c++) + { + found = XMatchVisualInfo (xinfo->display, xinfo->screen, + depth [d], class [c], &visual_info); + if (found) + fprintf (stderr, "%s : %d bit colordepth.\n", + class_text [c], depth [d]); + } if (!found && fiasco_get_verbosity ()) - error ("Can't find a 16/24/32 bit TrueColor/DirectColor display"); + error ("Can't find a 16/24/32 bit TrueColor/DirectColor display"); } - + /* Width and height of the display window */ hint.x = hint.y = 0; hint.min_width = hint.max_width = hint.width = width; @@ -249,22 +249,22 @@ open_window (const char *titlename, const char *iconname, { mask |= CWColormap; xswa.colormap = XCreateColormap (xinfo->display, - DefaultRootWindow (xinfo->display), - visual_info.visual, AllocNone); + DefaultRootWindow (xinfo->display), + visual_info.visual, AllocNone); } xswa.background_pixel = bg; xswa.border_pixel = fg; xinfo->window = XCreateWindow (xinfo->display, - DefaultRootWindow (xinfo->display), 0, 0, - width, height, 1, visual_info.depth, - InputOutput, visual_info.visual, - mask, &xswa); + DefaultRootWindow (xinfo->display), 0, 0, + width, height, 1, visual_info.depth, + InputOutput, visual_info.visual, + mask, &xswa); XSelectInput (xinfo->display, xinfo->window, StructureNotifyMask); /* Tell other applications about this window */ XSetStandardProperties (xinfo->display, xinfo->window, titlename, iconname, - None, NULL, 0, &hint); + None, NULL, 0, &hint); /* Map window. */ XMapWindow (xinfo->display, xinfo->window); @@ -290,23 +290,23 @@ alloc_ximage (x11_info_t *xinfo, unsigned width, unsigned height) * No return value. * * Side effects: - * 'ximage->ximage' and 'ximage->pixels' are set to useful values. + * 'ximage->ximage' and 'ximage->pixels' are set to useful values. */ { char dummy; - + #ifdef USE_SHM if (XShmQueryExtension(xinfo->display)) { if (fiasco_get_verbosity ()) - fprintf (stderr, "Trying shared memory.\n"); + fprintf (stderr, "Trying shared memory.\n"); shmem_flag = 1; } else { shmem_flag = 0; if (fiasco_get_verbosity ()) - fprintf (stderr, + fprintf (stderr, "Shared memory does not work on this system\n" "Reverting to normal Xlib.\n"); } @@ -319,34 +319,34 @@ alloc_ximage (x11_info_t *xinfo, unsigned width, unsigned height) if (shmem_flag) { xinfo->ximage = XShmCreateImage (xinfo->display, - DefaultVisual (xinfo->display, - xinfo->screen), - DefaultDepth (xinfo->display, - xinfo->screen), ZPixmap, - NULL, &shminfo1, width, height); + DefaultVisual (xinfo->display, + xinfo->screen), + DefaultDepth (xinfo->display, + xinfo->screen), ZPixmap, + NULL, &shminfo1, width, height); /* If no go, then revert to normal Xlib calls. */ if (xinfo->ximage == NULL) { - if (fiasco_get_verbosity ()) - fprintf (stderr, - "Shared memory error, disabling (Ximage error).\n"); - goto shmemerror; + if (fiasco_get_verbosity ()) + fprintf (stderr, + "Shared memory error, disabling (Ximage error).\n"); + goto shmemerror; } /* Success here, continue. */ shminfo1.shmid = shmget (IPC_PRIVATE, xinfo->ximage->bytes_per_line - * xinfo->ximage->height, IPC_CREAT | 0777); + * xinfo->ximage->height, IPC_CREAT | 0777); if (shminfo1.shmid < 0) { - XDestroyImage (xinfo->ximage); - if (fiasco_get_verbosity ()) - fprintf (stderr, - "Shared memory error, disabling (seg id error).\n"); - goto shmemerror; + XDestroyImage (xinfo->ximage); + if (fiasco_get_verbosity ()) + fprintf (stderr, + "Shared memory error, disabling (seg id error).\n"); + goto shmemerror; } shminfo1.shmaddr = (char *) shmat (shminfo1.shmid, 0, 0); @@ -354,13 +354,13 @@ alloc_ximage (x11_info_t *xinfo, unsigned width, unsigned height) if (shminfo1.shmaddr == ((char *) -1)) { - XDestroyImage (xinfo->ximage); - if (shminfo1.shmaddr != ((char *) -1)) - shmdt (shminfo1.shmaddr); - if (fiasco_get_verbosity ()) - fprintf (stderr, - "Shared memory error, disabling (address error).\n"); - goto shmemerror; + XDestroyImage (xinfo->ximage); + if (shminfo1.shmaddr != ((char *) -1)) + shmdt (shminfo1.shmaddr); + if (fiasco_get_verbosity ()) + fprintf (stderr, + "Shared memory error, disabling (address error).\n"); + goto shmemerror; } xinfo->ximage->data = shminfo1.shmaddr; @@ -372,18 +372,18 @@ alloc_ximage (x11_info_t *xinfo, unsigned width, unsigned height) if (gXErrorFlag) { - /* Ultimate failure here. */ - XDestroyImage (xinfo->ximage); - shmdt (shminfo1.shmaddr); - if (fiasco_get_verbosity ()) - fprintf (stderr, "Shared memory error, disabling.\n"); - gXErrorFlag = 0; - goto shmemerror; + /* Ultimate failure here. */ + XDestroyImage (xinfo->ximage); + shmdt (shminfo1.shmaddr); + if (fiasco_get_verbosity ()) + fprintf (stderr, "Shared memory error, disabling.\n"); + gXErrorFlag = 0; + goto shmemerror; } else - shmctl (shminfo1.shmid, IPC_RMID, 0); + shmctl (shminfo1.shmid, IPC_RMID, 0); if (fiasco_get_verbosity ()) - fprintf (stderr, "Sharing memory.\n"); + fprintf (stderr, "Sharing memory.\n"); } else { @@ -392,19 +392,19 @@ alloc_ximage (x11_info_t *xinfo, unsigned width, unsigned height) #endif /* USE_SHM */ xinfo->ximage = XCreateImage (xinfo->display, - DefaultVisual (xinfo->display, - xinfo->screen), - DefaultDepth (xinfo->display, - xinfo->screen), - ZPixmap, 0, &dummy, width, height, 8, 0); + DefaultVisual (xinfo->display, + xinfo->screen), + DefaultDepth (xinfo->display, + xinfo->screen), + ZPixmap, 0, &dummy, width, height, 8, 0); xinfo->pixels = calloc (width * height, - xinfo->ximage->depth <= 8 - ? sizeof (byte_t) - : (xinfo->ximage->depth <= 16 - ? sizeof (u_word_t) : sizeof (unsigned int))); + xinfo->ximage->depth <= 8 + ? sizeof (byte_t) + : (xinfo->ximage->depth <= 16 + ? sizeof (u_word_t) : sizeof (unsigned int))); if (!xinfo->pixels) - error ("Out of memory."); - + error ("Out of memory."); + #ifdef USE_SHM } diff --git a/converter/other/fiasco/display.h b/converter/other/fiasco/display.h index 8049456a..0f9c53dc 100644 --- a/converter/other/fiasco/display.h +++ b/converter/other/fiasco/display.h @@ -1,8 +1,8 @@ /* * display.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -27,10 +27,10 @@ typedef struct x11_info { Display *display; - int screen; /* default screen number */ - Window window; + int screen; /* default screen number */ + Window window; XImage *ximage; - GC gc; + GC gc; byte_t *pixels; } x11_info_t; @@ -40,7 +40,7 @@ void close_window (x11_info_t *xinfo); x11_info_t * open_window (const char *titlename, const char *iconname, - unsigned width, unsigned height); + unsigned width, unsigned height); void alloc_ximage (x11_info_t *xinfo, unsigned width, unsigned height); diff --git a/converter/other/fiasco/fiasco.h b/converter/other/fiasco/fiasco.h index 88f999fc..48226c47 100644 --- a/converter/other/fiasco/fiasco.h +++ b/converter/other/fiasco/fiasco.h @@ -1,8 +1,8 @@ /* - * fiasco.h + * fiasco.h + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner * @@ -46,7 +46,7 @@ __BEGIN_DECLS /**************************************************************************** - FIASCO data types + FIASCO data types ****************************************************************************/ /* @@ -56,9 +56,9 @@ __BEGIN_DECLS * FIASCO_ULTIMATE_VERBOSITY: Show debugging output */ typedef enum {FIASCO_NO_VERBOSITY, - FIASCO_SOME_VERBOSITY, - FIASCO_ULTIMATE_VERBOSITY} fiasco_verbosity_e; - + FIASCO_SOME_VERBOSITY, + FIASCO_ULTIMATE_VERBOSITY} fiasco_verbosity_e; + /* * Image tiling methods: * VARIANCE_ASC: Tiles are sorted by variance. @@ -71,9 +71,9 @@ typedef enum {FIASCO_NO_VERBOSITY, * in the upper left corner. */ typedef enum {FIASCO_TILING_SPIRAL_ASC, - FIASCO_TILING_SPIRAL_DSC, - FIASCO_TILING_VARIANCE_ASC, - FIASCO_TILING_VARIANCE_DSC} fiasco_tiling_e; + FIASCO_TILING_SPIRAL_DSC, + FIASCO_TILING_VARIANCE_ASC, + FIASCO_TILING_VARIANCE_DSC} fiasco_tiling_e; /* * Range of reduced precision format: @@ -83,29 +83,29 @@ typedef enum {FIASCO_TILING_SPIRAL_ASC, * FIASCO_RPF_RANGE_2_00: use interval [-2.00,2.00] */ typedef enum {FIASCO_RPF_RANGE_0_75, - FIASCO_RPF_RANGE_1_00, - FIASCO_RPF_RANGE_1_50, - FIASCO_RPF_RANGE_2_00} fiasco_rpf_range_e; + FIASCO_RPF_RANGE_1_00, + FIASCO_RPF_RANGE_1_50, + FIASCO_RPF_RANGE_2_00} fiasco_rpf_range_e; /* * Type of progress meter to be used during coding * FIASCO_PROGRESS_NONE: no output at all - * FIASCO_PROGRESS_BAR: RPM style progress bar using 50 hash marks ###### - * FIASCO_PROGRESS_PERCENT: percentage meter 50% + * FIASCO_PROGRESS_BAR: RPM style progress bar using 50 hash marks ###### + * FIASCO_PROGRESS_PERCENT: percentage meter 50% */ typedef enum {FIASCO_PROGRESS_NONE, - FIASCO_PROGRESS_BAR, - FIASCO_PROGRESS_PERCENT} fiasco_progress_e; + FIASCO_PROGRESS_BAR, + FIASCO_PROGRESS_PERCENT} fiasco_progress_e; /* * Class to encapsulate FIASCO images. */ typedef struct fiasco_image { - void (*delete) (struct fiasco_image *image); - unsigned (*get_width) (struct fiasco_image *image); - unsigned (*get_height) (struct fiasco_image *image); - int (*is_color) (struct fiasco_image *image); + void (*delete) (struct fiasco_image *image); + unsigned (*get_width) (struct fiasco_image *image); + unsigned (*get_height) (struct fiasco_image *image); + int (*is_color) (struct fiasco_image *image); void *private; } fiasco_image_t; @@ -114,17 +114,17 @@ typedef struct fiasco_image */ typedef struct fiasco_decoder { - int (*delete) (struct fiasco_decoder *decoder); - int (*write_frame) (struct fiasco_decoder *decoder, - const char *filename); - fiasco_image_t * (*get_frame) (struct fiasco_decoder *decoder); - unsigned (*get_length) (struct fiasco_decoder *decoder); - unsigned (*get_rate) (struct fiasco_decoder *decoder); - unsigned (*get_width) (struct fiasco_decoder *decoder); - unsigned (*get_height) (struct fiasco_decoder *decoder); - const char * (*get_title) (struct fiasco_decoder *decoder); - const char * (*get_comment) (struct fiasco_decoder *decoder); - int (*is_color) (struct fiasco_decoder *decoder); + int (*delete) (struct fiasco_decoder *decoder); + int (*write_frame) (struct fiasco_decoder *decoder, + const char *filename); + fiasco_image_t * (*get_frame) (struct fiasco_decoder *decoder); + unsigned (*get_length) (struct fiasco_decoder *decoder); + unsigned (*get_rate) (struct fiasco_decoder *decoder); + unsigned (*get_width) (struct fiasco_decoder *decoder); + unsigned (*get_height) (struct fiasco_decoder *decoder); + const char * (*get_title) (struct fiasco_decoder *decoder); + const char * (*get_comment) (struct fiasco_decoder *decoder); + int (*is_color) (struct fiasco_decoder *decoder); void *private; } fiasco_decoder_t; @@ -135,43 +135,43 @@ typedef struct fiasco_c_options { void (*delete) (struct fiasco_c_options *options); int (*set_tiling) (struct fiasco_c_options *options, - fiasco_tiling_e method, - unsigned exponent); + fiasco_tiling_e method, + unsigned exponent); int (*set_frame_pattern) (struct fiasco_c_options *options, - const char *pattern); + const char *pattern); int (*set_basisfile) (struct fiasco_c_options *options, - const char *filename); + const char *filename); int (*set_chroma_quality) (struct fiasco_c_options *options, - float quality_factor, - unsigned dictionary_size); + float quality_factor, + unsigned dictionary_size); int (*set_optimizations) (struct fiasco_c_options *options, - unsigned min_block_level, - unsigned max_block_level, - unsigned max_elements, - unsigned dictionary_size, - unsigned optimization_level); + unsigned min_block_level, + unsigned max_block_level, + unsigned max_elements, + unsigned dictionary_size, + unsigned optimization_level); int (*set_prediction) (struct fiasco_c_options *options, - int intra_prediction, - unsigned min_block_level, - unsigned max_block_level); + int intra_prediction, + unsigned min_block_level, + unsigned max_block_level); int (*set_video_param) (struct fiasco_c_options *options, - unsigned frames_per_second, - int half_pixel_prediction, - int cross_B_search, - int B_as_past_ref); + unsigned frames_per_second, + int half_pixel_prediction, + int cross_B_search, + int B_as_past_ref); int (*set_quantization) (struct fiasco_c_options *options, - unsigned mantissa, - fiasco_rpf_range_e range, - unsigned dc_mantissa, - fiasco_rpf_range_e dc_range); + unsigned mantissa, + fiasco_rpf_range_e range, + unsigned dc_mantissa, + fiasco_rpf_range_e dc_range); int (*set_progress_meter) (struct fiasco_c_options *options, - fiasco_progress_e type); + fiasco_progress_e type); int (*set_smoothing) (struct fiasco_c_options *options, - int smoothing); + int smoothing); int (*set_comment) (struct fiasco_c_options *options, - const char *comment); + const char *comment); int (*set_title) (struct fiasco_c_options *options, - const char *title); + const char *title); void *private; } fiasco_c_options_t; @@ -182,32 +182,32 @@ typedef struct fiasco_d_options { void (*delete) (struct fiasco_d_options *options); int (*set_smoothing) (struct fiasco_d_options *options, - int smoothing); + int smoothing); int (*set_magnification) (struct fiasco_d_options *options, - int level); + int level); int (*set_4_2_0_format) (struct fiasco_d_options *options, - int format); + int format); void *private; } fiasco_d_options_t; /* * Class to convert internal FIASCO image structure to a XImage structure. - * Method `renderer()' is used to convert internal image to XImage. - * Method `delete()' is used to delete and free internal image. + * Method `renderer()' is used to convert internal image to XImage. + * Method `delete()' is used to delete and free internal image. */ typedef struct fiasco_renderer { int (*render) (const struct fiasco_renderer *this, - unsigned char *data, - const fiasco_image_t *fiasco_image); + unsigned char *data, + const fiasco_image_t *fiasco_image); void (*delete) (struct fiasco_renderer *this); void *private; } fiasco_renderer_t; /**************************************************************************** - miscellaneous functions + miscellaneous functions ****************************************************************************/ - + /* Get last error message of FIASCO library */ const char *fiasco_get_error_message (void); @@ -218,19 +218,19 @@ void fiasco_set_verbosity (fiasco_verbosity_e level); fiasco_verbosity_e fiasco_get_verbosity (void); /**************************************************************************** - decoder functions + decoder functions ****************************************************************************/ /* Decode FIASCO image or sequence */ fiasco_decoder_t *fiasco_decoder_new (const char *filename, - const fiasco_d_options_t *options); + const fiasco_d_options_t *options); /* Flush and discard FIASCO decoder */ int fiasco_decoder_delete (fiasco_decoder_t *decoder); /* Decode next FIASCO frame and write to PNM image 'filename' */ int fiasco_decoder_write_frame (fiasco_decoder_t *decoder, - const char *filename); + const char *filename); /* Decode next FIASCO frame to FIASCO image structure */ fiasco_image_t *fiasco_decoder_get_frame (fiasco_decoder_t *decoder); @@ -259,7 +259,7 @@ const char * fiasco_decoder_get_comment (fiasco_decoder_t *decoder); /**************************************************************************** - image functions + image functions ****************************************************************************/ /* Create FIASCO image (from PNM image file) */ @@ -275,7 +275,7 @@ fiasco_image_new_stream(FILE * const ifP, int const format); /* Discard FIASCO image */ -void fiasco_image_delete (fiasco_image_t *image); +void fiasco_image_delete (fiasco_image_t *image); /* Get width of FIASCO image or sequence */ unsigned fiasco_image_get_width (fiasco_image_t *image); @@ -287,14 +287,14 @@ unsigned fiasco_image_get_height (fiasco_image_t *image); int fiasco_image_is_color (fiasco_image_t *image); /**************************************************************************** - renderer functions + renderer functions ****************************************************************************/ /* Constructor of FIASCO image structure to a XImage renderer */ fiasco_renderer_t * fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, - unsigned long blue_mask, unsigned bpp, - int double_resolution); + unsigned long blue_mask, unsigned bpp, + int double_resolution); /* Destructor of FIASCO image structure to a XImage renderer */ void @@ -303,21 +303,21 @@ fiasco_renderer_delete (fiasco_renderer_t *renderer); /* FIASCO image structure to a XImage renderer */ int fiasco_renderer_render (const fiasco_renderer_t *renderer, - unsigned char *ximage, - const fiasco_image_t *fiasco_image); + unsigned char *ximage, + const fiasco_image_t *fiasco_image); /**************************************************************************** - coder functions + coder functions ****************************************************************************/ /* Encode image or sequence by FIASCO */ int fiasco_coder (char const * const *inputname, - const char *outputname, - float quality, - const fiasco_c_options_t *options); + const char *outputname, + float quality, + const fiasco_c_options_t *options); /**************************************************************************** - coder options functions + coder options functions ****************************************************************************/ /* FIASCO additional options constructor */ @@ -328,25 +328,25 @@ void fiasco_c_options_delete (fiasco_c_options_t *options); /* Define `smoothing'-percentage along partitioning borders.*/ int fiasco_c_options_set_smoothing (fiasco_c_options_t *options, - int smoothing); + int smoothing); /* Set type of frame prediction for sequence of frames */ int fiasco_c_options_set_frame_pattern (fiasco_c_options_t *options, - const char *pattern); + const char *pattern); /* Set method and number of tiles for image tiling */ int fiasco_c_options_set_tiling (fiasco_c_options_t *options, - fiasco_tiling_e method, - unsigned exponent); + fiasco_tiling_e method, + unsigned exponent); /* Set FIASCO initial basis file */ int fiasco_c_options_set_basisfile (fiasco_c_options_t *options, - const char *filename); + const char *filename); /* Set quality and dictionary size of chroma compression */ int fiasco_c_options_set_chroma_quality (fiasco_c_options_t *options, - float quality_factor, - unsigned dictionary_size); + float quality_factor, + unsigned dictionary_size); /* * Since FIASCO internally works with binary trees, all functions @@ -354,62 +354,62 @@ int fiasco_c_options_set_chroma_quality (fiasco_c_options_t *options, * the corresponding binary tree than the traditional `width' and * `height' arguments. Refer to following table to convert these * values: - * + * * level | width | height * ------+-------+-------- - * 0 | 1 | 1 - * 1 | 1 | 2 - * 2 | 2 | 2 - * 3 | 2 | 4 - * 4 | 4 | 4 - * 5 | 4 | 8 - * 6 | 8 | 8 + * 0 | 1 | 1 + * 1 | 1 | 2 + * 2 | 2 | 2 + * 3 | 2 | 4 + * 4 | 4 | 4 + * 5 | 4 | 8 + * 6 | 8 | 8 * 7 | 8 | 16 * */ - + /* Set various optimization parameters. */ int fiasco_c_options_set_optimizations (fiasco_c_options_t *options, - unsigned min_block_level, - unsigned max_block_level, - unsigned max_elements, - unsigned dictionary_size, - unsigned optimization_level); + unsigned min_block_level, + unsigned max_block_level, + unsigned max_elements, + unsigned dictionary_size, + unsigned optimization_level); /* Set minimum and maximum size of image block prediction */ int fiasco_c_options_set_prediction (fiasco_c_options_t *options, - int intra_prediction, - unsigned min_block_level, - unsigned max_block_level); + int intra_prediction, + unsigned min_block_level, + unsigned max_block_level); /* Set various parameters used for video compensation */ int fiasco_c_options_set_video_param (fiasco_c_options_t *options, - unsigned frames_per_second, - int half_pixel_prediction, - int cross_B_search, - int B_as_past_ref); + unsigned frames_per_second, + int half_pixel_prediction, + int cross_B_search, + int B_as_past_ref); /* Set accuracy of coefficients quantization */ int fiasco_c_options_set_quantization (fiasco_c_options_t *options, - unsigned mantissa, - fiasco_rpf_range_e range, - unsigned dc_mantissa, - fiasco_rpf_range_e dc_range); + unsigned mantissa, + fiasco_rpf_range_e range, + unsigned dc_mantissa, + fiasco_rpf_range_e dc_range); /* Set type of progress meter */ int fiasco_c_options_set_progress_meter (fiasco_c_options_t *options, - fiasco_progress_e type); + fiasco_progress_e type); /* Set comment of FIASCO stream */ int fiasco_c_options_set_comment (fiasco_c_options_t *options, - const char *comment); + const char *comment); /* Set title of FIASCO stream */ int fiasco_c_options_set_title (fiasco_c_options_t *options, - const char *title); + const char *title); /**************************************************************************** - decoder options functions + decoder options functions ****************************************************************************/ /* FIASCO additional options constructor */ @@ -421,15 +421,15 @@ void fiasco_d_options_delete (fiasco_d_options_t *options); /* Define `smoothing'-percentage along partitioning borders.*/ int fiasco_d_options_set_smoothing (fiasco_d_options_t *options, - int smoothing); + int smoothing); /* Set magnification-'level' of decoded image */ int fiasco_d_options_set_magnification (fiasco_d_options_t *options, - int level); + int level); /* Set image format to 4:2:0 or 4:4:4 */ int fiasco_d_options_set_4_2_0_format (fiasco_d_options_t *options, - int format); + int format); __END_DECLS diff --git a/converter/other/fiasco/fiascotopnm.c b/converter/other/fiasco/fiascotopnm.c index e95e27fc..c97e201b 100644 --- a/converter/other/fiasco/fiascotopnm.c +++ b/converter/other/fiasco/fiascotopnm.c @@ -3,11 +3,11 @@ * * Written by: Ullrich Hafner * Michael Unger - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ - + /* * $Date: 2000/10/28 17:39:29 $ * $Author: hafner $ @@ -50,10 +50,10 @@ static x11_info_t *xinfo = NULL; /***************************************************************************** prototypes - + *****************************************************************************/ -static int +static int checkargs (int argc, char **argv, bool_t *double_resolution, bool_t *panel, int *fps, char **image_name, fiasco_d_options_t **options); static void @@ -75,10 +75,10 @@ show_stored_frames (unsigned char * const *frame_buffer, int last_frame, /***************************************************************************** public code - + *****************************************************************************/ -int +int main (int argc, char **argv) { char *image_name = NULL; /* output filename */ @@ -92,7 +92,7 @@ main (int argc, char **argv) last_arg = checkargs (argc, argv, &double_resolution, &panel, &fps, &image_name, &options); - + if (last_arg >= argc) video_decoder ("-", image_name, panel, double_resolution, fps, options); else @@ -106,7 +106,7 @@ main (int argc, char **argv) /***************************************************************************** private code - + *****************************************************************************/ static param_t params [] = @@ -133,7 +133,7 @@ static param_t params [] = {NULL, NULL, 0, 0, {0}, NULL, NULL } }; -static int +static int checkargs (int argc, char **argv, bool_t *double_resolution, bool_t *panel, int *fps, char **image_name, fiasco_d_options_t **options) /* @@ -180,21 +180,21 @@ checkargs (int argc, char **argv, bool_t *double_resolution, bool_t *panel, { int const n = *((int *) parameter_value (params, "smoothing")); - + if (!fiasco_d_options_set_smoothing (*options, MAX(-1, n))) error (fiasco_get_error_message ()); } { int const n = *((int *) parameter_value (params, "magnify")); - + if (!fiasco_d_options_set_magnification (*options, n)) error (fiasco_get_error_message ()); } - + { bool_t const n = *((bool_t *) parameter_value (params, "fast")); - + if (!fiasco_d_options_set_4_2_0_format (*options, n > 0 ? YES : NO)) error (fiasco_get_error_message ()); } @@ -211,7 +211,7 @@ video_decoder (const char *wfa_name, const char *image_name, bool_t panel, unsigned char **frame_buffer = NULL; binfo_t *binfo = NULL; /* buttons info */ #endif /* not X_DISPLAY_MISSING */ - + do { unsigned width, height, frames, n; @@ -220,23 +220,23 @@ video_decoder (const char *wfa_name, const char *image_name, bool_t panel, char *basename; /* basename of decoded frame */ char *suffix; /* suffix of decoded frame */ unsigned frame_time; - + if (!(decoder_state = fiasco_decoder_new (wfa_name, options))) error (fiasco_get_error_message ()); - - if (fps <= 0) /* then use value of FIASCO file */ + + if (fps <= 0) /* then use value of FIASCO file */ fps = fiasco_decoder_get_rate (decoder_state); frame_time = fps ? (1000 / fps) : (1000 / 25); if (!(width = fiasco_decoder_get_width (decoder_state))) error (fiasco_get_error_message ()); - + if (!(height = fiasco_decoder_get_height (decoder_state))) error (fiasco_get_error_message ()); if (!(frames = fiasco_decoder_get_length (decoder_state))) error (fiasco_get_error_message ()); - + get_output_template (image_name, wfa_name, fiasco_decoder_is_color (decoder_state), &basename, &suffix); @@ -249,9 +249,9 @@ video_decoder (const char *wfa_name, const char *image_name, bool_t panel, for (n = 0; n < frames; n++) { clock_t fps_timer; /* frames per second timer struct */ - + prg_timer (&fps_timer, START); - + if (image_name) /* just write frame to disk */ { if (frames == 1) /* just one image */ @@ -277,23 +277,23 @@ video_decoder (const char *wfa_name, const char *image_name, bool_t panel, else { fiasco_image_t *frame; - + if (!(frame = fiasco_decoder_get_frame (decoder_state))) error (fiasco_get_error_message ()); - + if (frames == 1) panel = NO; if (xinfo == NULL) /* initialize X11 window */ { - const char * const title = + const char * const title = fiasco_decoder_get_title (decoder_state); char titlename [MAXSTRLEN]; - + sprintf (titlename, "dfiasco " VERSION ": %s", strlen (title) > 0 ? title : wfa_name); - xinfo = + xinfo = open_window (titlename, "dfiasco", (width << (double_resolution ? 1 : 0)), (height << (double_resolution ? 1 : 0)) @@ -302,7 +302,7 @@ video_decoder (const char *wfa_name, const char *image_name, bool_t panel, height << (double_resolution ? 1 : 0)); if (panel) /* initialize button panel */ binfo = init_buttons (xinfo, n, frames, 30, 10); - renderer = + renderer = fiasco_renderer_new (xinfo->ximage->red_mask, xinfo->ximage->green_mask, xinfo->ximage->blue_mask, @@ -313,7 +313,7 @@ video_decoder (const char *wfa_name, const char *image_name, bool_t panel, } renderer->render (renderer, xinfo->pixels, frame); frame->delete (frame); - + if (frame_buffer != NULL) /* store next frame */ { size_t size = (width << (double_resolution ? 1 : 0)) @@ -343,17 +343,17 @@ video_decoder (const char *wfa_name, const char *image_name, bool_t panel, else if (panel) { check_events (xinfo, binfo, n, frames); - if (binfo->pressed [QUIT_BUTTON]) + if (binfo->pressed [QUIT_BUTTON]) /* start from beginning */ break; - if (binfo->pressed [STOP_BUTTON]) + if (binfo->pressed [STOP_BUTTON]) /* start from beginning */ n = frames; - + if (binfo->pressed [RECORD_BUTTON] && frame_buffer == NULL) { n = frames; - frame_buffer = + frame_buffer = calloc (frames, sizeof (unsigned char *)); if (!frame_buffer) error ("Out of memory."); @@ -364,17 +364,17 @@ video_decoder (const char *wfa_name, const char *image_name, bool_t panel, } #else if (frame_time) {/* defeat compiler warning */} -#endif /* not X_DISPLAY_MISSING */ +#endif /* not X_DISPLAY_MISSING */ } free (filename); - + fiasco_decoder_delete (decoder_state); } while (panel #ifndef X_DISPLAY_MISSING && !binfo->pressed [QUIT_BUTTON] #endif /* not X_DISPLAY_MISSING */ - + ); #ifndef X_DISPLAY_MISSING @@ -408,7 +408,7 @@ get_output_template (const char *image_name, const char *wfa_name, */ { if (!wfa_name || streq (wfa_name, "-")) - wfa_name = "stdin"; + wfa_name = "stdin"; /* * Generate filename template */ @@ -422,7 +422,7 @@ get_output_template (const char *image_name, const char *wfa_name, *basename = strdup (image_name); *suffix = strrchr (*basename, '.'); } - + if (*suffix) /* found name 'basename.suffix' */ { **suffix = 0; /* remove dot */ @@ -450,13 +450,13 @@ show_stored_frames (unsigned char * const *frame_buffer, int last_frame, */ { int n = last_frame; /* frame number */ - + while (1) { clock_t fps_timer; /* frames per second timer struct */ - + prg_timer (&fps_timer, START); - + display_image (0, 0, xinfo); check_events (xinfo, binfo, n, last_frame + 1); diff --git a/converter/other/fiasco/getopt.c b/converter/other/fiasco/getopt.c index 2f45c7cc..44fd03e6 100644 --- a/converter/other/fiasco/getopt.c +++ b/converter/other/fiasco/getopt.c @@ -66,12 +66,12 @@ /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ +#ifdef __GNU_LIBRARY__ /* Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting prototypes for getopt. */ #include <stdlib.h> #include <unistd.h> -#endif /* GNU C library. */ +#endif /* GNU C library. */ #if MSVCRT #include <windows.h> @@ -83,9 +83,9 @@ When compiling libc, the _ macro is predefined. */ #ifdef HAVE_LIBINTL_H # include <libintl.h> -# define _(msgid) gettext (msgid) +# define _(msgid) gettext (msgid) #else -# define _(msgid) (msgid) +# define _(msgid) (msgid) #endif #endif @@ -191,13 +191,13 @@ static enum /* Value of POSIXLY_CORRECT environment variable. */ static char *posixly_correct; -#ifdef __GNU_LIBRARY__ +#ifdef __GNU_LIBRARY__ /* We want to avoid inclusion of string.h with non-GNU libraries because there are many ways it can cause trouble. On some systems, it contains special magic macros that don't work in GCC. */ #include <string.h> -#define my_index strchr +#define my_index strchr #else /* Avoid depending on library functions or files @@ -213,7 +213,7 @@ my_index (str, chr) while (*str) { if (*str == chr) - return (char *) str; + return (char *) str; str++; } return 0; @@ -297,37 +297,37 @@ exchange (argv) while (top > middle && middle > bottom) { if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } + { + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + } + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } + { + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + } + /* Exclude the moved top segment from further swapping. */ + bottom += len; + } } /* Update records for the slots the non-options now occupy. */ @@ -379,16 +379,16 @@ _getopt_initialize (argc, argv, optstring) && argc == original_argc && argv == original_argv) { /* Bash 2.0 puts a special variable in the environment for each - command it runs, specifying which ARGV elements are the results of - file name wildcard expansion and therefore should not be - considered as options. */ + command it runs, specifying which ARGV elements are the results of + file name wildcard expansion and therefore should not be + considered as options. */ char var[100]; sprintf (var, "_%d_GNU_nonoption_argv_flags_", getpid ()); nonoption_flags = getenv (var); if (nonoption_flags == NULL) - nonoption_flags_len = 0; + nonoption_flags_len = 0; else - nonoption_flags_len = strlen (nonoption_flags); + nonoption_flags_len = strlen (nonoption_flags); } else nonoption_flags_len = 0; @@ -467,7 +467,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) if (!__getopt_initialized || optind == 0) { optstring = _getopt_initialize (argc, argv, optstring); - optind = 1; /* Don't scan ARGV[0], the program name. */ + optind = 1; /* Don't scan ARGV[0], the program name. */ __getopt_initialized = 1; } @@ -476,9 +476,9 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) from the shell indicating it is not an option. The later information is only used when the used in the GNU libc. */ #ifdef _LIBC -#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ - || (optind < nonoption_flags_len \ - && nonoption_flags[optind] == '1')) +#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ + || (optind < nonoption_flags_len \ + && nonoption_flags[optind] == '1')) #else #define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') #endif @@ -488,76 +488,76 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) /* Advance to the next ARGV-element. */ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been - moved back by the user (who may also have changed the arguments). */ + moved back by the user (who may also have changed the arguments). */ if (last_nonopt > optind) - last_nonopt = optind; + last_nonopt = optind; if (first_nonopt > optind) - first_nonopt = optind; + first_nonopt = optind; if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - exchange them so that the options come first. */ + { + /* If we have just processed some options following some non-options, + exchange them so that the options come first. */ - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (last_nonopt != optind) - first_nonopt = optind; + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (last_nonopt != optind) + first_nonopt = optind; - /* Skip any additional non-options - and extend the range of non-options previously skipped. */ + /* Skip any additional non-options + and extend the range of non-options previously skipped. */ - while (optind < argc && NONOPTION_P) - optind++; - last_nonopt = optind; - } + while (optind < argc && NONOPTION_P) + optind++; + last_nonopt = optind; + } /* The special ARGV-element `--' means premature end of options. - Skip it like a null option, - then exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ + Skip it like a null option, + then exchange with previous non-options as if it were an option, + then skip everything else like a non-option. */ if (optind != argc && !strcmp (argv[optind], "--")) - { - optind++; + { + optind++; - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = optind; - last_nonopt = argc; + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (first_nonopt == last_nonopt) + first_nonopt = optind; + last_nonopt = argc; - optind = argc; - } + optind = argc; + } /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ + and back over any non-options that we skipped and permuted. */ if (optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - optind = first_nonopt; - return -1; - } + { + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return -1; + } /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ + either stop the scan or describe it to the caller and pass it by. */ if (NONOPTION_P) - { - if (ordering == REQUIRE_ORDER) - return -1; - optarg = argv[optind++]; - return 1; - } + { + if (ordering == REQUIRE_ORDER) + return -1; + optarg = argv[optind++]; + return 1; + } /* We have found another option-ARGV-element. - Skip the initial punctuation. */ + Skip the initial punctuation. */ nextchar = (argv[optind] + 1 - + (longopts != NULL && argv[optind][1] == '-')); + + (longopts != NULL && argv[optind][1] == '-')); } /* Decode the current option-ARGV-element. */ @@ -577,7 +577,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) if (longopts != NULL && (argv[optind][1] == '-' - || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) + || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) { char *nameend; const struct option *p; @@ -588,124 +588,124 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) int option_index; for (nameend = nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; + /* Do nothing. */ ; /* Test all long options for either exact match - or abbreviated matches. */ + or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) - == (unsigned int) strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((unsigned int) (nameend - nextchar) + == (unsigned int) strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second or later nonexact match found. */ + ambig = 1; + } if (ambig && !exact) - { - if (opterr) - fprintf (stderr, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - optopt = 0; - return '?'; - } + { + if (opterr) + fprintf (stderr, _("%s: option `%s' is ambiguous\n"), + argv[0], argv[optind]); + nextchar += strlen (nextchar); + optind++; + optopt = 0; + return '?'; + } if (pfound != NULL) - { - option_index = indfound; - optind++; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = nameend + 1; - else - { + { + option_index = indfound; + optind++; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else + { if (opterr) { - if (argv[optind - 1][1] == '-') - /* --option */ - fprintf (stderr, - _("%s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - _("%s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[optind - 1][0], pfound->name); + if (argv[optind - 1][1] == '-') + /* --option */ + fprintf (stderr, + _("%s: option `--%s' doesn't allow an argument\n"), + argv[0], pfound->name); + else + /* +option or -option */ + fprintf (stderr, + _("%s: option `%c%s' doesn't allow an argument\n"), + argv[0], argv[optind - 1][0], pfound->name); } - nextchar += strlen (nextchar); - - optopt = pfound->val; - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (opterr) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } + nextchar += strlen (nextchar); + + optopt = pfound->val; + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (opterr) + fprintf (stderr, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]); + nextchar += strlen (nextchar); + optopt = pfound->val; + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ if (!long_only || argv[optind][1] == '-' - || my_index (optstring, *nextchar) == NULL) - { - if (opterr) - { - if (argv[optind][1] == '-') - /* --option */ - fprintf (stderr, _("%s: unrecognized option `--%s'\n"), - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), - argv[0], argv[optind][0], nextchar); - } - nextchar = (char *) ""; - optind++; - optopt = 0; - return '?'; - } + || my_index (optstring, *nextchar) == NULL) + { + if (opterr) + { + if (argv[optind][1] == '-') + /* --option */ + fprintf (stderr, _("%s: unrecognized option `--%s'\n"), + argv[0], nextchar); + else + /* +option or -option */ + fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), + argv[0], argv[optind][0], nextchar); + } + nextchar = (char *) ""; + optind++; + optopt = 0; + return '?'; + } } /* Look at and handle the next short option-character. */ @@ -720,188 +720,188 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) if (temp == NULL || c == ':') { - if (opterr) - { - if (posixly_correct) - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: illegal option -- %c\n"), - argv[0], c); - else - fprintf (stderr, _("%s: invalid option -- %c\n"), - argv[0], c); - } - optopt = c; - return '?'; + if (opterr) + { + if (posixly_correct) + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, _("%s: illegal option -- %c\n"), + argv[0], c); + else + fprintf (stderr, _("%s: invalid option -- %c\n"), + argv[0], c); + } + optopt = c; + return '?'; } /* Convenience. Treat POSIX -W foo same as long option --foo */ if (temp[0] == 'W' && temp[1] == ';') { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = 0; - int option_index; - - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (opterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - return c; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - - /* optarg is now the argument, see if it's in the - table of longopts. */ - - for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) - { - if (opterr) - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - return '?'; - } - if (pfound != NULL) - { - option_index = indfound; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = nameend + 1; - else - { - if (opterr) - fprintf (stderr, _("\ + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = 0; + int option_index; + + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (opterr) + { + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, _("%s: option requires an argument -- %c\n"), + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + return c; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + + /* optarg is now the argument, see if it's in the + table of longopts. */ + + for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((unsigned int) (nameend - nextchar) == strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second or later nonexact match found. */ + ambig = 1; + } + if (ambig && !exact) + { + if (opterr) + fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), + argv[0], argv[optind]); + nextchar += strlen (nextchar); + optind++; + return '?'; + } + if (pfound != NULL) + { + option_index = indfound; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else + { + if (opterr) + fprintf (stderr, _("\ %s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name); - - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (opterr) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - nextchar = NULL; - return 'W'; /* Let the application handle it. */ + argv[0], pfound->name); + + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (opterr) + fprintf (stderr, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]); + nextchar += strlen (nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + nextchar = NULL; + return 'W'; /* Let the application handle it. */ } if (temp[1] == ':') { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - optarg = nextchar; - optind++; - } - else - optarg = NULL; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (opterr) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, - _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - nextchar = NULL; - } + if (temp[2] == ':') + { + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + optarg = nextchar; + optind++; + } + else + optarg = NULL; + nextchar = NULL; + } + else + { + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (opterr) + { + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, + _("%s: option requires an argument -- %c\n"), + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } } return c; } @@ -914,12 +914,12 @@ getopt (argc, argv, optstring) const char *optstring; { return _getopt_internal (argc, argv, optstring, - (const struct option *) 0, - (int *) 0, - 0); + (const struct option *) 0, + (int *) 0, + 0); } -#endif /* Not ELIDE_CODE. */ +#endif /* Not ELIDE_CODE. */ #ifdef TEST @@ -940,51 +940,51 @@ main (argc, argv) c = getopt (argc, argv, "abc:d:0123456789"); if (c == -1) - break; + break; switch (c) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } } if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) - printf ("%s ", argv[optind++]); + printf ("%s ", argv[optind++]); printf ("\n"); } diff --git a/converter/other/fiasco/getopt.h b/converter/other/fiasco/getopt.h index 9acca708..3c735e3d 100644 --- a/converter/other/fiasco/getopt.h +++ b/converter/other/fiasco/getopt.h @@ -22,7 +22,7 @@ #ifndef _GETOPT_H #define _GETOPT_H 1 -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif @@ -63,9 +63,9 @@ extern int optopt; zero. The field `has_arg' is: - no_argument (or 0) if the option does not take an argument, - required_argument (or 1) if the option requires an argument, - optional_argument (or 2) if the option takes an optional argument. + no_argument (or 0) if the option does not take an argument, + required_argument (or 1) if the option requires an argument, + optional_argument (or 2) if the option takes an optional argument. If the field `flag' is not NULL, it points to a variable that is set to the value given in the field `val' when the option is found, but @@ -90,9 +90,9 @@ struct option /* Names for the values of the `has_arg' field of `struct option'. */ -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 #if defined (__STDC__) && __STDC__ #ifdef __GNU_LIBRARY__ @@ -104,16 +104,16 @@ extern int getopt (int argc, char *const *argv, const char *shortopts); extern int getopt (); #endif /* __GNU_LIBRARY__ */ extern int getopt_long (int argc, char *const *argv, const char *shortopts, - const struct option *longopts, int *longind); + const struct option *longopts, int *longind); extern int getopt_long_only (int argc, char *const *argv, - const char *shortopts, - const struct option *longopts, int *longind); + const char *shortopts, + const struct option *longopts, int *longind); /* Internal only. Users should not call this directly. */ extern int _getopt_internal (int argc, char *const *argv, - const char *shortopts, - const struct option *longopts, int *longind, - int long_only); + const char *shortopts, + const struct option *longopts, int *longind, + int long_only); #else /* not __STDC__ */ extern int getopt (); extern int getopt_long (); @@ -122,7 +122,7 @@ extern int getopt_long_only (); extern int _getopt_internal (); #endif /* __STDC__ */ -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/converter/other/fiasco/getopt1.c b/converter/other/fiasco/getopt1.c index 8347bb13..4ed64b8b 100644 --- a/converter/other/fiasco/getopt1.c +++ b/converter/other/fiasco/getopt1.c @@ -60,7 +60,7 @@ #include <stdlib.h> #endif -#ifndef NULL +#ifndef NULL #define NULL 0 #endif @@ -92,7 +92,7 @@ getopt_long_only (argc, argv, options, long_options, opt_index) } -#endif /* Not ELIDE_CODE. */ +#endif /* Not ELIDE_CODE. */ #ifdef TEST @@ -112,74 +112,74 @@ main (argc, argv) int option_index = 0; static struct option long_options[] = { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} + {"add", 1, 0, 0}, + {"append", 0, 0, 0}, + {"delete", 1, 0, 0}, + {"verbose", 0, 0, 0}, + {"create", 0, 0, 0}, + {"file", 1, 0, 0}, + {0, 0, 0, 0} }; c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); + long_options, &option_index); if (c == -1) - break; + break; switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } + { + case 0: + printf ("option %s", long_options[option_index].name); + if (optarg) + printf (" with arg %s", optarg); + printf ("\n"); + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value `%s'\n", optarg); + break; + + case 'd': + printf ("option d with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } } if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) - printf ("%s ", argv[optind++]); + printf ("%s ", argv[optind++]); printf ("\n"); } diff --git a/converter/other/fiasco/input/basis.c b/converter/other/fiasco/input/basis.c index e5ced0d0..4be7f4ed 100644 --- a/converter/other/fiasco/input/basis.c +++ b/converter/other/fiasco/input/basis.c @@ -1,7 +1,7 @@ /* - * basis.c: WFA initial basis files + * basis.c: WFA initial basis files * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -43,7 +43,7 @@ typedef struct /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -58,7 +58,7 @@ static basis_file_t const basis_files[] = { /***************************************************************************** - public code + public code *****************************************************************************/ @@ -70,69 +70,69 @@ get_linked_basis (const char *basis_name, wfa_t *wfa) * according to the stored data, otherwise print a warning message. * * Return value: - * true on success, false if basis is not available yet. + * true on success, false if basis is not available yet. * * Side effects: - * 'wfa' struct is filled on success. + * 'wfa' struct is filled on success. */ { - bool_t success = NO; /* indicates if basis is found */ - unsigned n; /* counter */ - basis_values_t bv; /* basis values */ + bool_t success = NO; /* indicates if basis is found */ + unsigned n; /* counter */ + basis_values_t bv; /* basis values */ for (n = 0; basis_files [n].filename != NULL; n++) - if (streq (basis_files [n].filename, basis_name)) /* basis is stored */ + if (streq (basis_files [n].filename, basis_name)) /* basis is stored */ { - unsigned state, edge; - - (*basis_files [n].function) (&bv); /* initialize local variables */ - /* - * Generate WFA - */ - wfa->basis_states = wfa->states = bv.states + 1; - wfa->domain_type[0] = USE_DOMAIN_MASK; - wfa->final_distribution[0] = 128; - append_edge (0, 0, 1.0, 0, wfa); - append_edge (0, 0, 1.0, 1, wfa); - for (state = 1; state < wfa->basis_states; state++) - { - wfa->final_distribution [state] = bv.final [state - 1]; - wfa->domain_type [state] = bv.use_domain [state - 1] - ? USE_DOMAIN_MASK - : AUXILIARY_MASK; - } - for (edge = 0; isedge (bv.transitions [edge][0]); edge++) - append_edge (bv.transitions [edge][0], bv.transitions [edge][1], - bv.transitions [edge][2], bv.transitions [edge][3], - wfa); - - success = YES; - break; + unsigned state, edge; + + (*basis_files [n].function) (&bv); /* initialize local variables */ + /* + * Generate WFA + */ + wfa->basis_states = wfa->states = bv.states + 1; + wfa->domain_type[0] = USE_DOMAIN_MASK; + wfa->final_distribution[0] = 128; + append_edge (0, 0, 1.0, 0, wfa); + append_edge (0, 0, 1.0, 1, wfa); + for (state = 1; state < wfa->basis_states; state++) + { + wfa->final_distribution [state] = bv.final [state - 1]; + wfa->domain_type [state] = bv.use_domain [state - 1] + ? USE_DOMAIN_MASK + : AUXILIARY_MASK; + } + for (edge = 0; isedge (bv.transitions [edge][0]); edge++) + append_edge (bv.transitions [edge][0], bv.transitions [edge][1], + bv.transitions [edge][2], bv.transitions [edge][3], + wfa); + + success = YES; + break; } if (!success) warning ("WFA initial basis '%s' isn't linked with the executable yet." - "\nLoading basis from disk instead.", basis_name); + "\nLoading basis from disk instead.", basis_name); return success; } /***************************************************************************** - private code + private code *****************************************************************************/ /***************************************************************************** - basis "small.wfa" + basis "small.wfa" *****************************************************************************/ -static unsigned states_small = 2; -static bool_t use_domain_small[] = {YES, YES}; -static real_t final_small[] = {64, 64}; -static real_t transitions_small[][4] = {{1, 2, 0.5, 0}, {1, 2, 0.5, 1}, - {1, 0, 0.5, 1}, {2, 1, 1.0, 0}, - {2, 1, 1.0, 1}, {-1, 0, 0, 0}}; +static unsigned states_small = 2; +static bool_t use_domain_small[] = {YES, YES}; +static real_t final_small[] = {64, 64}; +static real_t transitions_small[][4] = {{1, 2, 0.5, 0}, {1, 2, 0.5, 1}, + {1, 0, 0.5, 1}, {2, 1, 1.0, 0}, + {2, 1, 1.0, 1}, {-1, 0, 0, 0}}; static void small_init (basis_values_t *bv) { diff --git a/converter/other/fiasco/input/basis.h b/converter/other/fiasco/input/basis.h index e2242198..d6d2f8b3 100644 --- a/converter/other/fiasco/input/basis.h +++ b/converter/other/fiasco/input/basis.h @@ -1,8 +1,8 @@ /* * basis.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/input/matrices.c b/converter/other/fiasco/input/matrices.c index d20a27eb..f59b5a30 100644 --- a/converter/other/fiasco/input/matrices.c +++ b/converter/other/fiasco/input/matrices.c @@ -1,7 +1,7 @@ /* - * matrices.c: Input of transition matrices + * matrices.c: Input of transition matrices * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -28,12 +28,12 @@ #include "matrices.h" #if STDC_HEADERS -# include <stdlib.h> +# include <stdlib.h> #endif /* not STDC_HEADERS */ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -48,7 +48,7 @@ compute_y_state (int state, int y_state, wfa_t *wfa); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -58,16 +58,16 @@ read_matrices (wfa_t *wfa, bitfile_t *input) * Read transitions of WFA given from the stream 'input'. * * Return value: - * number of edges + * number of edges * * Side effects: - * 'wfa->into' is filled with decoded values + * 'wfa->into' is filled with decoded values */ { - unsigned total; /* total number of edges in the WFA */ + unsigned total; /* total number of edges in the WFA */ unsigned root_state = wfa->wfainfo->color - ? wfa->tree [wfa->tree [wfa->root_state][0]][0] - : wfa->root_state; + ? wfa->tree [wfa->tree [wfa->root_state][0]][0] + : wfa->root_state; total = column_0_decoding (wfa, root_state, input); total += delta_decoding (wfa, root_state, input); @@ -79,7 +79,7 @@ read_matrices (wfa_t *wfa, bitfile_t *input) /***************************************************************************** - private code + private code *****************************************************************************/ @@ -91,34 +91,34 @@ delta_decoding (wfa_t *wfa, unsigned last_domain, bitfile_t *input) * 'last_domain' is the maximum state number used as domain image. * * Return value: - * number of non-zero matrix elements (WFA edges) + * number of non-zero matrix elements (WFA edges) * * Side effects: - * 'wfa->into' is filled with decoded values + * 'wfa->into' is filled with decoded values */ { - range_sort_t rs; /* ranges are sorted as in the coder */ - unsigned max_domain; /* dummy used for recursion */ - unsigned range; - unsigned count [MAXEDGES + 1]; - unsigned state, label; - unsigned *n_edges; /* number of elements per row */ - unsigned total = 0; /* total number of decoded edges */ + range_sort_t rs; /* ranges are sorted as in the coder */ + unsigned max_domain; /* dummy used for recursion */ + unsigned range; + unsigned count [MAXEDGES + 1]; + unsigned state, label; + unsigned *n_edges; /* number of elements per row */ + unsigned total = 0; /* total number of decoded edges */ /* * Generate a list of range blocks. * The order is the same as in the coder. */ rs.range_state = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (u_word_t)); + sizeof (u_word_t)); rs.range_label = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (byte_t)); + sizeof (byte_t)); rs.range_max_domain = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (u_word_t)); + sizeof (u_word_t)); rs.range_subdivided = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (bool_t)); - rs.range_no = 0; - max_domain = wfa->basis_states - 1; + sizeof (bool_t)); + rs.range_no = 0; + max_domain = wfa->basis_states - 1; sort_ranges (last_domain, &max_domain, &rs, wfa); /* @@ -127,42 +127,42 @@ delta_decoding (wfa_t *wfa, unsigned last_domain, bitfile_t *input) { arith_t *decoder; model_t *elements; - unsigned max_edges = read_rice_code (3, input); + unsigned max_edges = read_rice_code (3, input); /* * Get the probability array of the number of edges distribution * and allocate the corresponding model. */ { - unsigned edge; + unsigned edge; - for (edge = 0; edge <= max_edges; edge++) - count [edge] = read_rice_code ((int) log2 (last_domain) - 2, - input); - elements = alloc_model (max_edges + 1, 0, 0, count); + for (edge = 0; edge <= max_edges; edge++) + count [edge] = read_rice_code ((int) log2 (last_domain) - 2, + input); + elements = alloc_model (max_edges + 1, 0, 0, count); } /* * Get number of elements per matrix row */ { - unsigned row; - - n_edges = Calloc (wfa->states, sizeof (unsigned)); - decoder = alloc_decoder (input); - for (row = range = 0; range < rs.range_no; range++) - if (!rs.range_subdivided [range]) - { - state = rs.range_state [range]; - label = rs.range_label [range]; - - n_edges [row++] - = decode_symbol (decoder, elements) - - (isedge (wfa->into [state][label][0]) ? 1 : 0); - } - - free_decoder (decoder); - free_model (elements); + unsigned row; + + n_edges = Calloc (wfa->states, sizeof (unsigned)); + decoder = alloc_decoder (input); + for (row = range = 0; range < rs.range_no; range++) + if (!rs.range_subdivided [range]) + { + state = rs.range_state [range]; + label = rs.range_label [range]; + + n_edges [row++] + = decode_symbol (decoder, elements) + - (isedge (wfa->into [state][label][0]) ? 1 : 0); + } + + free_decoder (decoder); + free_model (elements); } } @@ -175,8 +175,8 @@ delta_decoding (wfa_t *wfa, unsigned last_domain, bitfile_t *input) u_word_t *mapping_coder1 = Calloc (wfa->states, sizeof (word_t)); u_word_t *mapping2 = Calloc (wfa->states, sizeof (word_t)); u_word_t *mapping_coder2 = Calloc (wfa->states, sizeof (word_t)); - bool_t use_normal_domains = get_bit (input); - bool_t use_delta_domains = get_bit (input); + bool_t use_normal_domains = get_bit (input); + bool_t use_delta_domains = get_bit (input); /* * Generate array of states which are admitted domains. @@ -187,63 +187,63 @@ delta_decoding (wfa_t *wfa, unsigned last_domain, bitfile_t *input) * coding the motion compensated prediction error */ { - unsigned n1, n2, state; - - for (n1 = n2 = state = 0; state < wfa->states; state++) - { - mapping1 [n1] = state; - mapping_coder1 [state] = n1; - if (usedomain (state, wfa) - && (state < wfa->basis_states - || use_delta_domains || !wfa->delta_state [state])) - n1++; - - mapping2 [n2] = state; - mapping_coder2 [state] = n2; - if (usedomain (state, wfa) - && (state < wfa->basis_states || use_normal_domains - || wfa->delta_state [state])) - n2++; - } + unsigned n1, n2, state; + + for (n1 = n2 = state = 0; state < wfa->states; state++) + { + mapping1 [n1] = state; + mapping_coder1 [state] = n1; + if (usedomain (state, wfa) + && (state < wfa->basis_states + || use_delta_domains || !wfa->delta_state [state])) + n1++; + + mapping2 [n2] = state; + mapping_coder2 [state] = n2; + if (usedomain (state, wfa) + && (state < wfa->basis_states || use_normal_domains + || wfa->delta_state [state])) + n2++; + } } for (row = 0, range = 0; range < rs.range_no; range++) - if (!rs.range_subdivided [range]) - { - u_word_t *mapping; - u_word_t *mapping_coder; - unsigned max_value; - unsigned edge; - unsigned state = rs.range_state [range]; - unsigned label = rs.range_label [range]; - unsigned last = 1; - - if (wfa->delta_state [state] || - wfa->mv_tree [state][label].type != NONE) - { - mapping = mapping2; - mapping_coder = mapping_coder2; - } - else - { - mapping = mapping1; - mapping_coder = mapping_coder1; - } - max_value = mapping_coder [rs.range_max_domain [range]]; - for (edge = n_edges [row]; edge; edge--) - { - unsigned domain; - - if (max_value - last) - domain = read_bin_code (max_value - last, input) + last; - else - domain = max_value; - append_edge (state, mapping [domain], -1, label, wfa); - last = domain + 1; - total++; - } - row++; - } + if (!rs.range_subdivided [range]) + { + u_word_t *mapping; + u_word_t *mapping_coder; + unsigned max_value; + unsigned edge; + unsigned state = rs.range_state [range]; + unsigned label = rs.range_label [range]; + unsigned last = 1; + + if (wfa->delta_state [state] || + wfa->mv_tree [state][label].type != NONE) + { + mapping = mapping2; + mapping_coder = mapping_coder2; + } + else + { + mapping = mapping1; + mapping_coder = mapping_coder1; + } + max_value = mapping_coder [rs.range_max_domain [range]]; + for (edge = n_edges [row]; edge; edge--) + { + unsigned domain; + + if (max_value - last) + domain = read_bin_code (max_value - last, input) + last; + else + domain = max_value; + append_edge (state, mapping [domain], -1, label, wfa); + last = domain + 1; + total++; + } + row++; + } Free (mapping1); Free (mapping_coder1); Free (mapping2); @@ -267,23 +267,23 @@ column_0_decoding (wfa_t *wfa, unsigned last_row, bitfile_t *input) * All rows from 'wfa->basis_states' up to 'last_row' are decoded. * * Return value: - * number of non-zero matrix elements (WFA edges) + * number of non-zero matrix elements (WFA edges) * * Side effects: - * 'wfa->into' is filled with decoded values + * 'wfa->into' is filled with decoded values */ { - unsigned row; /* current matrix row */ - unsigned total = 0; /* total number of edges in col 0 */ - unsigned *prob_ptr; /* pointer to current probability */ - unsigned *last; /* pointer to minimum probability */ - unsigned *first; /* pointer to maximum probability */ - unsigned *new_prob_ptr; /* ptr to probability of last domain */ - unsigned *prob; /* probability array */ - u_word_t high; /* Start of the current code range */ - u_word_t low; /* End of the current code range */ - u_word_t code; /* The present input code value */ - word_t *is_leaf; /* pointer to the tree structure */ + unsigned row; /* current matrix row */ + unsigned total = 0; /* total number of edges in col 0 */ + unsigned *prob_ptr; /* pointer to current probability */ + unsigned *last; /* pointer to minimum probability */ + unsigned *first; /* pointer to maximum probability */ + unsigned *new_prob_ptr; /* ptr to probability of last domain */ + unsigned *prob; /* probability array */ + u_word_t high; /* Start of the current code range */ + u_word_t low; /* End of the current code range */ + u_word_t code; /* The present input code value */ + word_t *is_leaf; /* pointer to the tree structure */ /* * Compute the asymmetric probability array @@ -292,14 +292,14 @@ column_0_decoding (wfa_t *wfa, unsigned last_row, bitfile_t *input) */ { unsigned n; - unsigned index; /* probability index */ - unsigned exp; /* current exponent */ + unsigned index; /* probability index */ + unsigned exp; /* current exponent */ prob = Calloc (1 << (MAX_PROB + 1), sizeof (unsigned)); for (index = 0, n = MIN_PROB; n <= MAX_PROB; n++) - for (exp = 0; exp < 1U << n; exp++, index++) - prob [index] = n; + for (exp = 0; exp < 1U << n; exp++, index++) + prob [index] = n; } first = prob_ptr = new_prob_ptr = prob; @@ -307,8 +307,8 @@ column_0_decoding (wfa_t *wfa, unsigned last_row, bitfile_t *input) is_leaf = wfa->tree [wfa->basis_states]; /* use pointer arithmetics ... */ - high = HIGH; /* 1.0 */ - low = LOW; /* 0.0 */ + high = HIGH; /* 1.0 */ + low = LOW; /* 0.0 */ code = get_bits (input, 16); /* @@ -324,73 +324,73 @@ column_0_decoding (wfa_t *wfa, unsigned last_row, bitfile_t *input) */ for (row = wfa->basis_states; row <= last_row; row++) { - unsigned count; /* value in the current interval */ + unsigned count; /* value in the current interval */ /* * Read label 0 element */ - if (isrange (*is_leaf++)) /* valid matrix index */ + if (isrange (*is_leaf++)) /* valid matrix index */ { - count = high - ((high - low) >> *prob_ptr); - if (code < count) - { - if (prob_ptr < last) /* model update */ - prob_ptr++; - /* - * Decode the MPS '0' - */ - high = count - 1; - - RESCALE_INPUT_INTERVAL; - } - else - { - prob_ptr = ((prob_ptr - first) >> 1) + first; /* model update */ - /* - * Decode the LPS '1' - */ - low = count; - - RESCALE_INPUT_INTERVAL; - /* - * Restore the transition (weight = -1) - */ - append_edge (row, 0, -1, 0, wfa); - total++; - } + count = high - ((high - low) >> *prob_ptr); + if (code < count) + { + if (prob_ptr < last) /* model update */ + prob_ptr++; + /* + * Decode the MPS '0' + */ + high = count - 1; + + RESCALE_INPUT_INTERVAL; + } + else + { + prob_ptr = ((prob_ptr - first) >> 1) + first; /* model update */ + /* + * Decode the LPS '1' + */ + low = count; + + RESCALE_INPUT_INTERVAL; + /* + * Restore the transition (weight = -1) + */ + append_edge (row, 0, -1, 0, wfa); + total++; + } } /* * Read label 1 element */ if (isrange (*is_leaf++)) /* valid matrix index */ { - count = high - ((high - low) >> *prob_ptr); - if (code < count) - { - if (prob_ptr < last) - prob_ptr++; /* model update */ - /* - * Decode the MPS '0' - */ - high = count - 1; - - RESCALE_INPUT_INTERVAL; - } - else - { - prob_ptr = ((prob_ptr - first) >> 1) + first; /* model update */ - /* - * Decode the LPS '1' - */ - low = count; - - RESCALE_INPUT_INTERVAL; - /* - * Restore the transition (weight = -1) - */ - append_edge (row, 0, -1, 1, wfa); - total++; - } + count = high - ((high - low) >> *prob_ptr); + if (code < count) + { + if (prob_ptr < last) + prob_ptr++; /* model update */ + /* + * Decode the MPS '0' + */ + high = count - 1; + + RESCALE_INPUT_INTERVAL; + } + else + { + prob_ptr = ((prob_ptr - first) >> 1) + first; /* model update */ + /* + * Decode the LPS '1' + */ + low = count; + + RESCALE_INPUT_INTERVAL; + /* + * Restore the transition (weight = -1) + */ + append_edge (row, 0, -1, 1, wfa); + total++; + } } } @@ -408,24 +408,24 @@ chroma_decoding (wfa_t *wfa, bitfile_t *input) * chroma channels Cb and Cr from stream 'input'. * * Return value: - * number of non-zero matrix elements (WFA edges) + * number of non-zero matrix elements (WFA edges) * * Side effects: - * 'wfa->into' is filled with decoded values + * 'wfa->into' is filled with decoded values */ { - unsigned domain; /* current domain, counter */ - unsigned total = 0; /* total number of chroma edges */ - unsigned *prob_ptr; /* pointer to current probability */ - unsigned *last; /* pointer to minimum probability */ - unsigned *first; /* pointer to maximum probability */ - unsigned *new_prob_ptr; /* ptr to probability of last domain */ - unsigned *prob; /* probability array */ - u_word_t high; /* Start of the current code range */ - u_word_t low; /* End of the current code range */ - u_word_t code; /* The present input code value */ - word_t *y_domains; /* domain images corresponding to Y */ - int save_index; /* YES: store current probability */ + unsigned domain; /* current domain, counter */ + unsigned total = 0; /* total number of chroma edges */ + unsigned *prob_ptr; /* pointer to current probability */ + unsigned *last; /* pointer to minimum probability */ + unsigned *first; /* pointer to maximum probability */ + unsigned *new_prob_ptr; /* ptr to probability of last domain */ + unsigned *prob; /* probability array */ + u_word_t high; /* Start of the current code range */ + u_word_t low; /* End of the current code range */ + u_word_t code; /* The present input code value */ + word_t *y_domains; /* domain images corresponding to Y */ + int save_index; /* YES: store current probability */ /* * Compute the asymmetric probability array @@ -434,26 +434,26 @@ chroma_decoding (wfa_t *wfa, bitfile_t *input) */ { unsigned n; - unsigned index; /* probability index */ - unsigned exp; /* current exponent */ + unsigned index; /* probability index */ + unsigned exp; /* current exponent */ prob = Calloc (1 << (MAX_PROB + 1), sizeof (unsigned)); for (index = 0, n = MIN_PROB; n <= MAX_PROB; n++) - for (exp = 0; exp < 1U << n; exp++, index++) - prob [index] = n; + for (exp = 0; exp < 1U << n; exp++, index++) + prob [index] = n; } - high = HIGH; /* 1.0 */ - low = LOW; /* 0.0 */ + high = HIGH; /* 1.0 */ + low = LOW; /* 0.0 */ code = get_bits (input, 16); /* * Compute list of admitted domains */ y_domains = compute_hits (wfa->basis_states, - wfa->tree [wfa->tree [wfa->root_state][0]][0], - wfa->wfainfo->chroma_max_states, wfa); + wfa->tree [wfa->tree [wfa->root_state][0]][0], + wfa->wfainfo->chroma_max_states, wfa); first = prob_ptr = new_prob_ptr = prob; last = first + 1020; @@ -465,7 +465,7 @@ chroma_decoding (wfa_t *wfa, bitfile_t *input) */ for (domain = 0; y_domains [domain] != -1; domain++) { - unsigned row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; + unsigned row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; word_t *is_leaf = wfa->tree [row]; prob_ptr = new_prob_ptr; @@ -473,87 +473,87 @@ chroma_decoding (wfa_t *wfa, bitfile_t *input) for (; row < wfa->states; row++) { - unsigned count; /* value in the current interval */ - /* - * Read label 0 element - */ - if (isrange (*is_leaf++)) /* valid matrix index */ - { - count = high - ((high - low) >> *prob_ptr); - if (code < count) - { - if (prob_ptr < last) - prob_ptr++; - /* - * Decode the MPS '0' - */ - high = count - 1; - - RESCALE_INPUT_INTERVAL; - } - else - { - prob_ptr = ((prob_ptr - first) >> 1) + first; - /* - * Decode the LPS '1' - */ - low = count; - - RESCALE_INPUT_INTERVAL; - /* - * Restore the transition (weight = -1) - */ - append_edge (row, y_domains [domain], -1, 0, wfa); - total++; - } - } - /* - * Read label 1 element - */ - if (isrange (*is_leaf++)) /* valid matrix index */ - { - count = high - ((high - low) >> *prob_ptr); - if (code < count) - { - if (prob_ptr < last) - prob_ptr++; - /* - * Decode the MPS '0' - */ - high = count - 1; - - RESCALE_INPUT_INTERVAL; - } - else - { - prob_ptr = ((prob_ptr - first) >> 1) + first; - /* - * Decode the LPS '1' - */ - low = count; - - RESCALE_INPUT_INTERVAL; - /* - * Restore the transition (weight = -1) - */ - append_edge (row, y_domains [domain], -1, 1, wfa); - total++; - } - } - if (save_index) - { - save_index = NO; - new_prob_ptr = prob_ptr; - } + unsigned count; /* value in the current interval */ + /* + * Read label 0 element + */ + if (isrange (*is_leaf++)) /* valid matrix index */ + { + count = high - ((high - low) >> *prob_ptr); + if (code < count) + { + if (prob_ptr < last) + prob_ptr++; + /* + * Decode the MPS '0' + */ + high = count - 1; + + RESCALE_INPUT_INTERVAL; + } + else + { + prob_ptr = ((prob_ptr - first) >> 1) + first; + /* + * Decode the LPS '1' + */ + low = count; + + RESCALE_INPUT_INTERVAL; + /* + * Restore the transition (weight = -1) + */ + append_edge (row, y_domains [domain], -1, 0, wfa); + total++; + } + } + /* + * Read label 1 element + */ + if (isrange (*is_leaf++)) /* valid matrix index */ + { + count = high - ((high - low) >> *prob_ptr); + if (code < count) + { + if (prob_ptr < last) + prob_ptr++; + /* + * Decode the MPS '0' + */ + high = count - 1; + + RESCALE_INPUT_INTERVAL; + } + else + { + prob_ptr = ((prob_ptr - first) >> 1) + first; + /* + * Decode the LPS '1' + */ + low = count; + + RESCALE_INPUT_INTERVAL; + /* + * Restore the transition (weight = -1) + */ + append_edge (row, y_domains [domain], -1, 1, wfa); + total++; + } + } + if (save_index) + { + save_index = NO; + new_prob_ptr = prob_ptr; + } } } Free (y_domains); compute_y_state (wfa->tree [wfa->tree [wfa->root_state][0]][1], - wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa); + wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa); compute_y_state (wfa->tree [wfa->tree [wfa->root_state][1]][0], - wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa); + wfa->tree [wfa->tree [wfa->root_state][0]][0], wfa); first = prob_ptr = new_prob_ptr = prob; @@ -565,44 +565,44 @@ chroma_decoding (wfa_t *wfa, bitfile_t *input) * Again, quasi arithmetic decoding is used for this task. */ { - unsigned row; + unsigned row; for (row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; - row < wfa->states; row++) + row < wfa->states; row++) { - int label; /* current label */ - - for (label = 0; label < MAXLABELS; label++) - { - u_word_t count = high - ((high - low) >> *prob_ptr); - - if (code < count) - { - if (prob_ptr < last) - prob_ptr++; - /* - * Decode the MPS '0' - */ - high = count - 1; - - RESCALE_INPUT_INTERVAL; - } - else - { - prob_ptr = ((prob_ptr - first) >> 1) + first; - /* - * Decode the LPS '1' - */ - low = count; - - RESCALE_INPUT_INTERVAL; - /* - * Restore the transition (weight = -1) - */ - append_edge (row, wfa->y_state [row][label], -1, label, wfa); - total++; - } - } + int label; /* current label */ + + for (label = 0; label < MAXLABELS; label++) + { + u_word_t count = high - ((high - low) >> *prob_ptr); + + if (code < count) + { + if (prob_ptr < last) + prob_ptr++; + /* + * Decode the MPS '0' + */ + high = count - 1; + + RESCALE_INPUT_INTERVAL; + } + else + { + prob_ptr = ((prob_ptr - first) >> 1) + first; + /* + * Decode the LPS '1' + */ + low = count; + + RESCALE_INPUT_INTERVAL; + /* + * Restore the transition (weight = -1) + */ + append_edge (row, wfa->y_state [row][label], -1, label, wfa); + total++; + } + } } } @@ -625,20 +625,20 @@ compute_y_state (int state, int y_state, wfa_t *wfa) * No return value. * * Side effects: - * 'wfa->y_state' is filled with the generated tree structure. + * 'wfa->y_state' is filled with the generated tree structure. */ { unsigned label; for (label = 0; label < MAXLABELS; label++) if (isrange (y_state)) - wfa->y_state [state][label] = RANGE; + wfa->y_state [state][label] = RANGE; else { - wfa->y_state [state][label] = wfa->tree [y_state][label]; - if (!isrange (wfa->tree [state][label])) - compute_y_state (wfa->tree [state][label], - wfa->y_state [state][label], wfa); + wfa->y_state [state][label] = wfa->tree [y_state][label]; + if (!isrange (wfa->tree [state][label])) + compute_y_state (wfa->tree [state][label], + wfa->y_state [state][label], wfa); } } diff --git a/converter/other/fiasco/input/matrices.h b/converter/other/fiasco/input/matrices.h index 6d1cef15..193bc6a7 100644 --- a/converter/other/fiasco/input/matrices.h +++ b/converter/other/fiasco/input/matrices.h @@ -1,8 +1,8 @@ /* * matrices.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/input/mc.c b/converter/other/fiasco/input/mc.c index afc0c1c3..8d93d931 100644 --- a/converter/other/fiasco/input/mc.c +++ b/converter/other/fiasco/input/mc.c @@ -1,8 +1,8 @@ /* - * mc.c: Input of motion compensation + * mc.c: Input of motion compensation * * written by: Michael Unger - * Ullrich Hafner + * Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -31,27 +31,27 @@ /***************************************************************************** - local variables + local variables *****************************************************************************/ typedef struct huff_node { - int code_index; /* leaf if index >= 0 */ - struct huff_node *left; /* follow if '0' bit read */ - struct huff_node *right; /* follow if '1' bit read */ - int index_set [34]; + int code_index; /* leaf if index >= 0 */ + struct huff_node *left; /* follow if '0' bit read */ + struct huff_node *right; /* follow if '1' bit read */ + int index_set [34]; } huff_node_t; /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void decode_mc_tree (frame_type_e frame_type, unsigned max_state, - wfa_t *wfa, bitfile_t *input); + wfa_t *wfa, bitfile_t *input); static void decode_mc_coords (unsigned max_state, wfa_t *wfa, bitfile_t *input); static int @@ -63,7 +63,7 @@ create_huff_node (huff_node_t *hn, int bits_processed); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -76,12 +76,12 @@ read_mc (frame_type_e frame_type, wfa_t *wfa, bitfile_t *input) * No return value. * * Side effects: - * 'wfa->mv_tree' is filled with the decoded values. + * 'wfa->mv_tree' is filled with the decoded values. */ { unsigned max_state = wfa->wfainfo->color - ? wfa->tree [wfa->tree [wfa->root_state][0]][0] - : wfa->states; + ? wfa->tree [wfa->tree [wfa->root_state][0]][0] + : wfa->states; decode_mc_tree (frame_type, max_state, wfa, input); decode_mc_coords (max_state, wfa, input); @@ -89,13 +89,13 @@ read_mc (frame_type_e frame_type, wfa_t *wfa, bitfile_t *input) /***************************************************************************** - private code + private code *****************************************************************************/ static void decode_mc_tree (frame_type_e frame_type, unsigned max_state, - wfa_t *wfa, bitfile_t *input) + wfa_t *wfa, bitfile_t *input) /* * Read tree of motion compensation decisions of the 'input' stream. * Depending on 'frame_type' different decoding methods are used. @@ -104,13 +104,13 @@ decode_mc_tree (frame_type_e frame_type, unsigned max_state, * No return value. * * Side effects: - * 'wfa->mv_tree' is filled with decoded values. + * 'wfa->mv_tree' is filled with decoded values. */ { - unsigned state; /* current state */ - unsigned *queue; /* states in breadth first order */ - unsigned last; /* last node - (update for each new node) */ + unsigned state; /* current state */ + unsigned *queue; /* states in breadth first order */ + unsigned last; /* last node + (update for each new node) */ /* * Traverse tree in breadth first order (starting at level @@ -120,68 +120,68 @@ decode_mc_tree (frame_type_e frame_type, unsigned max_state, queue = Calloc (MAXSTATES, sizeof (unsigned)); for (last = 0, state = wfa->basis_states; state < max_state; state++) if (wfa->level_of_state [state] - 1 == (int) wfa->wfainfo->p_max_level) - queue [last++] = state; /* init level 'p_max_level' */ + queue [last++] = state; /* init level 'p_max_level' */ if (frame_type == P_FRAME) { - unsigned label; /* current label */ - unsigned current; /* current node to process */ + unsigned label; /* current label */ + unsigned current; /* current node to process */ for (current = 0; current < last; current++) - for (label = 0; label < MAXLABELS; label++) - { - state = queue[current]; - if (wfa->x [state][label] /* process visible states only */ - + width_of_level (wfa->level_of_state [state] - 1) - <= wfa->wfainfo->width - && - wfa->y [state][label] - + height_of_level (wfa->level_of_state [state] - 1) - <= wfa->wfainfo->height) - { - wfa->mv_tree [state][label].type - = get_bit (input) ? NONE : FORWARD; - } - else - wfa->mv_tree [state][label].type = NONE; - if (wfa->mv_tree [state][label].type == NONE && - !isrange (wfa->tree [state][label]) && - wfa->level_of_state [state] - 1 >= - (int) wfa->wfainfo->p_min_level) - queue [last++] = wfa->tree [state][label]; /* append child */ - } + for (label = 0; label < MAXLABELS; label++) + { + state = queue[current]; + if (wfa->x [state][label] /* process visible states only */ + + width_of_level (wfa->level_of_state [state] - 1) + <= wfa->wfainfo->width + && + wfa->y [state][label] + + height_of_level (wfa->level_of_state [state] - 1) + <= wfa->wfainfo->height) + { + wfa->mv_tree [state][label].type + = get_bit (input) ? NONE : FORWARD; + } + else + wfa->mv_tree [state][label].type = NONE; + if (wfa->mv_tree [state][label].type == NONE && + !isrange (wfa->tree [state][label]) && + wfa->level_of_state [state] - 1 >= + (int) wfa->wfainfo->p_min_level) + queue [last++] = wfa->tree [state][label]; /* append child */ + } } else { - unsigned label; /* current label */ - unsigned current; /* current node to process */ + unsigned label; /* current label */ + unsigned current; /* current node to process */ for (current = 0; current < last; current++) - for (label = 0; label < MAXLABELS; label++) - { - state = queue[current]; - if (wfa->x [state][label] /* process visible states only */ - + width_of_level (wfa->level_of_state [state] - 1) - > wfa->wfainfo->width - || - wfa->y [state][label] - + height_of_level (wfa->level_of_state [state] - 1) - > wfa->wfainfo->height) - wfa->mv_tree[state][label].type = NONE; - else if (get_bit (input)) /* 1 */ - wfa->mv_tree[state][label].type = NONE; - else if (get_bit (input)) /* 01 */ - wfa->mv_tree[state][label].type = INTERPOLATED; - else if (get_bit (input)) /* 001 */ - wfa->mv_tree[state][label].type = BACKWARD; - else /* 000 */ - wfa->mv_tree[state][label].type = FORWARD; - if (wfa->mv_tree[state][label].type == NONE && - !isrange (wfa->tree[state][label]) && - wfa->level_of_state[state] - 1 - >= (int) wfa->wfainfo->p_min_level) - queue[last++] = wfa->tree[state][label]; /* append child */ - } + for (label = 0; label < MAXLABELS; label++) + { + state = queue[current]; + if (wfa->x [state][label] /* process visible states only */ + + width_of_level (wfa->level_of_state [state] - 1) + > wfa->wfainfo->width + || + wfa->y [state][label] + + height_of_level (wfa->level_of_state [state] - 1) + > wfa->wfainfo->height) + wfa->mv_tree[state][label].type = NONE; + else if (get_bit (input)) /* 1 */ + wfa->mv_tree[state][label].type = NONE; + else if (get_bit (input)) /* 01 */ + wfa->mv_tree[state][label].type = INTERPOLATED; + else if (get_bit (input)) /* 001 */ + wfa->mv_tree[state][label].type = BACKWARD; + else /* 000 */ + wfa->mv_tree[state][label].type = FORWARD; + if (wfa->mv_tree[state][label].type == NONE && + !isrange (wfa->tree[state][label]) && + wfa->level_of_state[state] - 1 + >= (int) wfa->wfainfo->p_min_level) + queue[last++] = wfa->tree[state][label]; /* append child */ + } } INPUT_BYTE_ALIGN (input); @@ -198,12 +198,12 @@ decode_mc_coords (unsigned max_state, wfa_t *wfa, bitfile_t *input) * No return value. * * Side effects: - * 'wfa->mv_tree' is filled with decoded values. + * 'wfa->mv_tree' is filled with decoded values. */ { - unsigned label; /* current label */ - unsigned state; /* current state */ - mv_t *mv; /* current motion vector */ + unsigned label; /* current label */ + unsigned state; /* current state */ + mv_t *mv; /* current motion vector */ static huff_node_t *huff_mv_root = NULL; /* root of huffman tree */ if (huff_mv_root == NULL) @@ -212,26 +212,26 @@ decode_mc_coords (unsigned max_state, wfa_t *wfa, bitfile_t *input) for (state = wfa->basis_states; state < max_state; state++) for (label = 0; label < MAXLABELS; label++) { - mv = &wfa->mv_tree[state][label]; - switch (mv->type) - { - case NONE: - break; - case FORWARD: - mv->fx = get_mv (1, huff_mv_root, input); - mv->fy = get_mv (1, huff_mv_root, input); - break; - case BACKWARD: - mv->bx = get_mv (1, huff_mv_root, input); - mv->by = get_mv (1, huff_mv_root, input); - break; - case INTERPOLATED: - mv->fx = get_mv (1, huff_mv_root, input); - mv->fy = get_mv (1, huff_mv_root, input); - mv->bx = get_mv (1, huff_mv_root, input); - mv->by = get_mv (1, huff_mv_root, input); - break; - } + mv = &wfa->mv_tree[state][label]; + switch (mv->type) + { + case NONE: + break; + case FORWARD: + mv->fx = get_mv (1, huff_mv_root, input); + mv->fy = get_mv (1, huff_mv_root, input); + break; + case BACKWARD: + mv->bx = get_mv (1, huff_mv_root, input); + mv->by = get_mv (1, huff_mv_root, input); + break; + case INTERPOLATED: + mv->fx = get_mv (1, huff_mv_root, input); + mv->fy = get_mv (1, huff_mv_root, input); + mv->bx = get_mv (1, huff_mv_root, input); + mv->by = get_mv (1, huff_mv_root, input); + break; + } } INPUT_BYTE_ALIGN (input); @@ -249,11 +249,11 @@ get_mv (int f_code, huff_node_t *hn, bitfile_t *input) while (hn->code_index < 0) { if (hn->code_index == -2) - error ("wrong huffman code !"); + error ("wrong huffman code !"); if (get_bit (input)) - hn = hn->right; + hn = hn->right; else - hn = hn->left; + hn = hn->left; } vlc_code = hn->code_index - 16; if (vlc_code == 0 || f_code == 1) @@ -275,7 +275,7 @@ create_huff_tree (void) * Construct huffman tree from code table */ { - unsigned i; + unsigned i; huff_node_t *huff_root = Calloc (1, sizeof (huff_node_t)); /* @@ -286,7 +286,7 @@ create_huff_tree (void) for (i = 0; i < 33; i++) huff_root->index_set [i] = i; - huff_root->index_set [i] = -1; /* end marker */ + huff_root->index_set [i] = -1; /* end marker */ create_huff_node (huff_root, 0); @@ -299,14 +299,14 @@ create_huff_node (huff_node_t *hn, int bits_processed) * Create one node in the huffman tree */ { - int lind = 0; /* next index of left huff_node */ - int rind = 0; /* next index of right huff_node */ + int lind = 0; /* next index of left huff_node */ + int rind = 0; /* next index of right huff_node */ int code_len, i, ind; hn->code_index = -1; - if (hn->index_set [0] < 0) /* empty index set ? */ + if (hn->index_set [0] < 0) /* empty index set ? */ { - hn->code_index = -2; /* error */ + hn->code_index = -2; /* error */ return; } hn->left = Calloc (1, sizeof (huff_node_t)); @@ -315,19 +315,19 @@ create_huff_node (huff_node_t *hn, int bits_processed) for (i = 0; (ind = hn->index_set[i]) >= 0; i++) { code_len = mv_code_table[ind][1]; - if (code_len == bits_processed) /* generate leaf */ + if (code_len == bits_processed) /* generate leaf */ { - hn->code_index = ind; - Free (hn->left); - Free (hn->right); - return; + hn->code_index = ind; + Free (hn->left); + Free (hn->right); + return; } if (mv_code_table[ind][0] & (1 << (code_len - 1 - bits_processed))) - hn->right->index_set[rind++] = ind; + hn->right->index_set[rind++] = ind; else - hn->left->index_set[lind++] = ind; + hn->left->index_set[lind++] = ind; } - hn->right->index_set[rind] = -1; /* set end markers */ + hn->right->index_set[rind] = -1; /* set end markers */ hn->left->index_set[lind] = -1; create_huff_node (hn->left, bits_processed + 1); create_huff_node (hn->right, bits_processed + 1); diff --git a/converter/other/fiasco/input/mc.h b/converter/other/fiasco/input/mc.h index 9d9d714d..a61f7e4a 100644 --- a/converter/other/fiasco/input/mc.h +++ b/converter/other/fiasco/input/mc.h @@ -2,8 +2,8 @@ * mc.h * * written by: Michael Unger - * Ullrich Hafner - + * Ullrich Hafner + * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/input/nd.c b/converter/other/fiasco/input/nd.c index 129a150e..0317073a 100644 --- a/converter/other/fiasco/input/nd.c +++ b/converter/other/fiasco/input/nd.c @@ -1,7 +1,7 @@ /* - * nd.c: Input of prediction tree + * nd.c: Input of prediction tree * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -30,7 +30,7 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -41,7 +41,7 @@ decode_nd_tree (wfa_t *wfa, bitfile_t *input); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -52,7 +52,7 @@ read_nd (wfa_t *wfa, bitfile_t *input) * ND is used only at levels {'wfa->p_min_level', ... , 'wfa->p_max_level'}. * * Side effects: - * 'wfa->into' and 'wfa->weights' are filled with the decoded values + * 'wfa->into' and 'wfa->weights' are filled with the decoded values */ { unsigned total = decode_nd_tree (wfa, input); @@ -63,7 +63,7 @@ read_nd (wfa_t *wfa, bitfile_t *input) /***************************************************************************** - private code + private code *****************************************************************************/ @@ -75,16 +75,16 @@ decode_nd_tree (wfa_t *wfa, bitfile_t *input) * No return value. * * Side effects: - * 'wfa->into' is filled with the decoded values + * 'wfa->into' is filled with the decoded values */ { - lqueue_t *queue; /* queue of states */ - int next, state; /* state and its current child */ - unsigned total = 0; /* total number of predicted states */ - u_word_t sum0, sum1; /* Probability model */ - u_word_t code; /* The present input code value */ - u_word_t low; /* Start of the current code range */ - u_word_t high; /* End of the current code range */ + lqueue_t *queue; /* queue of states */ + int next, state; /* state and its current child */ + unsigned total = 0; /* total number of predicted states */ + u_word_t sum0, sum1; /* Probability model */ + u_word_t code; /* The present input code value */ + u_word_t low; /* Start of the current code range */ + u_word_t high; /* End of the current code range */ /* * Initialize arithmetic decoder @@ -108,78 +108,78 @@ decode_nd_tree (wfa_t *wfa, bitfile_t *input) if (wfa->level_of_state [next] > wfa->wfainfo->p_max_level + 1) { - /* - * Nondetermismn is not allowed at levels larger than - * 'wfa->wfainfo->p_max_level'. - */ - for (label = 0; label < MAXLABELS; label++) - if (ischild (state = wfa->tree [next][label])) - queue_append (queue, &state); /* continue with children */ + /* + * Nondetermismn is not allowed at levels larger than + * 'wfa->wfainfo->p_max_level'. + */ + for (label = 0; label < MAXLABELS; label++) + if (ischild (state = wfa->tree [next][label])) + queue_append (queue, &state); /* continue with children */ } else if (wfa->level_of_state [next] > wfa->wfainfo->p_min_level) { - for (label = 0; label < MAXLABELS; label++) - if (ischild (state = wfa->tree [next][label])) - { - unsigned count; /* Current interval count */ - unsigned range; /* Current interval range */ - - count = (((code - low) + 1) * sum1 - 1) / ((high - low) + 1); - if (count < sum0) - { - /* - * Decode a '0' symbol - * First, the range is expanded to account for the - * symbol removal. - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum0) / sum1 - 1 ); - RESCALE_INPUT_INTERVAL; - /* - * Update the frequency counts - */ - sum0++; - sum1++; - if (sum1 > 50) /* scale the symbol frequencies */ - { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; - } - if (wfa->level_of_state [state] > wfa->wfainfo->p_min_level) - queue_append (queue, &state); - } - else - { - /* - * Decode a '1' symbol - * First, the range is expanded to account for the - * symbol removal. - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum1) / sum1 - 1); - low = low + (u_word_t) ((range * sum0) / sum1); - RESCALE_INPUT_INTERVAL; - /* - * Update the frequency counts - */ - sum1++; - if (sum1 > 50) /* scale the symbol frequencies */ - { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; - } - append_edge (next, 0, -1, label, wfa); - total++; - } - } + for (label = 0; label < MAXLABELS; label++) + if (ischild (state = wfa->tree [next][label])) + { + unsigned count; /* Current interval count */ + unsigned range; /* Current interval range */ + + count = (((code - low) + 1) * sum1 - 1) / ((high - low) + 1); + if (count < sum0) + { + /* + * Decode a '0' symbol + * First, the range is expanded to account for the + * symbol removal. + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum0) / sum1 - 1 ); + RESCALE_INPUT_INTERVAL; + /* + * Update the frequency counts + */ + sum0++; + sum1++; + if (sum1 > 50) /* scale the symbol frequencies */ + { + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; + } + if (wfa->level_of_state [state] > wfa->wfainfo->p_min_level) + queue_append (queue, &state); + } + else + { + /* + * Decode a '1' symbol + * First, the range is expanded to account for the + * symbol removal. + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum1) / sum1 - 1); + low = low + (u_word_t) ((range * sum0) / sum1); + RESCALE_INPUT_INTERVAL; + /* + * Update the frequency counts + */ + sum1++; + if (sum1 > 50) /* scale the symbol frequencies */ + { + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; + } + append_edge (next, 0, -1, label, wfa); + total++; + } + } } } free_queue (queue); @@ -199,21 +199,21 @@ decode_nd_coefficients (unsigned total, wfa_t *wfa, bitfile_t *input) * No return value. * * Side effects: - * 'wfa->weights' is filled with the decoded values. + * 'wfa->weights' is filled with the decoded values. */ { - unsigned *coefficients; /* array of factors to encode */ - unsigned *ptr; /* pointer to current factor */ + unsigned *coefficients; /* array of factors to encode */ + unsigned *ptr; /* pointer to current factor */ /* * Decode array of coefficients stored with arithmetic coding */ { - const int scaling = 50; /* scaling factor of prob. model */ + const int scaling = 50; /* scaling factor of prob. model */ unsigned c_symbols = 1 << (wfa->wfainfo->dc_rpf->mantissa_bits + 1); ptr = coefficients = decode_array (input, NULL, &c_symbols, 1, - total, scaling); + total, scaling); } /* @@ -223,15 +223,15 @@ decode_nd_coefficients (unsigned total, wfa_t *wfa, bitfile_t *input) unsigned state, label; for (state = wfa->basis_states; state < wfa->states; state++) - for (label = 0; label < MAXLABELS; label++) - if (ischild (wfa->tree [state][label]) - && isedge (wfa->into [state][label][0])) - { - wfa->weight [state][label][0] = btor (*ptr++, - wfa->wfainfo->dc_rpf); - wfa->int_weight [state][label][0] - = wfa->weight [state][label][0] * 512 + 0.5; - } + for (label = 0; label < MAXLABELS; label++) + if (ischild (wfa->tree [state][label]) + && isedge (wfa->into [state][label][0])) + { + wfa->weight [state][label][0] = btor (*ptr++, + wfa->wfainfo->dc_rpf); + wfa->int_weight [state][label][0] + = wfa->weight [state][label][0] * 512 + 0.5; + } } Free (coefficients); } diff --git a/converter/other/fiasco/input/nd.h b/converter/other/fiasco/input/nd.h index 0fe06cf1..57f46440 100644 --- a/converter/other/fiasco/input/nd.h +++ b/converter/other/fiasco/input/nd.h @@ -1,8 +1,8 @@ /* * nd.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/input/read.c b/converter/other/fiasco/input/read.c index c3aa77a8..50e271e5 100644 --- a/converter/other/fiasco/input/read.c +++ b/converter/other/fiasco/input/read.c @@ -1,7 +1,7 @@ /* - * read.c: Input of WFA files + * read.c: Input of WFA files * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -46,17 +46,17 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void read_tiling (tiling_t *tiling, unsigned image_width, unsigned image_height, - unsigned image_level, bitfile_t *input); + unsigned image_level, bitfile_t *input); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -66,14 +66,14 @@ open_wfa (const char *filename, wfa_info_t *wi) * Open WFA file 'filename' and read header information. * * Return value: - * Pointer to input stream (fileposition: first WFA frame) + * Pointer to input stream (fileposition: first WFA frame) * * Side effects: - * The values of the header of 'filename' are copied to 'wfainfo'. + * The values of the header of 'filename' are copied to 'wfainfo'. * */ { - bitfile_t *input; /* pointer to WFA bitfile */ + bitfile_t *input; /* pointer to WFA bitfile */ assert (filename && wi); @@ -83,7 +83,7 @@ open_wfa (const char *filename, wfa_info_t *wi) * Check whether 'filename' is a regular WFA file */ { - unsigned n; + unsigned n; const char *str; if (!(input = open_bitfile (filename, "FIASCO_DATA", READ_ACCESS))) @@ -92,57 +92,57 @@ open_wfa (const char *filename, wfa_info_t *wi) for (str = FIASCO_MAGIC, n = strlen (FIASCO_MAGIC); n; n--) if (get_bits (input, 8) != (unsigned) *str++) error ("Input file %s is not a valid FIASCO file!", filename); - get_bits (input, 8); /* fetch newline */ + get_bits (input, 8); /* fetch newline */ } /* * Read WFA header information */ { - char basis_name [MAXSTRLEN]; /* temp. buffer */ - const unsigned rice_k = 8; /* parameter of Rice Code */ - char *str = basis_name; + char basis_name [MAXSTRLEN]; /* temp. buffer */ + const unsigned rice_k = 8; /* parameter of Rice Code */ + char *str = basis_name; while ((*str++ = get_bits (input, 8)) != 0 - && str < basis_name + MAXSTRLEN) - ; + && str < basis_name + MAXSTRLEN) + ; if (str == basis_name + MAXSTRLEN) - error ("Input file %s is not a valid FIASCO file!", filename); + error ("Input file %s is not a valid FIASCO file!", filename); { - wi->release = read_rice_code (rice_k, input); + wi->release = read_rice_code (rice_k, input); - if (wi->release > FIASCO_BINFILE_RELEASE) - error ("Can't decode FIASCO files of file format release `%d'." - "\nCurrent file format release is `%d'.", wi->release, - FIASCO_BINFILE_RELEASE); + if (wi->release > FIASCO_BINFILE_RELEASE) + error ("Can't decode FIASCO files of file format release `%d'." + "\nCurrent file format release is `%d'.", wi->release, + FIASCO_BINFILE_RELEASE); } if (wi->release > 1) { - header_type_e type; - - while ((type = read_rice_code (rice_k, input)) != HEADER_END) - { - char buffer [MAXSTRLEN]; - unsigned n = 0; - - switch (type) - { - case HEADER_TITLE: - while ((buffer [n++] = get_bits (input, 8))) - ; - wi->title = strdup (buffer); - break; - case HEADER_COMMENT: - while ((buffer [n++] = get_bits (input, 8))) - ; - wi->comment = strdup (buffer); - break; - default: /* should not happen */ - break; - } - } + header_type_e type; + + while ((type = read_rice_code (rice_k, input)) != HEADER_END) + { + char buffer [MAXSTRLEN]; + unsigned n = 0; + + switch (type) + { + case HEADER_TITLE: + while ((buffer [n++] = get_bits (input, 8))) + ; + wi->title = strdup (buffer); + break; + case HEADER_COMMENT: + while ((buffer [n++] = get_bits (input, 8))) + ; + wi->comment = strdup (buffer); + break; + default: /* should not happen */ + break; + } + } } wi->basis_name = strdup (basis_name); @@ -155,65 +155,65 @@ open_wfa (const char *filename, wfa_info_t *wi) * Compute bintree level */ { - unsigned lx = log2 (wi->width - 1) + 1; - unsigned ly = log2 (wi->height - 1) + 1; + unsigned lx = log2 (wi->width - 1) + 1; + unsigned ly = log2 (wi->height - 1) + 1; - wi->level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0); + wi->level = MAX(lx, ly) * 2 - ((ly == lx + 1) ? 1 : 0); } wi->chroma_max_states = wi->color ? read_rice_code (rice_k, input) : -1; wi->p_min_level = read_rice_code (rice_k, input); wi->p_max_level = read_rice_code (rice_k, input); wi->frames = read_rice_code (rice_k, input); - wi->smoothing = read_rice_code (rice_k, input); + wi->smoothing = read_rice_code (rice_k, input); /* * Read RPF models from disk */ { - unsigned mantissa; - fiasco_rpf_range_e range; - - mantissa = get_bits (input, 3) + 2; - range = get_bits (input, 2); - wi->rpf = alloc_rpf (mantissa, range); - - if (get_bit (input)) /* different DC model */ - { - mantissa = get_bits (input, 3) + 2; - range = get_bits (input, 2); - wi->dc_rpf = alloc_rpf (mantissa, range); - } - else /* use same model for DC coefficients */ - wi->dc_rpf = alloc_rpf (wi->rpf->mantissa_bits, - wi->rpf->range_e); - - if (get_bit (input)) /* different delta model */ - { - mantissa = get_bits (input, 3) + 2; - range = get_bits (input, 2); - wi->d_rpf = alloc_rpf (mantissa, range); - } - else - wi->d_rpf = alloc_rpf (wi->rpf->mantissa_bits, - wi->rpf->range_e); - - if (get_bit (input)) /* different DC delta model */ - { - mantissa = get_bits (input, 3) + 2; - range = get_bits (input, 2); - wi->d_dc_rpf = alloc_rpf (mantissa, range); - } - else - wi->d_dc_rpf = alloc_rpf (wi->dc_rpf->mantissa_bits, - wi->dc_rpf->range_e); + unsigned mantissa; + fiasco_rpf_range_e range; + + mantissa = get_bits (input, 3) + 2; + range = get_bits (input, 2); + wi->rpf = alloc_rpf (mantissa, range); + + if (get_bit (input)) /* different DC model */ + { + mantissa = get_bits (input, 3) + 2; + range = get_bits (input, 2); + wi->dc_rpf = alloc_rpf (mantissa, range); + } + else /* use same model for DC coefficients */ + wi->dc_rpf = alloc_rpf (wi->rpf->mantissa_bits, + wi->rpf->range_e); + + if (get_bit (input)) /* different delta model */ + { + mantissa = get_bits (input, 3) + 2; + range = get_bits (input, 2); + wi->d_rpf = alloc_rpf (mantissa, range); + } + else + wi->d_rpf = alloc_rpf (wi->rpf->mantissa_bits, + wi->rpf->range_e); + + if (get_bit (input)) /* different DC delta model */ + { + mantissa = get_bits (input, 3) + 2; + range = get_bits (input, 2); + wi->d_dc_rpf = alloc_rpf (mantissa, range); + } + else + wi->d_dc_rpf = alloc_rpf (wi->dc_rpf->mantissa_bits, + wi->dc_rpf->range_e); } - if (wi->frames > 1) /* motion compensation stuff */ + if (wi->frames > 1) /* motion compensation stuff */ { - wi->fps = read_rice_code (rice_k, input); - wi->search_range = read_rice_code (rice_k, input); - wi->half_pixel = get_bit (input) ? YES : NO; - wi->B_as_past_ref = get_bit (input) ? YES : NO; + wi->fps = read_rice_code (rice_k, input); + wi->search_range = read_rice_code (rice_k, input); + wi->half_pixel = get_bit (input) ? YES : NO; + wi->B_as_past_ref = get_bit (input) ? YES : NO; } } @@ -230,12 +230,12 @@ read_basis (const char *filename, wfa_t *wfa) * No return value. * * Side effects: - * wfa->into, wfa->weights, wfa->final_distribution, wfa->basis_states - * wfa->domain_type wfa->wfainfo->basis_name, are filled with the - * values of the WFA basis. + * wfa->into, wfa->weights, wfa->final_distribution, wfa->basis_states + * wfa->domain_type wfa->wfainfo->basis_name, are filled with the + * values of the WFA basis. */ { - FILE *input; /* ASCII WFA initial basis file */ + FILE *input; /* ASCII WFA initial basis file */ assert (filename && wfa); @@ -243,27 +243,27 @@ read_basis (const char *filename, wfa_t *wfa) !streq (wfa->wfainfo->basis_name, filename)) { if (wfa->wfainfo->basis_name) - Free (wfa->wfainfo->basis_name); + Free (wfa->wfainfo->basis_name); wfa->wfainfo->basis_name = strdup (filename); } if (get_linked_basis (filename, wfa)) - return; /* basis is linked with executable */ + return; /* basis is linked with executable */ /* * Check whether 'wfa_name' is a regular ASCII WFA initial basis file */ { - char magic [MAXSTRLEN]; /* WFA magic number */ + char magic [MAXSTRLEN]; /* WFA magic number */ if (!(input = open_file (filename, "FIASCO_DATA", READ_ACCESS))) - file_error(filename); + file_error(filename); if (fscanf (input, MAXSTRLEN_SCANF, magic) != 1) - error ("Format error: ASCII FIASCO initial basis file %s", filename); + error ("Format error: ASCII FIASCO initial basis file %s", filename); else if (!streq (FIASCO_BASIS_MAGIC, magic)) - error ("Input file %s is not an ASCII FIASCO initial basis!", - filename); + error ("Input file %s is not an ASCII FIASCO initial basis!", + filename); } /* @@ -273,74 +273,74 @@ read_basis (const char *filename, wfa_t *wfa) * Don't define any transitions of state 0 in an initial basis. * * Header: - * type |description - * ----------------+----------- - * string |MAGIC Number "Wfa" - * int |Number of basis states 'N' - * bool_t-array[N] |use vector in linear combinations, - * |0: don't use vector (auxiliary state) - * |1: use vector in linear combinations - * float-array[N] |final distribution of every state + * type |description + * ----------------+----------- + * string |MAGIC Number "Wfa" + * int |Number of basis states 'N' + * bool_t-array[N] |use vector in linear combinations, + * |0: don't use vector (auxiliary state) + * |1: use vector in linear combinations + * float-array[N] |final distribution of every state * * Transitions: * - * <state 1> current state - * <label> <into> <weight> transition 1 of current state - * <label> <into> <weight> transition 2 of current state + * <state 1> current state + * <label> <into> <weight> transition 1 of current state + * <label> <into> <weight> transition 2 of current state * ... - * <-1> last transition marker + * <-1> last transition marker * <state 2> * ... - * <-1> last transition marker + * <-1> last transition marker * <state N> * ... * - * <-1> last transition marker - * <-1> last state marker + * <-1> last transition marker + * <-1> last state marker */ { unsigned state; if (fscanf (input ,"%u", &wfa->basis_states) != 1) - error ("Format error: ASCII FIASCO initial basis file %s", filename); + error ("Format error: ASCII FIASCO initial basis file %s", filename); /* * State 0 is assumed to be the constant function f(x, y) = 128. */ wfa->domain_type [0] = USE_DOMAIN_MASK; wfa->final_distribution [0] = 128; - wfa->states = wfa->basis_states; + wfa->states = wfa->basis_states; wfa->basis_states++; append_edge (0, 0, 1.0, 0, wfa); append_edge (0, 0, 1.0, 1, wfa); for (state = 1; state < wfa->basis_states; state++) - wfa->domain_type [state] - = read_int (input) ? USE_DOMAIN_MASK : AUXILIARY_MASK; + wfa->domain_type [state] + = read_int (input) ? USE_DOMAIN_MASK : AUXILIARY_MASK; for (state = 1; state < wfa->basis_states; state++) - wfa->final_distribution[state] = read_real (input); + wfa->final_distribution[state] = read_real (input); /* * Read transitions */ for (state = 1; state < wfa->basis_states; state++) { - unsigned domain; - int label; - real_t weight; - - if (read_int (input) != (int) state) - error ("Format error: ASCII FIASCO initial basis file %s", - filename); - - while((label = read_int (input)) != -1) - { - domain = read_int (input); - weight = read_real (input); - append_edge (state, domain, weight, label, wfa); - } + unsigned domain; + int label; + real_t weight; + + if (read_int (input) != (int) state) + error ("Format error: ASCII FIASCO initial basis file %s", + filename); + + while((label = read_int (input)) != -1) + { + domain = read_int (input); + weight = read_real (input); + append_edge (state, domain, weight, label, wfa); + } } } @@ -357,13 +357,13 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) * No return value. * * Side effects: - * wfa->into, wfa->weights, wfa->final_distribution, wfa->states - * wfa->x, wfa->y, wfa->level_of_state, wfa->domain_type + * wfa->into, wfa->weights, wfa->final_distribution, wfa->states + * wfa->x, wfa->y, wfa->level_of_state, wfa->domain_type * mt->type, mt->number are filled with the values of the WFA file. */ { - tiling_t tiling; /* tiling information */ - unsigned frame_number; /* current frame number */ + tiling_t tiling; /* tiling information */ + unsigned frame_number; /* current frame number */ assert (wfa && input); @@ -371,14 +371,14 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) * Frame header information */ { - const unsigned rice_k = 8; /* parameter of Rice Code */ + const unsigned rice_k = 8; /* parameter of Rice Code */ wfa->states = read_rice_code (rice_k, input); wfa->frame_type = read_rice_code (rice_k, input); frame_number = read_rice_code (rice_k, input); } - if (wfa->wfainfo->release > 1) /* no alignment in version 1 */ + if (wfa->wfainfo->release > 1) /* no alignment in version 1 */ { INPUT_BYTE_ALIGN (input); } @@ -386,9 +386,9 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) /* * Read image tiling info */ - if (get_bit (input)) /* tiling performed ? */ + if (get_bit (input)) /* tiling performed ? */ read_tiling (&tiling, wfa->wfainfo->width, wfa->wfainfo->height, - wfa->wfainfo->level, input); + wfa->wfainfo->level, input); else tiling.exponent = 0; @@ -404,30 +404,30 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) unsigned state; for (state = wfa->basis_states; state < wfa->states; state++) - if ((!wfa->wfainfo->color - || (int) state <= wfa->tree [wfa->tree [wfa->root_state][0]][0]) - && - (!tiling.exponent || - wfa->level_of_state [state] <= (wfa->wfainfo->level - - tiling.exponent)) - && ((wfa->x [state][0] - + width_of_level (wfa->level_of_state [state])) - <= wfa->wfainfo->width) - && ((wfa->y [state][0] - + height_of_level (wfa->level_of_state [state])) - <= wfa->wfainfo->height)) - wfa->domain_type [state] = USE_DOMAIN_MASK; - else - wfa->domain_type [state] = 0; + if ((!wfa->wfainfo->color + || (int) state <= wfa->tree [wfa->tree [wfa->root_state][0]][0]) + && + (!tiling.exponent || + wfa->level_of_state [state] <= (wfa->wfainfo->level + - tiling.exponent)) + && ((wfa->x [state][0] + + width_of_level (wfa->level_of_state [state])) + <= wfa->wfainfo->width) + && ((wfa->y [state][0] + + height_of_level (wfa->level_of_state [state])) + <= wfa->wfainfo->height)) + wfa->domain_type [state] = USE_DOMAIN_MASK; + else + wfa->domain_type [state] = 0; } if (tiling.exponent) Free (tiling.vorder); - if (get_bit (input)) /* nondeterministic prediction used */ + if (get_bit (input)) /* nondeterministic prediction used */ read_nd (wfa, input); - if (wfa->frame_type != I_FRAME) /* motion compensation used */ + if (wfa->frame_type != I_FRAME) /* motion compensation used */ read_mc (wfa->frame_type, wfa, input); locate_delta_images (wfa); @@ -439,7 +439,7 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) unsigned edges = read_matrices (wfa, input); if (edges) - read_weights (edges, wfa, input); + read_weights (edges, wfa, input); } /* @@ -449,8 +449,8 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) unsigned state; for (state = wfa->basis_states; state <= wfa->states; state++) - wfa->final_distribution[state] - = compute_final_distribution (state, wfa); + wfa->final_distribution[state] + = compute_final_distribution (state, wfa); } return frame_number; @@ -458,13 +458,13 @@ read_next_wfa (wfa_t *wfa, bitfile_t *input) /***************************************************************************** - private code + private code *****************************************************************************/ static void read_tiling (tiling_t *tiling, unsigned image_width, unsigned image_height, - unsigned image_level, bitfile_t *input) + unsigned image_level, bitfile_t *input) /* * Read image tiling information from the given file 'input' * and store parameters in struct 'tiling'. @@ -472,32 +472,32 @@ read_tiling (tiling_t *tiling, unsigned image_width, unsigned image_height, * No return value. */ { - const unsigned rice_k = 8; /* parameter of Rice Code */ + const unsigned rice_k = 8; /* parameter of Rice Code */ tiling->exponent = read_rice_code (rice_k, input); - if (get_bit (input)) /* variance order */ + if (get_bit (input)) /* variance order */ { - unsigned tile; /* current image tile */ - unsigned x0, y0; /* NW corner of image tile */ - unsigned width, height; /* size of image tile */ + unsigned tile; /* current image tile */ + unsigned x0, y0; /* NW corner of image tile */ + unsigned width, height; /* size of image tile */ tiling->vorder = Calloc (1 << tiling->exponent, sizeof (int)); for (tile = 0; tile < 1U << tiling->exponent; tile++) { - locate_subimage (image_level, image_level - tiling->exponent, tile, - &x0, &y0, &width, &height); - if (x0 < image_width && y0 < image_height) - tiling->vorder [tile] = get_bits (input, tiling->exponent); - else - tiling->vorder [tile] = -1; + locate_subimage (image_level, image_level - tiling->exponent, tile, + &x0, &y0, &width, &height); + if (x0 < image_width && y0 < image_height) + tiling->vorder [tile] = get_bits (input, tiling->exponent); + else + tiling->vorder [tile] = -1; } } - else /* spiral order */ + else /* spiral order */ { tiling->vorder = Calloc (1 << tiling->exponent, sizeof (int)); compute_spiral (tiling->vorder, image_width, image_height, - tiling->exponent, get_bit (input) ? YES : NO); + tiling->exponent, get_bit (input) ? YES : NO); } } diff --git a/converter/other/fiasco/input/read.h b/converter/other/fiasco/input/read.h index 1f59f103..f41cb874 100644 --- a/converter/other/fiasco/input/read.h +++ b/converter/other/fiasco/input/read.h @@ -1,8 +1,8 @@ /* * read.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/input/tree.c b/converter/other/fiasco/input/tree.c index 74ceeb68..8d81ae1b 100644 --- a/converter/other/fiasco/input/tree.c +++ b/converter/other/fiasco/input/tree.c @@ -1,7 +1,7 @@ /* - * tree.c: Input of bintree partitioning + * tree.c: Input of bintree partitioning * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -30,22 +30,22 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static unsigned restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, - unsigned y, unsigned *dst_state, - word_t (*bfo_tree)[MAXLABELS], - wfa_t *wfa, tiling_t *tiling); + unsigned y, unsigned *dst_state, + word_t (*bfo_tree)[MAXLABELS], + wfa_t *wfa, tiling_t *tiling); static void decode_tree (bitfile_t *input, byte_t *data, unsigned n_data, unsigned scaling, - u_word_t sum0, u_word_t sum1); + u_word_t sum0, u_word_t sum1); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -58,12 +58,12 @@ read_tree (wfa_t *wfa, tiling_t *tiling, bitfile_t *input) * No return value. * * Side effects: - * 'wfa->tree', 'wfa->x', 'wfa->y', 'wfa->level_of_state' + * 'wfa->tree', 'wfa->x', 'wfa->y', 'wfa->level_of_state' * are filled with decoded values. */ { - byte_t *bitstring; /* the encoded data */ - word_t (*bfo_tree)[MAXLABELS]; /* node numbers in BFO */ + byte_t *bitstring; /* the encoded data */ + word_t (*bfo_tree)[MAXLABELS]; /* node numbers in BFO */ /* * Read WFA tree stored in breadth first order @@ -80,15 +80,15 @@ read_tree (wfa_t *wfa, tiling_t *tiling, bitfile_t *input) * Generate tree using a breadth first traversal */ { - unsigned next; /* next free node number of the tree */ - unsigned state; - unsigned label; - byte_t *buffer = bitstring; /* pointer to decoded data */ + unsigned next; /* next free node number of the tree */ + unsigned state; + unsigned label; + byte_t *buffer = bitstring; /* pointer to decoded data */ bfo_tree = Calloc (wfa->states * MAXLABELS, sizeof (word_t)); for (state = 0, next = 1; state < next; state++) - for (label = 0; label < MAXLABELS; label++) - bfo_tree [state][label] = *buffer++ ? next++ : RANGE; + for (label = 0; label < MAXLABELS; label++) + bfo_tree [state][label] = *buffer++ ? next++ : RANGE; } /* @@ -98,9 +98,9 @@ read_tree (wfa_t *wfa, tiling_t *tiling, bitfile_t *input) unsigned dst_state = wfa->basis_states; wfa->root_state - = restore_depth_first_order (0, (wfa->wfainfo->level - + (wfa->wfainfo->color ? 2 : 0)), - 0, 0, &dst_state, bfo_tree, wfa, tiling); + = restore_depth_first_order (0, (wfa->wfainfo->level + + (wfa->wfainfo->color ? 2 : 0)), + 0, 0, &dst_state, bfo_tree, wfa, tiling); } Free (bitstring); @@ -109,15 +109,15 @@ read_tree (wfa_t *wfa, tiling_t *tiling, bitfile_t *input) /***************************************************************************** - private code + private code *****************************************************************************/ static unsigned restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, - unsigned y, unsigned *dst_state, - word_t (*bfo_tree)[MAXLABELS], - wfa_t *wfa, tiling_t *tiling) + unsigned y, unsigned *dst_state, + word_t (*bfo_tree)[MAXLABELS], + wfa_t *wfa, tiling_t *tiling) /* * Map state 'src_state' (breadth first order) * to state '*dst_state' (depth first order) @@ -127,17 +127,17 @@ restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, * of size 'image_level'. 'tiling' defines the image partitioning. * * Return value: - * new node number in depth first order + * new node number in depth first order * * Side effects: - * 'wfa->tree', 'wfa->x', 'wfa->y', 'wfa->level_of_state' + * 'wfa->tree', 'wfa->x', 'wfa->y', 'wfa->level_of_state' * are filled with decoded values. */ { - unsigned newx [MAXLABELS]; /* x coordinate of children */ - unsigned newy [MAXLABELS]; /* y coordinate of children */ - unsigned x0, y0; /* NW corner of image tile */ - unsigned width, height; /* size of image tile */ + unsigned newx [MAXLABELS]; /* x coordinate of children */ + unsigned newy [MAXLABELS]; /* y coordinate of children */ + unsigned x0, y0; /* NW corner of image tile */ + unsigned width, height; /* size of image tile */ /* * If tiling is performed then replace current coordinates @@ -148,14 +148,14 @@ restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, for (tile = 0; tile < 1U << tiling->exponent; tile++) { - locate_subimage (wfa->wfainfo->level, level, tile, - &x0, &y0, &width, &height); - if (x0 == x && y0 == y) /* matched ! */ - { - locate_subimage (wfa->wfainfo->level, level, tiling->vorder[tile], - &x, &y, &width, &height); - break; - } + locate_subimage (wfa->wfainfo->level, level, tile, + &x0, &y0, &width, &height); + if (x0 == x && y0 == y) /* matched ! */ + { + locate_subimage (wfa->wfainfo->level, level, tiling->vorder[tile], + &x, &y, &width, &height); + break; + } } } /* @@ -175,24 +175,24 @@ restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, * Remap node numbers */ { - int child [MAXLABELS]; /* children of current node (state) */ - int domain; /* current domain */ + int child [MAXLABELS]; /* children of current node (state) */ + int domain; /* current domain */ unsigned label; for (label = 0; label < MAXLABELS; label++) - if (!isrange (domain = bfo_tree [src_state][label])) - child [label] = restore_depth_first_order (domain, level - 1, - newx [label], - newy [label], dst_state, - bfo_tree, wfa, tiling); - else - child [label] = RANGE; + if (!isrange (domain = bfo_tree [src_state][label])) + child [label] = restore_depth_first_order (domain, level - 1, + newx [label], + newy [label], dst_state, + bfo_tree, wfa, tiling); + else + child [label] = RANGE; for (label = 0; label < MAXLABELS; label++) { - wfa->tree [*dst_state][label] = child [label]; - wfa->x [*dst_state][label] = newx [label]; - wfa->y [*dst_state][label] = newy [label]; + wfa->tree [*dst_state][label] = child [label]; + wfa->x [*dst_state][label] = newx [label]; + wfa->y [*dst_state][label] = newy [label]; } wfa->level_of_state [*dst_state] = level; } @@ -208,26 +208,26 @@ restore_depth_first_order (unsigned src_state, unsigned level, unsigned x, static void decode_tree (bitfile_t *input, byte_t *data, unsigned n_data, unsigned scaling, - u_word_t sum0, u_word_t sum1) + u_word_t sum0, u_word_t sum1) /* * Decode bintree partitioning using adaptive binary arithmetic decoding. - * 'input' input stream, - * 'data' buffer for decoded szmbols, - * 'n_data' number of symbols to decode, - * 'scaling' rescale probability models if range > 'scaling' - * 'sum0' initial totals of symbol '0' - * 'sum1' initial totals of symbol '1' + * 'input' input stream, + * 'data' buffer for decoded szmbols, + * 'n_data' number of symbols to decode, + * 'scaling' rescale probability models if range > 'scaling' + * 'sum0' initial totals of symbol '0' + * 'sum1' initial totals of symbol '1' * * No return value. * * Side effects: - * 'data []' is filled with the decoded bitstring + * 'data []' is filled with the decoded bitstring */ { - u_word_t code; /* The present input code value */ - u_word_t low; /* Start of the current code range */ - u_word_t high; /* End of the current code range */ - unsigned n; /* Data counter */ + u_word_t code; /* The present input code value */ + u_word_t low; /* Start of the current code range */ + u_word_t high; /* End of the current code range */ + unsigned n; /* Data counter */ assert (data); @@ -237,64 +237,64 @@ decode_tree (bitfile_t *input, byte_t *data, unsigned n_data, unsigned scaling, for (n = n_data; n; n--) { - unsigned count; /* Current interval count */ - unsigned range; /* Current interval range */ + unsigned count; /* Current interval count */ + unsigned range; /* Current interval range */ count = (((code - low) + 1) * sum1 - 1) / ((high - low) + 1); if (count < sum0) { - /* - * Decode a '0' symbol - * First, the range is expanded to account for the symbol removal. - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum0) / sum1 - 1 ); - - RESCALE_INPUT_INTERVAL; - - *data++ = 0; - /* - * Update the frequency counts - */ - sum0++; - sum1++; - if (sum1 > scaling) /* scale the symbol frequencies */ - { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; - } + /* + * Decode a '0' symbol + * First, the range is expanded to account for the symbol removal. + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum0) / sum1 - 1 ); + + RESCALE_INPUT_INTERVAL; + + *data++ = 0; + /* + * Update the frequency counts + */ + sum0++; + sum1++; + if (sum1 > scaling) /* scale the symbol frequencies */ + { + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; + } } else { - /* - * Decode a '1' symbol - * First, the range is expanded to account for the symbol removal. - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum1) / sum1 - 1); - low = low + (u_word_t) ((range * sum0) / sum1); - - RESCALE_INPUT_INTERVAL; - - *data++ = 1; - /* - * Update the frequency counts - */ - sum1++; - if (sum1 > scaling) /* scale the symbol frequencies */ - { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; - } + /* + * Decode a '1' symbol + * First, the range is expanded to account for the symbol removal. + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum1) / sum1 - 1); + low = low + (u_word_t) ((range * sum0) / sum1); + + RESCALE_INPUT_INTERVAL; + + *data++ = 1; + /* + * Update the frequency counts + */ + sum1++; + if (sum1 > scaling) /* scale the symbol frequencies */ + { + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; + } } } INPUT_BYTE_ALIGN (input); diff --git a/converter/other/fiasco/input/tree.h b/converter/other/fiasco/input/tree.h index f743ee98..31b73fa5 100644 --- a/converter/other/fiasco/input/tree.h +++ b/converter/other/fiasco/input/tree.h @@ -1,8 +1,8 @@ /* * tree.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/input/weights.c b/converter/other/fiasco/input/weights.c index 8a1e8899..debf38ad 100644 --- a/converter/other/fiasco/input/weights.c +++ b/converter/other/fiasco/input/weights.c @@ -2,7 +2,7 @@ * weights.c: Input of weights * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -32,7 +32,7 @@ /***************************************************************************** public code - + *****************************************************************************/ void @@ -55,7 +55,7 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input) unsigned offset1, offset2; /* prob. model offsets. */ unsigned offset3, offset4; /* prob. model offsets. */ bool_t delta_approx = NO; /* true if delta has been used */ - + /* * Check whether delta approximation has been used */ @@ -65,7 +65,7 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input) delta_approx = YES; break; } - + /* * Generate array of corresponding levels (context of probability model) */ @@ -82,7 +82,7 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input) min_level = d_min_level = MAXLEVEL; max_level = d_max_level = 0; dc = d_dc = NO; - + for (state = wfa->basis_states; state < wfa->states; state++) for (label = 0; label < MAXLABELS; label++) if (isrange (wfa->tree [state][label])) @@ -156,7 +156,7 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input) c_symbols [i] = 1 << (wfa->wfainfo->rpf->mantissa_bits + 1); for (; i < offset4; i++) c_symbols [i] = 1 << (wfa->wfainfo->d_rpf->mantissa_bits + 1); - + weights_array = decode_array (input, level_array, c_symbols, offset4, total, scale); Free (c_symbols); @@ -198,7 +198,7 @@ read_weights (unsigned total, wfa_t *wfa, bitfile_t *input) = wfa->weight [state][label][edge] * 512 + 0.5; } } - + Free (weights_array); } - + diff --git a/converter/other/fiasco/input/weights.h b/converter/other/fiasco/input/weights.h index 36cea5c2..4a6bdf0a 100644 --- a/converter/other/fiasco/input/weights.h +++ b/converter/other/fiasco/input/weights.h @@ -1,8 +1,8 @@ /* * weights.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * 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.c b/converter/other/fiasco/lib/arith.c index e61e753e..7fac0c6d 100644 --- a/converter/other/fiasco/lib/arith.c +++ b/converter/other/fiasco/lib/arith.c @@ -1,7 +1,7 @@ /* - * arith.c: Adaptive arithmetic coding and decoding + * arith.c: Adaptive arithmetic coding and decoding * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -26,7 +26,7 @@ /****************************************************************************** - public code + public code ******************************************************************************/ @@ -37,7 +37,7 @@ alloc_encoder (bitfile_t *output) * Initialize the arithmetic coder. * * Return value: - * A pointer to the new coder structure + * A pointer to the new coder structure */ { arith_t *arith = Calloc (1, sizeof (arith_t)); @@ -47,7 +47,7 @@ alloc_encoder (bitfile_t *output) arith->low = LOW; arith->high = HIGH; arith->underflow = 0; - arith->file = output; + arith->file = output; return arith; } @@ -62,9 +62,9 @@ free_encoder (arith_t *arith) * No return value. */ { - u_word_t low; /* start of the current code range */ - u_word_t high; /* end of the current code range */ - u_word_t underflow; /* number of underflow bits pending */ + u_word_t low; /* start of the current code range */ + u_word_t high; /* end of the current code range */ + u_word_t underflow; /* number of underflow bits pending */ bitfile_t *output; assert (arith); @@ -94,22 +94,22 @@ encode_symbol (unsigned symbol, arith_t *arith, model_t *model) * symbol counts are rescaled). * * Return value: - * information content of the encoded symbol. + * information content of the encoded symbol. * * Side effects: - * 'model' is updated (probability distribution) - * 'arith' is updated (coder state) + * 'model' is updated (probability distribution) + * 'arith' is updated (coder state) */ { - u_word_t low_count; /* lower bound of 'symbol' interval */ - u_word_t high_count; /* upper bound of 'symbol' interval */ - u_word_t scale; /* range of all 'm' symbol intervals */ - unsigned range; /* range of current interval */ - unsigned index; /* index of probability model */ - u_word_t low; /* start of the current code range */ - u_word_t high; /* end of the current code range */ - u_word_t underflow; /* number of underflow bits pending */ - bitfile_t *output; /* output file */ + u_word_t low_count; /* lower bound of 'symbol' interval */ + u_word_t high_count; /* upper bound of 'symbol' interval */ + u_word_t scale; /* range of all 'm' symbol intervals */ + unsigned range; /* range of current interval */ + unsigned index; /* index of probability model */ + u_word_t low; /* start of the current code range */ + u_word_t high; /* end of the current code range */ + u_word_t underflow; /* number of underflow bits pending */ + bitfile_t *output; /* output file */ assert (model && arith); @@ -123,28 +123,28 @@ encode_symbol (unsigned symbol, arith_t *arith, model_t *model) assert (high > low); - if (model->order > 0) /* order-'n' model*/ + if (model->order > 0) /* order-'n' model*/ { - unsigned power; /* multiplicator */ + unsigned power; /* multiplicator */ unsigned i; /* * Compute index of the probability model to use. * See init_model() for more details. */ - power = 1; /* multiplicator */ - index = 0; /* address of prob. model */ + power = 1; /* multiplicator */ + index = 0; /* address of prob. model */ for (i = 0; i < model->order; i++) /* generate a M-nary number */ { - index += model->context [i] * power; - power *= model->symbols; + index += model->context [i] * power; + power *= model->symbols; } - index *= model->symbols + 1; /* we need space for M + 1 elements */ + index *= model->symbols + 1; /* we need space for M + 1 elements */ for (i = 0; i < model->order - 1; i++) - model->context [i] = model->context [i + 1]; + model->context [i] = model->context [i + 1]; model->context [i] = symbol; } else @@ -163,7 +163,7 @@ encode_symbol (unsigned symbol, arith_t *arith, model_t *model) RESCALE_OUTPUT_INTERVAL; - if (model->scale > 0) /* adaptive model */ + if (model->scale > 0) /* adaptive model */ { unsigned i; @@ -171,23 +171,23 @@ encode_symbol (unsigned symbol, arith_t *arith, model_t *model) * Update probability model */ for (i = symbol + 1; i <= model->symbols; i++) - model->totals [index + i]++; + model->totals [index + i]++; if (model->totals [index + model->symbols] > model->scale) /* scaling */ { - for (i = 1; i <= model->symbols; i++) - { - model->totals [index + i] >>= 1; - if (model->totals [index + i] <= model->totals [index + i - 1]) - model->totals [index + i] = model->totals [index + i - 1] + 1; - } + for (i = 1; i <= model->symbols; i++) + { + model->totals [index + i] >>= 1; + if (model->totals [index + i] <= model->totals [index + i - 1]) + model->totals [index + i] = model->totals [index + i - 1] + 1; + } } } /* * Store interval values */ - arith->low = low; - arith->high = high; + arith->low = low; + arith->high = high; arith->underflow = underflow; return - log2 ((high_count - low_count) / (real_t) scale); @@ -195,8 +195,8 @@ encode_symbol (unsigned symbol, arith_t *arith, model_t *model) void encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, - const unsigned *c_symbols, unsigned n_context, unsigned n_data, - unsigned scaling) + const unsigned *c_symbols, unsigned n_context, unsigned n_data, + unsigned scaling) /* * Arithmetic coding of #'n_data' symbols given in the array 'data'. * If 'n_context' > 1 then a number (context [n]) is assigned to every @@ -207,10 +207,10 @@ encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, * No return value. */ { - u_word_t **totals; /* probability model */ + u_word_t **totals; /* probability model */ if (!n_context) - n_context = 1; /* always use one context */ + n_context = 1; /* always use one context */ assert (output && c_symbols && data); assert (n_context == 1 || context); @@ -224,13 +224,13 @@ encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, for (c = 0; c < n_context; c++) { - unsigned i; + unsigned i; - totals [c] = Calloc (c_symbols [c] + 1, sizeof (u_word_t)); - totals [c][0] = 0; + totals [c] = Calloc (c_symbols [c] + 1, sizeof (u_word_t)); + totals [c][0] = 0; - for (i = 0; i < c_symbols [c]; i++) - totals [c][i + 1] = totals [c][i] + 1; + for (i = 0; i < c_symbols [c]; i++) + totals [c][i + 1] = totals [c][i] + 1; } } @@ -238,52 +238,52 @@ encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, * Encode array elements */ { - u_word_t low = 0; /* Start of the current code range */ - u_word_t high = 0xffff; /* End of the current code range */ - u_word_t underflow = 0; /* Number of underflow bits pending */ + u_word_t low = 0; /* Start of the current code range */ + u_word_t high = 0xffff; /* End of the current code range */ + u_word_t underflow = 0; /* Number of underflow bits pending */ unsigned n; for (n = 0; n < n_data; n++) { - u_word_t low_count; /* lower bound of 'symbol' interval */ - u_word_t high_count; /* upper bound of 'symbol' interval */ - u_word_t scale; /* range of all 'm' symbol intervals */ - unsigned range; /* current range */ - int d; /* current data symbol */ - int c; /* context of current data symbol */ - - d = data [n]; - c = n_context > 1 ? context [n] : 0; - - scale = totals [c][c_symbols [c]]; - low_count = totals [c][d]; - high_count = totals [c][d + 1]; - - /* - * Rescale high and low for the new symbol. - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * high_count) / scale - 1); - low = low + (u_word_t) ((range * low_count) / scale); - RESCALE_OUTPUT_INTERVAL; - - /* - * Update probability models - */ - { - unsigned i; - - for (i = d + 1; i < c_symbols [c] + 1; i++) - totals [c][i]++; - - if (totals [c][c_symbols [c]] > scaling) /* scaling */ - for (i = 1; i < c_symbols [c] + 1; i++) - { - totals [c][i] >>= 1; - if (totals [c][i] <= totals [c][i - 1]) - totals [c][i] = totals [c][i - 1] + 1; - } - } + u_word_t low_count; /* lower bound of 'symbol' interval */ + u_word_t high_count; /* upper bound of 'symbol' interval */ + u_word_t scale; /* range of all 'm' symbol intervals */ + unsigned range; /* current range */ + int d; /* current data symbol */ + int c; /* context of current data symbol */ + + d = data [n]; + c = n_context > 1 ? context [n] : 0; + + scale = totals [c][c_symbols [c]]; + low_count = totals [c][d]; + high_count = totals [c][d + 1]; + + /* + * Rescale high and low for the new symbol. + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * high_count) / scale - 1); + low = low + (u_word_t) ((range * low_count) / scale); + RESCALE_OUTPUT_INTERVAL; + + /* + * Update probability models + */ + { + unsigned i; + + for (i = d + 1; i < c_symbols [c] + 1; i++) + totals [c][i]++; + + if (totals [c][c_symbols [c]] > scaling) /* scaling */ + for (i = 1; i < c_symbols [c] + 1; i++) + { + totals [c][i] >>= 1; + if (totals [c][i] <= totals [c][i - 1]) + totals [c][i] = totals [c][i - 1] + 1; + } + } } /* * Flush arithmetic encoder @@ -299,7 +299,7 @@ encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, { unsigned c; for (c = 0; c < n_context; c++) - Free (totals [c]); + Free (totals [c]); Free (totals); } } @@ -312,7 +312,7 @@ alloc_decoder (bitfile_t *input) * 16 input bits from the stream 'input'. * * Return value: - * A pointer to the new decoder structure + * A pointer to the new decoder structure */ { @@ -338,7 +338,7 @@ free_decoder (arith_t *arith) * No return value. * * Side effects: - * structure 'arith' is discarded. + * structure 'arith' is discarded. */ { assert (arith); @@ -357,22 +357,22 @@ decode_symbol (arith_t *arith, model_t *model) * decoding the symbol (if necessary also rescale the symbol counts). * * Return value: - * decoded symbol + * decoded symbol * * Side effects: - * 'model' is updated (probability distribution) - * 'arith' is updated (decoder state) + * 'model' is updated (probability distribution) + * 'arith' is updated (decoder state) */ { - unsigned range; /* range of current interval */ - unsigned count; /* value in the current interval */ - unsigned index; /* index of probability model */ - unsigned symbol; /* decoded symbol */ - u_word_t scale; /* range of all 'm' symbol intervals */ - u_word_t low; /* start of the current code range */ - u_word_t high; /* end of the current code range */ - u_word_t code; /* the present input code value */ - bitfile_t *input; /* input file */ + unsigned range; /* range of current interval */ + unsigned count; /* value in the current interval */ + unsigned index; /* index of probability model */ + unsigned symbol; /* decoded symbol */ + u_word_t scale; /* range of all 'm' symbol intervals */ + u_word_t low; /* start of the current code range */ + u_word_t high; /* end of the current code range */ + u_word_t code; /* the present input code value */ + bitfile_t *input; /* input file */ assert (arith && model); @@ -386,25 +386,25 @@ decode_symbol (arith_t *arith, model_t *model) assert (high > low); - if (model->order > 0) /* order-'n' model */ + if (model->order > 0) /* order-'n' model */ { - unsigned power; /* multiplicator */ + unsigned power; /* multiplicator */ unsigned i; /* * Compute index of the probability model to use. * See init_model() for more details. */ - power = 1; /* multiplicator */ - index = 0; /* address of prob. model */ + power = 1; /* multiplicator */ + index = 0; /* address of prob. model */ for (i = 0; i < model->order; i++) /* generate a m-nary number */ { - index += model->context[i] * power; - power *= model->symbols; + index += model->context[i] * power; + power *= model->symbols; } - index *= model->symbols + 1; /* we need space for m + 1 elements */ + index *= model->symbols + 1; /* we need space for m + 1 elements */ } else index = 0; @@ -414,15 +414,15 @@ decode_symbol (arith_t *arith, model_t *model) count = ((code - low + 1) * scale - 1) / range; for (symbol = model->symbols; count < model->totals [index + symbol]; - symbol--) + symbol--) ; - if (model->order > 0) /* order-'n' model */ + if (model->order > 0) /* order-'n' model */ { unsigned i; for (i = 0; i < model->order - 1; i++) - model->context [i] = model->context [i + 1]; + model->context [i] = model->context [i + 1]; model->context [i] = symbol; } @@ -430,8 +430,8 @@ decode_symbol (arith_t *arith, model_t *model) * Compute interval boundaries */ { - u_word_t low_count; /* lower bound of 'symbol' interval */ - u_word_t high_count; /* upper bound of 'symbol' interval */ + u_word_t low_count; /* lower bound of 'symbol' interval */ + u_word_t high_count; /* upper bound of 'symbol' interval */ low_count = model->totals [index + symbol]; high_count = model->totals [index + symbol + 1]; @@ -441,7 +441,7 @@ decode_symbol (arith_t *arith, model_t *model) RESCALE_INPUT_INTERVAL; - if (model->scale > 0) /* adaptive model */ + if (model->scale > 0) /* adaptive model */ { unsigned i; @@ -449,15 +449,15 @@ decode_symbol (arith_t *arith, model_t *model) * Update probability model */ for (i = symbol + 1; i <= model->symbols; i++) - model->totals [index + i]++; + model->totals [index + i]++; if (model->totals [index + model->symbols] > model->scale) /* scaling */ { - for (i = 1; i <= model->symbols; i++) - { - model->totals [index + i] >>= 1; - if (model->totals [index + i] <= model->totals [index + i - 1]) - model->totals [index + i] = model->totals [index + i - 1] + 1; - } + for (i = 1; i <= model->symbols; i++) + { + model->totals [index + i] >>= 1; + if (model->totals [index + i] <= model->totals [index + i - 1]) + model->totals [index + i] = model->totals [index + i - 1] + 1; + } } } @@ -473,8 +473,8 @@ decode_symbol (arith_t *arith, model_t *model) unsigned * decode_array (bitfile_t *input, const unsigned *context, - const unsigned *c_symbols, unsigned n_context, - unsigned n_data, unsigned scaling) + const unsigned *c_symbols, unsigned n_context, + unsigned n_data, unsigned scaling) /* * Arithmetic decoding of #'n_data' symbols. * If 'n_context' > 1 then a number (context [n]) is assigned to every @@ -483,14 +483,14 @@ decode_array (bitfile_t *input, const unsigned *context, * Rescale probability models if range > 'scaling'. * * Return value: - * pointer to array containing the decoded symbols + * pointer to array containing the decoded symbols */ { - unsigned *data; /* array to store decoded symbols */ - u_word_t **totals; /* probability model */ + unsigned *data; /* array to store decoded symbols */ + u_word_t **totals; /* probability model */ if (n_context < 1) - n_context = 1; /* always use one context */ + n_context = 1; /* always use one context */ assert (input && c_symbols); assert (n_context == 1 || context); @@ -505,13 +505,13 @@ decode_array (bitfile_t *input, const unsigned *context, for (c = 0; c < n_context; c++) { - unsigned i; + unsigned i; - totals [c] = Calloc (c_symbols [c] + 1, sizeof (u_word_t)); - totals [c][0] = 0; + totals [c] = Calloc (c_symbols [c] + 1, sizeof (u_word_t)); + totals [c][0] = 0; - for (i = 0; i < c_symbols [c]; i++) - totals [c][i + 1] = totals [c][i] + 1; + for (i = 0; i < c_symbols [c]; i++) + totals [c][i + 1] = totals [c][i] + 1; } } @@ -520,54 +520,54 @@ decode_array (bitfile_t *input, const unsigned *context, */ { u_word_t code = get_bits (input, 16); /* The present input code value */ - u_word_t low = 0; /* Start of the current code range */ - u_word_t high = 0xffff; /* End of the current code range */ + u_word_t low = 0; /* Start of the current code range */ + u_word_t high = 0xffff; /* End of the current code range */ unsigned n; for (n = 0; n < n_data; n++) { - u_word_t scale; /* range of all 'm' symbol intervals */ - u_word_t low_count; /* lower bound of 'symbol' interval */ - u_word_t high_count; /* upper bound of 'symbol' interval */ - unsigned count; /* value in the current interval */ - unsigned range; /* current interval range */ - unsigned d; /* current data symbol */ - unsigned c; /* context of current data symbol */ - - c = n_context > 1 ? context [n] : 0; - - assert (high > low); - scale = totals [c][c_symbols [c]]; - range = (high - low) + 1; - count = (((code - low) + 1 ) * scale - 1) / range; - - for (d = c_symbols [c]; count < totals [c][d]; d--) /* next symbol */ - ; - low_count = totals [c][d]; - high_count = totals [c][d + 1]; - - high = low + (u_word_t) ((range * high_count) / scale - 1 ); - low = low + (u_word_t) ((range * low_count) / scale ); - RESCALE_INPUT_INTERVAL; - - /* - * Updata probability models - */ - { - unsigned i; - - for (i = d + 1; i < c_symbols [c] + 1; i++) - totals [c][i]++; - - if (totals [c][c_symbols [c]] > scaling) /* scaling */ - for (i = 1; i < c_symbols [c] + 1; i++) - { - totals [c][i] >>= 1; - if (totals [c][i] <= totals [c][i - 1]) - totals [c][i] = totals [c][i - 1] + 1; - } - } - data [n] = d; + u_word_t scale; /* range of all 'm' symbol intervals */ + u_word_t low_count; /* lower bound of 'symbol' interval */ + u_word_t high_count; /* upper bound of 'symbol' interval */ + unsigned count; /* value in the current interval */ + unsigned range; /* current interval range */ + unsigned d; /* current data symbol */ + unsigned c; /* context of current data symbol */ + + c = n_context > 1 ? context [n] : 0; + + assert (high > low); + scale = totals [c][c_symbols [c]]; + range = (high - low) + 1; + count = (((code - low) + 1 ) * scale - 1) / range; + + for (d = c_symbols [c]; count < totals [c][d]; d--) /* next symbol */ + ; + low_count = totals [c][d]; + high_count = totals [c][d + 1]; + + high = low + (u_word_t) ((range * high_count) / scale - 1 ); + low = low + (u_word_t) ((range * low_count) / scale ); + RESCALE_INPUT_INTERVAL; + + /* + * Updata probability models + */ + { + unsigned i; + + for (i = d + 1; i < c_symbols [c] + 1; i++) + totals [c][i]++; + + if (totals [c][c_symbols [c]] > scaling) /* scaling */ + for (i = 1; i < c_symbols [c] + 1; i++) + { + totals [c][i] >>= 1; + if (totals [c][i] <= totals [c][i - 1]) + totals [c][i] = totals [c][i - 1] + 1; + } + } + data [n] = d; } INPUT_BYTE_ALIGN (input); } @@ -579,7 +579,7 @@ decode_array (bitfile_t *input, const unsigned *context, unsigned c; for (c = 0; c < n_context; c++) - Free (totals [c]); + Free (totals [c]); Free (totals); } @@ -599,17 +599,17 @@ alloc_model (unsigned m, unsigned scale, unsigned n, unsigned *totals) * the initial counts. * * Return value: - * a pointer to the new probability model structure. + * a pointer to the new probability model structure. * * Note: We recommend a small size of the alphabet because no escape codes * are used to encode/decode previously unseen symbols. * */ { - model_t *model; /* new probability model */ - unsigned num; /* number of contexts to allocate */ - bool_t cont; /* continue flag */ - bool_t dec; /* next order flag */ + model_t *model; /* new probability model */ + unsigned num; /* number of contexts to allocate */ + bool_t cont; /* continue flag */ + bool_t dec; /* next order flag */ unsigned i; /* @@ -630,56 +630,56 @@ alloc_model (unsigned m, unsigned scale, unsigned n, unsigned *totals) model->totals = Calloc (num * (model->symbols + 1), sizeof (unsigned)); for (i = 0; i < model->order; i++) - model->context[i] = 0; /* start with context 0,0, .. ,0 */ + model->context[i] = 0; /* start with context 0,0, .. ,0 */ cont = YES; - while (cont) /* repeat while context != M ... M */ + while (cont) /* repeat while context != M ... M */ { - int power; /* multiplicator */ - int index; /* index of probability model */ + int power; /* multiplicator */ + int index; /* index of probability model */ /* * There are m^n different contexts: * Let "context_1 context_2 ... context_n symbol" be the current input * stream then the index of the probability model is given by: * index = context_1 * M^0 + context_2 * M^1 + ... + context_n * M^(n-1) */ - power = 1; /* multiplicator */ - index = 0; /* address of prob. model */ + power = 1; /* multiplicator */ + index = 0; /* address of prob. model */ - for (i = 0; i < model->order; i++) /* generate a m-nary number */ + for (i = 0; i < model->order; i++) /* generate a m-nary number */ { - index += model->context[i] * power; - power *= model->symbols; + index += model->context[i] * power; + power *= model->symbols; } - index *= model->symbols + 1; /* size of each model is m + 1 */ + index *= model->symbols + 1; /* size of each model is m + 1 */ - model->totals [index + 0] = 0; /* always zero */ + model->totals [index + 0] = 0; /* always zero */ for (i = 1; i <= model->symbols; i++) /* prob of each symbol is 1/m or - as given in totals */ - model->totals[index + i] = model->totals [index + i - 1] - + (totals ? totals [i - 1] : 1); - - if (model->order == 0) /* order-0 model */ - cont = NO; - else /* try next context */ - for (i = model->order - 1, dec = YES; dec; i--) - { - dec = NO; - model->context[i]++; - if (model->context[i] >= model->symbols) - { - /* change previous context */ - model->context[i] = 0; - if (i > 0) /* there's still a context remaining */ - dec = YES; - else - cont = NO; /* all context models initialized */ - } - } + as given in totals */ + model->totals[index + i] = model->totals [index + i - 1] + + (totals ? totals [i - 1] : 1); + + if (model->order == 0) /* order-0 model */ + cont = NO; + else /* try next context */ + for (i = model->order - 1, dec = YES; dec; i--) + { + dec = NO; + model->context[i]++; + if (model->context[i] >= model->symbols) + { + /* change previous context */ + model->context[i] = 0; + if (i > 0) /* there's still a context remaining */ + dec = YES; + else + cont = NO; /* all context models initialized */ + } + } } for (i = 0; i < model->order; i++) - model->context[i] = 0; /* start with context 0,0, .. ,0 */ + model->context[i] = 0; /* start with context 0,0, .. ,0 */ return model; } @@ -693,13 +693,13 @@ free_model (model_t *model) * No return value. * * Side effects: - * struct 'model' is discarded + * struct 'model' is discarded */ { if (model != NULL) { if (model->context != NULL) - Free (model->context); + Free (model->context); Free (model->totals); Free (model); } diff --git a/converter/other/fiasco/lib/arith.h b/converter/other/fiasco/lib/arith.h index 04297eb5..152dabab 100644 --- a/converter/other/fiasco/lib/arith.h +++ b/converter/other/fiasco/lib/arith.h @@ -20,24 +20,24 @@ typedef struct model { - unsigned symbols; /* number of symbols in the alphabet */ - unsigned scale; /* if totals > scale rescale totals */ - unsigned order; /* order of the probability model */ - unsigned *context; /* context of the model */ - unsigned *totals; /* the totals */ + unsigned symbols; /* number of symbols in the alphabet */ + unsigned scale; /* if totals > scale rescale totals */ + unsigned order; /* order of the probability model */ + unsigned *context; /* context of the model */ + unsigned *totals; /* the totals */ } model_t; typedef struct arith { - u_word_t low; /* start of the current code range */ - u_word_t high; /* end of the current code range */ - u_word_t underflow; /* number of underflow bits pending */ - u_word_t code; /* the present input code value */ - bitfile_t *file; /* I/O stream */ + u_word_t low; /* start of the current code range */ + u_word_t high; /* end of the current code range */ + u_word_t underflow; /* number of underflow bits pending */ + u_word_t code; /* the present input code value */ + bitfile_t *file; /* I/O stream */ } arith_t; enum interval {LOW = 0x0000, FIRST_QUARTER = 0x4000, HALF = 0x8000, - THIRD_QUARTER = 0xc000, HIGH = 0xffff}; + THIRD_QUARTER = 0xc000, HIGH = 0xffff}; arith_t * alloc_encoder (bitfile_t *file); @@ -47,8 +47,8 @@ real_t encode_symbol (unsigned symbol, arith_t *arith, model_t *model); void encode_array (bitfile_t *output, const unsigned *data, const unsigned *context, - const unsigned *c_symbols, unsigned n_context, unsigned n_data, - unsigned scaling); + const unsigned *c_symbols, unsigned n_context, unsigned n_data, + unsigned scaling); arith_t * alloc_decoder (bitfile_t *input); void @@ -57,8 +57,8 @@ unsigned decode_symbol (arith_t *arith, model_t *model); unsigned * decode_array (bitfile_t *input, const unsigned *context, - const unsigned *c_symbols, unsigned n_context, - unsigned n_data, unsigned scaling); + const unsigned *c_symbols, unsigned n_context, + unsigned n_data, unsigned scaling); model_t * alloc_model (unsigned m, unsigned scale, unsigned n, unsigned *totals); void @@ -67,7 +67,7 @@ free_model (model_t *model); #define RESCALE_INPUT_INTERVAL for (;;) \ if ((high >= HALF) && (low < HALF) && \ ((low & FIRST_QUARTER) != FIRST_QUARTER \ - || (high & FIRST_QUARTER) != 0)) \ + || (high & FIRST_QUARTER) != 0)) \ { \ break; \ } \ @@ -88,8 +88,8 @@ free_model (model_t *model); high |= HALF + 1; \ code <<= 1; \ code += get_bit (input); \ - } - + } + #define RESCALE_OUTPUT_INTERVAL for (;;) \ { \ if (high < HALF) \ @@ -116,7 +116,7 @@ free_model (model_t *model); high <<= 1; \ high |= 1; \ low <<= 1; \ - } - + } + #endif /* not _ARITH_H */ diff --git a/converter/other/fiasco/lib/bit-io.h b/converter/other/fiasco/lib/bit-io.h index 08029824..6de7e396 100644 --- a/converter/other/fiasco/lib/bit-io.h +++ b/converter/other/fiasco/lib/bit-io.h @@ -1,7 +1,7 @@ /* * bit-io.h * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -27,14 +27,14 @@ typedef enum {READ_ACCESS, WRITE_ACCESS} openmode_e; typedef struct bitfile { - FILE *file; /* associated filepointer */ - char *filename; /* corresponding filename */ - byte_t *buffer; /* stream buffer */ - byte_t *ptr; /* pointer to current buffer pos */ - unsigned bytepos; /* current I/O byte */ - unsigned bitpos; /* current I/O bit */ - unsigned bits_processed; /* number of bits already processed */ - openmode_e mode; /* access mode */ + FILE *file; /* associated filepointer */ + char *filename; /* corresponding filename */ + byte_t *buffer; /* stream buffer */ + byte_t *ptr; /* pointer to current buffer pos */ + unsigned bytepos; /* current I/O byte */ + unsigned bitpos; /* current I/O bit */ + unsigned bits_processed; /* number of bits already processed */ + openmode_e mode; /* access mode */ } bitfile_t; FILE * @@ -47,7 +47,7 @@ void put_bits (bitfile_t *bitfile, unsigned value, unsigned bits); bool_t get_bit (bitfile_t *bitfile); -unsigned +unsigned get_bits (bitfile_t *bitfile, unsigned bits); void close_bitfile (bitfile_t *bitfile); diff --git a/converter/other/fiasco/lib/dither.c b/converter/other/fiasco/lib/dither.c index 669bb16c..c394f5ec 100644 --- a/converter/other/fiasco/lib/dither.c +++ b/converter/other/fiasco/lib/dither.c @@ -1,8 +1,8 @@ /* - * dither.c: Various dithering routines + * dither.c: Various dithering routines + * + * Adapted by: Ullrich Hafner * - * Adapted by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -10,17 +10,17 @@ /* * Copyright (c) 1995 Erik Corry * All rights reserved. - * + * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. - * + * * IN NO EVENT SHALL ERIK CORRY BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF ERIK CORRY HAS BEEN ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * ERIK CORRY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" @@ -52,25 +52,25 @@ /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ -static int +static int display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image); + const fiasco_image_t *fiasco_image); -static int +static int display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image); + const fiasco_image_t *fiasco_image); -static int +static int display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image); + const fiasco_image_t *fiasco_image); -static int +static int display_32_bit (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image); + const fiasco_image_t *fiasco_image); static int free_bits_at_bottom (unsigned long a); @@ -80,26 +80,26 @@ number_of_bits_set (unsigned long a); /***************************************************************************** - public code - + public code + *****************************************************************************/ fiasco_renderer_t * fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, - unsigned long blue_mask, unsigned bpp, - int double_resolution) + unsigned long blue_mask, unsigned bpp, + int double_resolution) /* * FIASCO renderer constructor. * Allocate memory for the FIASCO renderer structure and * initialize values. * `red_mask', `green_mask', and `blue_mask' are the corresponding masks - * of the X11R6 XImage structure. + * of the X11R6 XImage structure. * `bpp' gives the depth of the image in bits per pixel (16, 24, or 32). * If `double_resolution' is not 0 the the image width and height is doubled. * (fast pixel doubling, no interpolation!) * * Return value: - * pointer to the new structure or NULL on error + * pointer to the new structure or NULL on error */ { if (bpp != 16 && bpp != 24 && bpp !=32) @@ -111,30 +111,30 @@ fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, { fiasco_renderer_t *render = calloc (1, sizeof (fiasco_renderer_t)); renderer_private_t *private = calloc (1, sizeof (renderer_private_t)); - bool_t twopixels = (bpp == 16 && double_resolution); - int crval, cbval, i; /* counter */ + bool_t twopixels = (bpp == 16 && double_resolution); + int crval, cbval, i; /* counter */ if (!render || !private) { - set_error (_("Out of memory.")); - return NULL; + set_error (_("Out of memory.")); + return NULL; } switch (bpp) { - case 16: - render->render = display_16_bit; - break; - case 24: - if (red_mask > green_mask) - render->render = display_24_bit_rgb; - else - render->render = display_24_bit_bgr; - break; - case 32: - render->render = display_32_bit; - break; - default: - break; /* does not happen */ + case 16: + render->render = display_16_bit; + break; + case 24: + if (red_mask > green_mask) + render->render = display_24_bit_rgb; + else + render->render = display_24_bit_bgr; + break; + case 32: + render->render = display_32_bit; + break; + default: + break; /* does not happen */ } render->private = private; render->delete = fiasco_renderer_delete; @@ -146,42 +146,42 @@ fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, private->Cb_b_tab = calloc (256 + 2 * 1024, sizeof (int)); if (!private->Cr_r_tab || !private->Cr_g_tab - || !private->Cb_b_tab || !private->Cb_g_tab) + || !private->Cb_b_tab || !private->Cb_g_tab) { - set_error (_("Out of memory.")); - return NULL; + set_error (_("Out of memory.")); + return NULL; } - + for (i = 1024; i < 1024 + 256; i++) { - cbval = crval = i - 128 - 1024; + cbval = crval = i - 128 - 1024; - private->Cr_r_tab [i] = 1.4022 * crval + 0.5; - private->Cr_g_tab [i] = -0.7145 * crval + 0.5; - private->Cb_g_tab [i] = -0.3456 * cbval + 0.5; - private->Cb_b_tab [i] = 1.7710 * cbval + 0.5; + private->Cr_r_tab [i] = 1.4022 * crval + 0.5; + private->Cr_g_tab [i] = -0.7145 * crval + 0.5; + private->Cb_g_tab [i] = -0.3456 * cbval + 0.5; + private->Cb_b_tab [i] = 1.7710 * cbval + 0.5; } for (i = 0; i < 1024; i++) { - private->Cr_r_tab [i] = private->Cr_r_tab [1024]; - private->Cr_g_tab [i] = private->Cr_g_tab [1024]; - private->Cb_g_tab [i] = private->Cb_g_tab [1024]; - private->Cb_b_tab [i] = private->Cb_b_tab [1024]; + private->Cr_r_tab [i] = private->Cr_r_tab [1024]; + private->Cr_g_tab [i] = private->Cr_g_tab [1024]; + private->Cb_g_tab [i] = private->Cb_g_tab [1024]; + private->Cb_b_tab [i] = private->Cb_b_tab [1024]; } for (i = 1024 + 256; i < 2048 + 256; i++) { - private->Cr_r_tab [i] = private->Cr_r_tab [1024 + 255]; - private->Cr_g_tab [i] = private->Cr_g_tab [1024 + 255]; - private->Cb_g_tab [i] = private->Cb_g_tab [1024 + 255]; - private->Cb_b_tab [i] = private->Cb_b_tab [1024 + 255]; + private->Cr_r_tab [i] = private->Cr_r_tab [1024 + 255]; + private->Cr_g_tab [i] = private->Cr_g_tab [1024 + 255]; + private->Cb_g_tab [i] = private->Cb_g_tab [1024 + 255]; + private->Cb_b_tab [i] = private->Cb_b_tab [1024 + 255]; } private->Cr_r_tab += 1024 + 128; private->Cr_g_tab += 1024 + 128; private->Cb_g_tab += 1024 + 128; private->Cb_b_tab += 1024 + 128; - - /* + + /* * Set up entries 0-255 in rgb-to-pixel value tables. */ private->r_table = calloc (256 + 2 * 1024, sizeof (unsigned int)); @@ -190,38 +190,38 @@ fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, private->y_table = calloc (256 + 2 * 1024, sizeof (unsigned int)); if (!private->r_table || !private->g_table - || !private->b_table || !private->y_table) + || !private->b_table || !private->y_table) { - set_error (_("Out of memory.")); - return NULL; + set_error (_("Out of memory.")); + return NULL; } - + for (i = 0; i < 256; i++) { - private->r_table [i + 1024] - = i >> (8 - number_of_bits_set(red_mask)); - private->r_table [i + 1024] - <<= free_bits_at_bottom (red_mask); - private->g_table [i + 1024] - = i >> (8 - number_of_bits_set (green_mask)); - private->g_table [i + 1024] - <<= free_bits_at_bottom (green_mask); - private->b_table [i + 1024] - <<= free_bits_at_bottom (blue_mask); - private->b_table [i + 1024] - = i >> (8 - number_of_bits_set (blue_mask)); - if (twopixels) - { - private->r_table [i + 1024] = ((private->r_table [i + 1024] << 16) - | private->r_table [i + 1024]); - private->g_table [i + 1024] = ((private->g_table [i + 1024] << 16) - | private->g_table [i + 1024]); - private->b_table [i + 1024] = ((private->b_table [i + 1024] << 16) - | private->b_table [i + 1024]); - } - private->y_table [i + 1024] = (private->r_table [i + 1024] - | private->g_table [i + 1024] - | private->b_table [i + 1024]); + private->r_table [i + 1024] + = i >> (8 - number_of_bits_set(red_mask)); + private->r_table [i + 1024] + <<= free_bits_at_bottom (red_mask); + private->g_table [i + 1024] + = i >> (8 - number_of_bits_set (green_mask)); + private->g_table [i + 1024] + <<= free_bits_at_bottom (green_mask); + private->b_table [i + 1024] + <<= free_bits_at_bottom (blue_mask); + private->b_table [i + 1024] + = i >> (8 - number_of_bits_set (blue_mask)); + if (twopixels) + { + private->r_table [i + 1024] = ((private->r_table [i + 1024] << 16) + | private->r_table [i + 1024]); + private->g_table [i + 1024] = ((private->g_table [i + 1024] << 16) + | private->g_table [i + 1024]); + private->b_table [i + 1024] = ((private->b_table [i + 1024] << 16) + | private->b_table [i + 1024]); + } + private->y_table [i + 1024] = (private->r_table [i + 1024] + | private->g_table [i + 1024] + | private->b_table [i + 1024]); } /* @@ -230,14 +230,14 @@ fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, */ for (i = 0; i < 1024; i++) { - private->r_table [i] = private->r_table [1024]; - private->r_table [i + 1024 + 256] = private->r_table [1024 + 255]; - private->g_table [i] = private->g_table [1024]; - private->g_table [i + 1024 + 256] = private->g_table [1024 + 255]; - private->b_table [i] = private->b_table [1024]; - private->b_table [i + 1024 + 256] = private->b_table [1024 + 255]; - private->y_table [i] = private->y_table [1024]; - private->y_table [i + 1024 + 256] = private->y_table [1024 + 255]; + private->r_table [i] = private->r_table [1024]; + private->r_table [i + 1024 + 256] = private->r_table [1024 + 255]; + private->g_table [i] = private->g_table [1024]; + private->g_table [i + 1024 + 256] = private->g_table [1024 + 255]; + private->b_table [i] = private->b_table [1024]; + private->b_table [i + 1024 + 256] = private->b_table [1024 + 255]; + private->y_table [i] = private->y_table [1024]; + private->y_table [i + 1024 + 256] = private->y_table [1024 + 255]; } private->r_table += 1024; @@ -247,7 +247,7 @@ fiasco_renderer_new (unsigned long red_mask, unsigned long green_mask, return render; } - + } void @@ -259,7 +259,7 @@ fiasco_renderer_delete (fiasco_renderer_t *renderer) * No return value. * * Side effects: - * structure 'renderer' is discarded. + * structure 'renderer' is discarded. */ { if (!renderer) @@ -284,8 +284,8 @@ fiasco_renderer_delete (fiasco_renderer_t *renderer) int fiasco_renderer_render (const fiasco_renderer_t *renderer, - unsigned char *ximage, - const fiasco_image_t *fiasco_image) + unsigned char *ximage, + const fiasco_image_t *fiasco_image) { if (!renderer) { @@ -298,8 +298,8 @@ fiasco_renderer_render (const fiasco_renderer_t *renderer, /***************************************************************************** - private code - + private code + *****************************************************************************/ /* @@ -313,7 +313,7 @@ fiasco_renderer_render (const fiasco_renderer_t *renderer, * mode, since this involves getting down to byte level again. It is * assumed that the bits for each color are contiguous in the * longword. - * + * * Writing to memory is done in shorts or ints. (Unfortunately, short * is not very fast on Alpha, so there is room for improvement * here). There is no dither time check for overflow - instead the @@ -357,9 +357,9 @@ free_bits_at_bottom (unsigned long a) return 1 + free_bits_at_bottom ( a >> 1); } -static int +static int display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image) + const fiasco_image_t *fiasco_image) /* * Convert 'image' to 16 bit color bitmap. * If 'double_resolution' is true then double image size in both directions. @@ -367,13 +367,13 @@ display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, * No return value. * * Side effects: - * 'out[]' is filled with dithered image + * 'out[]' is filled with dithered image */ { const image_t *image; renderer_private_t *private; - byte_t *out; - + byte_t *out; + if (!this) { set_error (_("Parameter `%s' not defined (NULL)."), "this"); @@ -390,21 +390,21 @@ display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, return 0; } - out = (byte_t *) ximage; + out = (byte_t *) ximage; image = cast_image ((fiasco_image_t *) fiasco_image); if (!image) return 0; private = (renderer_private_t *) this->private; - + if (image->color) { - word_t *cbptr, *crptr; /* pointer to chroma bands */ - word_t *yptr; /* pointers to lumincance band */ - int yval, crval, cbval; /* pixel value in YCbCr color space */ - int R, G, B; /* pixel value in RGB color space */ - int n; /* pixel counter */ - int x, y; /* pixel coordinates */ - int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; + word_t *cbptr, *crptr; /* pointer to chroma bands */ + word_t *yptr; /* pointers to lumincance band */ + int yval, crval, cbval; /* pixel value in YCbCr color space */ + int R, G, B; /* pixel value in RGB color space */ + int n; /* pixel counter */ + int x, y; /* pixel coordinates */ + 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; @@ -420,245 +420,245 @@ display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, if (image->format == FORMAT_4_2_0) { - u_word_t *dst, *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - if (private->double_resolution) - { - yptr2 = yptr + image->width; - dst = (u_word_t *) out; - dst2 = dst + 4 * image->width; - for (y = image->height / 2; y; y--) - { - for (x = image->width / 2; x; x--) - { + u_word_t *dst, *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + if (private->double_resolution) + { + yptr2 = yptr + image->width; + dst = (u_word_t *) out; + dst2 = dst + 4 * image->width; + for (y = image->height / 2; y; y--) + { + for (x = image->width / 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr++ >> 4) + 128; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr++ / 16 + 128; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - } - memcpy (dst, dst - 2 * image->width, - 2 * image->width * sizeof (u_word_t)); - memcpy (dst2, dst2 - 2 * image->width, - 2 * image->width * sizeof (u_word_t)); - yptr += image->width; - yptr2 += image->width; - dst += 3 * image->width * 2; - dst2 += 3 * image->width * 2; - } - } - else - { - yptr2 = yptr + image->width; - dst = (u_word_t *) out; - dst2 = dst + image->width; - - for (y = image->height / 2; y; y--) - { - for (x = image->width / 2; x; x--) - { + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + } + memcpy (dst, dst - 2 * image->width, + 2 * image->width * sizeof (u_word_t)); + memcpy (dst2, dst2 - 2 * image->width, + 2 * image->width * sizeof (u_word_t)); + yptr += image->width; + yptr2 += image->width; + dst += 3 * image->width * 2; + dst2 += 3 * image->width * 2; + } + } + else + { + yptr2 = yptr + image->width; + dst = (u_word_t *) out; + dst2 = dst + image->width; + + for (y = image->height / 2; y; y--) + { + for (x = image->width / 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr++ >> 4) + 128; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr++ / 16 + 128; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - } - yptr += image->width; - yptr2 += image->width; - dst += image->width; - dst2 += image->width; - } - } + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + } + yptr += image->width; + yptr2 += image->width; + dst += image->width; + dst2 += image->width; + } + } } - else /* 4:4:4 format */ + else /* 4:4:4 format */ { - if (private->double_resolution) - { - unsigned int *dst; /* pointer to dithered pixels */ - - dst = (unsigned int *) out; - - for (y = image->height; y; y--) - { - for (x = image->width; x; x--) - { + if (private->double_resolution) + { + unsigned int *dst; /* pointer to dithered pixels */ + + dst = (unsigned int *) out; + + for (y = image->height; y; y--) + { + for (x = image->width; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - - *dst++ = r_table [R] | g_table [G] | b_table [B]; - } - memcpy (dst, dst - image->width, - image->width * sizeof (unsigned int)); - dst += image->width; - } - } - else - { - u_word_t *dst; /* pointer to dithered pixels */ - - dst = (u_word_t *) out; - - for (n = image->width * image->height; n; n--) - { + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + + *dst++ = r_table [R] | g_table [G] | b_table [B]; + } + memcpy (dst, dst - image->width, + image->width * sizeof (unsigned int)); + dst += image->width; + } + } + else + { + u_word_t *dst; /* pointer to dithered pixels */ + + dst = (u_word_t *) out; + + for (n = image->width * image->height; n; n--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - } - } + *dst++ = r_table [R] | g_table [G] | b_table [B]; + } + } } } else { - unsigned int *dst; /* pointer to dithered pixels */ - word_t *src; /* current pixel of frame */ + 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]; - + if (private->double_resolution) { - int x, y; /* pixel coordinates */ - - for (y = image->height; y; y--) - { - for (x = image->width; x; x--) - { - int value; - + int x, y; /* pixel coordinates */ + + for (y = image->height; y; y--) + { + for (x = image->width; x; x--) + { + int value; + #ifdef HAVE_SIGNED_SHIFT - value = y_table [*src++ >> 4]; + value = y_table [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - value = y_table [*src++ / 16]; + value = y_table [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = (value << 16) | value; - } - - memcpy (dst, dst - image->width, - image->width * sizeof (unsigned int)); - dst += image->width; - } + *dst++ = (value << 16) | value; + } + + memcpy (dst, dst - image->width, + image->width * sizeof (unsigned int)); + dst += image->width; + } } else { - int n; /* pixel counter */ - - for (n = image->width * image->height / 2; n; n--, src += 2) + int n; /* pixel counter */ + + for (n = image->width * image->height / 2; n; n--, src += 2) #ifdef HAVE_SIGNED_SHIFT -# if BYTE_ORDER == LITTLE_ENDIAN - *dst++ = (y_table [src [1] >> 4] << 16) | y_table [src [0] >> 4]; -# else - *dst++ = (y_table [src [0] >> 4] << 16) | y_table [src [1] >> 4]; -# endif +# if BYTE_ORDER == LITTLE_ENDIAN + *dst++ = (y_table [src [1] >> 4] << 16) | y_table [src [0] >> 4]; +# else + *dst++ = (y_table [src [0] >> 4] << 16) | y_table [src [1] >> 4]; +# endif #else /* not HAVE_SIGNED_SHIFT */ -# if BYTE_ORDER == LITTLE_ENDIAN - *dst++ = (y_table [src [1] / 16] << 16) | y_table [src [0] / 16]; -# else - *dst++ = (y_table [src [0] / 16] << 16) | y_table [src [1] / 16]; -# endif +# if BYTE_ORDER == LITTLE_ENDIAN + *dst++ = (y_table [src [1] / 16] << 16) | y_table [src [0] / 16]; +# else + *dst++ = (y_table [src [0] / 16] << 16) | y_table [src [1] / 16]; +# endif #endif /* not HAVE_SIGNED_SHIFT */ } } @@ -666,9 +666,9 @@ display_16_bit (const struct fiasco_renderer *this, unsigned char *ximage, return 1; } -static int +static int display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image) + const fiasco_image_t *fiasco_image) /* * Convert 'image' to 16 bit color bitmap. * If 'double_resolution' is true then double image size in both directions. @@ -676,13 +676,13 @@ display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, * No return value. * * Side effects: - * 'out[]' is filled with dithered image + * 'out[]' is filled with dithered image */ { - unsigned *gray_clip = init_clipping (); + unsigned *gray_clip = init_clipping (); const image_t *image; renderer_private_t *private; - byte_t *out; + byte_t *out; if (!gray_clip) return 0; @@ -702,17 +702,17 @@ display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, return 0; } - out = (byte_t *) ximage; + out = (byte_t *) ximage; image = cast_image ((fiasco_image_t *) fiasco_image); if (!image) return 0; private = (renderer_private_t *) this->private; - + if (image->color) { - 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; + 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; Cr_g_tab = private->Cr_g_tab; Cr_r_tab = private->Cr_r_tab; @@ -724,396 +724,396 @@ display_24_bit_bgr (const struct fiasco_renderer *this, unsigned char *ximage, if (image->format == FORMAT_4_2_0) { - if (private->double_resolution) - { - int yval1; /* lumincance pixel */ - int crval1, cbval1; /* chroma pixels */ - int yval2; /* pixel in YCbCr color space */ - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* pointer to dithered pixels */ - unsigned int *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - dst = (unsigned int *) out; - dst2 = dst + (image->width >> 1) * 3 * 2; - yptr2 = yptr + image->width; - - for (y = image->height >> 1; y; y--) - { - for (x = image->width >> 1; x; x--) - { + if (private->double_resolution) + { + int yval1; /* lumincance pixel */ + int crval1, cbval1; /* chroma pixels */ + int yval2; /* pixel in YCbCr color space */ + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* pointer to dithered pixels */ + unsigned int *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + dst = (unsigned int *) out; + dst2 = dst + (image->width >> 1) * 3 * 2; + yptr2 = yptr + image->width; + + for (y = image->height >> 1; y; y--) + { + for (x = image->width >> 1; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); - *dst++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); - *dst++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); + *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); + *dst++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); + *dst++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); - *dst2++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); - *dst2++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); - } - memcpy (dst, dst - (image->width >> 1) * 3, - (image->width >> 1) * 3 * sizeof (unsigned int)); - memcpy (dst2, dst2 - (image->width >> 1) * 3, - (image->width >> 1) * 3 * sizeof (unsigned int)); - dst += (image->width >> 1) * 3 * 3; - dst2 += (image->width >> 1) * 3 * 3; - yptr += image->width; - yptr2 += image->width; - } - } - else - { - int yval1; /* lumincance pixel */ - int crval1, cbval1; /* chroma pixels */ - int yval2; /* pixel in YCbCr color space */ - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* pointer to dithered pixels */ - unsigned int *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - dst = (unsigned int *) out; - dst2 = dst + (image->width >> 2) * 3; - yptr2 = yptr + image->width; - - for (y = image->height >> 1; y; y--) - { - for (x = image->width >> 2; x; x--) - { + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); + *dst2++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); + *dst2++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); + } + memcpy (dst, dst - (image->width >> 1) * 3, + (image->width >> 1) * 3 * sizeof (unsigned int)); + memcpy (dst2, dst2 - (image->width >> 1) * 3, + (image->width >> 1) * 3 * sizeof (unsigned int)); + dst += (image->width >> 1) * 3 * 3; + dst2 += (image->width >> 1) * 3 * 3; + yptr += image->width; + yptr2 += image->width; + } + } + else + { + int yval1; /* lumincance pixel */ + int crval1, cbval1; /* chroma pixels */ + int yval2; /* pixel in YCbCr color space */ + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* pointer to dithered pixels */ + unsigned int *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + dst = (unsigned int *) out; + dst2 = dst + (image->width >> 2) * 3; + yptr2 = yptr + image->width; + + for (y = image->height >> 1; y; y--) + { + for (x = image->width >> 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); - *dst = G2 | (R2 << 8); + *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); + *dst = G2 | (R2 << 8); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); - *dst2 = G2 | (R2 << 8); - + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); + *dst2 = G2 | (R2 << 8); + #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ |= (B1 << 16) | (G1 << 24); - *dst++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); + *dst++ |= (B1 << 16) | (G1 << 24); + *dst++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ |= (B1 << 16) | (G1 << 24); - *dst2++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); - } - dst += (image->width >> 2) * 3; - dst2 += (image->width >> 2) * 3; - yptr += image->width; - yptr2 += image->width; - } - } + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ |= (B1 << 16) | (G1 << 24); + *dst2++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); + } + dst += (image->width >> 2) * 3; + dst2 += (image->width >> 2) * 3; + yptr += image->width; + yptr2 += image->width; + } + } } - else /* 4:4:4 format */ + else /* 4:4:4 format */ { - if (private->double_resolution) - { - unsigned int R1, G1, B1; /* pixel1 in RGB color space */ - unsigned int R2, G2, B2; /* pixel2 in RGB color space */ - int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ - int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* dithered pixel pointer */ - - dst = (unsigned int *) out; - - for (y = image->height; y; y--) - { - for (x = image->width >> 1; x; x--) - { + if (private->double_resolution) + { + unsigned int R1, G1, B1; /* pixel1 in RGB color space */ + unsigned int R2, G2, B2; /* pixel2 in RGB color space */ + int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ + int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* dithered pixel pointer */ + + dst = (unsigned int *) out; + + for (y = image->height; y; y--) + { + for (x = image->width >> 1; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] - + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - - *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); - *dst++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); - *dst++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); - } - memcpy (dst, dst - 3 * (image->width >> 1), - 3 * (image->width >> 1) * sizeof (unsigned int)); - dst += 3 * (image->width >> 1); - } - } - else - { - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ - int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ - int n; /* pixel counter */ - unsigned int *dst; /* dithered pixel pointer */ - - dst = (unsigned int *) out; - - for (n = (image->width * image->height) >> 2; n; n--) - { + + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + + *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B1 << 24); + *dst++ = G1 | (R1 << 8) | (B2 << 16) | (G2 << 24); + *dst++ = R2 | (B2 << 8) | (G2 << 16) | (R2 << 24); + } + memcpy (dst, dst - 3 * (image->width >> 1), + 3 * (image->width >> 1) * sizeof (unsigned int)); + dst += 3 * (image->width >> 1); + } + } + else + { + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ + int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ + int n; /* pixel counter */ + unsigned int *dst; /* dithered pixel pointer */ + + dst = (unsigned int *) out; + + for (n = (image->width * image->height) >> 2; n; n--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); - *dst = G2 | (R2 << 8); + *dst++ = B1 | (G1 << 8) | (R1 << 16) | (B2 << 24); + *dst = G2 | (R2 << 8); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - - *dst++ |= (B1 << 16) | (G1 << 24); - *dst++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); - } - } + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + + *dst++ |= (B1 << 16) | (G1 << 24); + *dst++ = R1 | (B2 << 8) | (G2 << 16) | (R2 << 24); + } + } } } else { - unsigned int *dst; /* pointer to dithered pixels */ - word_t *src; /* current pixel of frame */ + unsigned int *dst; /* pointer to dithered pixels */ + word_t *src; /* current pixel of frame */ dst = (unsigned int *) out; src = image->pixels [GRAY]; if (private->double_resolution) { - int x, y; /* pixel counter */ - unsigned *shift_clipping = gray_clip + 128; - - for (y = image->height; y; y--) - { - for (x = image->width >> 1; x; x--) - { - unsigned int val1, val2; + int x, y; /* pixel counter */ + unsigned *shift_clipping = gray_clip + 128; + + for (y = image->height; y; y--) + { + for (x = image->width >> 1; x; x--) + { + unsigned int val1, val2; #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = val1 | (val1 << 8) | (val1 << 16) | (val1 << 24); - *dst++ = val1 | (val1 << 8) | (val2 << 16) | (val2 << 24); - *dst++ = val2 | (val2 << 8) | (val2 << 16) | (val2 << 24); - } + *dst++ = val1 | (val1 << 8) | (val1 << 16) | (val1 << 24); + *dst++ = val1 | (val1 << 8) | (val2 << 16) | (val2 << 24); + *dst++ = val2 | (val2 << 8) | (val2 << 16) | (val2 << 24); + } - memcpy (dst, dst - 3 * (image->width >> 1), - 3 * (image->width >> 1) * sizeof (unsigned int)); - dst += 3 * (image->width >> 1); - } + memcpy (dst, dst - 3 * (image->width >> 1), + 3 * (image->width >> 1) * sizeof (unsigned int)); + dst += 3 * (image->width >> 1); + } } else { - int n; /* pixel counter */ - unsigned *shift_clipping = gray_clip + 128; + int n; /* pixel counter */ + unsigned *shift_clipping = gray_clip + 128; - for (n = (image->width * image->height) >> 2; n; n--) - { - unsigned int val1, val2; + for (n = (image->width * image->height) >> 2; n; n--) + { + unsigned int val1, val2; #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = val1 | (val1 << 8) - | (val1 << 16) | (val2 << 24); /* RGBR */ - *dst = val2 | (val2 << 8); /* GB-- */ + *dst++ = val1 | (val1 << 8) + | (val1 << 16) | (val2 << 24); /* RGBR */ + *dst = val2 | (val2 << 8); /* GB-- */ #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - - *dst++ |= (val1 << 16) | (val1 << 24); /* --RG */ - *dst++ = val1 | (val2 << 8) - | (val2 << 16) | (val2 << 24); /* BRGB */ - } + + *dst++ |= (val1 << 16) | (val1 << 24); /* --RG */ + *dst++ = val1 | (val2 << 8) + | (val2 << 16) | (val2 << 24); /* BRGB */ + } } } - + return 1; } -static int +static int display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image) + const fiasco_image_t *fiasco_image) /* * Convert 'image' to 16 bit color bitmap. * If 'double_resolution' is true then double image size in both directions. @@ -1121,13 +1121,13 @@ display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, * No return value. * * Side effects: - * 'out[]' is filled with dithered image + * 'out[]' is filled with dithered image */ { - unsigned *gray_clip = init_clipping (); + unsigned *gray_clip = init_clipping (); const image_t *image; renderer_private_t *private; - byte_t *out; + byte_t *out; if (!gray_clip) return 0; @@ -1147,17 +1147,17 @@ display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, return 0; } - out = (byte_t *) ximage; + out = (byte_t *) ximage; image = cast_image ((fiasco_image_t *) fiasco_image); if (!image) return 0; private = (renderer_private_t *) this->private; - + if (image->color) { - 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; + 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; Cr_g_tab = private->Cr_g_tab; Cr_r_tab = private->Cr_r_tab; @@ -1169,396 +1169,396 @@ display_24_bit_rgb (const struct fiasco_renderer *this, unsigned char *ximage, if (image->format == FORMAT_4_2_0) { - if (private->double_resolution) - { - int yval1; /* lumincance pixel */ - int crval1, cbval1; /* chroma pixels */ - int yval2; /* pixel in YCbCr color space */ - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* pointer to dithered pixels */ - unsigned int *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - dst = (unsigned int *) out; - dst2 = dst + (image->width >> 1) * 3 * 2; - yptr2 = yptr + image->width; - - for (y = image->height >> 1; y; y--) - { - for (x = image->width >> 1; x; x--) - { + if (private->double_resolution) + { + int yval1; /* lumincance pixel */ + int crval1, cbval1; /* chroma pixels */ + int yval2; /* pixel in YCbCr color space */ + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* pointer to dithered pixels */ + unsigned int *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + dst = (unsigned int *) out; + dst2 = dst + (image->width >> 1) * 3 * 2; + yptr2 = yptr + image->width; + + for (y = image->height >> 1; y; y--) + { + for (x = image->width >> 1; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); - *dst++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); - *dst++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); + *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); + *dst++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); + *dst++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); - *dst2++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); - *dst2++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); - } - memcpy (dst, dst - (image->width >> 1) * 3, - (image->width >> 1) * 3 * sizeof (unsigned int)); - memcpy (dst2, dst2 - (image->width >> 1) * 3, - (image->width >> 1) * 3 * sizeof (unsigned int)); - dst += (image->width >> 1) * 3 * 3; - dst2 += (image->width >> 1) * 3 * 3; - yptr += image->width; - yptr2 += image->width; - } - } - else - { - int yval1; /* lumincance pixel */ - int crval1, cbval1; /* chroma pixels */ - int yval2; /* pixel in YCbCr color space */ - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* pointer to dithered pixels */ - unsigned int *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - dst = (unsigned int *) out; - dst2 = dst + (image->width >> 2) * 3; - yptr2 = yptr + image->width; - - for (y = image->height >> 1; y; y--) - { - for (x = image->width >> 2; x; x--) - { + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); + *dst2++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); + *dst2++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); + } + memcpy (dst, dst - (image->width >> 1) * 3, + (image->width >> 1) * 3 * sizeof (unsigned int)); + memcpy (dst2, dst2 - (image->width >> 1) * 3, + (image->width >> 1) * 3 * sizeof (unsigned int)); + dst += (image->width >> 1) * 3 * 3; + dst2 += (image->width >> 1) * 3 * 3; + yptr += image->width; + yptr2 += image->width; + } + } + else + { + int yval1; /* lumincance pixel */ + int crval1, cbval1; /* chroma pixels */ + int yval2; /* pixel in YCbCr color space */ + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* pointer to dithered pixels */ + unsigned int *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + dst = (unsigned int *) out; + dst2 = dst + (image->width >> 2) * 3; + yptr2 = yptr + image->width; + + for (y = image->height >> 1; y; y--) + { + for (x = image->width >> 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); - *dst = G2 | (B2 << 8); + *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); + *dst = G2 | (B2 << 8); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); - *dst2 = G2 | (B2 << 8); - + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); + *dst2 = G2 | (B2 << 8); + #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - *dst++ |= (R1 << 16) | (G1 << 24); - *dst++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); + *dst++ |= (R1 << 16) | (G1 << 24); + *dst++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr2++ >> 4) + 128; - yval2 = (*yptr2++ >> 4) + 128; + yval1 = (*yptr2++ >> 4) + 128; + yval2 = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr2++ / 16 + 128; - yval2 = *yptr2++ / 16 + 128; + yval1 = *yptr2++ / 16 + 128; + yval2 = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; - - *dst2++ |= (R1 << 16) | (G1 << 24); - *dst2++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); - } - dst += (image->width >> 2) * 3; - dst2 += (image->width >> 2) * 3; - yptr += image->width; - yptr2 += image->width; - } - } + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval1]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval1]]; + + *dst2++ |= (R1 << 16) | (G1 << 24); + *dst2++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); + } + dst += (image->width >> 2) * 3; + dst2 += (image->width >> 2) * 3; + yptr += image->width; + yptr2 += image->width; + } + } } - else /* 4:4:4 format */ + else /* 4:4:4 format */ { - if (private->double_resolution) - { - unsigned int R1, G1, B1; /* pixel1 in RGB color space */ - unsigned int R2, G2, B2; /* pixel2 in RGB color space */ - int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ - int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ - int x, y; /* pixel counter */ - unsigned int *dst; /* dithered pixel pointer */ - - dst = (unsigned int *) out; - - for (y = image->height; y; y--) - { - for (x = image->width >> 1; x; x--) - { + if (private->double_resolution) + { + unsigned int R1, G1, B1; /* pixel1 in RGB color space */ + unsigned int R2, G2, B2; /* pixel2 in RGB color space */ + int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ + int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ + int x, y; /* pixel counter */ + unsigned int *dst; /* dithered pixel pointer */ + + dst = (unsigned int *) out; + + for (y = image->height; y; y--) + { + for (x = image->width >> 1; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] - + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] - + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - - *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); - *dst++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); - *dst++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); - } - memcpy (dst, dst - 3 * (image->width >> 1), - 3 * (image->width >> 1) * sizeof (unsigned int)); - dst += 3 * (image->width >> 1); - } - } - else - { - unsigned int R1, G1, B1; /* pixel in RGB color space */ - unsigned int R2, G2, B2; /* pixel in RGB color space */ - int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ - int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ - int n; /* pixel counter */ - unsigned int *dst; /* dithered pixel pointer */ - - dst = (unsigned int *) out; - - for (n = (image->width * image->height) >> 2; n; n--) - { + + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + + *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R1 << 24); + *dst++ = G1 | (B1 << 8) | (R2 << 16) | (G2 << 24); + *dst++ = B2 | (R2 << 8) | (G2 << 16) | (B2 << 24); + } + memcpy (dst, dst - 3 * (image->width >> 1), + 3 * (image->width >> 1) * sizeof (unsigned int)); + dst += 3 * (image->width >> 1); + } + } + else + { + unsigned int R1, G1, B1; /* pixel in RGB color space */ + unsigned int R2, G2, B2; /* pixel in RGB color space */ + int yval1, crval1, cbval1; /* pixel1 in YCbCr space */ + int yval2, crval2, cbval2; /* pixel2 in YCbCr space */ + int n; /* pixel counter */ + unsigned int *dst; /* dithered pixel pointer */ + + dst = (unsigned int *) out; + + for (n = (image->width * image->height) >> 2; n; n--) + { #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); - *dst = G2 | (B2 << 8); + *dst++ = R1 | (G1 << 8) | (B1 << 16) | (R2 << 24); + *dst = G2 | (B2 << 8); #ifdef HAVE_SIGNED_SHIFT - yval1 = (*yptr++ >> 4) + 128; - yval2 = (*yptr++ >> 4) + 128; - crval1 = *crptr++ >> 4; - crval2 = *crptr++ >> 4; - cbval1 = *cbptr++ >> 4; - cbval2 = *cbptr++ >> 4; + yval1 = (*yptr++ >> 4) + 128; + yval2 = (*yptr++ >> 4) + 128; + crval1 = *crptr++ >> 4; + crval2 = *crptr++ >> 4; + cbval1 = *cbptr++ >> 4; + cbval2 = *cbptr++ >> 4; #else /* not HAVE_SIGNED_SHIFT */ - yval1 = *yptr++ / 16 + 128; - yval2 = *yptr++ / 16 + 128; - crval1 = *crptr++ / 16; - crval2 = *crptr++ / 16; - cbval1 = *cbptr++ / 16; - cbval2 = *cbptr++ / 16; + yval1 = *yptr++ / 16 + 128; + yval2 = *yptr++ / 16 + 128; + crval1 = *crptr++ / 16; + crval2 = *crptr++ / 16; + cbval1 = *cbptr++ / 16; + cbval2 = *cbptr++ / 16; #endif /* not HAVE_SIGNED_SHIFT */ - R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; - G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; - B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; - R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; - G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; - B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; - - *dst++ |= (R1 << 16) | (G1 << 24); - *dst++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); - } - } + R1 = gray_clip [yval1 + Cr_r_tab [crval1]]; + G1 = gray_clip [yval1 + Cr_g_tab [crval1] + Cb_g_tab [cbval1]]; + B1 = gray_clip [yval1 + Cb_b_tab [cbval1]]; + R2 = gray_clip [yval2 + Cr_r_tab [crval2]]; + G2 = gray_clip [yval2 + Cr_g_tab [crval2] + Cb_g_tab [cbval2]]; + B2 = gray_clip [yval2 + Cb_b_tab [cbval2]]; + + *dst++ |= (R1 << 16) | (G1 << 24); + *dst++ = B1 | (R2 << 8) | (G2 << 16) | (B2 << 24); + } + } } } else { - unsigned int *dst; /* pointer to dithered pixels */ - word_t *src; /* current pixel of frame */ + unsigned int *dst; /* pointer to dithered pixels */ + word_t *src; /* current pixel of frame */ dst = (unsigned int *) out; src = image->pixels [GRAY]; if (private->double_resolution) { - int x, y; /* pixel counter */ - unsigned *shift_clipping = gray_clip + 128; - - for (y = image->height; y; y--) - { - for (x = image->width >> 1; x; x--) - { - unsigned int val1, val2; + int x, y; /* pixel counter */ + unsigned *shift_clipping = gray_clip + 128; + + for (y = image->height; y; y--) + { + for (x = image->width >> 1; x; x--) + { + unsigned int val1, val2; #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = val1 | (val1 << 8) | (val1 << 16) | (val1 << 24); - *dst++ = val1 | (val1 << 8) | (val2 << 16) | (val2 << 24); - *dst++ = val2 | (val2 << 8) | (val2 << 16) | (val2 << 24); - } + *dst++ = val1 | (val1 << 8) | (val1 << 16) | (val1 << 24); + *dst++ = val1 | (val1 << 8) | (val2 << 16) | (val2 << 24); + *dst++ = val2 | (val2 << 8) | (val2 << 16) | (val2 << 24); + } - memcpy (dst, dst - 3 * (image->width >> 1), - 3 * (image->width >> 1) * sizeof (unsigned int)); - dst += 3 * (image->width >> 1); - } + memcpy (dst, dst - 3 * (image->width >> 1), + 3 * (image->width >> 1) * sizeof (unsigned int)); + dst += 3 * (image->width >> 1); + } } else { - int n; /* pixel counter */ - unsigned *shift_clipping = gray_clip + 128; + int n; /* pixel counter */ + unsigned *shift_clipping = gray_clip + 128; - for (n = (image->width * image->height) >> 2; n; n--) - { - unsigned int val1, val2; + for (n = (image->width * image->height) >> 2; n; n--) + { + unsigned int val1, val2; #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = val1 | (val1 << 8) - | (val1 << 16) | (val2 << 24); /* RGBR */ - *dst = val2 | (val2 << 8); /* GB-- */ + *dst++ = val1 | (val1 << 8) + | (val1 << 16) | (val2 << 24); /* RGBR */ + *dst = val2 | (val2 << 8); /* GB-- */ #ifdef HAVE_SIGNED_SHIFT - val1 = shift_clipping [*src++ >> 4]; - val2 = shift_clipping [*src++ >> 4]; + val1 = shift_clipping [*src++ >> 4]; + val2 = shift_clipping [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - val1 = shift_clipping [*src++ / 16]; - val2 = shift_clipping [*src++ / 16]; + val1 = shift_clipping [*src++ / 16]; + val2 = shift_clipping [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - - *dst++ |= (val1 << 16) | (val1 << 24); /* --RG */ - *dst++ = val1 | (val2 << 8) - | (val2 << 16) | (val2 << 24); /* BRGB */ - } + + *dst++ |= (val1 << 16) | (val1 << 24); /* --RG */ + *dst++ = val1 | (val2 << 8) + | (val2 << 16) | (val2 << 24); /* BRGB */ + } } } - + return 1; } -static int +static int display_32_bit (const struct fiasco_renderer *this, unsigned char *ximage, - const fiasco_image_t *fiasco_image) + const fiasco_image_t *fiasco_image) /* * Convert 'image' to 16 bit color bitmap. * If 'double_resolution' is true then double image size in both directions. @@ -1566,13 +1566,13 @@ display_32_bit (const struct fiasco_renderer *this, unsigned char *ximage, * No return value. * * Side effects: - * 'out[]' is filled with dithered image + * 'out[]' is filled with dithered image */ { const image_t *image; renderer_private_t *private; - byte_t *out; - + byte_t *out; + if (!this) { set_error (_("Parameter `%s' not defined (NULL)."), "this"); @@ -1589,21 +1589,21 @@ display_32_bit (const struct fiasco_renderer *this, unsigned char *ximage, return 0; } - out = (byte_t *) ximage; + out = (byte_t *) ximage; private = (renderer_private_t *) this->private; image = cast_image ((fiasco_image_t *) fiasco_image); if (!image) return 0; - + if (image->color) { - word_t *cbptr, *crptr; /* pointer to chroma bands */ - word_t *yptr; /* pointers to lumincance band */ - int yval, crval, cbval; /* pixel value in YCbCr color space */ - int R, G, B; /* pixel value in RGB color space */ - int n; /* pixel counter */ - int x, y; /* pixel coordinates */ - int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; + word_t *cbptr, *crptr; /* pointer to chroma bands */ + word_t *yptr; /* pointers to lumincance band */ + int yval, crval, cbval; /* pixel value in YCbCr color space */ + int R, G, B; /* pixel value in RGB color space */ + int n; /* pixel counter */ + int x, y; /* pixel coordinates */ + 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; @@ -1619,245 +1619,245 @@ display_32_bit (const struct fiasco_renderer *this, unsigned char *ximage, if (image->format == FORMAT_4_2_0) { - unsigned int *dst, *dst2; /* pointers to dithered pixels */ - word_t *yptr2; /* pointers to lumincance band */ - - if (private->double_resolution) - { - yptr2 = yptr + image->width; - dst = (unsigned int *) out; - dst2 = dst + 4 * image->width; - for (y = image->height / 2; y; y--) - { - for (x = image->width / 2; x; x--) - { + unsigned int *dst, *dst2; /* pointers to dithered pixels */ + word_t *yptr2; /* pointers to lumincance band */ + + if (private->double_resolution) + { + yptr2 = yptr + image->width; + dst = (unsigned int *) out; + dst2 = dst + 4 * image->width; + for (y = image->height / 2; y; y--) + { + for (x = image->width / 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr++ >> 4) + 128; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr++ / 16 + 128; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - } - memcpy (dst, dst - 2 * image->width, - 2 * image->width * sizeof (unsigned int)); - memcpy (dst2, dst2 - 2 * image->width, - 2 * image->width * sizeof (unsigned int)); - yptr += image->width; - yptr2 += image->width; - dst += 3 * image->width * 2; - dst2 += 3 * image->width * 2; - } - } - else - { - yptr2 = yptr + image->width; - dst = (unsigned int *) out; - dst2 = dst + image->width; - - for (y = image->height / 2; y; y--) - { - for (x = image->width / 2; x; x--) - { + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + } + memcpy (dst, dst - 2 * image->width, + 2 * image->width * sizeof (unsigned int)); + memcpy (dst2, dst2 - 2 * image->width, + 2 * image->width * sizeof (unsigned int)); + yptr += image->width; + yptr2 += image->width; + dst += 3 * image->width * 2; + dst2 += 3 * image->width * 2; + } + } + else + { + yptr2 = yptr + image->width; + dst = (unsigned int *) out; + dst2 = dst + image->width; + + for (y = image->height / 2; y; y--) + { + for (x = image->width / 2; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr++ >> 4) + 128; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr++ / 16 + 128; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; #ifdef HAVE_SIGNED_SHIFT - yval = (*yptr2++ >> 4) + 128; + yval = (*yptr2++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - yval = *yptr2++ / 16 + 128; + yval = *yptr2++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - *dst2++ = r_table [R] | g_table [G] | b_table [B]; - } - yptr += image->width; - yptr2 += image->width; - dst += image->width; - dst2 += image->width; - } - } + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + *dst2++ = r_table [R] | g_table [G] | b_table [B]; + } + yptr += image->width; + yptr2 += image->width; + dst += image->width; + dst2 += image->width; + } + } } - else /* 4:4:4 format */ + else /* 4:4:4 format */ { - if (private->double_resolution) - { - unsigned int *dst; /* pointer to dithered pixels */ - - dst = (unsigned int *) out; - - for (y = image->height; y; y--) - { - for (x = image->width; x; x--) - { + if (private->double_resolution) + { + unsigned int *dst; /* pointer to dithered pixels */ + + dst = (unsigned int *) out; + + for (y = image->height; y; y--) + { + for (x = image->width; x; x--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; - - *dst++ = r_table [R] | g_table [G] | b_table [B]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - } - memcpy (dst, dst - 2 * image->width, - 2 * image->width * sizeof (unsigned int)); - dst += image->width * 2; - } - } - else - { - unsigned int *dst; /* pointer to dithered pixels */ - - dst = (unsigned int *) out; - - for (n = image->width * image->height; n; n--) - { + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; + + *dst++ = r_table [R] | g_table [G] | b_table [B]; + *dst++ = r_table [R] | g_table [G] | b_table [B]; + } + memcpy (dst, dst - 2 * image->width, + 2 * image->width * sizeof (unsigned int)); + dst += image->width * 2; + } + } + else + { + unsigned int *dst; /* pointer to dithered pixels */ + + dst = (unsigned int *) out; + + for (n = image->width * image->height; n; n--) + { #ifdef HAVE_SIGNED_SHIFT - crval = *crptr++ >> 4; - cbval = *cbptr++ >> 4; - yval = (*yptr++ >> 4) + 128; + crval = *crptr++ >> 4; + cbval = *cbptr++ >> 4; + yval = (*yptr++ >> 4) + 128; #else /* not HAVE_SIGNED_SHIFT */ - crval = *crptr++ / 16; - cbval = *cbptr++ / 16; - yval = *yptr++ / 16 + 128; + crval = *crptr++ / 16; + cbval = *cbptr++ / 16; + yval = *yptr++ / 16 + 128; #endif /* not HAVE_SIGNED_SHIFT */ - R = yval + Cr_r_tab [crval]; - G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; - B = yval + Cb_b_tab [cbval]; + R = yval + Cr_r_tab [crval]; + G = yval + Cr_g_tab [crval] + Cb_g_tab [cbval]; + B = yval + Cb_b_tab [cbval]; - *dst++ = r_table [R] | g_table [G] | b_table [B]; - } - } + *dst++ = r_table [R] | g_table [G] | b_table [B]; + } + } } } else { - unsigned int *dst; /* pointer to dithered pixels */ - word_t *src; /* current pixel of frame */ + 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]; - + if (private->double_resolution) { - int x, y; /* pixel coordinates */ - - for (y = image->height; y; y--) - { - for (x = image->width; x; x--) - { - int value; + int x, y; /* pixel coordinates */ + + for (y = image->height; y; y--) + { + for (x = image->width; x; x--) + { + int value; #ifdef HAVE_SIGNED_SHIFT - value = y_table [*src++ >> 4]; + value = y_table [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - value = y_table [*src++ / 16]; + value = y_table [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ - *dst++ = value; - *dst++ = value; - } - - memcpy (dst, dst - 2 * image->width, - 2 * image->width * sizeof (unsigned int)); - dst += 2 * image->width; - } + *dst++ = value; + *dst++ = value; + } + + memcpy (dst, dst - 2 * image->width, + 2 * image->width * sizeof (unsigned int)); + dst += 2 * image->width; + } } else { - int n; /* pixel counter */ - - for (n = image->width * image->height; n; n--) + int n; /* pixel counter */ + + for (n = image->width * image->height; n; n--) #ifdef HAVE_SIGNED_SHIFT - *dst++ = y_table [*src++ >> 4]; + *dst++ = y_table [*src++ >> 4]; #else /* not HAVE_SIGNED_SHIFT */ - *dst++ = y_table [*src++ / 16]; + *dst++ = y_table [*src++ / 16]; #endif /* not HAVE_SIGNED_SHIFT */ } } - + return 1; } - + diff --git a/converter/other/fiasco/lib/dither.h b/converter/other/fiasco/lib/dither.h index 767bca28..e786af1f 100644 --- a/converter/other/fiasco/lib/dither.h +++ b/converter/other/fiasco/lib/dither.h @@ -1,8 +1,8 @@ /* * dither.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -19,9 +19,9 @@ typedef struct renderer_private { - int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; + int *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab; unsigned int *r_table, *g_table, *b_table, *y_table; - bool_t double_resolution; + bool_t double_resolution; } renderer_private_t; #endif /* _DITHER_H */ diff --git a/converter/other/fiasco/lib/error.c b/converter/other/fiasco/lib/error.c index 394f896f..30d0cf97 100644 --- a/converter/other/fiasco/lib/error.c +++ b/converter/other/fiasco/lib/error.c @@ -1,11 +1,11 @@ /* - * error.c: Error handling + * error.c: Error handling * - * Written by: Stefan Frank - * Ullrich Hafner + * Written by: Stefan Frank + * Ullrich Hafner * - * Credits: Modelled after variable argument routines from Jef - * Poskanzer's pbmplus package. + * Credits: Modelled after variable argument routines from Jef + * Poskanzer's pbmplus package. * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -24,7 +24,7 @@ #include <string.h> #if HAVE_SETJMP_H -# include <setjmp.h> +# include <setjmp.h> #endif /* HAVE_SETJMP_H */ #include "types.h" @@ -36,12 +36,12 @@ /***************************************************************************** - local variables + local variables *****************************************************************************/ static fiasco_verbosity_e verboselevel = FIASCO_SOME_VERBOSITY; -static char *error_message = NULL; +static char *error_message = NULL; #if HAVE_SETJMP_H jmp_buf env; @@ -49,7 +49,7 @@ jmp_buf env; /***************************************************************************** - public code + public code *****************************************************************************/ @@ -195,7 +195,7 @@ warning(const char * const format, ...) { /*---------------------------------------------------------------------------- Issue a warning. -----------------------------------------------------------------------------*/ - va_list args; + va_list args; VA_START (args, format); diff --git a/converter/other/fiasco/lib/error.h b/converter/other/fiasco/lib/error.h index 4159ccd2..dd6a049f 100644 --- a/converter/other/fiasco/lib/error.h +++ b/converter/other/fiasco/lib/error.h @@ -1,6 +1,6 @@ /* * error.h - * + * * Written by: Stefan Frank * Ullrich Hafner * @@ -19,11 +19,11 @@ void file_error (const char *filename); void message (const char *format, ...); -void +void debug_message (const char *format, ...); void warning (const char *format, ...); -void +void info (const char *format, ...); const char * get_system_error (void); diff --git a/converter/other/fiasco/lib/image.h b/converter/other/fiasco/lib/image.h index c3c5f0df..d6a3c6c0 100644 --- a/converter/other/fiasco/lib/image.h +++ b/converter/other/fiasco/lib/image.h @@ -1,8 +1,8 @@ /* * image.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -31,11 +31,11 @@ typedef struct image { char id [8]; /* NUL-terminated "IFIASCO" */ unsigned reference_count; - unsigned width; /* Width of the image */ - unsigned height; /* Height of the image */ - bool_t color; /* Color or grayscale image */ - format_e format; /* Pixel format 4:4:4 or 4:2:0 */ - word_t *pixels [3]; /* Pixels in short format */ + unsigned width; /* Width of the image */ + unsigned height; /* Height of the image */ + bool_t color; /* Color or grayscale image */ + format_e format; /* Pixel format 4:4:4 or 4:2:0 */ + word_t *pixels [3]; /* Pixels in short format */ } image_t; image_t * @@ -48,7 +48,7 @@ void free_image (image_t *image); FILE * read_pnmheader (const char *image_name, unsigned *width, unsigned *height, - bool_t *color); + bool_t *color); image_t * read_image_stream(FILE * const ifP, diff --git a/converter/other/fiasco/lib/list.c b/converter/other/fiasco/lib/list.c index b67ff4b8..24ba4985 100644 --- a/converter/other/fiasco/lib/list.c +++ b/converter/other/fiasco/lib/list.c @@ -1,8 +1,8 @@ /* - * list.c: List operations + * list.c: List operations + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -27,8 +27,8 @@ /***************************************************************************** - public code - + public code + *****************************************************************************/ list_t * @@ -39,15 +39,15 @@ alloc_list (size_t size_of_element) * Size of list element values is given by 'size_of_element'. * * Return value: - * pointer to an empty list + * pointer to an empty list */ { list_t *new_list = Calloc (1, sizeof (list_t)); assert (size_of_element > 0); - new_list->head = NULL; - new_list->tail = NULL; + new_list->head = NULL; + new_list->tail = NULL; new_list->size_of_element = size_of_element; return new_list; @@ -62,11 +62,11 @@ free_list (list_t *list) * No return value. * * Side effects: - * struct 'list' is discarded + * struct 'list' is discarded */ { assert (list); - + while (list_remove (list, HEAD, NULL)) ; Free (list); @@ -76,7 +76,7 @@ void list_insert (list_t *list, pos_e pos, const void *data) /* * Insert a new 'list' element at head ('pos' = HEAD) or - * tail ('pos' = TAIL) of 'list'. + * tail ('pos' = TAIL) of 'list'. * 'data' is a pointer to a memory segment of size * 'list'->size_of_element containing the value to store. * The value is directly copied - no references are stored. @@ -84,14 +84,14 @@ list_insert (list_t *list, pos_e pos, const void *data) * No return value. * * Side effects: - * lists current tail or head is replaced by the new element + * lists current tail or head is replaced by the new element */ { node_t *element; assert (list && data); - element = Calloc (1, sizeof (node_t)); + element = Calloc (1, sizeof (node_t)); element->value = Calloc (1, list->size_of_element); memcpy (element->value, data, list->size_of_element); @@ -100,20 +100,20 @@ list_insert (list_t *list, pos_e pos, const void *data) element->next = NULL; element->prev = list->tail; if (list->tail) - list->tail->next = element; + list->tail->next = element; list->tail = element; if (!list->head) - list->head = element; + list->head = element; } - else /* pos == HEAD */ + else /* pos == HEAD */ { element->prev = NULL; element->next = list->head; if (list->head) - list->head->prev = element; + list->head->prev = element; list->head = element; if (!list->tail) - list->tail = element; + list->tail = element; } } @@ -123,57 +123,57 @@ list_remove (list_t *list, pos_e pos, void *data) * Remove 'list' element from head or tail of 'list'. * * Return value: - * TRUE on success, - * FALSE if list is empty or - * if list value data is NULL + * TRUE on success, + * FALSE if list is empty or + * if list value data is NULL * * Side effects: - * lists current head or tail is removed - * value of the removed list element (if not NULL) is copied to + * lists current head or tail is removed + * value of the removed list element (if not NULL) is copied to * 'data' (if 'data' is not NULL) */ { node_t *element; - void *valueptr; + void *valueptr; assert (list); - + if (pos == TAIL) { element = list->tail; if (element) { - list->tail = element->prev; - valueptr = element->value; - Free (element); + list->tail = element->prev; + valueptr = element->value; + Free (element); } else - valueptr = NULL; - if (!list->tail) /* 'element' was last node */ - list->head = NULL; + valueptr = NULL; + if (!list->tail) /* 'element' was last node */ + list->head = NULL; } - else /* pos == HEAD */ + else /* pos == HEAD */ { element = list->head; if (element) { - list->head = element->next; - valueptr = element->value; - Free (element); + list->head = element->next; + valueptr = element->value; + Free (element); } else - valueptr = NULL; - if (!list->head) /* 'element' was last node */ - list->tail = NULL; + valueptr = NULL; + if (!list->head) /* 'element' was last node */ + list->tail = NULL; } - if (valueptr) /* copy value of node */ + if (valueptr) /* copy value of node */ { - if (data) - memcpy (data, valueptr, list->size_of_element); + if (data) + memcpy (data, valueptr, list->size_of_element); Free (valueptr); } - + return valueptr ? TRUE : FALSE; } @@ -184,27 +184,27 @@ list_element_n (const list_t *list, pos_e pos, unsigned n, void *data) * (First element is list head if 'pos' == HEAD * or list tail if 'pos' == TAIL. * Accordingly, traverse the list in ascending or descending order). - * + * * Return value: - * TRUE on success, FALSE if there is no element 'n' + * TRUE on success, FALSE if there is no element 'n' * * Side effects: - * value of list element 'n' is copied to 'data' + * value of list element 'n' is copied to 'data' */ { node_t *element; assert (list && data); - + if (pos == HEAD) for (element = list->head; element != NULL && n; - element = element->next, n--) - ; + element = element->next, n--) + ; else for (element = list->tail; element != NULL && n; - element = element->prev, n--) - ; - + element = element->prev, n--) + ; + if (element) { memcpy (data, element->value, list->size_of_element); @@ -220,14 +220,14 @@ list_sizeof (const list_t *list) * Count number of 'list' elements. * * Return value: - * number of 'list' elements. + * number of 'list' elements. */ { node_t *element; unsigned n = 0; assert (list); - + for (element = list->head; element != NULL; element = element->next) n++; @@ -247,7 +247,7 @@ list_foreach (const list_t *list, void (*function)(void *, void *), void *data) node_t *element; assert (list && function && data); - + for (element = list->head; element; element = element->next) function (element->value, data); } diff --git a/converter/other/fiasco/lib/list.h b/converter/other/fiasco/lib/list.h index 68577dfd..3ba860c0 100644 --- a/converter/other/fiasco/lib/list.h +++ b/converter/other/fiasco/lib/list.h @@ -1,8 +1,8 @@ /* * list.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -22,16 +22,16 @@ typedef struct node { - struct node *prev; /* pointer to prev list element */ - struct node *next; /* pointer to next list element */ - void *value; /* pointer to value of node */ + struct node *prev; /* pointer to prev list element */ + struct node *next; /* pointer to next list element */ + void *value; /* pointer to value of node */ } node_t; typedef struct list { node_t *head; node_t *tail; - size_t size_of_element; /* number of bytes to store value */ + size_t size_of_element; /* number of bytes to store value */ } list_t; typedef enum {TAIL, HEAD} pos_e; @@ -41,26 +41,26 @@ typedef enum {TAIL, HEAD} pos_e; */ typedef list_t lqueue_t ; -#define alloc_queue alloc_list -#define free_queue free_list -#define queue_append(q, d) (list_insert ((q), TAIL, (d))) -#define queue_remove(q, d) (list_remove ((q), HEAD, (d))) +#define alloc_queue alloc_list +#define free_queue free_list +#define queue_append(q, d) (list_insert ((q), TAIL, (d))) +#define queue_remove(q, d) (list_remove ((q), HEAD, (d))) typedef list_t lstack_t ; -#define alloc_stack alloc_list -#define free_stack free_list -#define stack_push(q, d) (list_insert ((q), TAIL, (d))) -#define stack_pop(q, d) (list_remove ((q), TAIL, (d))) +#define alloc_stack alloc_list +#define free_stack free_list +#define stack_push(q, d) (list_insert ((q), TAIL, (d))) +#define stack_pop(q, d) (list_remove ((q), TAIL, (d))) list_t * alloc_list (size_t size_of_element); -void +void free_list (list_t *list); bool_t list_element_n (const list_t *list, pos_e pos, unsigned n, void *data); void list_foreach (const list_t *list, void (*function)(void *, void *), - void *data); + void *data); void list_insert (list_t *list, pos_e pos, const void *data); bool_t diff --git a/converter/other/fiasco/lib/macros.h b/converter/other/fiasco/lib/macros.h index 2f404a74..aafea45b 100644 --- a/converter/other/fiasco/lib/macros.h +++ b/converter/other/fiasco/lib/macros.h @@ -1,8 +1,8 @@ /* * macros.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -20,34 +20,34 @@ #include <string.h> /******************************************************************************* - System configuration section - + System configuration section + *******************************************************************************/ #ifndef SEEK_CUR -# define SEEK_CUR 1 +# define SEEK_CUR 1 #endif /* not SEEK_CUR */ /***************************************************************************** - Various macros - + Various macros + *****************************************************************************/ -#define square(x) ((x) * (x)) -#define first_band(color) ((unsigned) ((color) ? Y : GRAY)) +#define square(x) ((x) * (x)) +#define first_band(color) ((unsigned) ((color) ? Y : GRAY)) #define last_band(color) ((unsigned) ((color) ? Cr : GRAY)) -#define width_of_level(l) ((unsigned) (1 << ((l) >> 1))) -#define height_of_level(l) ((unsigned) (1 << (((l) + 1) >> 1))) -#define size_of_level(l) ((unsigned) (1 << (l))) -#define address_of_level(l) ((unsigned) (size_of_level (l) - 1)) -#define size_of_tree(l) ((unsigned) (address_of_level ((l) + 1))) -#define is_odd(n) (abs (n) % 2) -#define _(x) (x) +#define width_of_level(l) ((unsigned) (1 << ((l) >> 1))) +#define height_of_level(l) ((unsigned) (1 << (((l) + 1) >> 1))) +#define size_of_level(l) ((unsigned) (1 << (l))) +#define address_of_level(l) ((unsigned) (size_of_level (l) - 1)) +#define size_of_tree(l) ((unsigned) (address_of_level ((l) + 1))) +#define is_odd(n) (abs (n) % 2) +#define _(x) (x) -#define MAXSTRLEN 1024 -#define MAXSTRLEN_SCANF "%1024s" +#define MAXSTRLEN 1024 +#define MAXSTRLEN_SCANF "%1024s" typedef enum color {GRAY = 0, Y = 0, Cb = 1, Cr = 2} color_e; diff --git a/converter/other/fiasco/lib/misc.c b/converter/other/fiasco/lib/misc.c index c5629c5c..d02511de 100644 --- a/converter/other/fiasco/lib/misc.c +++ b/converter/other/fiasco/lib/misc.c @@ -1,11 +1,11 @@ /* - * misc.c: Some useful functions, that don't fit in one of - * the other files and that are needed by at least - * two modules. + * misc.c: Some useful functions, that don't fit in one of + * the other files and that are needed by at least + * two modules. + * + * Written by: Stefan Frank + * Ullrich Hafner * - * Written by: Stefan Frank - * Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -23,14 +23,14 @@ #include <ctype.h> #ifdef TIME_WITH_SYS_TIME -# include <sys/time.h> -# include <time.h> +# include <sys/time.h> +# include <time.h> #else /* not TIME_WITH_SYS_TIME */ -# if HAVE_SYS_TIME_H -# include <sys/time.h> -# else /* not HAVE_SYS_TIME_H */ -# include <time.h> -# endif /* not HAVE_SYS_TIME_H */ +# if HAVE_SYS_TIME_H +# include <sys/time.h> +# else /* not HAVE_SYS_TIME_H */ +# include <time.h> +# endif /* not HAVE_SYS_TIME_H */ #endif /* not TIME_WITH_SYS_TIME */ #include <stdlib.h> @@ -47,8 +47,8 @@ /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ static void @@ -56,8 +56,8 @@ remove_comments (FILE *file); /***************************************************************************** - public code - + public code + *****************************************************************************/ void * @@ -66,14 +66,14 @@ Calloc (size_t n, size_t size) * Allocate memory like calloc (). * * Return value: Pointer to the new block of memory on success, - * otherwise the program is terminated. + * otherwise the program is terminated. */ { - void *ptr; /* pointer to the new memory block */ + void *ptr; /* pointer to the new memory block */ if (n <= 0 || size <= 0) error ("Can't allocate memory for %d items of size %d", - (int) n, (int) size); + (int) n, (int) size); ptr = calloc (n, size); if (!ptr) @@ -100,20 +100,20 @@ unsigned prg_timer (clock_t *last_timer, enum action_e action) /* * If 'action' == START then store current value of system timer. - * If 'action' == STOP then compute number of elapsed micro seconds since - * the last time 'prg_timer' was called - * with 'action' == START. + * If 'action' == STOP then compute number of elapsed micro seconds since + * the last time 'prg_timer' was called + * with 'action' == START. * * Return value: - * Number of elapsed micro seconds if 'action' == STOP - * 0 if 'action' == START + * Number of elapsed micro seconds if 'action' == STOP + * 0 if 'action' == START * * Side effects: - * last_timer is set to current timer if action == START + * last_timer is set to current timer if action == START */ { assert (last_timer); - + if (action == START) { *last_timer = clock (); @@ -123,19 +123,19 @@ prg_timer (clock_t *last_timer, enum action_e action) return (clock () - *last_timer) / (CLOCKS_PER_SEC / 1000.0); } -real_t +real_t read_real (FILE *infile) -/* +/* * Read one real value from the given input stream 'infile'. - * + * * Return value: - * real value on success + * real value on success */ { float input; assert (infile); - + remove_comments (infile); if (fscanf(infile, "%f", &input) != 1) error("Can't read float value!"); @@ -143,26 +143,26 @@ read_real (FILE *infile) return (real_t) input; } -int +int read_int (FILE *infile) -/* +/* * Read one integer value from the given input stream 'infile'. * * Return value: - * integer value on success + * integer value on success */ { - int input; /* integer */ + int input; /* integer */ assert (infile); - + remove_comments (infile); if (fscanf(infile, "%d", &input) != 1) error("Can't read integer value!"); return input; } - + static void remove_comments (FILE *file) /* @@ -171,27 +171,27 @@ remove_comments (FILE *file) * No return value. */ { - int c; /* current character */ - + int c; /* current character */ + assert (file); - + do { while (isspace(c = getc (file))) - ; + ; if (c == EOF) - error ("EOF reached, input seems to be truncated!"); + error ("EOF reached, input seems to be truncated!"); if (c == '#') { - int dummy; - - while (((dummy = getc (file)) != '\n') && dummy != EOF) - ; - if (dummy == EOF) - error ("EOF reached, input seems to be truncated!"); + int dummy; + + while (((dummy = getc (file)) != '\n') && dummy != EOF) + ; + if (dummy == EOF) + error ("EOF reached, input seems to be truncated!"); } - else - ungetc (c, file); + else + ungetc (c, file); } while (c == '#'); } @@ -203,10 +203,10 @@ write_rice_code (unsigned value, unsigned rice_k, bitfile_t *output) * No return value. */ { - unsigned unary; /* unary part of Rice Code */ + unsigned unary; /* unary part of Rice Code */ assert (output); - + for (unary = value >> rice_k; unary; unary--) put_bit (output, 1); put_bit (output, 0); @@ -219,13 +219,13 @@ read_rice_code (unsigned rice_k, bitfile_t *input) * Read a Rice encoded integer (base 'rice_k') from the stream 'input'. * * Return value: - * decoded integer + * decoded integer */ { - unsigned unary; /* unary part of Rice code */ - + unsigned unary; /* unary part of Rice code */ + assert (input); - + for (unary = 0; get_bit (input); unary++) /* unary part */ ; @@ -243,15 +243,15 @@ write_bin_code (unsigned value, unsigned maxval, bitfile_t *output) { unsigned k; unsigned r; - + assert (output && maxval && value <= maxval); k = log2 (maxval + 1); r = (maxval + 1) % (1 << k); - if (value < maxval + 1 - 2 * r) /* 0, ... , maxval - 2r */ + if (value < maxval + 1 - 2 * r) /* 0, ... , maxval - 2r */ put_bits (output, value, k); - else /* maxval - 2r + 1, ..., maxval */ + else /* maxval - 2r + 1, ..., maxval */ put_bits (output, value + maxval + 1 - 2 * r, k + 1); } @@ -261,13 +261,13 @@ read_bin_code (unsigned maxval, bitfile_t *input) * Read a bincode encoded integer from the stream 'input'. * * Return value: - * decoded integer + * decoded integer */ { unsigned k; unsigned r; unsigned value; - + assert (input); k = log2 (maxval + 1); @@ -280,7 +280,7 @@ read_bin_code (unsigned maxval, bitfile_t *input) { value <<= 1; if (get_bit (input)) - value++; + value++; return value - maxval - 1 + 2 * r; } } @@ -292,12 +292,12 @@ bits_rice_code (unsigned value, unsigned rice_k) * with given Rice code 'rice_k'. * * Return value: - * number of bits + * number of bits */ { unsigned unary; unsigned bits = 0; - + for (unary = value >> rice_k; unary; unary--) bits++; bits += rice_k + 1; @@ -312,7 +312,7 @@ bits_bin_code (unsigned value, unsigned maxval) * with adjusted binary code of given maximum value 'maxval'. * * Return value: - * number of bits + * number of bits */ { unsigned k; @@ -332,30 +332,30 @@ init_clipping (void) * Initialize the clipping tables * * Return value: - * pointer to clipping table + * pointer to clipping table */ { - static unsigned *gray_clip = NULL; /* clipping array */ + static unsigned *gray_clip = NULL; /* clipping array */ - if (gray_clip == NULL) /* initialize clipping table */ + if (gray_clip == NULL) /* initialize clipping table */ { - int i; /* counter */ + int i; /* counter */ gray_clip = calloc (256 * 3, sizeof (unsigned)); if (!gray_clip) { - set_error (_("Out of memory.")); - return NULL; + set_error (_("Out of memory.")); + return NULL; } gray_clip += 256; for (i = -256; i < 512; i++) - if (i < 0) - gray_clip [i] = 0; - else if (i > 255) - gray_clip [i] = 255; - else - gray_clip [i] = i; + if (i < 0) + gray_clip [i] = 0; + else if (i > 255) + gray_clip [i] = 255; + else + gray_clip [i] = i; } return gray_clip; @@ -369,29 +369,29 @@ memmove (void *v_dst, const void *v_src, size_t n) * The memory areas may overlap. * * Return value: - * pointer 'dest' + * pointer 'dest' */ { - byte_t *to, *dst = (byte_t *) v_dst; - const byte_t *from, *src = (byte_t *) v_src; - + byte_t *to, *dst = (byte_t *) v_dst; + const byte_t *from, *src = (byte_t *) v_src; + assert (v_dst && v_src); - + if (dst <= src) { from = src; to = dst; for (; n; n--) - *to++ = *from++; + *to++ = *from++; } else - { + { from = src + (n - 1); to = dst + (n - 1); for (; n; n--) - *to-- = *from--; + *to-- = *from--; } - + return v_dst; } #endif /* not HAVE_MEMMOVE */ @@ -405,7 +405,7 @@ double Log2 (double x) /* * Return value: - * base-2 logarithm of 'x' + * base-2 logarithm of 'x' */ { return log (x) / 0.69314718; @@ -413,32 +413,32 @@ Log2 (double x) real_t variance (const word_t *pixels, unsigned x0, unsigned y0, - unsigned width, unsigned height, unsigned cols) + unsigned width, unsigned height, unsigned cols) /* - * Compute variance of subimage ('x0', y0', 'width', 'height') of + * Compute variance of subimage ('x0', y0', 'width', 'height') of * the image data given by 'pixels' ('cols' is the number of pixels * in one row of the image). * * Return value: - * variance + * variance */ { - real_t average; /* average of pixel values */ - real_t variance; /* variance of pixel values */ - unsigned x, y; /* pixel counter */ - unsigned n; /* number of pixels */ + real_t average; /* average of pixel values */ + real_t variance; /* variance of pixel values */ + unsigned x, y; /* pixel counter */ + unsigned n; /* number of pixels */ assert (pixels); - + for (average = 0, n = 0, y = y0; y < y0 + height; y++) for (x = x0; x < MIN(x0 + width, cols); x++, n++) - average += pixels [y * cols + x] / 16; + average += pixels [y * cols + x] / 16; average /= n; for (variance = 0, y = y0; y < y0 + height; y++) for (x = x0; x < MIN(x0 + width, cols); x++) - variance += square ((pixels [y * cols + x] / 16) - average); + variance += square ((pixels [y * cols + x] / 16) - average); return variance; } @@ -482,7 +482,7 @@ sort_asc_pair (const void *value1, const void *value2) { word_t v1 = ((pair_t *) value1)->key; word_t v2 = ((pair_t *) value2)->key; - + if (v1 < v2) return -1; else if (v1 > v2) diff --git a/converter/other/fiasco/lib/misc.h b/converter/other/fiasco/lib/misc.h index 6f643b7a..48f8bdaa 100644 --- a/converter/other/fiasco/lib/misc.h +++ b/converter/other/fiasco/lib/misc.h @@ -1,9 +1,9 @@ /* * misc.h * - * Written by: Stefan Frank - * Ullrich Hafner - * + * Written by: Stefan Frank + * Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -21,14 +21,14 @@ #include "config.h" #if TIME_WITH_SYS_TIME -# include <sys/time.h> -# include <time.h> +# include <sys/time.h> +# include <time.h> #else /* not TIME_WITH_SYS_TIME */ -# if HAVE_SYS_TIME_H -# include <sys/time.h> -# else /* not HAVE_SYS_TIME_H */ -# include <time.h> -# endif /* not HAVE_SYS_TIME_H */ +# if HAVE_SYS_TIME_H +# include <sys/time.h> +# else /* not HAVE_SYS_TIME_H */ +# include <time.h> +# endif /* not HAVE_SYS_TIME_H */ #endif /* not TIME_WITH_SYS_TIME */ #include <stdio.h> @@ -43,9 +43,9 @@ void Free (void *memory); unsigned prg_timer (clock_t *ptimer, enum action_e action); -int +int read_int(FILE *infile); -real_t +real_t read_real(FILE *infile); unsigned read_rice_code (unsigned rice_k, bitfile_t *input); @@ -63,7 +63,7 @@ unsigned * init_clipping (void); real_t variance (const word_t *pixels, unsigned x0, unsigned y0, - unsigned width, unsigned height, unsigned cols); + unsigned width, unsigned height, unsigned cols); #ifndef HAVE_MEMMOVE void * diff --git a/converter/other/fiasco/lib/mvcode.c b/converter/other/fiasco/lib/mvcode.c index d9ce91e2..0e6b6626 100644 --- a/converter/other/fiasco/lib/mvcode.c +++ b/converter/other/fiasco/lib/mvcode.c @@ -8,7 +8,7 @@ unsigned mv_code_table [33][2] = {0x19, 11}, {0x1b, 11}, {0x1d, 11}, {0x1f, 11}, {0x21, 11}, {0x23, 11}, {0x13, 10}, {0x15, 10}, {0x17, 10}, {0x7, 8}, {0x9, 8}, {0xb, 8}, {0x7, 7}, {0x3, 5}, {0x3, 4}, {0x3, 3}, {0x1, 1}, {0x2, 3}, {0x2, 4}, {0x2, 5}, - {0x6, 7}, {0xa, 8}, {0x8, 8}, {0x6, 8}, {0x16, 10}, {0x14, 10}, {0x12, 10}, + {0x6, 7}, {0xa, 8}, {0x8, 8}, {0x6, 8}, {0x16, 10}, {0x14, 10}, {0x12, 10}, {0x22, 11}, {0x20, 11}, {0x1e, 11}, {0x1c, 11}, {0x1a, 11}, {0x18, 11} }; diff --git a/converter/other/fiasco/lib/rpf.c b/converter/other/fiasco/lib/rpf.c index e6ff6e09..61e2f953 100644 --- a/converter/other/fiasco/lib/rpf.c +++ b/converter/other/fiasco/lib/rpf.c @@ -4,7 +4,7 @@ * 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> */ @@ -32,7 +32,7 @@ int const RPF_ZERO = -1; /***************************************************************************** private code - + *****************************************************************************/ @@ -62,25 +62,25 @@ rtob (real_t const f, * Convert real number 'f' into fixed point format. * The real number in [-'range'; +'range'] is scaled to [-1 ; +1]. * Sign and the first 'precision' - 1 bits of the mantissa are - * packed into one integer. + * packed into one integer. * * Return value: * real value in reduced precision format */ -{ +{ /* * Extract mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) */ double const normalized = f / rpfP->range; - /* 'f' scaled to [-1,+1] */ + /* '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; @@ -92,16 +92,16 @@ rtob (real_t const f, /* * Generate reduced precision mantissa. */ - if (fracExp.exponent > 0) + if (fracExp.exponent > 0) mantissa <<= fracExp.exponent; else - mantissa >>= -fracExp.exponent; - + mantissa >>= -fracExp.exponent; + mantissa >>= (23 - rpfP->mantissa_bits - 1); mantissa += 1; /* Round last bit. */ mantissa >>= 1; - + if (mantissa == 0) /* close to zero */ return RPF_ZERO; else if (mantissa >= (1U << rpfP->mantissa_bits)) /* overflow */ @@ -126,7 +126,7 @@ btor (int const binary, unsigned int mantissa; float sign; float f; - + if (binary == RPF_ZERO) return 0; @@ -137,16 +137,16 @@ btor (int const binary, * Restore IEEE float format: * mantissa (23 Bits), exponent (8 Bits) and sign (1 Bit) */ - + sign = (binary & 0x1) == 0 ? 1.0 : -1.0; - mantissa = (binary & ((0x1 << (rpfP->mantissa_bits + 1)) - 1)) >> 1; + mantissa = (binary & ((0x1 << (rpfP->mantissa_bits + 1)) - 1)) >> 1; mantissa <<= (23 - rpfP->mantissa_bits); - if (mantissa == 0) + if (mantissa == 0) f = sign; else f = sign * (float) mantissa / 8388608; - + return f * rpfP->range; /* expand [ -1 ; +1 ] to [ -range ; +range ] */ } @@ -163,7 +163,7 @@ alloc_rpf (unsigned const mantissa, * Number of mantissa bits is given by `mantissa'. * The range of the real values is in the interval [-`range', +`range']. * In case of invalid parameters, a structure with default values is - * returned. + * returned. * * Return value * pointer to the new rpf structure @@ -172,7 +172,7 @@ alloc_rpf (unsigned const mantissa, 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")); diff --git a/converter/other/fiasco/lib/rpf.h b/converter/other/fiasco/lib/rpf.h index e543f855..19e330fb 100644 --- a/converter/other/fiasco/lib/rpf.h +++ b/converter/other/fiasco/lib/rpf.h @@ -1,10 +1,10 @@ /* * rpf.h * - * Written by: Stefan Frank - * Richard Krampfl - * Ullrich Hafner - * + * Written by: Stefan Frank + * Richard Krampfl + * Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -24,14 +24,14 @@ typedef struct rpf { - unsigned mantissa_bits; /* number of bits used for mantissa */ - real_t range; /* scale value to [-range, +range] */ + unsigned mantissa_bits; /* number of bits used for mantissa */ + real_t range; /* scale value to [-range, +range] */ fiasco_rpf_range_e range_e; } rpf_t; int rtob (real_t real, const rpf_t *rpf); -real_t +real_t btor (int b, const rpf_t *rpf); rpf_t * alloc_rpf (unsigned mantissa, fiasco_rpf_range_e range); diff --git a/converter/other/fiasco/lib/types.h b/converter/other/fiasco/lib/types.h index 02e40a90..ce216ce5 100644 --- a/converter/other/fiasco/lib/types.h +++ b/converter/other/fiasco/lib/types.h @@ -2,7 +2,7 @@ * types.h * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/output/matrices.c b/converter/other/fiasco/output/matrices.c index 7dc0e6d9..32289dec 100644 --- a/converter/other/fiasco/output/matrices.c +++ b/converter/other/fiasco/output/matrices.c @@ -1,8 +1,8 @@ /* - * matrices.c: Output of transitions matrices + * matrices.c: Output of transitions matrices + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -38,13 +38,13 @@ /***************************************************************************** - prototypes - + prototypes + *****************************************************************************/ static unsigned delta_encoding (bool_t use_normal_domains, bool_t use_delta_domains, - const wfa_t *wfa, unsigned last_domain, bitfile_t *output); + const wfa_t *wfa, unsigned last_domain, bitfile_t *output); static unsigned column_0_encoding (const wfa_t *wfa, unsigned last_row, bitfile_t *output); static unsigned @@ -52,75 +52,75 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output); /***************************************************************************** - public code - + public code + *****************************************************************************/ unsigned write_matrices (bool_t use_normal_domains, bool_t use_delta_domains, - const wfa_t *wfa, bitfile_t *output) + const wfa_t *wfa, bitfile_t *output) /* * Write transition matrices of 'wfa' to stream 'output'. * * Return value: - * number of transitions encoded + * number of transitions encoded */ { - unsigned root_state; /* root of luminance */ - unsigned total = 0; /* number of transitions */ - + unsigned root_state; /* root of luminance */ + unsigned total = 0; /* number of transitions */ + root_state = wfa->wfainfo->color - ? wfa->tree [wfa->tree [wfa->root_state][0]][0] - : wfa->root_state; - + ? wfa->tree [wfa->tree [wfa->root_state][0]][0] + : wfa->root_state; + total = column_0_encoding (wfa, root_state, output); total += delta_encoding (use_normal_domains, use_delta_domains, - wfa, root_state, output); - + wfa, root_state, output); + if (wfa->wfainfo->color) total += chroma_encoding (wfa, output); - + return total; } /***************************************************************************** - private code - + private code + *****************************************************************************/ static unsigned delta_encoding (bool_t use_normal_domains, bool_t use_delta_domains, - const wfa_t *wfa, unsigned last_domain, bitfile_t *output) + const wfa_t *wfa, unsigned last_domain, bitfile_t *output) /* * Write transition matrices with delta coding to stream 'input'. * 'last_domain' is the maximum state number used as domain image. * * Return value: - * number of non-zero matrix elements (WFA edges) + * number of non-zero matrix elements (WFA edges) */ { - range_sort_t rs; /* ranges are sorted as in the coder */ - unsigned max_domain; /* dummy used for recursion */ - unsigned total = 0; - + range_sort_t rs; /* ranges are sorted as in the coder */ + unsigned max_domain; /* dummy used for recursion */ + unsigned total = 0; + /* * Generate a list of range blocks. * The order is the same as in the coder. */ rs.range_state = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (u_word_t)); + sizeof (u_word_t)); rs.range_label = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (byte_t)); + sizeof (byte_t)); rs.range_max_domain = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (u_word_t)); + sizeof (u_word_t)); rs.range_subdivided = Calloc ((last_domain + 1) * MAXLABELS, - sizeof (bool_t)); - rs.range_no = 0; - max_domain = wfa->basis_states - 1; + sizeof (bool_t)); + rs.range_no = 0; + max_domain = wfa->basis_states - 1; sort_ranges (last_domain, &max_domain, &rs, wfa); - + /* * Compute and write distribution of #edges */ @@ -132,138 +132,138 @@ delta_encoding (bool_t use_normal_domains, bool_t use_delta_domains, unsigned edges = 0; unsigned M = 0; unsigned bits = bits_processed (output); - + for (n = 0; n < MAXEDGES + 1; n++) - count [n] = 0; - + count [n] = 0; + for (state = wfa->basis_states; state <= last_domain; state++) - for (label = 0; label < MAXLABELS; label++) - if (isrange (wfa->tree [state][label])) - { - for (edge = 0; isedge (wfa->into [state][label][edge]); edge++) - ; - count [edge]++; - edges++; - M = MAX(edge, M); - } + for (label = 0; label < MAXLABELS; label++) + if (isrange (wfa->tree [state][label])) + { + for (edge = 0; isedge (wfa->into [state][label][edge]); edge++) + ; + count [edge]++; + edges++; + M = MAX(edge, M); + } write_rice_code (M, 3, output); for (n = 0; n <= M; n++) /* NETPBM: The following causes a crash when last_domain < 4, because it requests writing of a negative number of bits. And we have seen - last_domain = 3. But we have no clue what last_domain means, or + last_domain = 3. But we have no clue what last_domain means, or even what a rice code is, so we don't know where the error lies. - -Bryan 2001.02.09 + -Bryan 2001.02.09 */ - write_rice_code (count [n], (int) log2 (last_domain) - 2, output); + write_rice_code (count [n], (int) log2 (last_domain) - 2, output); /* * Arithmetic coding of values */ { - unsigned range; - model_t *elements = alloc_model (M + 1, 0, 0, count); - arith_t *encoder = alloc_encoder (output); - - for (range = 0; range < rs.range_no; range++) - if (!rs.range_subdivided [range]) - { - state = rs.range_state [range]; - label = rs.range_label [range]; - for (edge = 0; isedge (wfa->into [state][label][edge]); edge++) - ; - - encode_symbol (edge, encoder, elements); - } - free_encoder (encoder); - free_model (elements); + unsigned range; + model_t *elements = alloc_model (M + 1, 0, 0, count); + arith_t *encoder = alloc_encoder (output); + + for (range = 0; range < rs.range_no; range++) + if (!rs.range_subdivided [range]) + { + state = rs.range_state [range]; + label = rs.range_label [range]; + for (edge = 0; isedge (wfa->into [state][label][edge]); edge++) + ; + + encode_symbol (edge, encoder, elements); + } + free_encoder (encoder); + free_model (elements); } debug_message ("delta-#edges: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, edges, - edges > 0 ? ((bits_processed (output) - bits) / - (double) edges) : 0); + bits_processed (output) - bits, edges, + edges > 0 ? ((bits_processed (output) - bits) / + (double) edges) : 0); } /* * Write matrix elements */ { - unsigned bits = bits_processed (output); + unsigned bits = bits_processed (output); u_word_t *mapping1 = Calloc (wfa->states, sizeof (u_word_t)); u_word_t *mapping2 = Calloc (wfa->states, sizeof (u_word_t)); - unsigned range; + unsigned range; put_bit (output, use_normal_domains); put_bit (output, use_delta_domains); - + /* * Generate array of states which are admitted domains. * When coding intra frames 'mapping1' == 'mapping2' otherwise - * 'mapping1' is a list of 'normal' domains which are admitted for + * 'mapping1' is a list of 'normal' domains which are admitted for * coding intra blocks * 'mapping2' is a list of 'delta' domains which are admitted for - * coding the motion compensated prediction error + * coding the motion compensated prediction error */ { - unsigned n1, n2, state; - - for (n1 = n2 = state = 0; state < wfa->states; state++) - { - mapping1 [state] = n1; - if (usedomain (state, wfa) - && (state < wfa->basis_states || use_delta_domains - || !wfa->delta_state [state])) - n1++; - - mapping2 [state] = n2; - if (usedomain (state, wfa) - && (state < wfa->basis_states || use_normal_domains - || wfa->delta_state [state])) - n2++; - } - debug_message ("# normal states = %d, # delta states = %d," - " # WFA states = %d", n1, n2, wfa->states); + unsigned n1, n2, state; + + for (n1 = n2 = state = 0; state < wfa->states; state++) + { + mapping1 [state] = n1; + if (usedomain (state, wfa) + && (state < wfa->basis_states || use_delta_domains + || !wfa->delta_state [state])) + n1++; + + mapping2 [state] = n2; + if (usedomain (state, wfa) + && (state < wfa->basis_states || use_normal_domains + || wfa->delta_state [state])) + n2++; + } + debug_message ("# normal states = %d, # delta states = %d," + " # WFA states = %d", n1, n2, wfa->states); } - + for (range = 0; range < rs.range_no; range++) - if (!rs.range_subdivided [range]) - { - unsigned state = rs.range_state [range]; - unsigned label = rs.range_label [range]; - unsigned last = 1; - u_word_t *mapping; - unsigned max_value; - unsigned edge; - word_t domain; - - if (wfa->delta_state [state] || - wfa->mv_tree [state][label].type != NONE) - mapping = mapping2; - else - mapping = mapping1; - - max_value = mapping [rs.range_max_domain [range]]; - - for (edge = 0; isedge (domain = wfa->into [state][label][edge]); - edge++) - if (domain > 0) - { - total++; - if (max_value - last) - { - write_bin_code (mapping [domain] - last, - max_value - last, output); - last = mapping [domain] + 1; - } - } - } + if (!rs.range_subdivided [range]) + { + unsigned state = rs.range_state [range]; + unsigned label = rs.range_label [range]; + unsigned last = 1; + u_word_t *mapping; + unsigned max_value; + unsigned edge; + word_t domain; + + if (wfa->delta_state [state] || + wfa->mv_tree [state][label].type != NONE) + mapping = mapping2; + else + mapping = mapping1; + + max_value = mapping [rs.range_max_domain [range]]; + + for (edge = 0; isedge (domain = wfa->into [state][label][edge]); + edge++) + if (domain > 0) + { + total++; + if (max_value - last) + { + write_bin_code (mapping [domain] - last, + max_value - last, output); + last = mapping [domain] + 1; + } + } + } debug_message ("delta-index: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total, - total > 0 ? ((bits_processed (output) - bits) / - (double) total) : 0); + bits_processed (output) - bits, total, + total > 0 ? ((bits_processed (output) - bits) / + (double) total) : 0); Free (mapping1); Free (mapping2); } - + Free (rs.range_state); Free (rs.range_label); Free (rs.range_max_domain); @@ -280,17 +280,17 @@ column_0_encoding (const wfa_t *wfa, unsigned last_row, bitfile_t *output) * All rows from 'wfa->basis_states' up to 'last_row' are decoded. * * Return value: - * number of non-zero matrix elements (WFA edges) + * number of non-zero matrix elements (WFA edges) */ { - u_word_t high; /* Start of the current code range */ - u_word_t low; /* End of the current code range */ - unsigned *prob; /* probability array */ - unsigned row; /* current matrix row */ - unsigned label; /* current matrix label */ - unsigned underflow; /* Underflow bits */ - unsigned index; /* probability index */ - unsigned total = 0; /* Number of '1' elements */ + u_word_t high; /* Start of the current code range */ + u_word_t low; /* End of the current code range */ + unsigned *prob; /* probability array */ + unsigned row; /* current matrix row */ + unsigned label; /* current matrix label */ + unsigned underflow; /* Underflow bits */ + unsigned index; /* probability index */ + unsigned total = 0; /* Number of '1' elements */ unsigned bits = bits_processed (output); /* @@ -300,18 +300,18 @@ column_0_encoding (const wfa_t *wfa, unsigned last_row, bitfile_t *output) */ { unsigned n; - unsigned exp; /* current exponent */ - + unsigned exp; /* current exponent */ + prob = Calloc (1 << (MAX_PROB + 1), sizeof (unsigned)); - + for (index = 0, n = MIN_PROB; n <= MAX_PROB; n++) - for (exp = 0; exp < 1U << n; exp++, index++) - prob [index] = n; + for (exp = 0; exp < 1U << n; exp++, index++) + prob [index] = n; } - - high = HIGH; /* 1.0 */ - low = LOW; /* 0.0 */ - underflow = 0; /* no underflow bits */ + + high = HIGH; /* 1.0 */ + low = LOW; /* 0.0 */ + underflow = 0; /* no underflow bits */ index = 0; @@ -325,50 +325,50 @@ column_0_encoding (const wfa_t *wfa, unsigned last_row, bitfile_t *output) */ for (row = wfa->basis_states; row <= last_row; row++) for (label = 0; label < MAXLABELS; label++) - if (isrange (wfa->tree [row][label])) - { - if (wfa->into [row][label][0] != 0) - { - /* - * encode the MPS '0' - */ - high = high - ((high - low) >> prob [index]) - 1; - RESCALE_OUTPUT_INTERVAL; - - if (index < 1020) - index++; - } - else - { - /* - * encode the LPS '1' - */ - low = high - ((high - low) >> prob [index]); - - RESCALE_OUTPUT_INTERVAL; - - total++; - index >>= 1; - } - } + if (isrange (wfa->tree [row][label])) + { + if (wfa->into [row][label][0] != 0) + { + /* + * encode the MPS '0' + */ + high = high - ((high - low) >> prob [index]) - 1; + RESCALE_OUTPUT_INTERVAL; + + if (index < 1020) + index++; + } + else + { + /* + * encode the LPS '1' + */ + low = high - ((high - low) >> prob [index]); + + RESCALE_OUTPUT_INTERVAL; + + total++; + index >>= 1; + } + } /* * Flush the quasi-arithmetic encoder */ low = high; RESCALE_OUTPUT_INTERVAL; - + OUTPUT_BYTE_ALIGN (output); Free (prob); debug_message ("delta-state0: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total, - total > 0 ? ((bits_processed (output) - bits) / - (double) total) : 0); + bits_processed (output) - bits, total, + total > 0 ? ((bits_processed (output) - bits) / + (double) total) : 0); return total; -} +} static unsigned chroma_encoding (const wfa_t *wfa, bitfile_t *output) @@ -377,24 +377,24 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output) * chroma channels Cb and Cr to stream 'output'. * * Return value: - * number of non-zero matrix elements (WFA edges) + * number of non-zero matrix elements (WFA edges) */ { - unsigned domain; /* current domain, counter */ - unsigned label; /* current label */ - unsigned total = 0; /* number of '1' elements */ - u_word_t high; /* Start of the current code range */ - u_word_t low; /* End of the current code range */ - unsigned underflow; /* underflow bits */ - unsigned *prob; /* probability array */ - unsigned index; /* probability index, counter */ - unsigned next_index; /* probability of last domain */ - unsigned row; /* current matrix row */ + unsigned domain; /* current domain, counter */ + unsigned label; /* current label */ + unsigned total = 0; /* number of '1' elements */ + u_word_t high; /* Start of the current code range */ + u_word_t low; /* End of the current code range */ + unsigned underflow; /* underflow bits */ + unsigned *prob; /* probability array */ + unsigned index; /* probability index, counter */ + unsigned next_index; /* probability of last domain */ + unsigned row; /* current matrix row */ word_t *y_domains; - unsigned count = 0; /* number of transitions for part 1 */ + unsigned count = 0; /* number of transitions for part 1 */ unsigned bits = bits_processed (output); - + /* * Compute the asymmetric probability array * prob[] = { 1/2, 1/2, 1/4, 1/4, 1/4, 1/4, @@ -402,24 +402,24 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output) */ { unsigned n; - unsigned exp; /* current exponent */ - + unsigned exp; /* current exponent */ + prob = Calloc (1 << (MAX_PROB + 1), sizeof (unsigned)); - + for (index = 0, n = MIN_PROB; n <= MAX_PROB; n++) - for (exp = 0; exp < 1U << n; exp++, index++) - prob [index] = n; + for (exp = 0; exp < 1U << n; exp++, index++) + prob [index] = n; } - - high = HIGH; /* 1.0 */ - low = LOW; /* 0.0 */ - underflow = 0; /* no underflow bits */ + + high = HIGH; /* 1.0 */ + low = LOW; /* 0.0 */ + underflow = 0; /* no underflow bits */ next_index = index = 0; y_domains = compute_hits (wfa->basis_states, - wfa->tree [wfa->tree [wfa->root_state][0]][0], - wfa->wfainfo->chroma_max_states, wfa); + wfa->tree [wfa->tree [wfa->root_state][0]][0], + wfa->wfainfo->chroma_max_states, wfa); /* * First of all, read all matrix columns given in the list 'y_domains' @@ -428,67 +428,67 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output) */ for (domain = 0; y_domains [domain] != -1; domain++) { - bool_t save_index = YES; /* YES: store current prob. index */ - + bool_t save_index = YES; /* YES: store current prob. index */ + row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; index = next_index; - + for (; row < wfa->states; row++) { - for (label = 0; label < MAXLABELS; label++) - if (isrange (wfa->tree [row][label])) - { - unsigned edge; - int into; - bool_t match; /* approx with current domain found */ - - for (match = NO, edge = 0; - isedge (into = wfa->into [row][label][edge]) - && (unsigned) into < row; - edge++) - if (into == y_domains [domain] - && into != wfa->y_state [row][label]) - match = YES; - if (!match) - { - /* - * encode the MPS '0' - */ - high = high - ((high - low) >> prob [index]) - 1; - - RESCALE_OUTPUT_INTERVAL; - - if (index < 1020) - index++; - } - else - { - /* - * encode the LPS '1' - */ - low = high - ((high - low) >> prob [index]); - - RESCALE_OUTPUT_INTERVAL; - - total++; - index >>= 1; - } - } - if (save_index) - { - next_index = index; - save_index = NO; - } + for (label = 0; label < MAXLABELS; label++) + if (isrange (wfa->tree [row][label])) + { + unsigned edge; + int into; + bool_t match; /* approx with current domain found */ + + for (match = NO, edge = 0; + isedge (into = wfa->into [row][label][edge]) + && (unsigned) into < row; + edge++) + if (into == y_domains [domain] + && into != wfa->y_state [row][label]) + match = YES; + if (!match) + { + /* + * encode the MPS '0' + */ + high = high - ((high - low) >> prob [index]) - 1; + + RESCALE_OUTPUT_INTERVAL; + + if (index < 1020) + index++; + } + else + { + /* + * encode the LPS '1' + */ + low = high - ((high - low) >> prob [index]); + + RESCALE_OUTPUT_INTERVAL; + + total++; + index >>= 1; + } + } + if (save_index) + { + next_index = index; + save_index = NO; + } } } debug_message ("CbCr_matrix: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total, - total > 0 ? ((bits_processed (output) - bits) / - (double) total) : 0); + bits_processed (output) - bits, total, + total > 0 ? ((bits_processed (output) - bits) / + (double) total) : 0); count = total; bits = bits_processed (output); - + /* * Encode the additional column which indicates whether there * are transitions to a state with same spatial coordinates @@ -500,32 +500,32 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output) next_index = index = 0; for (row = wfa->tree [wfa->tree [wfa->root_state][0]][0] + 1; - row < wfa->states; row++) + row < wfa->states; row++) for (label = 0; label < MAXLABELS; label++) - if (!wfa->y_column [row][label]) - { - /* - * encode the MPS '0' - */ - high = high - ((high - low) >> prob [index]) - 1; - - RESCALE_OUTPUT_INTERVAL; - - if (index < 1020) - index++; - } - else - { - /* - * encode the LPS '1' - */ - low = high - ((high - low) >> prob [index]); - - RESCALE_OUTPUT_INTERVAL; - - index >>= 1; - total++; - } + if (!wfa->y_column [row][label]) + { + /* + * encode the MPS '0' + */ + high = high - ((high - low) >> prob [index]) - 1; + + RESCALE_OUTPUT_INTERVAL; + + if (index < 1020) + index++; + } + else + { + /* + * encode the LPS '1' + */ + low = high - ((high - low) >> prob [index]); + + RESCALE_OUTPUT_INTERVAL; + + index >>= 1; + total++; + } /* * Flush the quasi-arithmetic encoder @@ -536,12 +536,12 @@ chroma_encoding (const wfa_t *wfa, bitfile_t *output) OUTPUT_BYTE_ALIGN (output); debug_message ("Yreferences: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total - count, - total - count > 0 ? ((bits_processed (output) - bits) / - (double) (total - count)) : 0); + bits_processed (output) - bits, total - count, + total - count > 0 ? ((bits_processed (output) - bits) / + (double) (total - count)) : 0); Free (prob); Free (y_domains); - + return total; } diff --git a/converter/other/fiasco/output/matrices.h b/converter/other/fiasco/output/matrices.h index 44671496..6e6ec8a5 100644 --- a/converter/other/fiasco/output/matrices.h +++ b/converter/other/fiasco/output/matrices.h @@ -1,8 +1,8 @@ /* * matrices.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -22,7 +22,7 @@ unsigned write_matrices (bool_t use_normal_domains, bool_t use_delta_domains, - const wfa_t *wfa, bitfile_t *output); + const wfa_t *wfa, bitfile_t *output); #endif /* _MATRICES_H */ diff --git a/converter/other/fiasco/output/mc.c b/converter/other/fiasco/output/mc.c index 170a2648..06ed0524 100644 --- a/converter/other/fiasco/output/mc.c +++ b/converter/other/fiasco/output/mc.c @@ -1,8 +1,8 @@ /* - * mc.c: Output of motion compensation + * mc.c: Output of motion compensation * - * Written by: Michael Unger - * Ullrich Hafner + * Written by: Michael Unger + * Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -29,7 +29,7 @@ /***************************************************************************** - local variables + local variables *****************************************************************************/ @@ -55,19 +55,19 @@ enum vlc_e {CODE = 0, BITS = 1}; /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void encode_mc_tree (unsigned max_state, frame_type_e frame_type, const wfa_t *wfa, - bitfile_t *output); + bitfile_t *output); static void encode_mc_coords (unsigned max_state, const wfa_t *wfa, bitfile_t *output); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -75,8 +75,8 @@ void write_mc (frame_type_e frame_type, const wfa_t *wfa, bitfile_t *output) { unsigned max_state = wfa->wfainfo->color - ? wfa->tree[wfa->tree[wfa->root_state][0]][0] - : wfa->states; + ? wfa->tree[wfa->tree[wfa->root_state][0]][0] + : wfa->states; encode_mc_tree (max_state, frame_type, wfa, output); encode_mc_coords (max_state, wfa, output); @@ -84,13 +84,13 @@ write_mc (frame_type_e frame_type, const wfa_t *wfa, bitfile_t *output) /***************************************************************************** - private code + private code *****************************************************************************/ static void encode_mc_tree (unsigned max_state, frame_type_e frame_type, const wfa_t *wfa, - bitfile_t *output) + bitfile_t *output) /* * Write tree of motion compensation decisions to the 'output' stream. * Depending on 'frame_type' different decoding methods are used. @@ -99,20 +99,20 @@ encode_mc_tree (unsigned max_state, frame_type_e frame_type, const wfa_t *wfa, * No return value. */ { - unsigned label; /* current label */ - unsigned state; /* current state */ - unsigned total = 0; /* number of motion tree decisions */ - unsigned queue [MAXSTATES]; /* state numbers in BFO */ - unsigned current; /* current node to process */ - unsigned last; /* last node (update every new node) */ - mc_type_e type; /* type of motion compensation */ - unsigned (*mc_tree_codes)[2]; /* pointer to VLC table */ + unsigned label; /* current label */ + unsigned state; /* current state */ + unsigned total = 0; /* number of motion tree decisions */ + unsigned queue [MAXSTATES]; /* state numbers in BFO */ + unsigned current; /* current node to process */ + unsigned last; /* last node (update every new node) */ + mc_type_e type; /* type of motion compensation */ + unsigned (*mc_tree_codes)[2]; /* pointer to VLC table */ unsigned bits = bits_processed (output); /* number of bits used */ if (frame_type == P_FRAME) - mc_tree_codes = p_frame_codes; /* binary code */ + mc_tree_codes = p_frame_codes; /* binary code */ else - mc_tree_codes = b_frame_codes; /* variable length code */ + mc_tree_codes = b_frame_codes; /* variable length code */ /* * Traverse tree in breadth first order (starting at @@ -122,37 +122,37 @@ encode_mc_tree (unsigned max_state, frame_type_e frame_type, const wfa_t *wfa, for (last = 0, state = wfa->basis_states; state < max_state; state++) if (wfa->level_of_state [state] - 1 == (int) wfa->wfainfo->p_max_level) - queue [last++] = state; /* init level = 'mc_max_level' */ + queue [last++] = state; /* init level = 'mc_max_level' */ for (current = 0; current < last; current++) for (label = 0; label < MAXLABELS; label++) { - state = queue [current]; - type = wfa->mv_tree [state][label].type; - if (wfa->x [state][label] - + width_of_level (wfa->level_of_state [state] - 1) - <= wfa->wfainfo->width - && - wfa->y [state][label] - + height_of_level (wfa->level_of_state [state] - 1) - <= wfa->wfainfo->height) - { - put_bits (output, mc_tree_codes [type][CODE], - mc_tree_codes [type][BITS]); - total++; - } - if (type == NONE && !isrange (wfa->tree [state][label]) && - wfa->level_of_state [state] - 1 >= - (int) wfa->wfainfo->p_min_level) - queue [last++] = wfa->tree [state][label]; /* append child */ + state = queue [current]; + type = wfa->mv_tree [state][label].type; + if (wfa->x [state][label] + + width_of_level (wfa->level_of_state [state] - 1) + <= wfa->wfainfo->width + && + wfa->y [state][label] + + height_of_level (wfa->level_of_state [state] - 1) + <= wfa->wfainfo->height) + { + put_bits (output, mc_tree_codes [type][CODE], + mc_tree_codes [type][BITS]); + total++; + } + if (type == NONE && !isrange (wfa->tree [state][label]) && + wfa->level_of_state [state] - 1 >= + (int) wfa->wfainfo->p_min_level) + queue [last++] = wfa->tree [state][label]; /* append child */ } OUTPUT_BYTE_ALIGN (output); debug_message ("mc-tree: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total, - total > 0 ? ((bits_processed (output) - bits) / - (double) total) : 0); + bits_processed (output) - bits, total, + total > 0 ? ((bits_processed (output) - bits) / + (double) total) : 0); } static void @@ -165,85 +165,85 @@ encode_mc_coords (unsigned max_state, const wfa_t *wfa, bitfile_t *output) * No return value. */ { - unsigned state; /* current state */ - unsigned label; /* current label */ - unsigned level_count [MAXLEVEL]; /* number of mv per level */ - unsigned level; /* counter */ - unsigned ftotal = 0; /* #forward motion tree decisions */ - unsigned btotal = 0; /* #backward decisions */ - unsigned itotal = 0; /* #interpolated decisions */ + unsigned state; /* current state */ + unsigned label; /* current label */ + unsigned level_count [MAXLEVEL]; /* number of mv per level */ + unsigned level; /* counter */ + unsigned ftotal = 0; /* #forward motion tree decisions */ + unsigned btotal = 0; /* #backward decisions */ + unsigned itotal = 0; /* #interpolated decisions */ unsigned bits = bits_processed (output); /* number of bits used */ unsigned sr = wfa->wfainfo->search_range; /* search range */ for (level = wfa->wfainfo->p_max_level; - level >= wfa->wfainfo->p_min_level; level--) + level >= wfa->wfainfo->p_min_level; level--) level_count [level] = 0; for (state = wfa->basis_states; state < max_state; state++) for (label = 0; label < MAXLABELS; label++) { - mv_t *mv = &wfa->mv_tree[state][label]; /* motion vector info */ - - if (mv->type != NONE) - { - level_count [wfa->level_of_state [state] - 1]++; - switch (mv->type) - { - case FORWARD: - put_bits (output, - mv_code_table[(mv->fx + sr)][CODE], - mv_code_table[(mv->fx + sr)][BITS]); - put_bits (output, - mv_code_table[(mv->fy + sr)][CODE], - mv_code_table[(mv->fy + sr)][BITS]); - ftotal++; - break; - case BACKWARD: - put_bits (output, - mv_code_table[(mv->bx + sr)][CODE], - mv_code_table[(mv->bx + sr)][BITS]); - put_bits (output, - mv_code_table[(mv->by + sr)][CODE], - mv_code_table[(mv->by + sr)][BITS]); - btotal++; - break; - case INTERPOLATED: - put_bits (output, - mv_code_table[(mv->fx + sr)][CODE], - mv_code_table[(mv->fx + sr)][BITS]); - put_bits (output, - mv_code_table[(mv->fy + sr)][CODE], - mv_code_table[(mv->fy + sr)][BITS]); - put_bits (output, - mv_code_table[(mv->bx + sr)][CODE], - mv_code_table[(mv->bx + sr)][BITS]); - put_bits (output, - mv_code_table[(mv->by + sr)][CODE], - mv_code_table[(mv->by + sr)][BITS]); - itotal++; - break; - default: - break; - } - } + mv_t *mv = &wfa->mv_tree[state][label]; /* motion vector info */ + + if (mv->type != NONE) + { + level_count [wfa->level_of_state [state] - 1]++; + switch (mv->type) + { + case FORWARD: + put_bits (output, + mv_code_table[(mv->fx + sr)][CODE], + mv_code_table[(mv->fx + sr)][BITS]); + put_bits (output, + mv_code_table[(mv->fy + sr)][CODE], + mv_code_table[(mv->fy + sr)][BITS]); + ftotal++; + break; + case BACKWARD: + put_bits (output, + mv_code_table[(mv->bx + sr)][CODE], + mv_code_table[(mv->bx + sr)][BITS]); + put_bits (output, + mv_code_table[(mv->by + sr)][CODE], + mv_code_table[(mv->by + sr)][BITS]); + btotal++; + break; + case INTERPOLATED: + put_bits (output, + mv_code_table[(mv->fx + sr)][CODE], + mv_code_table[(mv->fx + sr)][BITS]); + put_bits (output, + mv_code_table[(mv->fy + sr)][CODE], + mv_code_table[(mv->fy + sr)][BITS]); + put_bits (output, + mv_code_table[(mv->bx + sr)][CODE], + mv_code_table[(mv->bx + sr)][BITS]); + put_bits (output, + mv_code_table[(mv->by + sr)][CODE], + mv_code_table[(mv->by + sr)][BITS]); + itotal++; + break; + default: + break; + } + } } OUTPUT_BYTE_ALIGN (output); debug_message ("Motion compensation: %d forward, %d backward, " - "%d interpolated", ftotal, btotal, itotal); + "%d interpolated", ftotal, btotal, itotal); for (level = wfa->wfainfo->p_max_level; - level >= wfa->wfainfo->p_min_level; level--) + level >= wfa->wfainfo->p_min_level; level--) debug_message ("Level %d: %d motion vectors", level, level_count[level]); { unsigned total = ftotal * 2 + btotal * 2 + itotal * 4; debug_message ("mv-coord: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total, - total > 0 ? ((bits_processed (output) - bits) / - (double) total) : 0); + bits_processed (output) - bits, total, + total > 0 ? ((bits_processed (output) - bits) / + (double) total) : 0); } return; diff --git a/converter/other/fiasco/output/mc.h b/converter/other/fiasco/output/mc.h index cacddfe7..9e15ae3d 100644 --- a/converter/other/fiasco/output/mc.h +++ b/converter/other/fiasco/output/mc.h @@ -1,9 +1,9 @@ /* * mc.h * - * Written by: Michael Unger - * Ullrich Hafner - * + * Written by: Michael Unger + * Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/output/nd.c b/converter/other/fiasco/output/nd.c index b1dd6746..67b8b106 100644 --- a/converter/other/fiasco/output/nd.c +++ b/converter/other/fiasco/output/nd.c @@ -1,7 +1,7 @@ /* - * nd.c: Output of prediction tree + * nd.c: Output of prediction tree * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -31,7 +31,7 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -42,7 +42,7 @@ encode_nd_coefficients (unsigned total, const wfa_t *wfa, bitfile_t *output); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -63,7 +63,7 @@ write_nd (const wfa_t *wfa, bitfile_t *output) /***************************************************************************** - private code + private code *****************************************************************************/ @@ -75,13 +75,13 @@ encode_nd_tree (const wfa_t *wfa, bitfile_t *output) * No return value. */ { - lqueue_t *queue; /* queue of states */ - int state, next; /* state and its current child */ - unsigned used, not_used; /* counter ND used/not used */ - u_word_t low; /* Start of the current code range */ - u_word_t high; /* End of the current code range */ - u_word_t underflow; /* Number of underflow bits pending */ - u_word_t sum0, sum1; /* Probability model */ + lqueue_t *queue; /* queue of states */ + int state, next; /* state and its current child */ + unsigned used, not_used; /* counter ND used/not used */ + u_word_t low; /* Start of the current code range */ + u_word_t high; /* End of the current code range */ + u_word_t underflow; /* Number of underflow bits pending */ + u_word_t sum0, sum1; /* Probability model */ unsigned bits = bits_processed (output); used = not_used = 0; @@ -108,60 +108,60 @@ encode_nd_tree (const wfa_t *wfa, bitfile_t *output) if (wfa->level_of_state [next] > wfa->wfainfo->p_max_level + 1) { - /* - * Nondetermismn is not allowed at levels larger than - * 'wfa->wfainfo->p_max_level'. - */ - for (label = 0; label < MAXLABELS; label++) - if (ischild (state = wfa->tree [next][label])) - queue_append (queue, &state); /* continue with children */ + /* + * Nondetermismn is not allowed at levels larger than + * 'wfa->wfainfo->p_max_level'. + */ + for (label = 0; label < MAXLABELS; label++) + if (ischild (state = wfa->tree [next][label])) + queue_append (queue, &state); /* continue with children */ } else if (wfa->level_of_state [next] > wfa->wfainfo->p_min_level) { - for (label = 0; label < MAXLABELS; label++) - if (ischild (state = wfa->tree [next][label])) - { - unsigned range; /* Current interval range */ - - if (isedge (wfa->into [next][label][0])) /* prediction used */ - { - used++; - - /* - * Encode a '1' symbol - */ - range = (high - low) + 1; - low = low + (u_word_t) ((range * sum0) / sum1); - RESCALE_OUTPUT_INTERVAL; - } - else /* no predict., continue with children */ - { - not_used++; - if (wfa->level_of_state [state] > wfa->wfainfo->p_min_level) - queue_append (queue, &state); - - /* - * Encode a '0' symbol - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum0) / sum1 - 1); - RESCALE_OUTPUT_INTERVAL; - sum0++; - } - /* - * Update the frequency counts - */ - sum1++; - if (sum1 > 50) /* Scale the symbol frequencies */ - { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; - } - } + for (label = 0; label < MAXLABELS; label++) + if (ischild (state = wfa->tree [next][label])) + { + unsigned range; /* Current interval range */ + + if (isedge (wfa->into [next][label][0])) /* prediction used */ + { + used++; + + /* + * Encode a '1' symbol + */ + range = (high - low) + 1; + low = low + (u_word_t) ((range * sum0) / sum1); + RESCALE_OUTPUT_INTERVAL; + } + else /* no predict., continue with children */ + { + not_used++; + if (wfa->level_of_state [state] > wfa->wfainfo->p_min_level) + queue_append (queue, &state); + + /* + * Encode a '0' symbol + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum0) / sum1 - 1); + RESCALE_OUTPUT_INTERVAL; + sum0++; + } + /* + * Update the frequency counts + */ + sum1++; + if (sum1 > 50) /* Scale the symbol frequencies */ + { + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; + } + } } } @@ -175,14 +175,14 @@ encode_nd_tree (const wfa_t *wfa, bitfile_t *output) OUTPUT_BYTE_ALIGN (output); debug_message ("%d nd fields: %d used nd, %d used not nd", used + not_used, - used, not_used); + used, not_used); { unsigned total = used + not_used; debug_message ("nd-tree: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total, - total > 0 ? ((bits_processed (output) - bits) / - (double) total) : 0); + bits_processed (output) - bits, total, + total > 0 ? ((bits_processed (output) - bits) / + (double) total) : 0); } return used; @@ -201,42 +201,42 @@ encode_nd_coefficients (unsigned total, const wfa_t *wfa, bitfile_t *output) unsigned bits = bits_processed (output); { - unsigned *coefficients; /* array of factors to encode */ - unsigned *ptr; /* pointer to current factor */ - unsigned state, label, edge; - word_t domain; + unsigned *coefficients; /* array of factors to encode */ + unsigned *ptr; /* pointer to current factor */ + unsigned state, label, edge; + word_t domain; ptr = coefficients = Calloc (total, sizeof (unsigned)); for (state = wfa->basis_states; state < wfa->states; state++) - for (label = 0; label < MAXLABELS; label++) - if (ischild (wfa->tree [state][label]) - && isedge (wfa->into [state][label][0])) - for (edge = 0; isedge (domain = wfa->into [state][label][edge]); - edge++) - { - if (ptr - coefficients >= (int) total) - error ("Can't write more than %d coefficients.", total); - - *ptr++ = rtob (wfa->weight [state][label][edge], - wfa->wfainfo->dc_rpf); - } + for (label = 0; label < MAXLABELS; label++) + if (ischild (wfa->tree [state][label]) + && isedge (wfa->into [state][label][0])) + for (edge = 0; isedge (domain = wfa->into [state][label][edge]); + edge++) + { + if (ptr - coefficients >= (int) total) + error ("Can't write more than %d coefficients.", total); + + *ptr++ = rtob (wfa->weight [state][label][edge], + wfa->wfainfo->dc_rpf); + } /* * Encode array of coefficients with arithmetic coding */ { - const int scaling = 50; /* scaling factor of prob. model */ - unsigned c_symbols = 1 << (wfa->wfainfo->dc_rpf->mantissa_bits + 1); + const int scaling = 50; /* scaling factor of prob. model */ + unsigned c_symbols = 1 << (wfa->wfainfo->dc_rpf->mantissa_bits + 1); - encode_array (output, coefficients, NULL, &c_symbols, 1, - total, scaling); + encode_array (output, coefficients, NULL, &c_symbols, 1, + total, scaling); } debug_message ("nd-factors: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total, - total ? ((bits_processed (output) - bits) - / (double) total) : 0); + bits_processed (output) - bits, total, + total ? ((bits_processed (output) - bits) + / (double) total) : 0); Free (coefficients); } } diff --git a/converter/other/fiasco/output/nd.h b/converter/other/fiasco/output/nd.h index 01a37838..7b8ea9fe 100644 --- a/converter/other/fiasco/output/nd.h +++ b/converter/other/fiasco/output/nd.h @@ -1,8 +1,8 @@ /* * nd.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/output/tree.c b/converter/other/fiasco/output/tree.c index 55080a51..02afec50 100644 --- a/converter/other/fiasco/output/tree.c +++ b/converter/other/fiasco/output/tree.c @@ -1,7 +1,7 @@ /* - * tree.c: Output of bintree partitioning + * tree.c: Output of bintree partitioning * - * Written by: Ullrich Hafner + * Written by: Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -29,17 +29,17 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ static void encode_tree (bitfile_t *output, const byte_t *data, unsigned n_data, - unsigned scaling, u_word_t sum0, u_word_t sum1); + unsigned scaling, u_word_t sum0, u_word_t sum1); /***************************************************************************** - public code + public code *****************************************************************************/ @@ -53,13 +53,13 @@ write_tree (const wfa_t *wfa, bitfile_t *output) * No return value. */ { - unsigned queue [MAXSTATES]; /* state numbers in BFO */ - unsigned current; /* current node to process */ - unsigned last; /* last node (update every new node) */ - unsigned label; /* current label */ - int into; /* next child */ - byte_t *tree_string; /* bitstring to encode */ - unsigned total = 0; /* number of ranges */ + unsigned queue [MAXSTATES]; /* state numbers in BFO */ + unsigned current; /* current node to process */ + unsigned last; /* last node (update every new node) */ + unsigned label; /* current label */ + int into; /* next child */ + byte_t *tree_string; /* bitstring to encode */ + unsigned total = 0; /* number of ranges */ unsigned bits = bits_processed (output); /* number of bits */ /* @@ -72,17 +72,17 @@ write_tree (const wfa_t *wfa, bitfile_t *output) queue [0] = wfa->root_state; for (last = 1, current = 0; current < last; current++) for (label = 0; label < MAXLABELS; label++) - if (!isrange (into = wfa->tree [queue[current]][label])) /* child ? */ - { - queue [last++] = into; - tree_string [total++] = 1; - } - else /* or range ? */ - tree_string [total++] = 0; + if (!isrange (into = wfa->tree [queue[current]][label])) /* child ? */ + { + queue [last++] = into; + tree_string [total++] = 1; + } + else /* or range ? */ + tree_string [total++] = 0; if (total != (wfa->states - wfa->basis_states) * MAXLABELS) error ("total [%d] != (states - basis_states) * 2 [%d]", total, - (wfa->states - wfa->basis_states) * MAXLABELS); + (wfa->states - wfa->basis_states) * MAXLABELS); { unsigned scale = total / 20 ; @@ -93,20 +93,20 @@ write_tree (const wfa_t *wfa, bitfile_t *output) Free (tree_string); debug_message ("tree: %5d bits. (%5d symbols => %5.2f bps)", - bits_processed (output) - bits, total, - total > 0 ? ((bits_processed (output) - bits) - / (double) total) : 0); + bits_processed (output) - bits, total, + total > 0 ? ((bits_processed (output) - bits) + / (double) total) : 0); } /***************************************************************************** - private code + private code *****************************************************************************/ static void encode_tree (bitfile_t *output, const byte_t *data, unsigned n_data, - unsigned scaling, u_word_t sum0, u_word_t sum1) + unsigned scaling, u_word_t sum0, u_word_t sum1) /* * Encode bintree data with adaptive binary arithmetic coding. * Write 'n_data' output symbols stored in 'data' to stream 'output'. @@ -116,10 +116,10 @@ encode_tree (bitfile_t *output, const byte_t *data, unsigned n_data, * No return value. */ { - u_word_t low; /* Start of the current code range */ - u_word_t high; /* End of the current code range */ - u_word_t underflow; /* Number of underflow bits pending */ - unsigned n; /* Data counter */ + u_word_t low; /* Start of the current code range */ + u_word_t high; /* End of the current code range */ + u_word_t underflow; /* Number of underflow bits pending */ + unsigned n; /* Data counter */ low = 0; high = 0xffff; @@ -127,29 +127,29 @@ encode_tree (bitfile_t *output, const byte_t *data, unsigned n_data, for (n = n_data; n; n--) { - unsigned range; /* Current interval range */ + unsigned range; /* Current interval range */ if (!*data++) { - /* - * encode a '0' - */ - range = (high - low) + 1; - high = low + (u_word_t) ((range * sum0) / sum1 - 1); + /* + * encode a '0' + */ + range = (high - low) + 1; + high = low + (u_word_t) ((range * sum0) / sum1 - 1); - RESCALE_OUTPUT_INTERVAL; + RESCALE_OUTPUT_INTERVAL; - sum0++; + sum0++; } else { - /* - * encode a '1' - */ - range = (high - low) + 1; - low = low + (u_word_t) ((range * sum0) / sum1); + /* + * encode a '1' + */ + range = (high - low) + 1; + low = low + (u_word_t) ((range * sum0) / sum1); - RESCALE_OUTPUT_INTERVAL; + RESCALE_OUTPUT_INTERVAL; } /* * Update the frequency counts @@ -157,12 +157,12 @@ encode_tree (bitfile_t *output, const byte_t *data, unsigned n_data, sum1++; if (sum1 > scaling) /* Scale the symbol frequencies */ { - sum0 >>= 1; - sum1 >>= 1; - if (!sum0) - sum0 = 1; - if (sum0 >= sum1) - sum1 = sum0 + 1; + sum0 >>= 1; + sum1 >>= 1; + if (!sum0) + sum0 = 1; + if (sum0 >= sum1) + sum1 = sum0 + 1; } } /* diff --git a/converter/other/fiasco/output/tree.h b/converter/other/fiasco/output/tree.h index 50fe2279..bcf50ec1 100644 --- a/converter/other/fiasco/output/tree.h +++ b/converter/other/fiasco/output/tree.h @@ -1,8 +1,8 @@ /* * tree.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/output/weights.c b/converter/other/fiasco/output/weights.c index 0203fef0..4eb068ac 100644 --- a/converter/other/fiasco/output/weights.c +++ b/converter/other/fiasco/output/weights.c @@ -1,8 +1,8 @@ /* - * weights.c: Output of weights + * weights.c: Output of weights + * + * Written by: Ullrich Hafner * - * Written by: Ullrich Hafner - * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -32,8 +32,8 @@ /***************************************************************************** - public code - + public code + *****************************************************************************/ void @@ -45,20 +45,20 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) * No return value. */ { - unsigned state, label; /* current label */ - unsigned offset1, offset2; /* model offsets. */ - unsigned offset3, offset4; /* model offsets. */ - unsigned *weights_array; /* array of weights to encode */ - unsigned *wptr; /* pointer to current weight */ - unsigned *level_array; /* array of corresponding levels */ - unsigned *lptr; /* pointer to current corr. level */ - int min_level, max_level; /* min and max range level */ - int d_min_level, d_max_level; /* min and max delta range level */ - bool_t dc, d_dc; /* true if dc or delta dc are used */ - bool_t delta_approx = NO; /* true if delta has been used */ - unsigned delta_count = 0; /* number of delta ranges */ - unsigned bits = bits_processed (output); - + unsigned state, label; /* current label */ + unsigned offset1, offset2; /* model offsets. */ + unsigned offset3, offset4; /* model offsets. */ + unsigned *weights_array; /* array of weights to encode */ + unsigned *wptr; /* pointer to current weight */ + unsigned *level_array; /* array of corresponding levels */ + unsigned *lptr; /* pointer to current corr. level */ + int min_level, max_level; /* min and max range level */ + int d_min_level, d_max_level; /* min and max delta range level */ + bool_t dc, d_dc; /* true if dc or delta dc are used */ + bool_t delta_approx = NO; /* true if delta has been used */ + unsigned delta_count = 0; /* number of delta ranges */ + unsigned bits = bits_processed (output); + /* * Check whether delta approximation has been used */ @@ -68,14 +68,14 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) delta_approx = YES; break; } - + /* * Generate array of corresponding levels (context of probability model) */ min_level = d_min_level = MAXLEVEL; max_level = d_max_level = 0; - dc = d_dc = NO; - + dc = d_dc = NO; + for (state = wfa->basis_states; state < wfa->states; state++) for (label = 0; label < MAXLABELS; label++) if (isrange (wfa->tree [state][label])) @@ -95,24 +95,24 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) dc = YES; } } - if (min_level > max_level) /* no lc found */ + if (min_level > max_level) /* no lc found */ max_level = min_level - 1; if (d_min_level > d_max_level) d_max_level = d_min_level - 1; /* * Context model: - * 0 DC weight - * 1 Delta DC weight - * 2-k normal weights per level - * k+1 - m Delta weights per level + * 0 DC weight + * 1 Delta DC weight + * 2-k normal weights per level + * k+1 - m Delta weights per level */ offset1 = dc ? 1 : 0; offset2 = offset1 + (d_dc ? 1 : 0); offset3 = offset2 + (max_level - min_level + 1); offset4 = offset3 + (d_max_level - d_min_level + 1); - + /* * Weights are encoded as follows: * all weights of state n @@ -127,15 +127,15 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) for (label = 0; label < MAXLABELS; label++) if (isrange (wfa->tree [state][label])) { - int edge; /* current edge */ - int domain; /* current domain (context of model) */ - + int edge; /* current edge */ + int domain; /* current domain (context of model) */ + for (edge = 0; isedge (domain = wfa->into [state][label][edge]); edge++) { if (wptr - weights_array >= (int) total) error ("Can't write more than %d weights.", total); - if (domain) /* not DC component */ + if (domain) /* not DC component */ { if (delta_approx && wfa->delta_state [state]) /* delta */ { @@ -153,7 +153,7 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) + wfa->level_of_state [state] - 1 - min_level; } } - else /* DC component */ + else /* DC component */ { if (delta_approx && wfa->delta_state [state]) /* delta */ { @@ -172,9 +172,9 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) } { - unsigned i; - unsigned *c_symbols = Calloc (offset4, sizeof (int)); - const int scale = 500; /* scaling of probability model */ + unsigned i; + unsigned *c_symbols = Calloc (offset4, sizeof (int)); + const int scale = 500; /* scaling of probability model */ c_symbols [0] = 1 << (wfa->wfainfo->dc_rpf->mantissa_bits + 1); if (offset1 != offset2) @@ -184,12 +184,12 @@ write_weights (unsigned total, const wfa_t *wfa, bitfile_t *output) c_symbols [i] = 1 << (wfa->wfainfo->rpf->mantissa_bits + 1); for (; i < offset4; i++) c_symbols [i] = 1 << (wfa->wfainfo->d_rpf->mantissa_bits + 1); - + encode_array (output, weights_array, level_array, c_symbols, offset4, total, scale); Free (c_symbols); } - + debug_message ("%d delta weights out of %d.", delta_count, total); debug_message ("weights: %5d bits. (%5d symbols => %5.2f bps)", bits_processed (output) - bits, total, diff --git a/converter/other/fiasco/output/weights.h b/converter/other/fiasco/output/weights.h index f22bd9f8..505918ad 100644 --- a/converter/other/fiasco/output/weights.h +++ b/converter/other/fiasco/output/weights.h @@ -1,8 +1,8 @@ /* * weights.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/output/write.c b/converter/other/fiasco/output/write.c index d6faee26..8c825a12 100644 --- a/converter/other/fiasco/output/write.c +++ b/converter/other/fiasco/output/write.c @@ -2,7 +2,7 @@ * write.c: Output of WFA files * * Written by: Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -32,11 +32,11 @@ #include "mc.h" #include "nd.h" #include "write.h" - + /***************************************************************************** prototypes - + *****************************************************************************/ static void @@ -46,7 +46,7 @@ write_tiling (const tiling_t *tiling, bitfile_t *output); public code - + *****************************************************************************/ @@ -61,26 +61,26 @@ write_next_wfa (const wfa_t *wfa, const coding_t *c, bitfile_t *output) { unsigned edges = 0; /* number of transitions */ unsigned bits; - + debug_message ("--------------------------------------" "--------------------------------------"); if (c->mt->number == 0) /* first WFA */ write_header (wfa->wfainfo, output); - + bits = bits_processed (output); - + /* * Frame header information */ { const int rice_k = 8; /* parameter of Rice Code */ - write_rice_code (wfa->states, rice_k, output); - write_rice_code (c->mt->frame_type, rice_k, output); - write_rice_code (c->mt->number, rice_k, output); + write_rice_code (wfa->states, rice_k, output); + write_rice_code (c->mt->frame_type, rice_k, output); + write_rice_code (c->mt->number, rice_k, output); } - + OUTPUT_BYTE_ALIGN (output); debug_message ("frame-header: %5d bits.", bits_processed (output) - bits); @@ -99,7 +99,7 @@ write_next_wfa (const wfa_t *wfa, const coding_t *c, bitfile_t *output) if (c->options.prediction) /* write nondeterministic approx. */ { - put_bit (output, 1); + put_bit (output, 1); write_nd (wfa, output); } else @@ -107,7 +107,7 @@ write_next_wfa (const wfa_t *wfa, const coding_t *c, bitfile_t *output) if (c->mt->frame_type != I_FRAME) /* write motion compensation info */ write_mc (c->mt->frame_type, wfa, output); - + edges = write_matrices (c->options.normal_domains, c->options.delta_domains, wfa, output); @@ -140,7 +140,7 @@ write_header (const wfa_info_t *wi, bitfile_t *output) for (text = wi->basis_name; *text; text++) put_bits (output, *text, 8); put_bits (output, *text, 8); - + write_rice_code (FIASCO_BINFILE_RELEASE, rice_k, output); write_rice_code (HEADER_TITLE, rice_k, output); @@ -149,24 +149,24 @@ write_header (const wfa_info_t *wi, bitfile_t *output) text++) put_bits (output, *text, 8); put_bits (output, 0, 8); - + write_rice_code (HEADER_COMMENT, rice_k, output); for (text = wi->comment; text && *text && text - wi->comment < MAXSTRLEN - 2; text++) put_bits (output, *text, 8); put_bits (output, 0, 8); - + write_rice_code (HEADER_END, rice_k, output); - - write_rice_code (wi->max_states, rice_k, output); - put_bit (output, wi->color ? 1 : 0); + + write_rice_code (wi->max_states, rice_k, output); + put_bit (output, wi->color ? 1 : 0); write_rice_code (wi->width, rice_k, output); write_rice_code (wi->height, rice_k, output); if (wi->color) - write_rice_code (wi->chroma_max_states, rice_k, output); - write_rice_code (wi->p_min_level, rice_k, output); - write_rice_code (wi->p_max_level, rice_k, output); + write_rice_code (wi->chroma_max_states, rice_k, output); + write_rice_code (wi->p_min_level, rice_k, output); + write_rice_code (wi->p_max_level, rice_k, output); write_rice_code (wi->frames, rice_k, output); write_rice_code (wi->smoothing, rice_k, output); @@ -202,9 +202,9 @@ write_header (const wfa_info_t *wi, bitfile_t *output) if (wi->frames > 1) /* motion compensation stuff */ { - write_rice_code (wi->fps, rice_k, output); - write_rice_code (wi->search_range, rice_k, output); - put_bit (output, wi->half_pixel ? 1 : 0); + write_rice_code (wi->fps, rice_k, output); + write_rice_code (wi->search_range, rice_k, output); + put_bit (output, wi->half_pixel ? 1 : 0); put_bit (output, wi->B_as_past_ref ? 1 : 0); } @@ -215,7 +215,7 @@ write_header (const wfa_info_t *wi, bitfile_t *output) /***************************************************************************** private code - + *****************************************************************************/ static void @@ -228,21 +228,21 @@ write_tiling (const tiling_t *tiling, bitfile_t *output) { const unsigned rice_k = 8; /* parameter of Rice Code */ unsigned bits = bits_processed (output); - + write_rice_code (tiling->exponent, rice_k, output); if (tiling->method == FIASCO_TILING_VARIANCE_ASC || tiling->method == FIASCO_TILING_VARIANCE_DSC) { unsigned tile; /* current image tile */ - put_bit (output, 1); + put_bit (output, 1); for (tile = 0; tile < 1U << tiling->exponent; tile++) if (tiling->vorder [tile] != -1) /* image tile is visible */ put_bits (output, tiling->vorder [tile], tiling->exponent); } else { - put_bit (output, 0); + put_bit (output, 0); put_bit (output, tiling->method == FIASCO_TILING_SPIRAL_ASC); } diff --git a/converter/other/fiasco/output/write.h b/converter/other/fiasco/output/write.h index 6bdc2f1b..1fb3393c 100644 --- a/converter/other/fiasco/output/write.h +++ b/converter/other/fiasco/output/write.h @@ -1,8 +1,8 @@ /* * write.h * - * Written by: Ullrich Hafner - * + * Written by: Ullrich Hafner + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ diff --git a/converter/other/fiasco/params.c b/converter/other/fiasco/params.c index 29f52afc..32145fc3 100644 --- a/converter/other/fiasco/params.c +++ b/converter/other/fiasco/params.c @@ -1,8 +1,8 @@ /* - * params.c: Parameter file and command line parsing + * params.c: Parameter file and command line parsing * - * Written by: Stefan Frank - * Ullrich Hafner + * Written by: Stefan Frank + * Ullrich Hafner * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner @@ -24,12 +24,12 @@ #include <stdio.h> #include <ctype.h> -#include <math.h> /* strtod() on SUN sparc */ +#include <math.h> /* strtod() on SUN sparc */ #include <stdlib.h> #include <string.h> -#include <getopt.h> /* system or ../lib */ +#include <getopt.h> /* system or ../lib */ #include "pm_c_util.h" #include "nstring.h" @@ -46,7 +46,7 @@ /***************************************************************************** - prototypes + prototypes *****************************************************************************/ @@ -64,7 +64,7 @@ usage (const param_t *params, const char *progname, const char *synopsis, /***************************************************************************** - public code + public code *****************************************************************************/ @@ -84,29 +84,29 @@ parseargs (param_t *usr_params, * 'synopsis' contains a brief description of the program and * 'comment' may contain some additional advice. * Initialization order of parameters: - * 1.) Default values given by the param_t struct - * 2.) System parameter-file ('path'/'sys_file_name') - * 3.) User parameter-file ($HOME/'usr_file_name') - * 4.) Command line parameters - * 5.) Parameter-file forced by option -f (--config-file) + * 1.) Default values given by the param_t struct + * 2.) System parameter-file ('path'/'sys_file_name') + * 3.) User parameter-file ($HOME/'usr_file_name') + * 4.) Command line parameters + * 5.) Parameter-file forced by option -f (--config-file) * * Return value: - * index in ARGV of the first ARGV-element that is not an option. + * index in ARGV of the first ARGV-element that is not an option. * * Side effects: - * the elements of ARGV are permuted + * the elements of ARGV are permuted * usr_params [].value is modified */ { - extern int optind; /* index in ARGV of the 1st element - that is not an option */ - bool_t detailed_help = NO; /* NO if all parameters can be modified - with short options too */ - unsigned n1; /* number of user parameters */ - unsigned n2; /* number of system parameters */ - bool_t read_config_file = NO; /* will override command line */ - param_t *params; /* array of user and system params */ - param_t *sys_params; /* array of system parameters */ + extern int optind; /* index in ARGV of the 1st element + that is not an option */ + bool_t detailed_help = NO; /* NO if all parameters can be modified + with short options too */ + unsigned n1; /* number of user parameters */ + unsigned n2; /* number of system parameters */ + bool_t read_config_file = NO; /* will override command line */ + param_t *params; /* array of user and system params */ + param_t *sys_params; /* array of system parameters */ param_t detailed_sys_params [] = /* detailed system parameters */ { {"version", NULL, 'v', PFLAG, {0}, NULL, @@ -121,7 +121,7 @@ parseargs (param_t *usr_params, "Print detailed help, then exit."}, {NULL, NULL, 0, PSTR, {0}, NULL, NULL } }; - param_t short_sys_params [] = /* short system parameters */ + param_t short_sys_params [] = /* short system parameters */ { {"version", NULL, 'v', PFLAG, {0}, NULL, "Print program version number, then exit."}, @@ -133,10 +133,10 @@ parseargs (param_t *usr_params, "Print this help, then exit."}, {NULL, NULL, 0, PSTR, {0}, NULL, NULL } }; - char *sys_path; /* path to system config file */ + char *sys_path; /* path to system config file */ sys_path = calloc (strlen (path) + strlen (sys_file_name) + 2, - sizeof (char)); + sizeof (char)); if (!sys_path) error ("Out of memory."); sprintf (sys_path, "%s/%s", path, sys_file_name); @@ -179,12 +179,12 @@ parseargs (param_t *usr_params, FILE *parameter_file = open_file (sys_path, NULL, READ_ACCESS); if (parameter_file == NULL) /* - warning ("No system resource file found."); + warning ("No system resource file found."); */ {} else { - read_parameter_file (params, parameter_file); - fclose (parameter_file); + read_parameter_file (params, parameter_file); + fclose (parameter_file); } } /* @@ -194,138 +194,138 @@ parseargs (param_t *usr_params, FILE *parameter_file = open_file (usr_file_name, "HOME", READ_ACCESS); if (parameter_file != NULL) { - read_parameter_file (params, parameter_file); - fclose (parameter_file); + read_parameter_file (params, parameter_file); + fclose (parameter_file); } } /* * Parse command line options */ { - extern char *optarg; /* argument of current option */ - struct option *long_options; /* array of long options */ - int option_index = 0; - char optstr [MAXSTRLEN]; /* string containing the legitimate - option characters */ - int optchar; /* found option character */ + extern char *optarg; /* argument of current option */ + struct option *long_options; /* array of long options */ + int option_index = 0; + char optstr [MAXSTRLEN]; /* string containing the legitimate + option characters */ + int optchar; /* found option character */ /* * Build short option string for getopt_long (). */ { - param_t *p; /* counter */ - char *ptr_optstr; /* pointer to position in string */ - - ptr_optstr = optstr; - for (p = params; p->name != NULL; p++) - if (p->optchar != '\0') - { - *ptr_optstr++ = p->optchar; - if (p->type == POSTR) - { - *ptr_optstr++ = ':'; - *ptr_optstr++ = ':'; - } - else if (p->type != PFLAG) - *ptr_optstr++ = ':'; - } - *ptr_optstr = '\0'; + param_t *p; /* counter */ + char *ptr_optstr; /* pointer to position in string */ + + ptr_optstr = optstr; + for (p = params; p->name != NULL; p++) + if (p->optchar != '\0') + { + *ptr_optstr++ = p->optchar; + if (p->type == POSTR) + { + *ptr_optstr++ = ':'; + *ptr_optstr++ = ':'; + } + else if (p->type != PFLAG) + *ptr_optstr++ = ':'; + } + *ptr_optstr = '\0'; } /* * Build long option string for getopt_long (). */ { - int i; - - long_options = calloc (n1 + n2 + 1, sizeof (struct option)); - if (!long_options) - error ("Out of memory."); - for (i = 0; params [i].name != NULL; i++) - { - long_options [i].name = params [i].name; - switch (params [i].type) - { - case PFLAG: - long_options [i].has_arg = 0; - break; - case POSTR: - long_options [i].has_arg = 2; - break; - case PINT: - case PSTR: - case PFLOAT: - default: - long_options [i].has_arg = 1; - break; - } - long_options [i].has_arg = params [i].type != PFLAG; - long_options [i].flag = NULL; - long_options [i].val = 0; - } + int i; + + long_options = calloc (n1 + n2 + 1, sizeof (struct option)); + if (!long_options) + error ("Out of memory."); + for (i = 0; params [i].name != NULL; i++) + { + long_options [i].name = params [i].name; + switch (params [i].type) + { + case PFLAG: + long_options [i].has_arg = 0; + break; + case POSTR: + long_options [i].has_arg = 2; + break; + case PINT: + case PSTR: + case PFLOAT: + default: + long_options [i].has_arg = 1; + break; + } + long_options [i].has_arg = params [i].type != PFLAG; + long_options [i].flag = NULL; + long_options [i].val = 0; + } } /* * Parse command line */ while ((optchar = getopt_long (argc, argv, optstr, long_options, - &option_index)) != EOF) + &option_index)) != EOF) { - int param_index = -1; - - switch (optchar) - { - case 0: - param_index = option_index; - break; - case ':': - if (detailed_help) - fprintf (stderr, - "Try `%s -h' or `%s --help' for " - "more information.\n", - argv [0], argv [0]); - else - fprintf (stderr, "Try `%s --help' for more information.\n", - argv [0]); - exit (2); - break; - case '?': - if (detailed_help) - fprintf (stderr, - "Try `%s -h' or `%s --help' " - "for more information.\n", - argv [0], argv [0]); - else - fprintf (stderr, "Try `%s --help' for more information.\n", - argv [0]); - exit (2); - break; - default: - { - int i; - - for (i = 0; params [i].name != NULL; i++) - if (params [i].optchar == optchar) - { - param_index = i; - break; - } - } - } - /* - * Check for system options - */ - if (param_index >= 0) - { - set_parameter (params + param_index, optarg ? optarg : ""); - if (streq (params [param_index].name, "help")) - usage (params, argv [0], synopsis, comment, non_opt_string, - YES, sys_path, usr_file_name); - else if (streq (params [param_index].name, "info")) - usage (params, argv [0], synopsis, comment, non_opt_string, - NO, sys_path, usr_file_name); - else if (streq (params [param_index].name, "version")) - { + int param_index = -1; + + switch (optchar) + { + case 0: + param_index = option_index; + break; + case ':': + if (detailed_help) + fprintf (stderr, + "Try `%s -h' or `%s --help' for " + "more information.\n", + argv [0], argv [0]); + else + fprintf (stderr, "Try `%s --help' for more information.\n", + argv [0]); + exit (2); + break; + case '?': + if (detailed_help) + fprintf (stderr, + "Try `%s -h' or `%s --help' " + "for more information.\n", + argv [0], argv [0]); + else + fprintf (stderr, "Try `%s --help' for more information.\n", + argv [0]); + exit (2); + break; + default: + { + int i; + + for (i = 0; params [i].name != NULL; i++) + if (params [i].optchar == optchar) + { + param_index = i; + break; + } + } + } + /* + * Check for system options + */ + if (param_index >= 0) + { + set_parameter (params + param_index, optarg ? optarg : ""); + if (streq (params [param_index].name, "help")) + usage (params, argv [0], synopsis, comment, non_opt_string, + YES, sys_path, usr_file_name); + else if (streq (params [param_index].name, "info")) + usage (params, argv [0], synopsis, comment, non_opt_string, + NO, sys_path, usr_file_name); + else if (streq (params [param_index].name, "version")) + { fprintf (stderr, "%s " VERSION "\n", argv [0]); { /* Kludge for standard Netpbm version announcement */ @@ -337,15 +337,15 @@ parseargs (param_t *usr_params, pm_proginit(&argc, (const char **) modified_argv); } exit (2); - } - else if (streq (params [param_index].name, "verbose")) - fiasco_set_verbosity ( + } + else if (streq (params [param_index].name, "verbose")) + fiasco_set_verbosity ( * (fiasco_verbosity_e *) parameter_value (params, "verbose")); - else if (streq (params [param_index].name, "config")) - read_config_file = YES; - param_index = -1; /* clear index flag */ - } + else if (streq (params [param_index].name, "config")) + read_config_file = YES; + param_index = -1; /* clear index flag */ + } } free (long_options); @@ -360,21 +360,21 @@ parseargs (param_t *usr_params, if ((filename = (char *) parameter_value (params, "config")) != NULL) { - FILE *parameter_file; /* input file */ - - warning ("Options set in file `%s' will override" - " command line options.", filename); - parameter_file = open_file (filename, NULL, READ_ACCESS); - if (parameter_file != NULL) - { - read_parameter_file (params, parameter_file); - fclose (parameter_file); - } - else - file_error (filename); + FILE *parameter_file; /* input file */ + + warning ("Options set in file `%s' will override" + " command line options.", filename); + parameter_file = open_file (filename, NULL, READ_ACCESS); + if (parameter_file != NULL) + { + read_parameter_file (params, parameter_file); + fclose (parameter_file); + } + else + file_error (filename); } else - error ("Invalid config filename."); + error ("Invalid config filename."); } memcpy (usr_params, params, n1 * sizeof (param_t)); /* fill user struct */ @@ -389,7 +389,7 @@ parameter_value (const param_t *params, const char *name) * Extract value of parameter 'name.' of the given parameters 'params'. * * Return value: - * value of given parameter + * value of given parameter */ { int pind = get_parameter_index (params, name); @@ -412,7 +412,7 @@ ask_and_set (param_t *params, const char *name, const char *msg) * No return value. * * Side effects: - * 'params ['name'].value' is changed + * 'params ['name'].value' is changed */ { char answer [MAXSTRLEN]; @@ -426,18 +426,18 @@ ask_and_set (param_t *params, const char *name, const char *msg) switch (params [index].type) { - case PFLAG: /* Unusual, at least. */ - warning ("Flags should be initialized and set on demand, " - "not request"); + case PFLAG: /* Unusual, at least. */ + warning ("Flags should be initialized and set on demand, " + "not request"); case PINT: case PSTR: case POSTR: case PFLOAT: - scanf (MAXSTRLEN_SCANF, answer); - set_parameter (¶ms [index], answer); - break; + scanf (MAXSTRLEN_SCANF, answer); + set_parameter (¶ms [index], answer); + break; default: - error ("Invalid parameter type for %s", name); + error ("Invalid parameter type for %s", name); } } @@ -459,22 +459,22 @@ write_parameters (const param_t *params, FILE *output) fprintf (output, "# %s = ", params [pind].name); switch (params [pind].type) { - case PFLAG: - fprintf (output, "%s\n", params [pind].value.b ? "TRUE" : "FALSE"); - break; - case PINT: - fprintf (output, "%d\n", params [pind].value.i); - break; - case PFLOAT: - fprintf (output, "%.4f\n", (double) params [pind].value.f); - break; - case PSTR: - case POSTR: - fprintf (output, "%s\n", params [pind].value.s); - break; - default: - error ("Invalid type %d for parameter %s", - params [pind].type, params [pind].name); + case PFLAG: + fprintf (output, "%s\n", params [pind].value.b ? "TRUE" : "FALSE"); + break; + case PINT: + fprintf (output, "%d\n", params [pind].value.i); + break; + case PFLOAT: + fprintf (output, "%.4f\n", (double) params [pind].value.f); + break; + case PSTR: + case POSTR: + fprintf (output, "%s\n", params [pind].value.s); + break; + default: + error ("Invalid type %d for parameter %s", + params [pind].type, params [pind].name); } } fputc ('\n', output); @@ -482,7 +482,7 @@ write_parameters (const param_t *params, FILE *output) /***************************************************************************** - private code + private code *****************************************************************************/ @@ -494,7 +494,7 @@ set_parameter (param_t *parameter, const char *value) * No return value. * * Side effects: - * 'parameter.value' is changed accordingly + * 'parameter.value' is changed accordingly */ { assert (parameter); @@ -502,61 +502,61 @@ set_parameter (param_t *parameter, const char *value) switch (parameter->type) { case PFLAG: - if (value != NULL && *value != '\0') - { - if (strcaseeq (value, "TRUE")) - parameter->value.b = YES; - else if (strcaseeq (value, "FALSE")) - parameter->value.b = NO; - else if (strcaseeq (value, "YES")) - parameter->value.b = YES; - else if (strcaseeq (value, "NO")) - parameter->value.b = NO; - else - { - long int data; - char *endptr; - - data = strtol (value, &endptr, 0); - if (*endptr != '\0' || endptr == value) - warning ("Invalid value `%s' converted to %d", - value, (int) data); - parameter->value.b = data ? YES : NO; - } - } - else - parameter->value.b = !parameter->value.b; - break; + if (value != NULL && *value != '\0') + { + if (strcaseeq (value, "TRUE")) + parameter->value.b = YES; + else if (strcaseeq (value, "FALSE")) + parameter->value.b = NO; + else if (strcaseeq (value, "YES")) + parameter->value.b = YES; + else if (strcaseeq (value, "NO")) + parameter->value.b = NO; + else + { + long int data; + char *endptr; + + data = strtol (value, &endptr, 0); + if (*endptr != '\0' || endptr == value) + warning ("Invalid value `%s' converted to %d", + value, (int) data); + parameter->value.b = data ? YES : NO; + } + } + else + parameter->value.b = !parameter->value.b; + break; case PINT: - { - long int data; - char *endptr; - - data = strtol (value, &endptr, 0); - if (*endptr != '\0' || endptr == value) - warning ("Invalid value `%s' converted to %d", - value, (int) data); - parameter->value.i = data; - } - break; + { + long int data; + char *endptr; + + data = strtol (value, &endptr, 0); + if (*endptr != '\0' || endptr == value) + warning ("Invalid value `%s' converted to %d", + value, (int) data); + parameter->value.i = data; + } + break; case PFLOAT: - { - double data; - char *endptr; - - data = strtod (value, &endptr); - if (*endptr != '\0' || endptr == value) - warning ("Invalid value `%s' converted to %f", - value, (double) data); - parameter->value.f = data; - } - break; + { + double data; + char *endptr; + + data = strtod (value, &endptr); + if (*endptr != '\0' || endptr == value) + warning ("Invalid value `%s' converted to %f", + value, (double) data); + parameter->value.f = data; + } + break; case PSTR: case POSTR: - parameter->value.s = value ? strdup (value) : NULL; - break; + parameter->value.s = value ? strdup (value) : NULL; + break; default: - error ("Invalid parameter type for %s", parameter->name); + error ("Invalid parameter type for %s", parameter->name); } } @@ -566,7 +566,7 @@ get_parameter_index (const param_t *params, const char *search_string) * Search for parameter with name 'search_string' in parameter struct. * * Return value: - * index of parameter or -1 if no matching parameter has been found + * index of parameter or -1 if no matching parameter has been found */ { int n; @@ -577,8 +577,8 @@ get_parameter_index (const param_t *params, const char *search_string) for (n = 0; params [n].name != NULL; n++) if (strcaseeq (params [n].name, search_string)) { - index = n; - break; + index = n; + break; } return index; @@ -592,7 +592,7 @@ read_parameter_file (param_t *params, FILE *file) * No return value. * * Side effects: - * 'params [].value' are changed if specified in 'file' + * 'params [].value' are changed if specified in 'file' */ { char buffer [MAXSTRLEN]; @@ -602,41 +602,41 @@ read_parameter_file (param_t *params, FILE *file) while (fgets (buffer, MAXSTRLEN, file) != NULL) { - char *b; /* temporary variable */ - char *name; /* parameter name */ - char *value; /* parameter value */ - int pind; /* current argument number */ + char *b; /* temporary variable */ + char *name; /* parameter name */ + char *value; /* parameter value */ + int pind; /* current argument number */ b = strchr (buffer, '#'); - if (b != NULL) /* Strip comments. */ - *b = '\0'; + if (b != NULL) /* Strip comments. */ + *b = '\0'; b = strchr (buffer, '='); - if (b == NULL) /* Strip lines that contain no '=' */ - continue; - *b = '\0'; /* Replace '=' by string terminator */ + if (b == NULL) /* Strip lines that contain no '=' */ + continue; + *b = '\0'; /* Replace '=' by string terminator */ /* * Extract value of parameter */ for (value = b + 1; ISSPACE (*value); value++) - ; /* Delete leading spaces */ + ; /* Delete leading spaces */ for (b = value + strlen (value) - 1; b >= value && ISSPACE (*b); b--) - *b = '\0'; /* Delete trailing spaces. */ + *b = '\0'; /* Delete trailing spaces. */ /* * Extract parameter name */ for (name = buffer; ISSPACE (*name); name++) - ; /* Delete leading spaces */ + ; /* Delete leading spaces */ for (b = name + strlen (name) - 1; b >= name && ISSPACE (*b); b--) - *b = '\0'; /* Delete trailing spaces. */ + *b = '\0'; /* Delete trailing spaces. */ pind = get_parameter_index (params, name); if (pind >= 0) - set_parameter (¶ms [pind], value); + set_parameter (¶ms [pind], value); n++; } @@ -660,7 +660,7 @@ usage (const param_t *params, const char *progname, const char *synopsis, * No return value. */ { - int i; + int i; size_t width = 0; fprintf (stderr, "Usage: %s [OPTION]...%s\n", progname, diff --git a/converter/other/fiasco/params.h b/converter/other/fiasco/params.h index a1164cf7..dd79d43d 100644 --- a/converter/other/fiasco/params.h +++ b/converter/other/fiasco/params.h @@ -3,7 +3,7 @@ * * Written by: Stefan Frank * Ullrich Hafner - * + * * This file is part of FIASCO (Fractal Image And Sequence COdec) * Copyright (C) 1994-2000 Ullrich Hafner */ @@ -43,13 +43,13 @@ typedef struct param_t } param_t; int -parseargs (param_t *usr_params, - int argc, char **argv, +parseargs (param_t *usr_params, + int argc, char **argv, const char *synopsis, - const char *comment, - const char *non_opt_string, + const char *comment, + const char *non_opt_string, const char *path, - const char *sys_file_name, + const char *sys_file_name, const char *usr_file_name); void write_parameters (const param_t *params, FILE *output); |