diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stitch/fill.c	Fri May 20 15:19:45 2011 +0100
@@ -0,0 +1,289 @@
+/*
+    Copyright (c) Applied Psychology Unit, Medical Research Council. 1988, 1989
+    ===========================================================================
+
+    Permission to use, copy, modify, and distribute this software without fee 
+    is hereby granted for research purposes, provided that this copyright 
+    notice appears in all copies and in all supporting documentation, and that 
+    the software is not redistributed for any fee (except for a nominal shipping 
+    charge). Anyone wanting to incorporate all or part of this software in a
+    commercial product must obtain a license from the Medical Research Council.
+
+    The MRC makes no representations about the suitability of this 
+    software for any purpose.  It is provided "as is" without express or implied 
+    warranty.
+ 
+    THE MRC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 
+    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE
+    A.P.U. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY 
+    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
+    AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
+    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+/*
+    fill.c
+    ======
+
+
+    window filling source
+
+
+    Copyright (c), 1989  The Medical Research Council, Applied Psychology Unit.
+
+
+    Author  : John Holdsworth
+    Written : 11th May, 1989.
+
+    Edited  :
+
+
+*/
+
+#include "windows.h"
+#include "stitch.h"
+#include "source.h"
+#include "fill.h"
+
+#ifndef lint
+static char *sccs_id = "@(#)fill.c	1.9     J. Holdsworth (MRC-APU)  11/8/90" ;
+#endif
+
+
+static int *Match( n1, n2 )
+int n1, n2 ;
+{
+    DeclareNewArray( int, array, n2+16, "for match" ) ;
+    float scale ;
+    int i ;
+
+    if( n2 > 1 )
+    {
+	scale = ( abs( n1 ) - 1. ) / ( n2 - 1. ) ;
+
+	if( n1 > 0 )
+	    for( i=0 ; i < n2 ; i++ )
+		array[ i ] = i * scale + .5 ;
+	else
+	    for( i=0 ; i < n2 ; i++ )
+		array[ i ] = abs( n1 ) - 1 - (int) ( i * scale + .5 ) ;
+
+	for( i=n2 ; i < n2 + 16 ; i++ )
+	    array[ i ] = 0 ;
+    }
+    else
+	array[ 0 ] = 0 ;
+
+    return( array ) ;
+}
+
+struct _fill_state { WindowObject window ; int row_flag, frame, framepoints, frames, major_count, *major, *minor ; short black, white ; } ;
+
+static void fill_callback( state, bytes, buffer )
+struct _fill_state *state ;
+ByteCount *bytes ;
+short *buffer ;
+{
+    short *bptr = buffer ;
+
+    while( (char *) bptr < (char *) buffer + *bytes ) {
+
+	if( state->frames != 0 && state->frame % state->frames == 0 ) {
+	    state->frame = 0 ;
+	    state->major_count=0 ;
+	}
+
+	while( state->major[ state->major_count ] == state->frame ) {
+	    state->major_count++ ;
+	    if( state->row_flag )
+		FillRow( state->window, state->major_count, bptr, state->black, state->white, state->minor,  Width( state->window ) ) ;
+	    else
+		FillCol( state->window, state->major_count, bptr, state->black, state->white, state->minor, Height( state->window ) ) ;
+	}
+
+	state->frame++ ;
+
+	bptr += state->framepoints ;
+    }
+
+    return ;
+}
+
+static void excite_callback( state, bytes, buffer )
+struct _fill_state *state ;
+ByteCount *bytes ;
+short *buffer ;
+{
+    double origin = 1. + ( Height( state->window ) - 1. ) * ( 0. - state->black ) / ( state->white - state->black ) ;
+
+    Clear( state->window ) ;
+
+    Function( state->window, buffer, ToPoints( short, *bytes ), 1, origin, (double) ( state->white - state->black ) ) ;
+
+    return ;
+}
+
+static void smear_callback( state, bytes, buffer )
+struct _fill_state *state ;
+ByteCount *bytes ;
+short *buffer ;
+{
+    double origin = 1. + ( Height( state->window ) - 1. ) * ( 0. - state->black ) / ( state->white - state->black ) ;
+
+    Function( state->window, buffer, ToPoints( short, *bytes ), 1, origin, (double) ( state->white - state->black ) ) ;
+
+    return ;
+}
+
+
+static void fill_close( state )
+struct _fill_state *state ;
+{
+    Delete( state->major ) ;
+    Delete( state->minor ) ;
+
+    Delete( state ) ;
+
+    return ;
+}
+
+/*
+Source SourceFill( source, black, white, window, framewidth, frameheight, frames, cfs )
+Source source ;
+int black, white ;
+WindowObject window ;
+int framewidth, frameheight ;
+long frames ;
+double *cfs ;
+{
+    DeclareNew( struct _fill_state *, state ) ;
+    double mincf, spancf, pixcf ;
+    int row, chan ;
+
+    state->window = window ;
+
+    state->black  = black ;
+    state->white  = white ;
+
+    state->major  = Match( (int) frames, Width( window ) ) ;
+    state->minor  = Match( frameheight, Height( window ) ) ;
+
+    if( cfs != (double *) 0 ) {
+	chan = 0 ;
+	mincf  = cfs[0] ;
+	spancf = cfs[frameheight-1]-mincf ;
+
+	for( row=0 ; row<Height( window ) ; row++ ) {
+
+	    pixcf = mincf + ( row + 0.5 ) / Height( window ) * spancf ;
+
+	    while( cfs[chan]<pixcf )
+		chan++ ;
+
+	    state->minor[row] = chan ;
+	}
+    }
+
+    state->major_count = 0 ;
+    state->frame       = 0 ;
+    state->frames      = 0 ;
+    state->framepoints = 0 ;
+
+    state->row_flag    = 0 ;
+
+    switch( abs( framewidth ) ) {
+	case 1 :
+	    return ( NewTappingSource( (Pointer) state,   fill_callback, fill_close, source, "fill.c filling" ) ) ;
+	case 2 :
+	    return ( NewTappingSource( (Pointer) state, excite_callback, fill_close, source, "fill.c filling" ) ) ;
+	case 3 :
+	    return ( NewTappingSource( (Pointer) state,  smear_callback, fill_close, source, "fill.c filling" ) ) ;
+    }
+}
+*/
+
+static Source FillEither( window, source, black, white, framepoints, frames, scale, row_flag )
+WindowObject window ;
+Source source ;
+int black, white ;
+int framepoints, frames ;
+double *scale ;
+int row_flag ;
+{
+    DeclareNew( struct _fill_state *, state ) ;
+    int minor_pixels, major_pixels ;
+    double min, span, value ;
+    int row, chan ;
+
+    if( row_flag ) {
+	minor_pixels   =  Width( window ) ;
+	major_pixels   = Height( window ) ;
+    }
+    else {
+	minor_pixels   = Height( window ) ;
+	major_pixels   =  Width( window ) ;
+    }
+
+    state->window = window ;
+
+    state->black    = black ;
+    state->white    = white ;
+
+    state->major  = Match(      frames, major_pixels ) ;
+    state->minor  = Match( framepoints, minor_pixels ) ;
+
+    if( !row_flag ) /* reverse match array for columns for now */
+	for( chan=0 ; chan<minor_pixels/2 ; chan++ ) {
+	    row = state->minor[minor_pixels-1-chan] ;
+	    state->minor[minor_pixels-1-chan] = state->minor[chan] ;
+	    state->minor[chan]= row ;
+	}
+
+    if( scale != (double *) 0 ) {
+
+	chan = 0 ;
+	min  = scale[0] ;
+	span = scale[framepoints-1]-min ;
+
+	for( row=0 ; row < minor_pixels ; row++ ) {
+
+	    value = min + ( row + 0.5 ) / minor_pixels * span ;
+
+	    while( scale[chan] < value )
+		chan++ ;
+
+	    state->minor[row] = chan ;
+	}
+    }
+
+    state->framepoints = framepoints ;
+    state->frames      = frames ;
+    state->frame       = 0 ;
+    state->major_count = 0 ;
+
+    state->row_flag    = row_flag ;
+
+    return ( NewTappingSource( (Pointer) state, fill_callback, fill_close, source, "fill.c filling" ) ) ;
+}
+
+Source fillAcross(       window, source, black, white, framepoints, frames, scale )
+WindowObject window ;
+Source source ;
+int black, white ;
+int framepoints, frames ;
+double *scale ;
+{
+    return ( FillEither( window, source, black, white, framepoints, frames, scale, 0 ) ) ;
+}
+
+Source fillDown(         window, source, black, white, framepoints, frames, scale )
+WindowObject window ;
+Source source ;
+int black, white ;
+int framepoints, frames ;
+double *scale ;
+{
+    return ( FillEither( window, source, black, white, framepoints, frames, scale, 1 ) ) ;
+}
+
+