1 /*
2  *  basis.c:		WFA initial basis files
3  *
4  *  Written by:		Ullrich Hafner
5  *
6  *  This file is part of FIASCO (Fractal Image And Sequence COdec)
7  *  Copyright (C) 1994-2000 Ullrich Hafner
8  */
9 
10 /*
11  *  $Date: 2000/06/25 16:38:06 $
12  *  $Author: hafner $
13  *  $Revision: 5.3 $
14  *  $State: Exp $
15  */
16 
17 #include "config.h"
18 
19 #include "nstring.h"
20 
21 #include "types.h"
22 #include "macros.h"
23 #include "error.h"
24 
25 #include "wfa.h"
26 #include "wfalib.h"
27 
28 #include "basis.h"
29 
30 typedef struct basis_values
31 {
32    unsigned  states;
33    real_t   *final;
34    bool_t   *use_domain;
35    real_t (*transitions)[4];
36 } basis_values_t;
37 
38 typedef struct
39 {
40     const char *filename;
41     void (*function)(basis_values_t *bv);
42 } basis_file_t;
43 
44 /*****************************************************************************
45 
46 				prototypes
47 
48 *****************************************************************************/
49 
50 static void
51 small_init (basis_values_t *bv);
52 
53 static basis_file_t const basis_files[] = {
54     {"small.fco", small_init},
55     {"small.wfa", small_init},
56     {NULL, NULL}
57 };
58 
59 /*****************************************************************************
60 
61 				public code
62 
63 *****************************************************************************/
64 
65 bool_t
get_linked_basis(const char * basis_name,wfa_t * wfa)66 get_linked_basis (const char *basis_name, wfa_t *wfa)
67 /*
68  *  Check whether given WFA initial basis 'basis_name' is already linked
69  *  with the executable. If the basis is available then fill the 'wfa' struct
70  *  according to the stored data, otherwise print a warning message.
71  *
72  *  Return value:
73  *	true on success, false if basis is not available yet.
74  *
75  *  Side effects:
76  *	'wfa' struct is filled on success.
77  */
78 {
79    bool_t	  success = NO;		/* indicates if basis is found */
80    unsigned	  n;			/* counter */
81    basis_values_t bv;			/* basis values */
82 
83    for (n = 0; basis_files [n].filename != NULL; n++)
84       if (streq (basis_files [n].filename, basis_name))	/* basis is stored */
85       {
86 	 unsigned state, edge;
87 
88 	 (*basis_files [n].function) (&bv); /* initialize local variables */
89 	 /*
90 	  *  Generate WFA
91 	  */
92 	 wfa->basis_states = wfa->states = bv.states + 1;
93 	 wfa->domain_type[0]             = USE_DOMAIN_MASK;
94 	 wfa->final_distribution[0]      = 128;
95 	 append_edge (0, 0, 1.0, 0, wfa);
96 	 append_edge (0, 0, 1.0, 1, wfa);
97 	 for (state = 1; state < wfa->basis_states; state++)
98 	 {
99 	    wfa->final_distribution [state] = bv.final [state - 1];
100 	    wfa->domain_type [state]        = bv.use_domain [state - 1]
101 					      ? USE_DOMAIN_MASK
102 					      : AUXILIARY_MASK;
103 	 }
104 	 for (edge = 0; isedge (bv.transitions [edge][0]); edge++)
105 	    append_edge (bv.transitions [edge][0], bv.transitions [edge][1],
106 			 bv.transitions [edge][2], bv.transitions [edge][3],
107 			 wfa);
108 
109 	 success = YES;
110 	 break;
111       }
112 
113    if (!success)
114       warning ("WFA initial basis '%s' isn't linked with the executable yet."
115 	       "\nLoading basis from disk instead.", basis_name);
116 
117    return success;
118 }
119 
120 /*****************************************************************************
121 
122 				private code
123 
124 *****************************************************************************/
125 
126 /*****************************************************************************
127 				basis "small.wfa"
128 *****************************************************************************/
129 
130 static unsigned	states_small           = 2;
131 static bool_t	use_domain_small[]     = {YES, YES};
132 static real_t 	final_small[]          = {64, 64};
133 static real_t 	transitions_small[][4] = {{1, 2, 0.5, 0}, {1, 2, 0.5, 1},
134 				      	 {1, 0, 0.5, 1}, {2, 1, 1.0, 0},
135 				      	 {2, 1, 1.0, 1}, {-1, 0, 0, 0}};
136 static void
small_init(basis_values_t * bv)137 small_init (basis_values_t *bv)
138 {
139    bv->states      = states_small;
140    bv->final       = final_small;
141    bv->use_domain  = use_domain_small;
142    bv->transitions = transitions_small;
143 }
144 
145 
146 
147