about summary refs log tree commit diff
path: root/converter/other/fiasco/input/basis.c
blob: aa371ea10fc715c01569e3b30be18c24a4fac9c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 *  basis.c:		WFA initial basis files	
 *
 *  Written by:		Ullrich Hafner
 *		
 *  This file is part of FIASCO (Fractal Image And Sequence COdec)
 *  Copyright (C) 1994-2000 Ullrich Hafner
 */

/*
 *  $Date: 2000/06/25 16:38:06 $
 *  $Author: hafner $
 *  $Revision: 5.3 $
 *  $State: Exp $
 */

#include "config.h"

#include "nstring.h"

#include "types.h"
#include "macros.h"
#include "error.h"

#include "wfa.h"
#include "wfalib.h"

#include "basis.h"

typedef struct basis_values
{
   unsigned  states;
   real_t   *final;
   bool_t   *use_domain;
   real_t (*transitions)[4];
} basis_values_t;

typedef struct
{
    const char *filename;
    void (*function)(basis_values_t *bv);
} basis_file_t;

/*****************************************************************************

				prototypes
  
*****************************************************************************/

static void
small_init (basis_values_t *bv);

static basis_file_t const basis_files[] = { 
    {"small.fco", small_init},
    {"small.wfa", small_init},
    {NULL, NULL} 
};

/*****************************************************************************

				public code
  
*****************************************************************************/

bool_t
get_linked_basis (const char *basis_name, wfa_t *wfa)
/*
 *  Check wether given WFA initial basis 'basis_name' is already linked
 *  with the excecutable. If the basis is available then fill the 'wfa' struct
 *  according to the stored data, otherwise print a warning message.
 *
 *  Return value:
 *	true on success, false if basis is not available yet.
 *
 *  Side effects:
 *	'wfa' struct is filled on success.
 */
{
   bool_t	  success = NO;		/* indicates if basis is found */
   unsigned	  n;			/* counter */
   basis_values_t bv;			/* basis values */
   
   for (n = 0; basis_files [n].filename != NULL; n++)
      if (streq (basis_files [n].filename, basis_name))	/* basis is stored */
      {
	 unsigned state, edge;		
	 
	 (*basis_files [n].function) (&bv); /* initialize local variables */
	 /*
	  *  Generate WFA
	  */
	 wfa->basis_states = wfa->states = bv.states + 1;
	 wfa->domain_type[0]             = USE_DOMAIN_MASK; 
	 wfa->final_distribution[0]      = 128;
	 append_edge (0, 0, 1.0, 0, wfa);
	 append_edge (0, 0, 1.0, 1, wfa);
	 for (state = 1; state < wfa->basis_states; state++)
	 {
	    wfa->final_distribution [state] = bv.final [state - 1];
	    wfa->domain_type [state]        = bv.use_domain [state - 1]
					      ? USE_DOMAIN_MASK
					      : AUXILIARY_MASK;
	 }
	 for (edge = 0; isedge (bv.transitions [edge][0]); edge++)
	    append_edge (bv.transitions [edge][0], bv.transitions [edge][1],
			 bv.transitions [edge][2], bv.transitions [edge][3],
			 wfa);
	 
	 success = YES;
	 break;
      }

   if (!success)
      warning ("WFA initial basis '%s' isn't linked with the excecutable yet."
	       "\nLoading basis from disk instead.", basis_name);

   return success;
}

/*****************************************************************************

				private code
  
*****************************************************************************/

/*****************************************************************************
				basis "small.wfa"
*****************************************************************************/

static unsigned	states_small           = 2;
static bool_t	use_domain_small[]     = {YES, YES};
static real_t 	final_small[]          = {64, 64};
static real_t 	transitions_small[][4] = {{1, 2, 0.5, 0}, {1, 2, 0.5, 1},
				      	 {1, 0, 0.5, 1}, {2, 1, 1.0, 0},
				      	 {2, 1, 1.0, 1}, {-1, 0, 0, 0}};
static void
small_init (basis_values_t *bv)
{
   bv->states      = states_small;
   bv->final       = final_small;
   bv->use_domain  = use_domain_small;
   bv->transitions = transitions_small;
}