comparison stitch/fill.c @ 0:5242703e91d3 tip

Initial checkin for AIM92 aimR8.2 (last updated May 1997).
author tomwalters
date Fri, 20 May 2011 15:19:45 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:5242703e91d3
1 /*
2 Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
3 ===========================================================================
4
5 Permission to use, copy, modify, and distribute this software without fee
6 is hereby granted for research purposes, provided that this copyright
7 notice appears in all copies and in all supporting documentation, and that
8 the software is not redistributed for any fee (except for a nominal shipping
9 charge). Anyone wanting to incorporate all or part of this software in a
10 commercial product must obtain a license from the Medical Research Council.
11
12 The MRC makes no representations about the suitability of this
13 software for any purpose. It is provided "as is" without express or implied
14 warranty.
15
16 THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
17 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
18 A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
19 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
20 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 */
23
24 /*
25 fill.c
26 ======
27
28
29 window filling source
30
31
32 Copyright (c), 1989 The Medical Research Council, Applied Psychology Unit.
33
34
35 Author : John Holdsworth
36 Written : 11th May, 1989.
37
38 Edited :
39
40
41 */
42
43 #include "windows.h"
44 #include "stitch.h"
45 #include "source.h"
46 #include "fill.h"
47
48 #ifndef lint
49 static char *sccs_id = "@(#)fill.c 1.9 J. Holdsworth (MRC-APU) 11/8/90" ;
50 #endif
51
52
53 static int *Match( n1, n2 )
54 int n1, n2 ;
55 {
56 DeclareNewArray( int, array, n2+16, "for match" ) ;
57 float scale ;
58 int i ;
59
60 if( n2 > 1 )
61 {
62 scale = ( abs( n1 ) - 1. ) / ( n2 - 1. ) ;
63
64 if( n1 > 0 )
65 for( i=0 ; i < n2 ; i++ )
66 array[ i ] = i * scale + .5 ;
67 else
68 for( i=0 ; i < n2 ; i++ )
69 array[ i ] = abs( n1 ) - 1 - (int) ( i * scale + .5 ) ;
70
71 for( i=n2 ; i < n2 + 16 ; i++ )
72 array[ i ] = 0 ;
73 }
74 else
75 array[ 0 ] = 0 ;
76
77 return( array ) ;
78 }
79
80 struct _fill_state { WindowObject window ; int row_flag, frame, framepoints, frames, major_count, *major, *minor ; short black, white ; } ;
81
82 static void fill_callback( state, bytes, buffer )
83 struct _fill_state *state ;
84 ByteCount *bytes ;
85 short *buffer ;
86 {
87 short *bptr = buffer ;
88
89 while( (char *) bptr < (char *) buffer + *bytes ) {
90
91 if( state->frames != 0 && state->frame % state->frames == 0 ) {
92 state->frame = 0 ;
93 state->major_count=0 ;
94 }
95
96 while( state->major[ state->major_count ] == state->frame ) {
97 state->major_count++ ;
98 if( state->row_flag )
99 FillRow( state->window, state->major_count, bptr, state->black, state->white, state->minor, Width( state->window ) ) ;
100 else
101 FillCol( state->window, state->major_count, bptr, state->black, state->white, state->minor, Height( state->window ) ) ;
102 }
103
104 state->frame++ ;
105
106 bptr += state->framepoints ;
107 }
108
109 return ;
110 }
111
112 static void excite_callback( state, bytes, buffer )
113 struct _fill_state *state ;
114 ByteCount *bytes ;
115 short *buffer ;
116 {
117 double origin = 1. + ( Height( state->window ) - 1. ) * ( 0. - state->black ) / ( state->white - state->black ) ;
118
119 Clear( state->window ) ;
120
121 Function( state->window, buffer, ToPoints( short, *bytes ), 1, origin, (double) ( state->white - state->black ) ) ;
122
123 return ;
124 }
125
126 static void smear_callback( state, bytes, buffer )
127 struct _fill_state *state ;
128 ByteCount *bytes ;
129 short *buffer ;
130 {
131 double origin = 1. + ( Height( state->window ) - 1. ) * ( 0. - state->black ) / ( state->white - state->black ) ;
132
133 Function( state->window, buffer, ToPoints( short, *bytes ), 1, origin, (double) ( state->white - state->black ) ) ;
134
135 return ;
136 }
137
138
139 static void fill_close( state )
140 struct _fill_state *state ;
141 {
142 Delete( state->major ) ;
143 Delete( state->minor ) ;
144
145 Delete( state ) ;
146
147 return ;
148 }
149
150 /*
151 Source SourceFill( source, black, white, window, framewidth, frameheight, frames, cfs )
152 Source source ;
153 int black, white ;
154 WindowObject window ;
155 int framewidth, frameheight ;
156 long frames ;
157 double *cfs ;
158 {
159 DeclareNew( struct _fill_state *, state ) ;
160 double mincf, spancf, pixcf ;
161 int row, chan ;
162
163 state->window = window ;
164
165 state->black = black ;
166 state->white = white ;
167
168 state->major = Match( (int) frames, Width( window ) ) ;
169 state->minor = Match( frameheight, Height( window ) ) ;
170
171 if( cfs != (double *) 0 ) {
172 chan = 0 ;
173 mincf = cfs[0] ;
174 spancf = cfs[frameheight-1]-mincf ;
175
176 for( row=0 ; row<Height( window ) ; row++ ) {
177
178 pixcf = mincf + ( row + 0.5 ) / Height( window ) * spancf ;
179
180 while( cfs[chan]<pixcf )
181 chan++ ;
182
183 state->minor[row] = chan ;
184 }
185 }
186
187 state->major_count = 0 ;
188 state->frame = 0 ;
189 state->frames = 0 ;
190 state->framepoints = 0 ;
191
192 state->row_flag = 0 ;
193
194 switch( abs( framewidth ) ) {
195 case 1 :
196 return ( NewTappingSource( (Pointer) state, fill_callback, fill_close, source, "fill.c filling" ) ) ;
197 case 2 :
198 return ( NewTappingSource( (Pointer) state, excite_callback, fill_close, source, "fill.c filling" ) ) ;
199 case 3 :
200 return ( NewTappingSource( (Pointer) state, smear_callback, fill_close, source, "fill.c filling" ) ) ;
201 }
202 }
203 */
204
205 static Source FillEither( window, source, black, white, framepoints, frames, scale, row_flag )
206 WindowObject window ;
207 Source source ;
208 int black, white ;
209 int framepoints, frames ;
210 double *scale ;
211 int row_flag ;
212 {
213 DeclareNew( struct _fill_state *, state ) ;
214 int minor_pixels, major_pixels ;
215 double min, span, value ;
216 int row, chan ;
217
218 if( row_flag ) {
219 minor_pixels = Width( window ) ;
220 major_pixels = Height( window ) ;
221 }
222 else {
223 minor_pixels = Height( window ) ;
224 major_pixels = Width( window ) ;
225 }
226
227 state->window = window ;
228
229 state->black = black ;
230 state->white = white ;
231
232 state->major = Match( frames, major_pixels ) ;
233 state->minor = Match( framepoints, minor_pixels ) ;
234
235 if( !row_flag ) /* reverse match array for columns for now */
236 for( chan=0 ; chan<minor_pixels/2 ; chan++ ) {
237 row = state->minor[minor_pixels-1-chan] ;
238 state->minor[minor_pixels-1-chan] = state->minor[chan] ;
239 state->minor[chan]= row ;
240 }
241
242 if( scale != (double *) 0 ) {
243
244 chan = 0 ;
245 min = scale[0] ;
246 span = scale[framepoints-1]-min ;
247
248 for( row=0 ; row < minor_pixels ; row++ ) {
249
250 value = min + ( row + 0.5 ) / minor_pixels * span ;
251
252 while( scale[chan] < value )
253 chan++ ;
254
255 state->minor[row] = chan ;
256 }
257 }
258
259 state->framepoints = framepoints ;
260 state->frames = frames ;
261 state->frame = 0 ;
262 state->major_count = 0 ;
263
264 state->row_flag = row_flag ;
265
266 return ( NewTappingSource( (Pointer) state, fill_callback, fill_close, source, "fill.c filling" ) ) ;
267 }
268
269 Source fillAcross( window, source, black, white, framepoints, frames, scale )
270 WindowObject window ;
271 Source source ;
272 int black, white ;
273 int framepoints, frames ;
274 double *scale ;
275 {
276 return ( FillEither( window, source, black, white, framepoints, frames, scale, 0 ) ) ;
277 }
278
279 Source fillDown( window, source, black, white, framepoints, frames, scale )
280 WindowObject window ;
281 Source source ;
282 int black, white ;
283 int framepoints, frames ;
284 double *scale ;
285 {
286 return ( FillEither( window, source, black, white, framepoints, frames, scale, 1 ) ) ;
287 }
288
289