head	1.6;
access;
symbols
	bobbase:1.3
	bob:1.3.1
	r2_1:1.3
	r2_0:1.3
	r1_1_beta:1.2
	r1_1_alpha:1.1
	r1_0:1.1
	r0_11:1.1;
locks
	thoth:1.3.1.2; strict;
comment	@// @;


1.6
date	94.12.30.19.17.06;	author fjsoria;	state Exp;
branches;
next	1.5;

1.5
date	94.12.22.21.36.40;	author fjsoria;	state Exp;
branches;
next	1.4;

1.4
date	94.12.22.19.12.06;	author fjsoria;	state Exp;
branches;
next	1.3;

1.3
date	94.08.22.15.20.29;	author thoth;	state Exp;
branches
	1.3.1.1;
next	1.2;

1.2
date	94.07.25.17.26.39;	author thoth;	state Exp;
branches;
next	1.1;

1.1
date	94.03.02.13.59.21;	author jnw;	state Exp;
branches;
next	;

1.3.1.1
date	94.12.28.16.45.50;	author thoth;	state Exp;
branches;
next	1.3.1.2;

1.3.1.2
date	95.01.13.19.37.42;	author thoth;	state Exp;
branches;
next	;


desc
@RGB image .c file
@


1.6
log
@added more static data
@
text
@// Emacs: -*- C++ -*-

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

static char copyright[] = "Copyright 1993, Center for Computer Vision and Visualization,\nUniversity of Florida.  All rights reserved.\n";

static char IntDI_rcsid[] = "$Id: RGBDI.c,v 1.5 1994/12/22 21:36:40 fjsoria Exp fjsoria $";

//
// $Log: RGBDI.c,v $
// Revision 1.5  1994/12/22  21:36:40  fjsoria
// static data member template fix
//
// Revision 1.4  1994/12/22  19:12:06  fjsoria
// added static data member for IA_VectorI
//
// Revision 1.3  1994/08/22  15:20:29  thoth
// DOS-inspired name rework.
//
// Revision 1.2  1994/07/25  17:26:39  thoth
// Name sanitization
//
// Revision 1.1  1994/03/02  13:59:21  jnw
// Initial revision
//
//

#include	"Closure.h"
#include	"PSIter.h"

#include	"RGBDI.h"
#include	"VectorI.h"
#include	"ConstI.h"
#include	"ClosureI.h"
#include	"ErrorI.h"
#include	"ImageIter.h"

#include	<math.h>
#include	<fstream.h>
#include	<values.h>

//
//
//

#include "restrict.h"

#ifdef IA_NO_AUTOINST_OF_STATIC_DATA
#include "FuncI.h"
#include "LazyXlationI.h"
char IA_VectorI<IA_Point<int>, IA_RGB>::dummy;
char IA_ConstI<IA_Point<int>, IA_RGB>::dummy;
char IA_ClosureI<IA_Point<int>, IA_RGB>::dummy;
char IA_FunctionRefI<IA_Point<int>, IA_RGB>::dummy = 0;
char IA_LazyXlationI<IA_Point<int>, IA_RGB>::dummy;
char IA_FunctionI<IA_Point<int>, IA_RGB>::dummy = 0;
#endif

IA_BaseImage<IA_Point<int>,IA_RGB> *restrict_toD(const IA_BaseImage<IA_Point<int>,IA_RGB> *im, const IA_Set<IA_Point<int> > &ips) {
    return restrictD_toD(im, ips);
}

IA_BaseImage<IA_Point<int>,IA_RGB> *restrict_toD(const IA_BaseImage<IA_Point<double>,IA_RGB> *im, const IA_Set<IA_Point<int> > &ips) {
    return restrictC_toD(im, ips);
}

//
//

istream &wsc(istream &);	// from UcharDI.c

inline int int_rgb_max(int i, IA_RGB rgb){
    int j = (rgb.red()>rgb.green())
	? (rgb.red()>rgb.blue()?rgb.red():rgb.blue())
	: (rgb.green()>rgb.blue()?rgb.green():rgb.blue());
    return i>j?i:j;
}
    

inline int ppm_max(IA_Image<IA_Point<int>,IA_RGB> im)
{
    IA_IVIter<IA_Point<int>,IA_RGB>	iter(im);
    IA_RGB rgb;
    int i=0;
    
    while(iter(rgb)){
	i = int_rgb_max(i,rgb);
    }
    return i;
}

IA_Image<IA_Point<int>,IA_RGB> IA_Image<IA_Point<int>,IA_RGB>::read_PPM(istream &i, int*maxval_ret)
{
    int	width, height,maxval;
    int	code;
    if (i.get()=='P' && ((code=i.get())=='6' || code == '3')
	&& i>>wsc>>width>>wsc>>height>>wsc>>maxval) {
	if (maxval_ret)
	    *maxval_ret = maxval;
	{
	    int	ch = i.get();
	    if (ch!='\n')
		i.putback(ch);
	}
	const unsigned	size=width*height;
	IA_RGB	*data = new IA_RGB[size];
	if (code=='6') {
	    // p6 format
	    u_char	*tmp = new u_char[3*size];
	    if (!i.read(tmp, 3*size)) {
		delete[] data;
		ia_throw(IA::PNM_IO_ERROR, __FILE__, __LINE__);
		return IA_Image<IA_Point<int>,IA_RGB>();
	    }
	    for (unsigned i=0; i<size; i++)
		data[i] = IA_RGB(&(tmp[i*3]));
	    delete[] tmp;
	} else {
	    // P3 format
	    u_char tmp[3];
	    for (unsigned i=0; i<size; i++) {
		for (unsigned j=0; j < 3; j++) {
		    if (!cin >> tmp[j]) {
			delete[] data;
			ia_throw(IA::PNM_IO_ERROR, __FILE__, __LINE__);
			return IA_Image<IA_Point<int>,IA_RGB>();
		    }
		}
		data[i] = IA_RGB(tmp);
	    }
	}
	return IA_Image<IA_Point<int>,IA_RGB>
	    (IA_Set<IA_Point<int> >(IA_Point<int>(0,0), IA_Point<int>(height-1,width-1)),
	     data, size, 1);
    } else {
	ia_throw(IA::PNM_IO_ERROR, __FILE__, __LINE__);
	return IA_Image<IA_Point<int>,IA_RGB>();
    }
}

IA_Image<IA_Point<int>,IA_RGB> IA_Image<IA_Point<int>,IA_RGB>::read_PPM(const char *fname, int *maxval)
{
    ifstream	in(fname);
    return read_PPM(in, maxval);
}

ostream &IA_Image<IA_Point<int>,IA_RGB>::write_PPM(ostream &o, unsigned maxval) const
{
    IA_Set<IA_Point<int> > boxydomain(domain().inf(),domain().sup());
    IA_Point<int>	width(domain().sup()-domain().inf()+1);

    // We only support P6 writing at this time.
    o<<"P6\n";

    o<<width[1] << " " << width[0] << " " << maxval << "\n";
    IA_PSIter<IA_Point<int> >	iter(boxydomain);
    IA_Point<int>	ip;

    while (iter(ip)) {
	IA_RGB pixel;

	pixel = domain().contains(ip)?(*this)(ip):IA_RGB(0);
	o.put(pixel.red());
	o.put(pixel.green());
	o.put(pixel.blue());
    }
    return o;
}

ostream &IA_Image<IA_Point<int>,IA_RGB>::write_PPM(ostream &o) const
{
    return write_PPM(o,ppm_max(*this));
}

void IA_Image<IA_Point<int>,IA_RGB>::write_PPM(const char *fname, unsigned maxval) const
{
    ofstream	out(fname);
    write_PPM(out, maxval);
}

void IA_Image<IA_Point<int>,IA_RGB>::write_PPM(const char *fname) const
{
    ofstream	out(fname);
    write_PPM(out, ppm_max(*this));
}

//
// below are included the implementations of every image-image
// and image-scalar operation we could think of for RGB images.
//

inline int to_int(IA_RGB color){
    return color.to_int();
}

inline float to_float(IA_RGB color){
    return color.to_float();
}

inline u_char red(IA_RGB color){
    return color.red();
}

inline u_char green(IA_RGB color){
    return color.green();
}

inline u_char blue(IA_RGB color){
    return color.blue();
}

#include "RGBIOps.c"

//
//
//

#if 0

class blah : public IA_ClosureI<IA_Point<int>,IA_RGB> {
  public:
    blah() 
    :IA_ClosureI<IA_Point<int>,IA_RGB>(IA_Set<IA_Point<int> >()) {}
    ostream &print_this(ostream &o) const { return o;}
    int operator()(const IA_Point<int> &) const { return 0; }
    IA_ClosureI<IA_Point<int>,IA_RGB* clone_self() const { return 0; }
};

static void dummy001()
{
    IA_Point<int>		ip;
    IA_Set<IA_Point<int> >	ps;
    IA_Image<IA_Point<int>,IA_RGB>	i1;
    IA_Image<IA_Point<int>,IA_RGB>
	i2(i1),
	i3(ps,IA_RGB(0)),
	i4(ps, (IA_RGB*)0, 0, 1),
	i5(ps, (IA_RGB*)0, 0),
	i6(blah()),
	i7(ps, (IA_RGB(*)(const IA_Point<int>&))0),
	i10(IA_CoreImage<IA_Point<int>,IA_RGB>());
    IA_RGB	sc;

    i1 = i1.restrict(i2.range());
    i1 = i1.xlated(ip);
    (IA_CoreImage<IA_Point<int>,IA_RGB>&)i1 = IA_RGB(2);
    (void)i1.type();
    i1[ip] = i1(ip);
    i1 = i1.restrict(i2.domain());
    (void)i1.extend(i2);
    (void)i1.reduce((int (*)(const int&,const int&)) 0, IA_RGB(0));
    (void)i1.reduce((int (*)( int, int)) 0, IA_RGB(0));
    cout << (IA_CoreImage<IA_Point<int>,IA_RGB&)i1;

#if 0
    IA_Image<IA_Point<int>,IA_RGB>::read_IAA("");
    IA_Image<IA_Point<int>,IA_RGB>::read_IAA("","");

    i1.write_IAA("");
    i1.write_IAA("","");
#endif

    IA_IVIter<IA_Point<int>,IA_RGB>	iter1(i1), iter2;
    IA_IPIter<IA_Point<int>,IA_RGB>	iter3(i2), iter4;
    iter1 = iter2;
    iter3 = iter4;
#if 1
    iter1.reset();
    iter1(sc);
    iter3.reset();
    iter3(ip, sc);
#endif
#if 0
    compose(i1, (IA_Point<int>(*)(const IA_Point<int>&))0);
    compose(i1, *(IA_Closure<IA_Point<int>, IA_Point<int> >*)0);
    compose((IA_RGB(*)(IA_RGB))0, i1);
#endif

    IA_ValueSet<int>	vs(i1.range());
    // I shouldn\'t have to do the following two lines
    // vs.value_type_compare(0,0);
}
#endif
@


1.5
log
@static data member template fix
@
text
@d10 1
a10 1
static char IntDI_rcsid[] = "$Id: RGBDI.c,v 1.4 1994/12/22 19:12:06 fjsoria Exp fjsoria $";
d14 3
d53 1
d58 2
@


1.4
log
@added static data member for IA_VectorI
@
text
@d10 1
a10 1
static char IntDI_rcsid[] = "$Id: RGBDI.c,v 1.3 1994/08/22 15:20:29 thoth Exp fjsoria $";
d14 3
d49 1
d51 3
@


1.3
log
@DOS-inspired name rework.
@
text
@d10 1
a10 1
static char IntDI_rcsid[] = "$Id: RGBDI.c,v 1.2 1994/07/25 17:26:39 thoth Exp thoth $";
d14 3
d44 4
@


1.3.1.1
log
@Image I/O is now ROF.
removed obsolete instantiation cruft.
@
text
@d10 1
a10 1
static char IntDI_rcsid[] = "$Id: RGBDI.c,v 1.3 1994/08/22 15:20:29 thoth Exp thoth $";
a13 3
// Revision 1.3  1994/08/22  15:20:29  thoth
// DOS-inspired name rework.
//
d75 1
a75 1
IA_Image<IA_Point<int>,IA_RGB> read_PPM(istream &i, int*maxval_ret)
d95 1
a95 1
		ia_throw(Image_PNMIO_Exception(__FILE__, __LINE__));
d108 1
a108 1
			ia_throw(Image_PNMIO_Exception(__FILE__, __LINE__));
d116 1
a116 1
	    (IA_boxy_pset(IA_Point<int>(0,0), IA_Point<int>(height-1,width-1)),
d119 1
a119 1
	ia_throw(Image_PNMIO_Exception(__FILE__, __LINE__));
d124 1
a124 1
IA_Image<IA_Point<int>,IA_RGB> read_PPM(const char *fname, int *maxval)
d130 1
a130 1
ostream &write_PPM(const IA_CoreImage<IA_Point<int>,IA_RGB> &img, ostream &o, unsigned maxval)
d132 2
a133 3
    IA_Set<IA_Point<int> > boxydomain
	= IA_boxy_pset(img.domain().inf(),img.domain().sup());
    IA_Point<int>	width(img.domain().sup()-img.domain().inf()+1);
d145 1
a145 1
	pixel = img.domain().contains(ip)?img(ip):IA_RGB(0);
d153 1
a153 1
ostream &write_PPM(const IA_CoreImage<IA_Point<int>,IA_RGB> &img, ostream &o)
d155 1
a155 2
    int	max = ppm_max(img);
    return write_PPM(img, o, max>0 ? max : 1);
d158 1
a158 2
void write_PPM(const IA_CoreImage<IA_Point<int>,IA_RGB> &img,
	       const char *fname, unsigned maxval)
d161 1
a161 1
    write_PPM(img, out, maxval);
d164 1
a164 2
void write_PPM(const IA_CoreImage<IA_Point<int>,IA_RGB> &img,
	       const char *fname)
d167 1
a167 2
    int	max = ppm_max(img);
    write_PPM(img,out, max>0 ? max : 1);
d200 67
@


1.3.1.2
log
@CoreImage has been re-merged with Image.  All special stuff should be
friends of FBI now.
@
text
@d10 1
a10 1
static char IntDI_rcsid[] = "$Id: RGBDI.c,v 1.3.1.1 1994/12/28 16:45:50 thoth Exp thoth $";
a13 4
// Revision 1.3.1.1  1994/12/28  16:45:50  thoth
// Image I/O is now ROF.
// removed obsolete instantiation cruft.
//
d133 1
a133 1
ostream &write_PPM(const IA_Image<IA_Point<int>,IA_RGB> &img, ostream &o, unsigned maxval)
d157 1
a157 1
ostream &write_PPM(const IA_Image<IA_Point<int>,IA_RGB> &img, ostream &o)
d163 1
a163 1
void write_PPM(const IA_Image<IA_Point<int>,IA_RGB> &img,
d170 1
a170 1
void write_PPM(const IA_Image<IA_Point<int>,IA_RGB> &img,
@


1.2
log
@Name sanitization
@
text
@d10 1
a10 1
static char IntDI_rcsid[] = "$Id: RGBDI.c,v 1.1 1994/03/02 13:59:21 jnw Exp $";
d14 3
d195 1
a195 1
#include "RGBImageOps.c"
@


1.1
log
@Initial revision
@
text
@d10 1
a10 1
static char IntDI_rcsid[] = "$Id$";
d13 3
a15 1
// $Log$
d17 1
d60 1
a60 1
inline int ppm_max(IA_Image<IA_IntPoint,IA_RGB> im)
d62 1
a62 1
    IA_IVIter<IA_IntPoint,IA_RGB>	iter(im);
d72 1
a72 1
IA_Image<IA_IntPoint,IA_RGB> IA_Image<IA_IntPoint,IA_RGB>::read_PPM(istream &i, int*maxval_ret)
d93 1
a93 1
		return IA_Image<IA_IntPoint,IA_RGB>();
d106 1
a106 1
			return IA_Image<IA_IntPoint,IA_RGB>();
d112 2
a113 2
	return IA_Image<IA_IntPoint,IA_RGB>
	    (IA_IntPointSet(IA_IntPoint(0,0), IA_IntPoint(height-1,width-1)),
d117 1
a117 1
	return IA_Image<IA_IntPoint,IA_RGB>();
d121 1
a121 1
IA_Image<IA_IntPoint,IA_RGB> IA_Image<IA_IntPoint,IA_RGB>::read_PPM(const char *fname, int *maxval)
d127 1
a127 1
ostream &IA_Image<IA_IntPoint,IA_RGB>::write_PPM(ostream &o, unsigned maxval) const
d129 2
a130 2
    IA_IntPointSet boxydomain(domain().inf(),domain().sup());
    IA_IntPoint	width(domain().sup()-domain().inf()+1);
d136 2
a137 2
    IA_PSIter<IA_IntPoint>	iter(boxydomain);
    IA_IntPoint	ip;
d150 1
a150 1
ostream &IA_Image<IA_IntPoint,IA_RGB>::write_PPM(ostream &o) const
d155 1
a155 1
void IA_Image<IA_IntPoint,IA_RGB>::write_PPM(const char *fname, unsigned maxval) const
d161 1
a161 1
void IA_Image<IA_IntPoint,IA_RGB>::write_PPM(const char *fname) const
d200 1
a200 1
class blah : public IA_ClosureI<IA_IntPoint,IA_RGB> {
d203 1
a203 1
    :IA_ClosureI<IA_IntPoint,IA_RGB>(IA_IntPointSet()) {}
d205 2
a206 2
    int operator()(const IA_IntPoint &) const { return 0; }
    IA_ClosureI<IA_IntPoint,IA_RGB* clone_self() const { return 0; }
d211 4
a214 4
    IA_IntPoint		ip;
    IA_IntPointSet	ps;
    IA_Image<IA_IntPoint,IA_RGB>	i1;
    IA_Image<IA_IntPoint,IA_RGB>
d220 2
a221 2
	i7(ps, (IA_RGB(*)(const IA_IntPoint&))0),
	i10(IA_CoreImage<IA_IntPoint,IA_RGB>());
d226 1
a226 1
    (IA_CoreImage<IA_IntPoint,IA_RGB>&)i1 = IA_RGB(2);
d233 1
a233 1
    cout << (IA_CoreImage<IA_IntPoint,IA_RGB&)i1;
d236 2
a237 2
    IA_Image<IA_IntPoint,IA_RGB>::read_IAA("");
    IA_Image<IA_IntPoint,IA_RGB>::read_IAA("","");
d243 2
a244 2
    IA_IVIter<IA_IntPoint,IA_RGB>	iter1(i1), iter2;
    IA_IPIter<IA_IntPoint,IA_RGB>	iter3(i2), iter4;
d254 2
a255 2
    compose(i1, (IA_IntPoint(*)(const IA_IntPoint&))0);
    compose(i1, *(IA_Closure<IA_IntPoint, IA_IntPoint>*)0);
@
