diff options
Diffstat (limited to 'converter/other/fiasco')
-rw-r--r-- | converter/other/fiasco/Makefile | 2 | ||||
-rw-r--r-- | converter/other/fiasco/binerror.c | 136 | ||||
-rw-r--r-- | converter/other/fiasco/binerror.h | 50 | ||||
-rw-r--r-- | converter/other/fiasco/buttons.c | 510 | ||||
-rw-r--r-- | converter/other/fiasco/buttons.h | 50 | ||||
-rw-r--r-- | converter/other/fiasco/display.c | 415 | ||||
-rw-r--r-- | converter/other/fiasco/display.h | 49 | ||||
-rw-r--r-- | converter/other/fiasco/fiascotopnm.c | 512 | ||||
-rw-r--r-- | converter/other/fiasco/params.c | 1139 | ||||
-rw-r--r-- | converter/other/fiasco/params.h | 6 | ||||
-rw-r--r-- | converter/other/fiasco/pnmtofiasco.c | 356 |
11 files changed, 858 insertions, 2367 deletions
diff --git a/converter/other/fiasco/Makefile b/converter/other/fiasco/Makefile index 392e843c..5ce529fd 100644 --- a/converter/other/fiasco/Makefile +++ b/converter/other/fiasco/Makefile @@ -25,7 +25,7 @@ FIASCOLIBS = codec/libfiasco_codec.a \ output/libfiasco_output.a \ lib/libfiasco_lib.a -ADDL_OBJECTS = binerror.o getopt.o getopt1.o params.o +ADDL_OBJECTS = getopt.o getopt1.o params.o OBJECTS = $(BINARIES:%=%.o) $(ADDL_OBJECTS) diff --git a/converter/other/fiasco/binerror.c b/converter/other/fiasco/binerror.c deleted file mode 100644 index dd40dc9b..00000000 --- a/converter/other/fiasco/binerror.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * error.c: Error handling - * - * 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 - */ - -/* - * $Date: 2000/03/20 21:29:59 $ - * $Author: hafner $ - * $Revision: 4.3 $ - * $State: Exp $ - */ - -#define _DEFAULT_SOURCE 1 /* New name for SVID & BSD source defines */ -#define _BSD_SOURCE 1 /* Make sure strdup() is in string.h */ -#define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ -#define _ERROR_C - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> - -#if STDC_HEADERS -# 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) -#endif /* not STDC_HEADERS */ -#include <string.h> - -#if HAVE_SETJMP_H -# include <setjmp.h> -#endif /* HAVE_SETJMP_H */ - -#include "fiasco.h" -#include "binerror.h" - -/***************************************************************************** - - global variables - -*****************************************************************************/ - -int error_line = 0; -const char *error_file = NULL; - -/***************************************************************************** - - local variables - -*****************************************************************************/ - -static const char *executable = "(name not initialized)"; - -/***************************************************************************** - - public code - -*****************************************************************************/ - -void -init_error_handling (const char *name) -/* - * Initialize filename of executable. - * - * No return value. - */ -{ - if (name) - executable = strdup (name); -} - -void -_error (const char *format, ...) -/* - * Print error message and exit. - * - * No return value. - */ -{ - va_list args; - - VA_START (args, format); - - fprintf (stderr, "%s: %s: line %d:\nError: ", - executable, error_file, error_line); - vfprintf (stderr, format, args); - fputc ('\n', stderr); - va_end(args); - - exit (1); -} - -void -_file_error (const char *filename) -/* - * Print file error message and exit. - * - * No return value. - */ -{ - fprintf (stderr, "%s: %s: line %d:\nError: ", - executable, error_file, error_line); - perror (filename); - - exit (2); -} - -void -_warning (const char *format, ...) -/* - * Issue a warning and continue execution. - * - * No return value. - */ -{ - va_list args; - - VA_START (args, format); - - fprintf (stderr, "%s: %s: line %d:\nWarning: ", - executable, error_file, error_line); - vfprintf (stderr, format, args); - fputc ('\n', stderr); - - va_end (args); -} diff --git a/converter/other/fiasco/binerror.h b/converter/other/fiasco/binerror.h deleted file mode 100644 index b30f53e0..00000000 --- a/converter/other/fiasco/binerror.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * error.h - * - * Written by: Stefan Frank - * Ullrich Hafner - * - * This file is part of FIASCO (Fractal Image And Sequence COdec) - * Copyright (C) 1994-2000 Ullrich Hafner - */ - -/* - * $Date: 2000/03/20 21:29:59 $ - * $Author: hafner $ - * $Revision: 4.3 $ - * $State: Exp $ - */ - -#ifndef _ERROR_H -#define _ERROR_H - -#define error error_line=__LINE__,error_file=__FILE__,_error -#define warning error_line=__LINE__,error_file=__FILE__,_warning -#define file_error(fn) error_line=__LINE__,error_file=__FILE__,_file_error(fn) - -#ifdef _ERROR_C -#define _EXTERN_TYPE -#else -#define _EXTERN_TYPE extern -#endif - -_EXTERN_TYPE int error_line; -_EXTERN_TYPE const char *error_file; - -void -init_error_handling (const char *name); -void -_error (const char *format, ...); -void -_warning (const char *format, ...); -void -_file_error (const char *filename); - -#if HAVE_ASSERT_H -# include <assert.h> -#else /* not HAVE_ASSERT_H */ -# 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 deleted file mode 100644 index 7a6c77a3..00000000 --- a/converter/other/fiasco/buttons.c +++ /dev/null @@ -1,510 +0,0 @@ -/* - * buttons.c: Draw MWFA player buttons in X11 window - * - * Written by: Ullrich Hafner - * - * This file is part of FIASCO (Fractal Image And Sequence COdec) - * Copyright (C) 1994-2000 Ullrich Hafner - */ - -/* - * $Date: 2000/06/15 17:23:11 $ - * $Author: hafner $ - * $Revision: 5.2 $ - * $State: Exp $ - */ - -#include "config.h" - -#ifndef X_DISPLAY_MISSING - -#include <X11/Xlib.h> -#include <X11/Intrinsic.h> -#include <X11/StringDefs.h> - -#if STDC_HEADERS -# include <stdlib.h> -#endif /* not STDC_HEADERS */ - -#include "types.h" -#include "macros.h" - -#include "display.h" -#include "binerror.h" -#include "buttons.h" - -/***************************************************************************** - - local variables - -*****************************************************************************/ - -static const int EVENT_MASK = (KeyPressMask | ButtonPressMask | - ButtonReleaseMask | ExposureMask); - -/***************************************************************************** - - prototypes - -*****************************************************************************/ - -static void -draw_progress_bar (x11_info_t *xinfo, binfo_t *binfo, unsigned n, - unsigned n_frames); -static void -draw_button (x11_info_t *xinfo, binfo_t *binfo, - buttons_t button, bool_t pressed); -static void -draw_control_panel (x11_info_t *xinfo, binfo_t *binfo, - unsigned n, unsigned n_frames); - -/***************************************************************************** - - public code - -*****************************************************************************/ - -binfo_t * -init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, - 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'. - * 'n' gives the current frame, 'whereas' n_frames is the total number of - * frames of the video stream. - * The size of the button toolbar is given by 'buttons_height', - * the size of the progressbar is given by 'progbar_height'. - * - * Return value: - * struct managing the toolbar and progressbar information - */ -{ - XGCValues values; - XEvent event; - Colormap cmap; - XColor gray, dgray, lgray, red; - XColor graye, dgraye, lgraye, rede; - 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; - binfo->record_is_rewind = NO; - - /* - * 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)); - XSelectInput(xinfo->display, binfo->window, StructureNotifyMask); - XMapWindow (xinfo->display, binfo->window); - do - { - XNextEvent (xinfo->display, &event); - } - while (event.type != MapNotify || event.xmap.event != binfo->window); - XSelectInput (xinfo->display, binfo->window, EVENT_MASK); - - /* - * Generate graphic contexts for different colors. - */ - cmap = DefaultColormap (xinfo->display, xinfo->screen); - XAllocNamedColor (xinfo->display, cmap, "#404040", &dgray, &dgraye); - 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); - 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); - 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); - 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); - 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); - 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); - - for (button = 0; button < NO_BUTTON; button++) - binfo->pressed [button] = NO; - - draw_control_panel (xinfo, binfo, n, n_frames); - - return binfo; -} - -void -wait_for_input (x11_info_t *xinfo) -/* - * Wait for key press or mouse click in window 'xinfo'. - * Redraw 'image' if event other then ButtonPress or KeyPress occurs. - * Enlarge or reduce size of image by factor 2^'enlarge_factor'. - * - * No return value. - * - * Side effect: - * program is terminated after key press or mouse click. - */ -{ - bool_t leave_loop = NO; - - XSelectInput (xinfo->display, xinfo->window, EVENT_MASK); - - while (!leave_loop) - { - XEvent event; - - XMaskEvent (xinfo->display, EVENT_MASK, &event); - switch (event.type) - { - case ButtonPress: - case KeyPress: - leave_loop = YES; - break; - default: - display_image (0, 0, xinfo); - break; - } - } -} - -void -check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n, unsigned n_frames) -/* - * Check the X11 event loop. If the PAUSE buttonin the of panel 'binfo' - * is activated wait until next event occurs. - * Redraw 'image' if event other then ButtonPress or ButtonRelease occurs. - * Enlarge or reduce size of image by factor 2^'enlarge_factor'. - * 'n' gives the current frame, 'whereas' n_frames is the total number of - * frames of the video stream. - * - * No return values. - * - * Side effects: - * 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]; - draw_progress_bar (xinfo, binfo, n, n_frames); - - if (binfo->pressed [PAUSE_BUTTON] && binfo->pressed [PLAY_BUTTON]) - { - XFlush (xinfo->display); - draw_button (xinfo, binfo, PLAY_BUTTON, NO); /* clear PLAY mode */ - XFlush (xinfo->display); - } - if (binfo->pressed [PAUSE_BUTTON] - && binfo->record_is_rewind && binfo->pressed [RECORD_BUTTON]) - { - XFlush (xinfo->display); - draw_button (xinfo, binfo, RECORD_BUTTON, NO); /* clear PLAY mode */ - XFlush (xinfo->display); - } - - if (binfo->pressed [STOP_BUTTON]) - { - XFlush (xinfo->display); - draw_button (xinfo, binfo, STOP_BUTTON, NO); /* clear STOP button */ - XFlush (xinfo->display); - } - - do - { - 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]); - } - } while (!leave_eventloop); - - if ((binfo->pressed [RECORD_BUTTON] && !binfo->record_is_rewind) - && n == n_frames - 1) - { - binfo->record_is_rewind = YES; - draw_button (xinfo, binfo, RECORD_BUTTON, NO); - } -} - -/***************************************************************************** - - private code - -*****************************************************************************/ - -static void -draw_control_panel (x11_info_t *xinfo, binfo_t *binfo, - unsigned n, unsigned n_frames) -/* - * Draw control panel 'binfo' with all buttons and progressbar in - * the given 'window'. - * 'n' gives the current frame, 'whereas' n_frames is the total number of - * frames of the video stream. - * - * No return value. - */ -{ - buttons_t button; - - XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY], - 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]); -} - -static void -draw_progress_bar (x11_info_t *xinfo, binfo_t *binfo, unsigned n, - 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 - * frames of the video stream. - * - * No return value. - */ -{ - unsigned x, y, width, height; - - 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); - XDrawLine (xinfo->display, binfo->window, binfo->gc [DGRAY], - x, y, x, y + height - 1); - XDrawLine (xinfo->display, binfo->window, binfo->gc [LGRAY], - 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++; width -= 2; height -= 2; - XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY], - 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); -} - -static void -draw_button (x11_info_t *xinfo, binfo_t *binfo, - 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. - * - * 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; - width = binfo->width / NO_BUTTON; - height = binfo->height - binfo->progbar_height - 1; - - if (width < 4 || height < 4) - return; - - if (pressed) - { - top = DGRAY; - bottom = LGRAY; - } - else - { - top = LGRAY; - bottom = DGRAY; - } - - x += 2; - width -= 4; - - XDrawLine (xinfo->display, binfo->window, binfo->gc [top], - x, y, x + width, y); - XDrawLine (xinfo->display, binfo->window, binfo->gc [top], - x, y, x, y + height - 1); - XDrawLine (xinfo->display, binfo->window, binfo->gc [bottom], - 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++; width -= 2; height -= 2; - XFillRectangle (xinfo->display, binfo->window, binfo->gc [NGRAY], - 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; - 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; - 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; - 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; - 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; - default: - break; - } - binfo->pressed [button] = pressed; -} - -#endif /* not X_DISPLAY_MISSING */ diff --git a/converter/other/fiasco/buttons.h b/converter/other/fiasco/buttons.h deleted file mode 100644 index 19c4935e..00000000 --- a/converter/other/fiasco/buttons.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * buttons.h - * - * Written by: Ullrich Hafner - * - * This file is part of FIASCO (Fractal Image And Sequence COdec) - * Copyright (C) 1994-2000 Ullrich Hafner - */ - -/* - * $Date: 2000/06/14 20:51:17 $ - * $Author: hafner $ - * $Revision: 5.1 $ - * $State: Exp $ - */ - -#ifndef _BUTTONS_H -#define _BUTTONS_H - -#ifndef X_DISPLAY_MISSING - -typedef enum grayscale_e {BLACK, NGRAY, LGRAY, DGRAY, RED, - THICKBLACK, NO_GC} grayscale_t; -typedef enum buttons_e {STOP_BUTTON, PLAY_BUTTON, PAUSE_BUTTON, RECORD_BUTTON, - QUIT_BUTTON, NO_BUTTON} buttons_t; - -typedef struct buttoninfo -{ - Window window; - bool_t pressed [NO_BUTTON]; - GC gc [NO_GC]; - unsigned width; - unsigned height; - unsigned progbar_height; - bool_t record_is_rewind; -} binfo_t; - -void -check_events (x11_info_t *xinfo, binfo_t *binfo, unsigned n, - unsigned n_frames); -void -wait_for_input (x11_info_t *xinfo); -binfo_t * -init_buttons (x11_info_t *xinfo, unsigned n, unsigned n_frames, - unsigned buttons_height, unsigned progbar_height); - -#endif /* not X_DISPLAY_MISSING */ - -#endif /* not _BUTTONS_H */ - diff --git a/converter/other/fiasco/display.c b/converter/other/fiasco/display.c deleted file mode 100644 index 5eed6aeb..00000000 --- a/converter/other/fiasco/display.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - * display.c: X11 display of frames - * - * 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> - * and tmndec (C) 1995, 1996 Telenor R&D, Norway - */ - -/* - * $Date: 2000/07/03 19:35:59 $ - * $Author: hafner $ - * $Revision: 5.2 $ - * $State: Exp $ - */ - -#include "config.h" - -#ifndef X_DISPLAY_MISSING - -#include <X11/Xlib.h> -#include <X11/Xutil.h> -#include <X11/keysym.h> - -#include <stdlib.h> -#include <string.h> - -#include "types.h" -#include "macros.h" -#include "display.h" -#include "binerror.h" - -/***************************************************************************** - - shared memory functions (if USE_SHM is defined) - -*****************************************************************************/ - -#ifdef USE_SHM - -#ifdef HAVE_FEATURES_H -#include <features.h> -#endif - -#include <sys/types.h> -#include <sys/ipc.h> -#include <sys/shm.h> -#include <X11/extensions/XShm.h> - -int -XShmQueryExtension (Display *dpy); -int -XShmGetEventBase (Display *dpy); - -static int -HandleXError (Display *dpy, XErrorEvent *event); -static void -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 -HandleXError (Display *dpy, XErrorEvent *event) -{ - gXErrorFlag = 1; - - return 0; -} - -static void -InstallXErrorHandler (x11_info_t *xinfo) -{ - XSetErrorHandler (HandleXError); - XFlush (xinfo->display); -} - -static void -DeInstallXErrorHandler (x11_info_t *xinfo) -{ - XSetErrorHandler (NULL); - XFlush (xinfo->display); -} - -#endif /* USE_SHM */ - -/***************************************************************************** - - 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'). - * - * 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 - * network. Frankly, this part of XImages is somewhat - * underdocumented, so this may not be exactly correct. - */ - if (*(char *) & byte_order_check == 1) - { - xinfo->ximage->byte_order = LSBFirst; - xinfo->ximage->bitmap_bit_order = LSBFirst; - } - else - { - 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); - XFlush (xinfo->display); - - while (!XCheckTypedEvent (xinfo->display, CompletionType, &xev)) - ; - } - else -#endif /* USE_SHM */ - { - 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); - } -} - -void -close_window (x11_info_t *xinfo) -{ -#ifdef USE_SHM - if (shmem_flag && xinfo->ximage) - { - XShmDetach (xinfo->display, &shminfo1); - XDestroyImage (xinfo->ximage); - xinfo->ximage = NULL; - shmdt (shminfo1.shmaddr); - } - else -#endif /* USE_SHM */ - if (xinfo->ximage) - { - XDestroyImage (xinfo->ximage); - xinfo->ximage = NULL; - } - if (xinfo->display) - { - XCloseDisplay (xinfo->display); - xinfo->display = NULL; - } -} - -x11_info_t * -open_window (const char *titlename, const char *iconname, - unsigned width, unsigned height) -/* - * Open a X11 window of size 'width'x'height'. - * If 'color' is false then allocate a colormap with grayscales. - * Window and icon titles are given by 'titlename' and 'iconname', - * respectively. - * - * Return value: - * 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)); - long visual_mask; - - if (!xinfo) - error ("Out of memory"); - /* - * Initialization of display - */ - xinfo->display = XOpenDisplay (NULL); - if (xinfo->display == NULL) - error ("Can't open display.\n" - "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}; - const char *class_text [] = {"TrueColor", "PseudoColor"}; - 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]); - } - if (!found && fiasco_get_verbosity ()) - 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; - hint.min_height = hint.max_height = hint.height = height; - hint.flags = PSize | PMinSize | PMaxSize; - - /* Get some colors */ - bg = WhitePixel (xinfo->display, xinfo->screen); - fg = BlackPixel (xinfo->display, xinfo->screen); - - /* Make the window */ - mask = CWBackPixel | CWBorderPixel; - if (visual_info.depth >= 16) - { - mask |= CWColormap; - xswa.colormap = XCreateColormap (xinfo->display, - 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); - - XSelectInput (xinfo->display, xinfo->window, StructureNotifyMask); - - /* Tell other applications about this window */ - XSetStandardProperties (xinfo->display, xinfo->window, titlename, iconname, - None, NULL, 0, &hint); - - /* Map window. */ - XMapWindow (xinfo->display, xinfo->window); - - /* Wait for map. */ - do - { - XNextEvent (xinfo->display, &xev); - } - while (xev.type != MapNotify || xev.xmap.event != xinfo->window); - - /* Allocate colors */ - - return xinfo; -} - -void -alloc_ximage (x11_info_t *xinfo, unsigned width, unsigned height) -/* - * Allocate ximage of size 'width'x'height'. - * If USE_SHM is defined then use shared memory extensions. - * - * No return value. - * - * Side effects: - * '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"); - shmem_flag = 1; - } - else - { - shmem_flag = 0; - if (fiasco_get_verbosity ()) - fprintf (stderr, - "Shared memory does not work on this system\n" - "Reverting to normal Xlib.\n"); - } - - if (shmem_flag) - CompletionType = XShmGetEventBase (xinfo->display) + ShmCompletion; - - InstallXErrorHandler (xinfo); - - if (shmem_flag) - { - xinfo->ximage = XShmCreateImage (xinfo->display, - 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; - } - - /* Success here, continue. */ - - shminfo1.shmid = shmget (IPC_PRIVATE, xinfo->ximage->bytes_per_line - * 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; - } - - shminfo1.shmaddr = (char *) shmat (shminfo1.shmid, 0, 0); - shminfo2.shmaddr = (char *) shmat (shminfo2.shmid, 0, 0); - - 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; - } - - xinfo->ximage->data = shminfo1.shmaddr; - xinfo->pixels = (byte_t *) xinfo->ximage->data; - shminfo1.readOnly = False; - - XShmAttach (xinfo->display, &shminfo1); - XSync (xinfo->display, False); - - 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; - } - else - shmctl (shminfo1.shmid, IPC_RMID, 0); - if (fiasco_get_verbosity ()) - fprintf (stderr, "Sharing memory.\n"); - } - else - { - shmemerror: - shmem_flag = 0; -#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); - xinfo->pixels = calloc (width * height, - 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."); - -#ifdef USE_SHM - } - - DeInstallXErrorHandler (xinfo); -#endif /* USE_SHM */ -} - -#endif /* not X_DISPLAY_MISSING */ diff --git a/converter/other/fiasco/display.h b/converter/other/fiasco/display.h deleted file mode 100644 index 0f9c53dc..00000000 --- a/converter/other/fiasco/display.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * display.h - * - * Written by: Ullrich Hafner - * - * This file is part of FIASCO (Fractal Image And Sequence COdec) - * Copyright (C) 1994-2000 Ullrich Hafner - */ - -/* - * $Date: 2000/06/14 20:51:17 $ - * $Author: hafner $ - * $Revision: 5.1 $ - * $State: Exp $ - */ - -#ifndef _DISPLAY_H -#define _DISPLAY_H - -#ifndef X_DISPLAY_MISSING - -#include <X11/Xlib.h> - -#include "types.h" -#include "image.h" - -typedef struct x11_info -{ - Display *display; - int screen; /* default screen number */ - Window window; - XImage *ximage; - GC gc; - byte_t *pixels; -} x11_info_t; - -void -display_image (unsigned x0, unsigned y0, x11_info_t *xinfo); -void -close_window (x11_info_t *xinfo); -x11_info_t * -open_window (const char *titlename, const char *iconname, - unsigned width, unsigned height); -void -alloc_ximage (x11_info_t *xinfo, unsigned width, unsigned height); - -#endif /* X_DISPLAY_MISSING */ - -#endif /* not _DISPLAY_H */ diff --git a/converter/other/fiasco/fiascotopnm.c b/converter/other/fiasco/fiascotopnm.c index c97e201b..340f9d4e 100644 --- a/converter/other/fiasco/fiascotopnm.c +++ b/converter/other/fiasco/fiascotopnm.c @@ -1,5 +1,5 @@ /* - * dwfa.c: Decoding of WFA-files + * Decode WFA-files * * Written by: Ullrich Hafner * Michael Unger @@ -25,99 +25,65 @@ #include <stdlib.h> #include <string.h> #include <math.h> +#include <getopt.h> +#include "mallocvar.h" #include "nstring.h" #include "types.h" #include "macros.h" -#include <getopt.h> - -#include "binerror.h" #include "misc.h" #include "params.h" #include "fiasco.h" -#ifndef X_DISPLAY_MISSING - -# include "display.h" -# include "buttons.h" - -static x11_info_t *xinfo = NULL; - -#endif /* not X_DISPLAY_MISSING */ - -/***************************************************************************** - - prototypes -*****************************************************************************/ - -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 -video_decoder (const char *wfa_name, const char *image_name, bool_t panel, - bool_t double_resolution, int fps, fiasco_d_options_t *options); -static void -get_output_template (const char *image_name, const char *wfa_name, - bool_t color, char **basename, char **suffix); - -#ifndef X_DISPLAY_MISSING static void -show_stored_frames (unsigned char * const *frame_buffer, int last_frame, - x11_info_t *xinfo, binfo_t *binfo, size_t size, - unsigned frame_time); - -#endif /* not X_DISPLAY_MISSING */ - -/***************************************************************************** - - public code +getOutputTemplate(const char * const imageName, + const char * const wfaName, + bool_t const color, + const char ** const basename, + const char ** const suffixP) { +/*---------------------------------------------------------------------------- + + Generate image filename template for output of image sequences. + 'wfa_name' is the filename of the WFA stream. + Images are either saved with filename 'basename'.'suffix' (still images) + or 'basename'.%03d.'suffix' (videos). +-----------------------------------------------------------------------------*/ + char * suffixLoc; + + /* Generate filename template */ + if (!imageName || streq(imageName, "") || streq(imageName, "-")) { + if (!wfaName || streq(wfaName, "-")) + *basename = strdup("stdin"); + else + *basename = strdup(wfaName); + suffixLoc = NULL; + } else { + *basename = strdup(imageName); + suffixLoc = strrchr(*basename, '.'); + } -*****************************************************************************/ + if (suffixLoc) { + /* found name 'basename.suffix' */ -int -main (int argc, char **argv) -{ - char *image_name = NULL; /* output filename */ - bool_t double_resolution = NO; /* double resolution of image */ - bool_t panel = NO; /* control panel */ - int fps = -1; /* frame display rate */ - fiasco_d_options_t *options = NULL; /* additional coder options */ - int last_arg; /* last processed cmdline parameter */ - - init_error_handling (argv[0]); - - 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 - while (last_arg++ < argc) - video_decoder (argv [last_arg - 1], image_name, panel, - double_resolution, fps, options); + *suffixLoc = '\0'; /* remove dot from *basename*/ - return 0; + if (*(suffixLoc+1) == '\0') + *suffixP = strdup(color ? "ppm" : "pgm"); + else + *suffixP = strdup(suffixLoc + 1); + } else /* no suffix found, generate one */ + *suffixP = strdup(color ? "ppm" : "pgm"); } -/***************************************************************************** - private code -*****************************************************************************/ - -static param_t params [] = -{ -#ifdef X_DISPLAY_MISSING +static param_t params [] = { {"output", "FILE", 'o', PSTR, {0}, "-", "Write raw PNM frame(s) to `%s'."}, -#else /* not X_DISPLAY_MISSING */ - {"output", "FILE", 'o', POSTR, {0}, NULL, - "Write raw PNM frame(s) to INPUT.ppm/pgm [or `%s']."}, -#endif /* not X_DISPLAY_MISSING */ {"double", NULL, 'd', PFLAG, {0}, "FALSE", "Interpolate images to double size before display."}, {"fast", NULL, 'r', PFLAG, {0}, "FALSE", @@ -134,349 +100,165 @@ static param_t params [] = }; static int -checkargs (int argc, char **argv, bool_t *double_resolution, bool_t *panel, - int *fps, char **image_name, fiasco_d_options_t **options) -/* - * Check validness of command line parameters and of the parameter files. - * - * Return value. - * index in argv of the first argv-element that is not an option. - * - * Side effects: - * 'double_resolution', 'panel', 'fps', 'image_name' and 'options' - * are modified. - */ -{ +checkargs(int argc, + const char ** const argv, + bool_t * const double_resolution, + bool_t * const panel, + int * const fps, + const char ** const image_name, + fiasco_d_options_t ** const options) { +/*---------------------------------------------------------------------------- + Check validness of command line parameters and of the parameter files. + + Return value: index in argv of the first argv-element that is not an option. + + Side effects: +-----------------------------------------------------------------------------*/ int optind; /* last processed commandline param */ - optind = parseargs (params, argc, argv, -#ifdef X_DISPLAY_MISSING - "Decode FIASCO-FILEs and write frame(s) to disk.", -#else /* not X_DISPLAY_MISSING */ - "Decode and display FIASCO-FILEs using X11.", -#endif /* not X_DISPLAY_MISSING */ - "With no FIASCO-FILE, or if FIASCO-FILE is -, " - "read standard input.\n" -#ifndef X_DISPLAY_MISSING - "With --output=[FILE] specified, " - "write frames without displaying them.\n\n" -#endif /* not X_DISPLAY_MISSING */ - "Environment:\n" - "FIASCO_DATA Search path for automata files. " - "Default: ./\n" - "FIASCO_IMAGES Save path for image files. " + optind = parseargs(params, argc, argv, + "Decode FIASCO-FILEs and write frame(s) to disk.", + "With no FIASCO-FILE, or if FIASCO-FILE is -, " + "read standard input.\n" + "Environment:\n" + "FIASCO_DATA Search path for automata files. " + "Default: ./\n" + "FIASCO_IMAGES Save path for image files. " "Default: ./", " [FIASCO-FILE]...", - FIASCO_SHARE, "system.fiascorc", ".fiascorc"); + FIASCO_SHARE, "system.fiascorc", ".fiascorc"); *image_name = (char *) parameter_value (params, "output"); *double_resolution = *((bool_t *) parameter_value (params, "double")); *panel = *((bool_t *) parameter_value (params, "panel")); - *fps = *((int *) parameter_value (params, "framerate")); + *fps = *((int *) parameter_value (params, "framerate")); - /* - * Additional options ... (have to be set with the fiasco_set_... methods) + /* Additional options ... (have to be set with the fiasco_set_... methods) */ - *options = fiasco_d_options_new (); + *options = fiasco_d_options_new(); { - int const n = *((int *) parameter_value (params, "smoothing")); + int const n = *((int *)parameter_value(params, "smoothing")); - if (!fiasco_d_options_set_smoothing (*options, MAX(-1, n))) - error (fiasco_get_error_message ()); + if (!fiasco_d_options_set_smoothing(*options, MAX(-1, n))) + pm_error("%s", fiasco_get_error_message()); } { - int const n = *((int *) parameter_value (params, "magnify")); + int const n = *((int *)parameter_value(params, "magnify")); - if (!fiasco_d_options_set_magnification (*options, n)) - error (fiasco_get_error_message ()); + if (!fiasco_d_options_set_magnification(*options, n)) + pm_error("%s", fiasco_get_error_message()); } { - bool_t const n = *((bool_t *) parameter_value (params, "fast")); + 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 ()); + if (!fiasco_d_options_set_4_2_0_format(*options, n > 0 ? YES : NO)) + pm_error("%s", fiasco_get_error_message ()); } return optind; } + + static void -video_decoder (const char *wfa_name, const char *image_name, bool_t panel, - bool_t double_resolution, int fps, fiasco_d_options_t *options) -{ -#ifndef X_DISPLAY_MISSING - fiasco_renderer_t *renderer = NULL; - unsigned char **frame_buffer = NULL; - binfo_t *binfo = NULL; /* buttons info */ -#endif /* not X_DISPLAY_MISSING */ - - do - { - unsigned width, height, frames, n; - fiasco_decoder_t *decoder_state; - char *filename; - 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 */ - fps = fiasco_decoder_get_rate (decoder_state); +video_decoder(const char * const wfa_name, + const char * const image_name, + bool_t const panel, + bool_t const double_resolution, + int const fpsArg, + fiasco_d_options_t * const options) { + do { + int fps; + unsigned int width, height; + unsigned int frames; + unsigned int n; + fiasco_decoder_t * decoder_state; + char * filename; + const char * basename; /* basename of decoded frame */ + const char * suffix; /* suffix of decoded frame */ + unsigned int frame_time; + + if (!(decoder_state = fiasco_decoder_new(wfa_name, options))) + pm_error("%s", fiasco_get_error_message ()); + + if (fpsArg <= 0) /* then use value of FIASCO file */ + fps = fiasco_decoder_get_rate(decoder_state); + else + fps = fpsArg; + frame_time = fps ? (1000 / fps) : (1000 / 25); - if (!(width = fiasco_decoder_get_width (decoder_state))) - error (fiasco_get_error_message ()); + if (!(width = fiasco_decoder_get_width(decoder_state))) + pm_error("%s", fiasco_get_error_message ()); - if (!(height = fiasco_decoder_get_height (decoder_state))) - error (fiasco_get_error_message ()); + if (!(height = fiasco_decoder_get_height(decoder_state))) + pm_error("%s", fiasco_get_error_message ()); - if (!(frames = fiasco_decoder_get_length (decoder_state))) - error (fiasco_get_error_message ()); + if (!(frames = fiasco_decoder_get_length(decoder_state))) + pm_error("%s", fiasco_get_error_message ()); - get_output_template (image_name, wfa_name, - fiasco_decoder_is_color (decoder_state), - &basename, &suffix); + getOutputTemplate(image_name, wfa_name, + fiasco_decoder_is_color(decoder_state), + &basename, &suffix); - filename = calloc (strlen (basename) + strlen (suffix) + 2 - + 10 + (int) (log10 (frames) + 1), sizeof (char)); - if (!filename) - error ("Out of memory."); + MALLOCARRAY_NOFAIL(filename, + strlen (basename) + strlen (suffix) + 2 + + 10 + (int) (log10 (frames) + 1)); - for (n = 0; n < frames; n++) - { + for (n = 0; n < frames; ++n) { clock_t fps_timer; /* frames per second timer struct */ - prg_timer (&fps_timer, START); + prg_timer(&fps_timer, START); - if (image_name) /* just write frame to disk */ - { - if (frames == 1) /* just one image */ - { - if (streq (image_name, "-")) - strcpy (filename, "-"); + if (image_name) { + /* just write frame to disk */ + if (frames == 1) { + if (streq(image_name, "-")) + strcpy(filename, "-"); else - sprintf (filename, "%s.%s", basename, suffix); - } - else - { - fprintf (stderr, "Decoding frame %d to file `%s.%0*d.%s\n", - n, basename, (int) (log10 (frames - 1) + 1), - n, suffix); - sprintf (filename, "%s.%0*d.%s", basename, - (int) (log10 (frames - 1) + 1), n, suffix); + sprintf(filename, "%s.%s", basename, suffix); + } else { + pm_message("Decoding frame %d to file `%s.%0*d.%s", + n, basename, (int) (log10 (frames - 1) + 1), + n, suffix); + sprintf(filename, "%s.%0*d.%s", basename, + (int) (log10 (frames - 1) + 1), n, suffix); } if (!fiasco_decoder_write_frame (decoder_state, filename)) - error (fiasco_get_error_message ()); - } -#ifndef X_DISPLAY_MISSING - 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 = - fiasco_decoder_get_title (decoder_state); - char titlename [MAXSTRLEN]; - - - sprintf (titlename, "dfiasco " VERSION ": %s", - strlen (title) > 0 ? title : wfa_name); - xinfo = - open_window (titlename, "dfiasco", - (width << (double_resolution ? 1 : 0)), - (height << (double_resolution ? 1 : 0)) - + (panel ? 30 : 0)); - alloc_ximage (xinfo, width << (double_resolution ? 1 : 0), - height << (double_resolution ? 1 : 0)); - if (panel) /* initialize button panel */ - binfo = init_buttons (xinfo, n, frames, 30, 10); - renderer = - fiasco_renderer_new (xinfo->ximage->red_mask, - xinfo->ximage->green_mask, - xinfo->ximage->blue_mask, - xinfo->ximage->bits_per_pixel, - double_resolution); - if (!renderer) - error (fiasco_get_error_message ()); - } - renderer->render (renderer, xinfo->pixels, frame); - frame->delete (frame); - - if (frame_buffer != NULL) /* store next frame */ - { - size_t size = (width << (double_resolution ? 1 : 0)) - * (height << (double_resolution ? 1 : 0)) - * (xinfo->ximage->depth <= 8 - ? sizeof (byte_t) - : (xinfo->ximage->depth <= 16 - ? sizeof (u_word_t) - : sizeof (unsigned int))); - - frame_buffer [n] = malloc (size); - if (!frame_buffer [n]) - error ("Out of memory."); - memcpy (frame_buffer [n], xinfo->pixels, size); - - if (n == frames - 1) - { - show_stored_frames (frame_buffer, frames - 1, - xinfo, binfo, size, frame_time); - break; - } - } - - display_image (0, 0, xinfo); - if (frames == 1) - wait_for_input (xinfo); - else if (panel) - { - check_events (xinfo, binfo, n, frames); - if (binfo->pressed [QUIT_BUTTON]) - /* start from beginning */ - break; - if (binfo->pressed [STOP_BUTTON]) - /* start from beginning */ - n = frames; - - if (binfo->pressed [RECORD_BUTTON] && frame_buffer == NULL) - { - n = frames; - frame_buffer = - calloc (frames, sizeof (unsigned char *)); - if (!frame_buffer) - error ("Out of memory."); - } - } - while (prg_timer (&fps_timer, STOP) < frame_time) /* wait */ - ; + pm_error("%s", fiasco_get_error_message ()); } -#else if (frame_time) {/* defeat compiler warning */} -#endif /* not X_DISPLAY_MISSING */ } - free (filename); + free(filename); - fiasco_decoder_delete (decoder_state); - } while (panel - -#ifndef X_DISPLAY_MISSING - && !binfo->pressed [QUIT_BUTTON] -#endif /* not X_DISPLAY_MISSING */ + fiasco_decoder_delete(decoder_state); + } while (panel); +} - ); +int +main(int argc, const char **argv) { -#ifndef X_DISPLAY_MISSING - if (renderer) - renderer->delete (renderer); + const char * imageName; /* output filename */ + bool_t doubleResolution;/* double resolution of image */ + bool_t panel; /* control panel */ + int fps; /* frame display rate */ + fiasco_d_options_t * options;/* additional coder options */ + unsigned int lastArg; /* last processed cmdline parameter */ - if (!image_name) - { - close_window (xinfo); - free (xinfo); - xinfo = NULL; - if (binfo) - free (binfo); - } -#endif /* not X_DISPLAY_MISSING */ -} + lastArg = checkargs(argc, argv, &doubleResolution, &panel, &fps, + &imageName, &options); -static void -get_output_template (const char *image_name, const char *wfa_name, - bool_t color, char **basename, char **suffix) -/* - * Generate image filename template for output of image sequences. - * 'wfa_name' is the filename of the WFA stream. - * Images are either saved with filename 'basename'.'suffix' (still images) - * or 'basename'.%03d.'suffix' (videos). - * - * No return value. - * - * Side effects: - * '*basename' and '*suffix' is set. - */ -{ - if (!wfa_name || streq (wfa_name, "-")) - wfa_name = "stdin"; - /* - * Generate filename template - */ - if (!image_name || streq (image_name, "") || streq (image_name, "-")) - { - *basename = strdup (wfa_name); - *suffix = NULL; - } + if (lastArg >= argc) + video_decoder("-", imageName, panel, doubleResolution, fps, options); else - { - *basename = strdup (image_name); - *suffix = strrchr (*basename, '.'); - } + while (lastArg++ < argc) + video_decoder(argv [lastArg - 1], imageName, panel, + doubleResolution, fps, options); - if (*suffix) /* found name 'basename.suffix' */ - { - **suffix = 0; /* remove dot */ - (*suffix)++; - if (**suffix == 0) - *suffix = strdup (color ? "ppm" : "pgm"); - } - else /* no suffix found, generate one */ - *suffix = strdup (color ? "ppm" : "pgm"); + return 0; } -#ifndef X_DISPLAY_MISSING - -static void -show_stored_frames (unsigned char * const *frame_buffer, int last_frame, - x11_info_t *xinfo, binfo_t *binfo, size_t size, - unsigned frame_time) -/* - * After a WFA video stream has been saved, all frames have been - * decoded and stored in memory. These frames are then displayed - * in an endless loop. - * - * This function never returns, the program is terminated if the - * STOP button is pressed. - */ -{ - 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); - - if (binfo->pressed [STOP_BUTTON]) - n = 0; - else if (binfo->pressed [QUIT_BUTTON]) - break; - else if (binfo->pressed [PLAY_BUTTON]) - n++; - else if (binfo->pressed [RECORD_BUTTON]) /* REWIND is mapped RECORD */ - n--; - if (n < 0) - n = last_frame; - if (n > last_frame) - n = 0; - - memcpy (xinfo->pixels, frame_buffer [n], size); - while (prg_timer (&fps_timer, STOP) < frame_time) /* wait */ - ; - }; -} -#endif /* not X_DISPLAY_MISSING */ diff --git a/converter/other/fiasco/params.c b/converter/other/fiasco/params.c index 32145fc3..042a14e2 100644 --- a/converter/other/fiasco/params.c +++ b/converter/other/fiasco/params.c @@ -22,6 +22,7 @@ #include "config.h" +#include <assert.h> #include <stdio.h> #include <ctype.h> #include <math.h> /* strtod() on SUN sparc */ @@ -32,6 +33,7 @@ #include <getopt.h> /* system or ../lib */ #include "pm_c_util.h" +#include "mallocvar.h" #include "nstring.h" #include "types.h" @@ -40,626 +42,181 @@ #include "misc.h" #include "fiasco.h" -#include "binerror.h" - #include "params.h" -/***************************************************************************** - - prototypes - -*****************************************************************************/ static void -read_parameter_file (param_t *params, FILE *file); -static int -get_parameter_index (const param_t *params, const char *search_string); -static void -set_parameter (param_t *parameter, const char *value); -static void -usage (const param_t *params, const char *progname, const char *synopsis, - const char *comment, const char *non_opt_string, - bool_t show_all_options, const char *sys_file_name, - const char *usr_file_name); +setParameter(param_t * const parameter, + const char * const value) { +/*---------------------------------------------------------------------------- -/***************************************************************************** + Set value of 'parameter' to 'value'. - public code + No return value. -*****************************************************************************/ + Side effects: + 'parameter.value' is changed accordingly -int -parseargs (param_t *usr_params, - int argc, char **argv, - const char *synopsis, - const char *comment, - const char *non_opt_string, - const char *path, - const char *sys_file_name, - const char *usr_file_name) -/* - * Perform the command line parsing. - * List of allowed parameters is given by 'usr_params'. - * Command line and number of parameters are given by 'argv' and 'argc'. - * '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) - * - * Return value: - * index in ARGV of the first ARGV-element that is not an option. - * - * Side effects: - * 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 */ - param_t detailed_sys_params [] = /* detailed system parameters */ - { - {"version", NULL, 'v', PFLAG, {0}, NULL, - "Print program version number, then exit."}, - {"verbose", "NUM", 'V', PINT, {0}, "1", - "Set level of verbosity to `%s'."}, - {"config", "FILE", 'f', PSTR, {0}, NULL, - "Load `%s' to initialize parameters."}, - {"info", NULL, 'h', PFLAG, {0}, NULL, - "Print brief help, then exit."}, - {"help", NULL, 'H', PFLAG, {0}, NULL, - "Print detailed help, then exit."}, - {NULL, NULL, 0, PSTR, {0}, NULL, NULL } - }; - param_t short_sys_params [] = /* short system parameters */ - { - {"version", NULL, 'v', PFLAG, {0}, NULL, - "Print program version number, then exit."}, - {"verbose", "NUM", 'V', PINT, {0}, "1", - "Set level of verbosity to `%s'."}, - {"config", "FILE", 'f', PSTR, {0}, NULL, - "Load `%s' to initialize parameters."}, - {"help", NULL, 'h', PFLAG, {0}, NULL, - "Print this help, then exit."}, - {NULL, NULL, 0, PSTR, {0}, NULL, NULL } - }; - char *sys_path; /* path to system config file */ - - sys_path = calloc (strlen (path) + strlen (sys_file_name) + 2, - sizeof (char)); - if (!sys_path) - error ("Out of memory."); - sprintf (sys_path, "%s/%s", path, sys_file_name); - - /* - * Set parameters defaults - */ - { - param_t *p; - - for (p = usr_params; p->name != NULL; p++) - { - set_parameter (p, p->default_value); - if (p->optchar == '\0') - detailed_help = YES; - } - - sys_params = detailed_help ? detailed_sys_params : short_sys_params; - - for (p = sys_params; p->name != NULL; p++) - set_parameter (p, p->default_value); - } - /* - * Append system command line option to user parameters - */ - for (n1 = 0; usr_params [n1].name != NULL; n1++) - ; - for (n2 = 0; sys_params [n2].name != NULL; n2++) - ; - params = calloc (n1 + n2 + 1, sizeof (param_t)); - if (!params) - error ("Out of memory."); - - memcpy (params, usr_params, n1 * sizeof (param_t)); - memcpy (params + n1, sys_params, (n2 + 1) * sizeof (param_t)); - /* - * Try to open the system resource file 'path'/'sys_file_name' - */ - { - FILE *parameter_file = open_file (sys_path, NULL, READ_ACCESS); - if (parameter_file == NULL) -/* - warning ("No system resource file found."); -*/ {} - else - { - read_parameter_file (params, parameter_file); - fclose (parameter_file); - } - } - /* - * Try to read user resource file $HOME/'usr_file_name' - */ - { - FILE *parameter_file = open_file (usr_file_name, "HOME", READ_ACCESS); - if (parameter_file != NULL) - { - 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 */ - - /* - * 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'; - } - - /* - * 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; - } - } - - /* - * Parse command line - */ - while ((optchar = getopt_long (argc, argv, optstr, long_options, - &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; +-----------------------------------------------------------------------------*/ + assert (parameter); - 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 */ - char * modified_argv[2]; - int argc; - modified_argv[0] = argv[0]; - modified_argv[1] = (char *) "--version"; - argc = 2; - pm_proginit(&argc, (const char **) modified_argv); - } - exit (2); + 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) + pm_message("Invalid value `%s' converted to %d", + value, (int) data); + parameter->value.b = data ? YES : NO; } - 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 */ - } - } - - free (long_options); - } - - /* - * Read config-file if specified by option -f - */ - if (read_config_file) - { - char *filename; - - 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); - } - else - error ("Invalid config filename."); - } - - memcpy (usr_params, params, n1 * sizeof (param_t)); /* fill user struct */ - free (sys_path); - - return optind; + } 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) + pm_message("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) + pm_message("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; + default: + pm_error("Invalid parameter type for %s", parameter->name); + } } -void * -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 - */ -{ - int pind = get_parameter_index (params, name); - if (pind < 0) - error ("Invalid parameter `%s'.", name); - if (params [pind].type == PSTR || params [pind].type == POSTR) - return (void *) params [pind].value.s; +static int +getParameterIndex(const param_t * const params, + const char * const 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 +-----------------------------------------------------------------------------*/ + int n; + int index = -1; + + assert (params && search_string); + + for (n = 0; params [n].name != NULL; n++) { + if (strcaseeq (params [n].name, search_string)) { + index = n; + break; + } + } - return (void *) &(params [pind].value); + return index; } -void -ask_and_set (param_t *params, const char *name, const char *msg) -/* - * Ask user (print given message 'msg') for missing mandatory - * parameter 'name' of the given parameters 'params'. - * - * No return value. - * - * Side effects: - * 'params ['name'].value' is changed - */ -{ - char answer [MAXSTRLEN]; - int index = get_parameter_index (params, name); - - if (index < 0) - error ("Invalid parameter %s.", name); - - if (msg) - fprintf (stderr, "%s\n", msg); - - switch (params [index].type) - { - 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; - default: - error ("Invalid parameter type for %s", name); - } -} -void -write_parameters (const param_t *params, FILE *output) -/* - * Write all parameter settings to 'output'. - * - * No return value. - */ -{ - int pind; - - if (!params || !output) - error ("Parameters must be not NULL."); - - for (pind = 0; params [pind].name != NULL; pind++) - { - 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); - } - } - fputc ('\n', output); -} -/***************************************************************************** +static void +readParameterFile(param_t * const params, + FILE * const file) { +/*---------------------------------------------------------------------------- - private code + Read parameter settings from 'file'. -*****************************************************************************/ + No return value. -static void -set_parameter (param_t *parameter, const char *value) -/* - * Set value of 'parameter' to 'value'. - * - * No return value. - * - * Side effects: - * 'parameter.value' is changed accordingly - */ -{ - assert (parameter); - - 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; - 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; - 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; - case PSTR: - case POSTR: - parameter->value.s = value ? strdup (value) : NULL; - break; - default: - error ("Invalid parameter type for %s", parameter->name); - } -} + Side effects: + 'params [].value' are changed if specified in 'file' +-----------------------------------------------------------------------------*/ + char buffer [MAXSTRLEN]; + int n = 0; -static int -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 - */ -{ - int n; - int index = -1; + assert (params && file); - assert (params && search_string); + while (fgets (buffer, MAXSTRLEN, file) != NULL) { + char *b; /* temporary variable */ + char *name; /* parameter name */ + char *value; /* parameter value */ + int pind; /* current argument number */ - for (n = 0; params [n].name != NULL; n++) - if (strcaseeq (params [n].name, search_string)) - { - index = n; - break; - } + b = strchr (buffer, '#'); + if (b != NULL) /* Strip comments. */ + *b = '\0'; - return index; -} + b = strchr (buffer, '='); + if (b == NULL) /* Strip lines that contain no '=' */ + continue; + *b = '\0'; /* Replace '=' by string terminator */ -static void -read_parameter_file (param_t *params, FILE *file) -/* - * Read parameter settings from 'file'. - * - * No return value. - * - * Side effects: - * 'params [].value' are changed if specified in 'file' - */ -{ - char buffer [MAXSTRLEN]; - int n = 0; - - assert (params && file); - - while (fgets (buffer, MAXSTRLEN, file) != NULL) - { - 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'; - - b = strchr (buffer, '='); - 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 */ - - for (b = value + strlen (value) - 1; b >= value && ISSPACE (*b); b--) - *b = '\0'; /* Delete trailing spaces. */ - - /* - * Extract parameter name - */ - for (name = buffer; ISSPACE (*name); name++) - ; /* Delete leading spaces */ - - for (b = name + strlen (name) - 1; b >= name && ISSPACE (*b); b--) - *b = '\0'; /* Delete trailing spaces. */ - - pind = get_parameter_index (params, name); - if (pind >= 0) - set_parameter (¶ms [pind], value); - - n++; - } + /* Extract value of parameter */ + for (value = b + 1; ISSPACE (*value); value++) + ; /* Delete leading spaces */ + + for (b = value + strlen (value) - 1; b >= value && ISSPACE (*b); b--) + *b = '\0'; /* Delete trailing spaces. */ + + /* Extract parameter name */ + for (name = buffer; ISSPACE (*name); name++) + ; /* Delete leading spaces */ + + for (b = name + strlen (name) - 1; b >= name && ISSPACE (*b); b--) + *b = '\0'; /* Delete trailing spaces. */ + + pind = getParameterIndex(params, name); + if (pind >= 0) + setParameter(¶ms[pind], value); + + ++n; + } } static void -usage (const param_t *params, const char *progname, const char *synopsis, - const char *comment, const char *non_opt_string, - bool_t show_all_options, const char *sys_file_name, - const char *usr_file_name) -/* - * Generates and prints command line description from param_t struct 'params'. - * 'progname' is the name of the executable, 'synopsis' a short program - * description, and 'comment' some more advice. - * If flag 'show_all_options' is set then print also options that are not - * associated with a short option character. - * 'sys_file_name' and 'usr_file_name' are filenames to parameter files. - * - * No return value. - */ -{ +usage(const param_t * const params, + const char * const progname, + const char * const synopsis, + const char * const comment, + const char * const non_opt_string, + bool_t const show_all_options, + const char * const sys_file_name, + const char * const usr_file_name) { +/*---------------------------------------------------------------------------- + + Generates and prints command line description from param_t struct 'params'. + 'progname' is the name of the executable, 'synopsis' a short program + description, and 'comment' some more advice. + If flag 'show_all_options' is set then print also options that are not + associated with a short option character. + 'sys_file_name' and 'usr_file_name' are filenames to parameter files. + + No return value. +-----------------------------------------------------------------------------*/ int i; size_t width = 0; @@ -671,9 +228,8 @@ usage (const param_t *params, const char *progname, const char *synopsis, fprintf (stderr, "Mandatory or optional arguments to long options " "are mandatory or optional\nfor short options too. " "Default values are surrounded by {}.\n"); - for (i = 0; params [i].name != NULL; i++) - if (params [i].optchar != '\0' || show_all_options) - { + for (i = 0; params [i].name != NULL; i++) { + if (params [i].optchar != '\0' || show_all_options) { if (params [i].type == POSTR) width = MAX(width, (strlen (params [i].name) + strlen (params [i].argument_name) + 2)); @@ -683,10 +239,9 @@ usage (const param_t *params, const char *progname, const char *synopsis, else width = MAX(width, (strlen (params [i].name)) - 1); } - - for (i = 0; params [i].name != NULL; i++) - if (params [i].optchar != '\0' || show_all_options) - { + } + for (i = 0; params [i].name != NULL; i++) { + if (params [i].optchar != '\0' || show_all_options) { if (params [i].optchar != '\0') fprintf (stderr, " -%c, --", params [i].optchar); else @@ -708,8 +263,7 @@ usage (const param_t *params, const char *progname, const char *synopsis, fprintf (stderr, params [i].use, params [i].argument_name); - switch (params [i].type) - { + switch (params [i].type) { case PFLAG: break; case PINT: @@ -724,20 +278,407 @@ usage (const param_t *params, const char *progname, const char *synopsis, fprintf (stderr, "{%s}", params [i].value.s); break; default: - error ("type %d for %s invalid", - params [i].type, params [i].name); + pm_error("type %d for %s invalid", + params [i].type, params [i].name); } fprintf (stderr, "\n"); } + } fprintf (stderr, "\n"); + fprintf (stderr, "Parameter initialization order:\n"); fprintf (stderr, "1.) %s\n2.) $HOME/%s\t 3.) command line\t 4.) --config=file", sys_file_name, usr_file_name); fprintf (stderr, "\n\n"); + if (comment != NULL) fprintf (stderr, "%s\n", comment); exit (1); } + + +const void * +parameter_value(const param_t * const params, + const char * const name) { +/*---------------------------------------------------------------------------- + Extract value of parameter 'name.' of the given parameters 'params'. + + Return value: value of given parameter + +-----------------------------------------------------------------------------*/ + int pind = getParameterIndex(params, name); + + if (pind < 0) + pm_error("Invalid parameter '%s'.", name); + + if (params[pind].type == PSTR || params[pind].type == POSTR) + return params[pind].value.s; + + return &(params[pind].value); +} + + + +int +parseargs(param_t * const usr_params, + int argc, + const char ** const argv, + const char * const synopsis, + const char * const comment, + const char * const non_opt_string, + const char * const path, + const char * const sys_file_name, + const char * const usr_file_name) { +/*---------------------------------------------------------------------------- + Perform the command line parsing. + List of allowed parameters is given by 'usr_params'. + Command line and number of parameters are given by 'argv' and 'argc'. + '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) + + Return value: + index in ARGV of the first ARGV-element that is not an option. + + Side effects: + 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 */ + param_t detailed_sys_params [] = /* detailed system parameters */ + { + {"version", NULL, 'v', PFLAG, {0}, NULL, + "Print program version number, then exit."}, + {"verbose", "NUM", 'V', PINT, {0}, "1", + "Set level of verbosity to `%s'."}, + {"config", "FILE", 'f', PSTR, {0}, NULL, + "Load `%s' to initialize parameters."}, + {"info", NULL, 'h', PFLAG, {0}, NULL, + "Print brief help, then exit."}, + {"help", NULL, 'H', PFLAG, {0}, NULL, + "Print detailed help, then exit."}, + {NULL, NULL, 0, PSTR, {0}, NULL, NULL } + }; + param_t short_sys_params [] = /* short system parameters */ + { + {"version", NULL, 'v', PFLAG, {0}, NULL, + "Print program version number, then exit."}, + {"verbose", "NUM", 'V', PINT, {0}, "1", + "Set level of verbosity to `%s'."}, + {"config", "FILE", 'f', PSTR, {0}, NULL, + "Load `%s' to initialize parameters."}, + {"help", NULL, 'h', PFLAG, {0}, NULL, + "Print this help, then exit."}, + {NULL, NULL, 0, PSTR, {0}, NULL, NULL } + }; + const char * sys_path; /* path to system config file */ + + pm_asprintf(&sys_path, "%s/%s", path, sys_file_name); + + /* Set parameters defaults */ + { + param_t *p; + + for (p = usr_params; p->name != NULL; p++) + { + setParameter(p, p->default_value); + if (p->optchar == '\0') + detailed_help = YES; + } + + sys_params = detailed_help ? detailed_sys_params : short_sys_params; + + for (p = sys_params; p->name != NULL; p++) + setParameter(p, p->default_value); + } + /* Append system command line option to user parameters */ + for (n1 = 0; usr_params [n1].name != NULL; n1++) + ; + for (n2 = 0; sys_params [n2].name != NULL; n2++) + ; + MALLOCARRAY_NOFAIL(params, n1 + n2 + 1); + + memcpy(params, usr_params, n1 * sizeof(param_t)); + memcpy(params + n1, sys_params, (n2 + 1) * sizeof(param_t)); + + { + /* Try to open the system resource file 'path'/'sys_file_name' */ + + FILE *parameter_file = open_file(sys_path, NULL, READ_ACCESS); + + if (parameter_file) { + readParameterFile(params, parameter_file); + fclose(parameter_file); + } + } + { + /* Try to read user resource file $HOME/'usr_file_name' */ + + FILE *parameter_file = open_file(usr_file_name, "HOME", READ_ACCESS); + + if (parameter_file) { + readParameterFile(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 */ + + { + /* 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'; + } + + { + /* Build long option string for getopt_long (). */ + + int i; + + MALLOCARRAY_NOFAIL(long_options, n1 + n2 + 1); + + 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, (char **)argv, optstr, + long_options, + &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) { + setParameter(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 */ + const char * modifiedArgv[2]; + int argc; + modifiedArgv[0] = argv[0]; + modifiedArgv[1] = (char *) "--version"; + argc = 2; + pm_proginit(&argc, modifiedArgv); + } + exit (2); + } 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 */ + } + } + free(long_options); + } + + /* Read config-file if specified by option -f */ + if (read_config_file) { + char * filename; + + if ((filename = (char *) parameter_value(params, "config")) != NULL) { + FILE * parameter_file; /* input file */ + + pm_message("Options set in file `%s' will override" + " command line options.", filename); + parameter_file = open_file(filename, NULL, READ_ACCESS); + if (parameter_file != NULL) { + readParameterFile(params, parameter_file); + fclose(parameter_file); + } else + pm_error("Failed to open config file '%s'", filename); + } else + pm_error("Invalid config filename."); + } + + memcpy(usr_params, params, n1 * sizeof (param_t)); /* fill user struct */ + pm_strfree(sys_path); + + return optind; +} + + + +void +ask_and_set(param_t * const params, + const char * const name, + const char * const msg) { +/*---------------------------------------------------------------------------- + Ask user (print given message 'msg') for missing mandatory + parameter 'name' of the given parameters 'params'. + + No return value. + + Side effects: + 'params ['name'].value' is changed +-----------------------------------------------------------------------------*/ + char answer[MAXSTRLEN]; + int index = getParameterIndex(params, name); + + if (index < 0) + pm_error("Invalid parameter '%s'.", name); + + if (msg) + pm_message("%s", msg); + + switch (params[index].type) { + case PFLAG: /* Unusual, at least. */ + pm_message("Flags should be initialized and set on demand, " + "not request"); + case PINT: + case PSTR: + case POSTR: + case PFLOAT: + scanf(MAXSTRLEN_SCANF, answer); + setParameter(¶ms [index], answer); + break; + default: + pm_error("Invalid parameter type for %s", name); + } +} + + + +void +write_parameters(const param_t * const params, + FILE * const output) { +/*---------------------------------------------------------------------------- + Write all parameter settings to 'output'. + + No return value. +-----------------------------------------------------------------------------*/ + unsigned int pind; + + if (!params || !output) + pm_error("Parameters must be not NULL."); + + for (pind = 0; params[pind].name != NULL; pind++) { + 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: + pm_error("Invalid type %d for parameter %s", + params[pind].type, params[pind].name); + } + } + fputc ('\n', output); +} + + + diff --git a/converter/other/fiasco/params.h b/converter/other/fiasco/params.h index dd79d43d..85b0b648 100644 --- a/converter/other/fiasco/params.h +++ b/converter/other/fiasco/params.h @@ -44,7 +44,7 @@ typedef struct param_t int parseargs (param_t *usr_params, - int argc, char **argv, + int argc, const char **argv, const char *synopsis, const char *comment, const char *non_opt_string, @@ -53,9 +53,11 @@ parseargs (param_t *usr_params, const char *usr_file_name); void write_parameters (const param_t *params, FILE *output); + void ask_and_set (param_t *params, const char *name, const char *msg); -void * + +const void * parameter_value (const param_t *params, const char *name); #endif /* not PARAMS_H */ diff --git a/converter/other/fiasco/pnmtofiasco.c b/converter/other/fiasco/pnmtofiasco.c index 9f63e7a1..311a21c3 100644 --- a/converter/other/fiasco/pnmtofiasco.c +++ b/converter/other/fiasco/pnmtofiasco.c @@ -1,5 +1,5 @@ /* - * cwfa.c: FIASCO coder + * FIASCO coder * * Written by: Ullrich Hafner * @@ -15,32 +15,25 @@ */ #include "config.h" -#include "pm_c_util.h" -#include "pnm.h" - #include <stdlib.h> #include <string.h> #include <string.h> +#include "pm_c_util.h" +#include "mallocvar.h" +#include "pnm.h" + #include "types.h" #include "macros.h" -#include "binerror.h" #include "misc.h" #include "params.h" #include "fiasco.h" -/***************************************************************************** - local variables -*****************************************************************************/ - -static param_t params [] = -{ - /* - * Options for standard user - */ +static param_t params[] = { + /* Options for standard user */ {"image-name", "FILE", 'i', PSTR, {0}, NULL, "Compress raw PPM/PGM image(s) `%s'."}, {"output-name", "FILE", 'o', PSTR, {0}, "-", @@ -136,244 +129,202 @@ static param_t params [] = {NULL, NULL, 0, PSTR, {0}, NULL, NULL } }; -/***************************************************************************** - - prototypes - -*****************************************************************************/ - -static void -checkargs (int argc, char **argv, char const ***image_template, - char **wfa_name, float *quality, fiasco_c_options_t **options); - -/***************************************************************************** - - public code - -*****************************************************************************/ - -int -main (int argc, char **argv) -{ - char const **image_template; /* template for input image files */ - char *wfa_name; /* filename of output WFA */ - float quality; /* approximation quality */ - fiasco_c_options_t *options; /* additional coder options */ - - pnm_init(&argc, argv); - - init_error_handling (argv [0]); - - checkargs (argc, argv, &image_template, &wfa_name, &quality, &options); - - if (fiasco_coder (image_template, wfa_name, quality, options)) - return 0; - else - { - fprintf (stderr, "%s", fiasco_get_error_message ()); - fprintf (stderr, "\n"); - return 1; - } -} - -/***************************************************************************** - - private code -*****************************************************************************/ static void -checkargs (int argc, char **argv, char const ***image_template, - char **wfa_name, float *quality, fiasco_c_options_t **options) -/* - * Check validness of command line parameters and of the parameter files. - * - * Return value: - * 1 on success - * 0 otherwise - * - * - * Side effects: - * 'image_template', 'wfa_name', 'quality' and 'options' are set. - */ -{ - int optind; /* last processed commandline param */ - char *image_name; /* filename given by option '--input_name' */ - int i; /* counter */ - - optind = parseargs (params, argc, argv, - "Compress raw PPM/PGM image FILEs to a FIASCO file.", - "With no image FILE, or if FILE is -, " - "read standard input.\n" - "FILE must be either a filename" - " or an image template of the form:\n" - "`prefix[start-end{+,-}step]suffix'\n" - "e.g., img0[12-01-1].pgm is substituted by" - " img012.pgm ... img001.pgm\n\n" - "Environment:\n" - "FIASCO_DATA Search and save path for FIASCO files. " - "Default: ./\n" - "FIASCO_IMAGES Search path for image files. " - "Default: ./", " [FILE]...", - FIASCO_SHARE, "system.fiascorc", ".fiascorc"); - - /* - * Default options ... - */ - image_name = (char *) parameter_value (params, "image-name"); - *wfa_name = (char *) parameter_value (params, "output-name"); - for (;;) - { - *quality = * (float *) parameter_value (params, "quality"); +checkargs(int argc, + const char ** argv, + const char *** const imageTemplateListP, + char ** const wfa_name, + float * const quality, + fiasco_c_options_t ** const options) { +/*---------------------------------------------------------------------------- + Check validness of command line parameters and of the parameter files. + + Return value: + 1 on success + 0 otherwise +-----------------------------------------------------------------------------*/ + int optind; /* last processed commandline param */ + char * image_name; /* filename given by option '--input_name' */ + const char ** imageTemplateList; + + optind = parseargs(params, argc, argv, + "Compress raw PPM/PGM image FILEs to a FIASCO file.", + "With no image FILE, or if FILE is -, " + "read standard input.\n" + "FILE must be either a filename" + " or an image template of the form:\n" + "`prefix[start-end{+,-}step]suffix'\n" + "e.g., img0[12-01-1].pgm is substituted by" + " img012.pgm ... img001.pgm\n\n" + "Environment:\n" + "FIASCO_DATA Search and save path for FIASCO files. " + "Default: ./\n" + "FIASCO_IMAGES Search path for image files. " + "Default: ./", " [FILE]...", + FIASCO_SHARE, "system.fiascorc", ".fiascorc"); + + /* Default options */ + image_name = (char *) parameter_value(params, "image-name"); + *wfa_name = (char *) parameter_value(params, "output-name"); + for (;;) { + *quality = * (float *) parameter_value(params, "quality"); if (*quality > 100) - fprintf (stderr, "Typical range of quality: (0,100].\n" - "Expect some trouble on slow machines.\n"); + pm_message("Typical range of quality: (0,100]. " + "Expect some trouble on slow machines."); if (*quality > 0) break; - ask_and_set (params, "quality", - "Please enter coding quality 'q' ('q' > 0): "); + ask_and_set(params, "quality", + "Please enter coding quality 'q' ('q' > 0): "); } - if (optind < argc) /* Additional command line param */ - { + /* Non-option command line params */ + if (optind < argc) { + unsigned int i; if (image_name) - error ("Multiple image_template arguments." - "\nOption --input-name %s already specified!", image_name); - - *image_template = calloc (argc - optind + 1, sizeof (char *)); - if (!*image_template) - error ("Out of memory."); - for (i = 0; optind < argc; i++, optind++) - (*image_template) [i] = argv [optind]; - (*image_template) [i] = NULL; - } - else /* option -i image_name */ - { - *image_template = calloc (2, sizeof (char *)); - if (!*image_template) - error ("Out of memory."); - (*image_template) [0] = image_name; - (*image_template) [1] = NULL; + pm_error("Multiple image name template arguments. " + "Option --image-name already specified with '%s'", + image_name); + + MALLOCARRAY_NOFAIL(imageTemplateList, argc - optind + 1); + + for (i = 0; optind < argc; ++i, ++optind) + imageTemplateList[i] = argv[optind]; + imageTemplateList[i] = NULL; + } else { + /* option -i image_name */ + + MALLOCARRAY_NOFAIL(imageTemplateList, 2); + + imageTemplateList[0] = image_name; + imageTemplateList[1] = NULL; } - /* - * Additional options ... (have to be set with the fiasco_set_... methods) + /* Additional options ... (have to be set with the fiasco_set_... methods) */ { - *options = fiasco_c_options_new (); + *options = fiasco_c_options_new(); { - char *pattern = (char *) parameter_value (params, "pattern"); + const char * const pattern = parameter_value(params, "pattern"); if (!fiasco_c_options_set_frame_pattern (*options, pattern)) - error (fiasco_get_error_message ()); + pm_error("%s", fiasco_get_error_message ()); } { - char *basis = (char *) parameter_value (params, "basis-name"); + const char *const basis = parameter_value(params, "basis-name"); if (!fiasco_c_options_set_basisfile (*options, basis)) - error (fiasco_get_error_message ()); + pm_error("%s", fiasco_get_error_message ()); } { - int n = * (int *) parameter_value (params, "chroma-dictionary"); - float q = * (float *) parameter_value (params, "chroma-qfactor"); + int const n = + *(int *)parameter_value(params, "chroma-dictionary"); + float const q = + *(float *)parameter_value(params, "chroma-qfactor"); - if (!fiasco_c_options_set_chroma_quality (*options, q, MAX(0, n))) - error (fiasco_get_error_message ()); + if (!fiasco_c_options_set_chroma_quality(*options, q, MAX(0, n))) + pm_error("%s", fiasco_get_error_message ()); } { - int n = *((int *) parameter_value (params, "smooth")); + int const n = *((int *)parameter_value(params, "smooth")); - if (!fiasco_c_options_set_smoothing (*options, MAX(0, n))) - error (fiasco_get_error_message ()); + if (!fiasco_c_options_set_smoothing(*options, MAX(0, n))) + pm_error("%s", fiasco_get_error_message ()); } { - int n = * (int *) parameter_value (params, "progress-meter"); + int const n = *(int *)parameter_value(params, "progress-meter"); fiasco_progress_e type = (n < 0) ? FIASCO_PROGRESS_NONE : (fiasco_progress_e) n; - if (!fiasco_c_options_set_progress_meter (*options, type)) - error (fiasco_get_error_message ()); + if (!fiasco_c_options_set_progress_meter(*options, type)) + pm_error("%s", fiasco_get_error_message ()); } { - char *t = (char *) parameter_value (params, "title"); + const char * const t = parameter_value(params, "title"); - if (strlen (t) > 0 && !fiasco_c_options_set_title (*options, t)) - error (fiasco_get_error_message ()); + if (strlen(t) > 0 && !fiasco_c_options_set_title(*options, t)) + pm_error("%s", fiasco_get_error_message ()); } { - char *c = (char *) parameter_value (params, "comment"); + const char * const c = parameter_value(params, "comment"); if (strlen (c) > 0 && !fiasco_c_options_set_comment (*options, c)) - error (fiasco_get_error_message ()); + pm_error("%s", fiasco_get_error_message ()); } { fiasco_tiling_e method = FIASCO_TILING_VARIANCE_DSC; - int e = * (int *) parameter_value (params, "tiling-exponent"); - char *m = (char *) parameter_value (params, "tiling-method"); + int const e = + *(int *)parameter_value(params, "tiling-exponent"); + const char * const m = parameter_value (params, "tiling-method"); - if (strcaseeq (m, "desc-variance")) + if (strcaseeq(m, "desc-variance")) method = FIASCO_TILING_VARIANCE_DSC; - else if (strcaseeq (m, "asc-variance")) + else if (strcaseeq(m, "asc-variance")) method = FIASCO_TILING_VARIANCE_ASC; - else if (strcaseeq (m, "asc-spiral")) + else if (strcaseeq(m, "asc-spiral")) method = FIASCO_TILING_SPIRAL_ASC; - else if (strcaseeq (m, "dsc-spiral")) + else if (strcaseeq(m, "dsc-spiral")) method = FIASCO_TILING_SPIRAL_DSC; else - error (_("Invalid tiling method `%s' specified."), m); + pm_error("Invalid tiling method `%s' specified.", m); - if (!fiasco_c_options_set_tiling (*options, method, MAX(0, e))) - error (fiasco_get_error_message ()); + if (!fiasco_c_options_set_tiling(*options, method, MAX(0, e))) + pm_error("%s", fiasco_get_error_message ()); } { - int M/* = * (int *) parameter_value (params, "max-level") */; - int m/* = * (int *) parameter_value (params, "min-level") */; - int N/* = * (int *) parameter_value (params, "max-elements") */; - int D = * (int *) parameter_value (params, "dictionary-size"); - int o = * (int *) parameter_value (params, "optimize"); - - if (o <= 0) - { + int M /* = * (int *) parameter_value (params, "max-level") */; + int m /* = * (int *) parameter_value (params, "min-level") */; + int N /* = * (int *) parameter_value (params, "max-elements") */; + int o; + int D = * (int *) parameter_value(params, "dictionary-size"); + int const optimizeOpt = + *(int *)parameter_value(params, "optimize"); + + if (optimizeOpt <= 0) { o = 0; M = 10; m = 6; N = 3; - } - else - { + } else { o -= 1; M = 12; m = 4; N = 5; } - if (!fiasco_c_options_set_optimizations (*options, m, M, N, - MAX(0, D), o)) - error (fiasco_get_error_message ()); + if (!fiasco_c_options_set_optimizations(*options, m, M, N, + MAX(0, D), o)) + pm_error("%s", fiasco_get_error_message ()); } { - int M = * (int *) parameter_value (params, "max-level"); - int m = * (int *) parameter_value (params, "min-level"); - int p = * (int *) parameter_value (params, "prediction"); + int const M = *(int *)parameter_value(params, "max-level"); + int const m = *(int *)parameter_value(params, "min-level"); + int const p = *(int *)parameter_value(params, "prediction"); if (!fiasco_c_options_set_prediction (*options, p, MAX(0, m), MAX(0, M))) - error (fiasco_get_error_message ()); + pm_error("%s", fiasco_get_error_message ()); } { - float r = * (float *)parameter_value(params, "rpf-range"); - float dc_r = * (float *)parameter_value(params, "dc-rpf-range"); - int m = * (int *) parameter_value(params, "rpf-mantissa"); - int dc_m = * (int *) parameter_value(params, "dc-rpf-mantissa"); - fiasco_rpf_range_e range, dc_range; + float const r = + *(float *)parameter_value(params, "rpf-range"); + float const dcR = + *(float *)parameter_value(params, "dc-rpf-range"); + int const m = + *(int *)parameter_value(params, "rpf-mantissa"); + int const dcM = + *(int *)parameter_value(params, "dc-rpf-mantissa"); + + fiasco_rpf_range_e range, dcRange; if (r < 1) range = FIASCO_RPF_RANGE_0_75; @@ -384,24 +335,49 @@ checkargs (int argc, char **argv, char const ***image_template, else range = FIASCO_RPF_RANGE_2_00; - if (dc_r < 1) - dc_range = FIASCO_RPF_RANGE_0_75; - else if (dc_r < 1.5) - dc_range = FIASCO_RPF_RANGE_1_00; - else if (dc_r < 2.0) - dc_range = FIASCO_RPF_RANGE_1_50; + if (dcR < 1) + dcRange = FIASCO_RPF_RANGE_0_75; + else if (dcR < 1.5) + dcRange = FIASCO_RPF_RANGE_1_00; + else if (dcR < 2.0) + dcRange = FIASCO_RPF_RANGE_1_50; else - dc_range = FIASCO_RPF_RANGE_2_00; + dcRange = FIASCO_RPF_RANGE_2_00; - if (!fiasco_c_options_set_quantization (*options, - MAX(0, m), range, - MAX(0, dc_m), dc_range)) - error (fiasco_get_error_message ()); + if (!fiasco_c_options_set_quantization(*options, + MAX(0, m), range, + MAX(0, dcM), dcRange)) + pm_error("%s", fiasco_get_error_message ()); } - if (fiasco_get_verbosity () == FIASCO_ULTIMATE_VERBOSITY) - write_parameters (params, stderr); + if (fiasco_get_verbosity() == FIASCO_ULTIMATE_VERBOSITY) + write_parameters(params, stderr); + } + *imageTemplateListP = imageTemplateList; +} + + + +int +main(int argc, const char **argv) { + + char const ** image_template; /* template for input image files */ + char * wfa_name; /* filename of output WFA */ + float quality; /* approximation quality */ + fiasco_c_options_t * options; /* additional coder options */ + int retval; + + pm_proginit(&argc, argv); + + checkargs(argc, argv, &image_template, &wfa_name, &quality, &options); + + if (fiasco_coder(image_template, wfa_name, quality, options)) + retval = 0; + else { + pm_message("Encoding failed. %s", fiasco_get_error_message()); + retval = 1; } + return retval; } |