// Emacs -*- C++ -*-

// Machine generated include file, do not modify.


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


//  $Log: uchar-operations.desc,v $
//  Revision 1.9.1.2  1995/01/31  16:02:40  thoth
//  Need to replace the upward conversions with something...

//  Revision 1.9.1.1  1994/12/28  17:23:06  thoth
//  scalar-image operations accept u_char instead of int now.

//  Revision 1.9  1994/12/19  19:58:48  ljr
//  DOS-inspired name rework.

//  Revision 1.8  1994/05/17  12:54:56  thoth
//  Improved operations generation scheme.  Lines from the op.desc file can
//  be quoted into the .c file to allow inclusion of infrastructure.  Also
//  the op.desc output can be redirected to several files.  The prefix
//  directive allows common information (include files) to be included in
//  every generated source file.

//  Revision 1.7  1994/02/03  16:22:48  thoth
//  Arguments to binary operations were specified "lhs rhs return" but are
//  now specified "return lhs rhs" to be consistent with function declaration
//  syntax.

//  Revision 1.6  1994/01/31  16:06:03  thoth
//  some extra constructors and the new conversions.
//  chi functions now return BitDIs.

//  Revision 1.5  1993/12/29  17:28:38  thoth
//  reductions require a zero now.

//  Revision 1.4  1993/11/17  18:45:41  thoth
//  we now have the product reduction and a sqr that returns an IntDI.

//  Revision 1.3  1993/10/05  19:34:57  thoth
//  binary max and min available. are now

//  Revision 1.2  1993/09/21  11:46:07  thoth
//  pointwise operations now named "chi" instead of "pwise".

//  Revision 1.1  93/09/15  13:05:29  thoth
//  Initial revision
//  
//  Revision 1.3  93/05/27  11:41:17  thoth
//  Copyright Notices
//  
//  Revision 1.2  93/05/18  21:45:40  thoth
//  New reductions to bring ucharDI up to speed.
//  
//  Revision 1.1  93/03/18  11:25:21  thoth
//  Initial revision
//  
#include "UcharDI.h"
#include "VectorI.h"
#include "ConstI.h"
#include "ImageIter.h"
#include "FBI.h"
#include "../valueset/OpTable.h"
//////////////////////////////////////////////////////////////////////
//
// Begin operation support routines for :
// unary pointwise sqr I(int) I(u_char)
//
// Emacs: -*- C++ -*-

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


//
// $Log: unary-op.templ,v $
// Revision 1.4.1.2  1995/01/13  19:37:42  thoth
// CoreImage has been re-merged with Image.  All special stuff should be
// friends of FBI now.
//
// Revision 1.4.1.1  1994/12/28  17:22:11  thoth
// image operations are friends of FBI now.
//
// Revision 1.4  1994/07/25  17:26:39  thoth
// Name sanitization
//
// Revision 1.3  1994/01/07  15:15:14  thoth
// Image class is now CoreImage and named image types are
// Image<P,T>.
//
// Revision 1.2  1993/12/29  17:33:18  thoth
// New operator scheme that prevents the need for trivial Image conversions.
//
// Revision 1.1  1993/09/15  13:07:16  thoth
// Initial revision
//
// Revision 1.2  93/05/27  11:49:04  thoth
// Copyright Notices
// 
// Revision 1.1  93/03/10  13:50:00  thoth
// Initial revision
// 

#ifndef UOT_int_u_char_sqr
#define UOT_int_u_char_sqr
IA_UnaryOperationsTable<IA_BaseImage<IA_Point<int>, int>*,
	IA_BaseImage<IA_Point<int>, u_char> >
	*IA_Image_IP_int_u_char_sqr_tbl;

void IA_fill_Image_IP_int_u_char_sqr_tbl();
#endif


IA_Image<IA_Point<int>, int>
sqr ( const IA_Image<IA_Point<int>, u_char> &arg)
{
    if (!IA_Image_IP_int_u_char_sqr_tbl)
	IA_fill_Image_IP_int_u_char_sqr_tbl();

    IA_BaseImage<IA_Point<int>, int>*(*f)
	(IA_BaseImage<IA_Point<int>, u_char> &);
    f = IA_Image_IP_int_u_char_sqr_tbl->lookup_operation (arg.type());

    
    IA_BaseImage<IA_Point<int>, u_char>	&bip =
	*IA_FBI<IA_Point<int>,IA_Point<int>,u_char,u_char,u_char>
	    ::extract_baseptr(arg);

    return IA_FBI<IA_Point<int>,IA_Point<int>, int,int,int>
	 ::make_Image(f(bip));
}

#ifndef vec_uop_int_u_char_sqr
#define vec_uop_int_u_char_sqr
static IA_BaseImage<IA_Point<int>, int>*
vec_uo_sqr(IA_BaseImage<IA_Point<int>, u_char> &lhs_)
{
    const IA_VectorI<IA_Point<int>, u_char> *lhs =
	(IA_VectorI<IA_Point<int>, u_char> *) &lhs_;

    const IA_Set<IA_Point<int> > domain = lhs->domain();
    const unsigned sz = domain.card();
    int *const vec = new int[sz];

    {
	int *ds = vec;
	const u_char *ls = lhs->vec;
	for (unsigned i=0; i<sz; i++) {
	    *(ds++) = sqr(*(ls++));
	}
    }
    return new IA_VectorI<IA_Point<int>, int>(domain, vec, sz, 1);
}
#endif // vec_uop_int_u_char_sqr

#ifndef scalar_uop_int_u_char_sqr
#define scalar_uop_int_u_char_sqr
static IA_BaseImage<IA_Point<int>, int>*
scalar_uo_sqr(IA_BaseImage<IA_Point<int>, u_char> &lhs_)
{
    const IA_ConstI<IA_Point<int>, u_char> *lhs =
	(IA_ConstI<IA_Point<int>, u_char> *) &lhs_;

    const IA_Set<IA_Point<int> > domain = lhs->domain();

    return new IA_ConstI<IA_Point<int>, int>(domain, sqr(lhs->value));
}
#endif // scalar_uop_int_u_char_sqr

// scalar-scalar operation is trivial

#ifndef iter_uop_int_u_char_sqr
#define iter_uop_int_u_char_sqr
static IA_BaseImage<IA_Point<int>, int>*
iter_uo_sqr(IA_BaseImage<IA_Point<int>, u_char> &lhs)
{
    const IA_Set<IA_Point<int> > domain = lhs.domain();
    const unsigned sz = domain.card();
    int *const vec = new int[sz];

    {
	int *ds = vec;
	u_char ltmp;
	IA_BaseIVIter<IA_Point<int>, u_char>	*liter = lhs.value_iterator();
	for (unsigned i=0; i<sz; i++) {
	    liter->next(ltmp);
	    *(ds++) = sqr(ltmp);
	}
	delete liter;
    }
    return new IA_VectorI<IA_Point<int>, int>(domain, vec, sz, 1);
}
#endif // iter_uop_int_u_char_sqr

#ifndef FILL_UOT_int_u_char_sqr
#define FILL_UOT_int_u_char_sqr
void IA_fill_Image_IP_int_u_char_sqr_tbl()
{
    if (IA_Image_IP_int_u_char_sqr_tbl)
	return;

    IA_UnaryOperationsTable<IA_BaseImage<IA_Point<int>, int>*,
	IA_BaseImage<IA_Point<int>, u_char> >::function f;
    f = iter_uo_sqr;

    IA_Image_IP_int_u_char_sqr_tbl = new IA_UnaryOperationsTable<IA_BaseImage<IA_Point<int>, int>*,
	IA_BaseImage<IA_Point<int>, u_char> >(iter_uo_sqr);
    IA_Image_IP_int_u_char_sqr_tbl->add_operation
	(IA_VectorI<IA_Point<int>, u_char>::s_type(),
	 vec_uo_sqr);
    IA_Image_IP_int_u_char_sqr_tbl->add_operation
	(IA_ConstI<IA_Point<int>, u_char>::s_type(),
	 scalar_uo_sqr);

}
#endif // UOT_int_u_char_sqr

