#
#	Copyright 1993, Center for Computer Vision and Visualization,
#	University of Florida.  All rights reserved.
#

#
# $Log: uchar-convolutions.desc,v $
# Revision 1.4  1993/11/17  18:45:15  thoth
# forward convolutions are now supported.
# template reductions are now supported.
#
# Revision 1.3  1993/09/27  15:55:30  thoth
# Make the xxxmax_product and xxxmin_product functions a little more robust.
#
# Revision 1.2  1993/09/21  11:45:04  thoth
# Give uchar convolutions the proper names.
#
# Revision 1.1  93/09/15  13:05:15  thoth
# Initial revision
# 
# Revision 1.2  93/05/27  11:41:16  thoth
# Copyright Notices
# 
# Revision 1.1  93/03/18  11:26:37  thoth
# Initial revision
# 

convolution u_char linear_product u_char u_char zero=0
init:	RTYPE	a = ZERO;
accum:	a += IVAL * TVAL;
final:	IRESULT = a;
forw_init:	IRESULT = ZERO;
forw_accumvar:	IRESULT += IVAL * TVAL;
end

# we have to be careful doing the following transforms
# machine integers are NOT mathematical integers...

#the following is especially suspect.  What if there was NO
#intersection between the original image and the template.  We get the
#max value of the template, not the minimum value of the uchar ( 0 ).
#  *sigh*

convolution u_char addmax_product u_char u_char zero=0
init:	RTYPE	a=ZERO;
accum:	int temp = IVAL+TVAL; if (temp>255) temp = 255; if (temp > a) a = temp;
accvar:	int temp = IVAL+TVAL; if (temp > a) a = temp;
final:	IRESULT = a;
forw_init:	IRESULT = ZERO;
forw_accumvar:	int temp = IVAL + TVAL; if (temp>255) temp = 255; if (temp > IRESULT) IRESULT = temp;
end

convolution u_char addmin_product u_char u_char  zero=255
init:	RTYPE	a=ZERO;
accum:	register IBTYPE ival = IVAL; if (ival == ZERO) continue; int temp = ival+TVAL; if (temp < a) a = temp;
accvar:	int temp = IVAL+TVAL; if (temp < a) a = temp;
final:	IRESULT = a;
forw_init:	IRESULT = ZERO;
forw_accumvar:	int temp = IVAL + TVAL; if (temp < IRESULT) IRESULT = temp;
end

# take advantage of the fact that we are doing integer arithmetic and
# probably have extra precision lying around.  If the ints on your
# machine are not twice the size of chars (almost impossible) then use
# a long for the temp variable

convolution u_char multmax_product u_char u_char zero=0
init:	RTYPE	a=ZERO;
accum:	register IBTYPE	ival = IVAL; int temp = ival*TVAL; if (temp>255) temp = 255; if (temp>a) a = temp;
accvar:	RTYPE temp = IVAL*TVAL; if (temp>255) temp = 255; if (temp>a) a = temp;
final:	IRESULT = a;
forw_init:	IRESULT = ZERO;
forw_accumvar:	int temp = IVAL+TVAL; if (temp>255) temp = 255; if (temp>IRESULT) IRESULT=temp;
end

# what do we do when the template has a zero and the image is
# undefined?  Currently we multiply +infty (255) by zero and get 0, a
# minimum value.  crap.

convolution u_char multmin_product u_char u_char zero=255
init:	RTYPE	a=ZERO;
accum:	register IBTYPE	ival = IVAL; int temp = ival*TVAL; if (temp>255) temp = 255; if (temp<a) a = temp;
accvar:	RTYPE temp = IVAL*TVAL; if (temp<a) a = temp;
final:	IRESULT = a;
forw_init:	IRESULT = ZERO;
forw_accumvar:	int temp = IVAL+TVAL; if (temp<IRESULT) IRESULT=temp;
end

reduction int sum u_char zero=0
accum:	IRESULT += TVAL;
end

reduction u_char max u_char zero=0
accum:	if (TVAL>IRESULT) IRESULT = TVAL;
end

reduction u_char min u_char zero=255
accum:	if (TVAL<IRESULT) IRESULT = TVAL;
end
