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

// Machine generated include file, do not modify.


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


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

//  Revision 1.6.1.1  1994/12/28  17:49:18  thoth
//  Image operations are now friendly with FBI.
//  Image ops now use operations table instead of switch.

//  Revision 1.6  1994/08/22  15:20:29  thoth
//  DOS-inspired name rework.

//  Revision 1.5  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.4  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.3  1994/01/31  15:51:12  thoth
//  converters to CoreImages now available.

//  Revision 1.2  1993/12/29  17:16:45  thoth
//  Bit Discrete Image now uses Bit type.

//  Revision 1.1  1993/11/29  22:25:25  thoth
//  Initial revision


#include "BitDI.h"
#include "VectorI.h"
#include "ConstI.h"
#include "ImageIter.h"
#include "FBI.h"
#include "../valueset/OpTable.h"
// conversion I(u_char) I(IA_Bit)
//////////////////////////////////////////////////////////////////////
//
// Begin operation support routines for :
// unary pointwise to_uchar subop= I(u_char) I(IA_Bit)
//
// 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_u_char_IA_Bit_to_uchar
#define UOT_u_char_IA_Bit_to_uchar
IA_UnaryOperationsTable<IA_BaseImage<IA_Point<int>, u_char>*,
	IA_BaseImage<IA_Point<int>, IA_Bit> >
	*IA_Image_IP_u_char_IA_Bit_to_uchar_tbl;

void IA_fill_Image_IP_u_char_IA_Bit_to_uchar_tbl();
#endif


IA_Image<IA_Point<int>, u_char>
to_uchar ( const IA_Image<IA_Point<int>, IA_Bit> &arg)
{
    if (!IA_Image_IP_u_char_IA_Bit_to_uchar_tbl)
	IA_fill_Image_IP_u_char_IA_Bit_to_uchar_tbl();

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

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

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

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

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

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

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

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

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

// scalar-scalar operation is trivial

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

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

#ifndef FILL_UOT_u_char_IA_Bit_to_uchar
#define FILL_UOT_u_char_IA_Bit_to_uchar
void IA_fill_Image_IP_u_char_IA_Bit_to_uchar_tbl()
{
    if (IA_Image_IP_u_char_IA_Bit_to_uchar_tbl)
	return;

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

    IA_Image_IP_u_char_IA_Bit_to_uchar_tbl = new IA_UnaryOperationsTable<IA_BaseImage<IA_Point<int>, u_char>*,
	IA_BaseImage<IA_Point<int>, IA_Bit> >(iter_uo_to_uchar);
    IA_Image_IP_u_char_IA_Bit_to_uchar_tbl->add_operation
	(IA_VectorI<IA_Point<int>, IA_Bit>::s_type(),
	 vec_uo_to_uchar);
    IA_Image_IP_u_char_IA_Bit_to_uchar_tbl->add_operation
	(IA_ConstI<IA_Point<int>, IA_Bit>::s_type(),
	 scalar_uo_to_uchar);

}
#endif // UOT_u_char_IA_Bit_to_uchar

//  Binary operations for the Bit Discrete Image
//////////////////////////////////////////////////////////////////////
//
// Begin operation support routines for :
// filename BIO-__ad.c
//
