head	1.7;
access;
symbols
	r2_1:1.7
	r2_0:1.6
	r1_1_beta:1.4
	r1_1_alpha:1.4
	r1_0:1.4
	r0_11:1.4;
locks; strict;
comment	@// @;


1.7
date	94.09.06.18.58.44;	author fjsoria;	state Exp;
branches;
next	1.6;

1.6
date	94.08.17.02.15.09;	author gmt;	state Exp;
branches;
next	1.5;

1.5
date	94.08.16.03.56.07;	author gmt;	state Exp;
branches;
next	1.4;

1.4
date	94.04.15.17.44.57;	author jnw;	state Exp;
branches;
next	1.3;

1.3
date	94.03.03.22.57.20;	author jnw;	state Exp;
branches;
next	1.2;

1.2
date	94.02.14.18.30.26;	author jnw;	state Exp;
branches;
next	1.1;

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


desc
@RGB.h defines a three byte representation of a color
in RGB space with the class
IA_RGB.
@


1.7
log
@corrected "warning: return to `int' from `double'" by casting to int
@
text
@// Emacs -*- C++ -*-

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

//
// RGB.h
//
// Defines the class IA_RGB, which can be employed to represent
// colors in Red-Green-Blue space with one byte precision for each
// color component

//
//  $Log: RGB.h,v $
// Revision 1.6  1994/08/17  02:15:09  gmt
// Now includes compat.h instead of ia.h or sys/types.h .
//
// Revision 1.5  1994/08/16  03:56:07  gmt
// Made to include <ia.h> instead of <sys/types.h> since types are now
// dealt with in one place.  Has a Mac specific ifdef wrapper for now,
// but should change to all soon.
// Also changed a case of "int friend" to "friend int" since SC++ v7 did
// not like it.
//
// Revision 1.4  1994/04/15  17:44:57  jnw
// Added decl for pseudocolor
//
// Revision 1.3  1994/03/03  22:57:20  jnw
// added include of sys/types.h for u_char
//
// Revision 1.2  1994/02/14  18:30:26  jnw
// Added initial comment
//
// Revision 1.1  1994/02/14  18:23:49  jnw
// Initial revision
//

#ifndef IA_RGB_h_
#define IA_RGB_h_

#include <iostream.h>

#include "compat.h"

class IA_RGB {
private:
    u_char rgb_array[3];
public:
    IA_RGB() {}

    IA_RGB(int r, int g, int b) {
	rgb_array[0] = r;
	rgb_array[1] = g;
	rgb_array[2] = b;
    }

    IA_RGB(u_char* ar) {
	rgb_array[0] = ar[0];
	rgb_array[1] = ar[1];
	rgb_array[2] = ar[2];
    }

    IA_RGB(const IA_RGB &v){
	rgb_array[0] = v.rgb_array[0];
	rgb_array[1] = v.rgb_array[1];
	rgb_array[2] = v.rgb_array[2];
    }
    
    IA_RGB(int gray) {
	rgb_array[0] = gray;
	rgb_array[1] = gray;
	rgb_array[2] = gray;
    }

    int to_int() const {
	// constants cribbed from ppmtopgm man page
	return (int) ((  .299*rgb_array[0]
		+ .587*rgb_array[1]
		+ .114*rgb_array[2])/3);
    }

    float to_float() const {
	// constants cribbed from ppmtopgm man page
	return (  .299*rgb_array[0]
		+ .587*rgb_array[1]
		+ .114*rgb_array[2])/3.0;
    }

    IA_RGB& operator=(const IA_RGB &v) { 
	rgb_array[0] = v.rgb_array[0];
	rgb_array[1] = v.rgb_array[1];
	rgb_array[2] = v.rgb_array[2];
	return *this;
    }

    IA_RGB& operator=(int v) { 
	rgb_array[0] = v;
	rgb_array[1] = v;
	rgb_array[2] = v;
	return *this;
    }

    u_char& red() {
	return rgb_array[0];
    }
    
    u_char& green() {
	return rgb_array[1];
    }
    
    u_char& blue() {
	return rgb_array[2];
    }

    friend int operator==(IA_RGB lhs, IA_RGB rhs) {
	return lhs.rgb_array[0] == rhs.rgb_array[0]
	    && lhs.rgb_array[1] == rhs.rgb_array[1]
	    && lhs.rgb_array[2] == rhs.rgb_array[2];
    }

    friend int operator!=(IA_RGB lhs, IA_RGB rhs) {
	return !(lhs == rhs);
    }

    friend ostream& operator<<(ostream &o, IA_RGB rgb) {
	return o << "#RGB<" << rgb.rgb_array[0] << ","
		 << rgb.rgb_array[1] << ","
		 << rgb.rgb_array[2] << ">";
    }
};

IA_RGB pseudocolor(u_char);
#endif // IA_RGB_h_
@


1.6
log
@Now includes compat.h instead of ia.h or sys/types.h .
@
text
@d15 3
d77 1
a77 1
	return (  .299*rgb_array[0]
d79 1
a79 1
		+ .114*rgb_array[2])/3;
@


1.5
log
@Made to include <ia.h> instead of <sys/types.h> since types are now
dealt with in one place.  Has a Mac specific ifdef wrapper for now,
but should change to all soon.
Also changed a case of "int friend" to "friend int" since SC++ v7 did
not like it.
@
text
@d15 7
d40 1
a40 5
#ifdef __SC__
#include "ia.h"
#else
#include <sys/types.h>
#endif
@


1.4
log
@Added decl for pseudocolor
@
text
@d15 3
d32 4
d37 1
d109 1
a109 1
    int friend operator==(IA_RGB lhs, IA_RGB rhs) {
a127 1

@


1.3
log
@added include of sys/types.h for u_char
@
text
@d15 3
d118 1
@


1.2
log
@Added initial comment
@
text
@d15 3
d26 1
d46 1
a46 1
    IA_RGB(IA_RGB &v){
d58 1
a58 1
    int to_int() {
d65 1
a65 1
    float to_float() {
d72 1
a72 1
    IA_RGB& operator=(IA_RGB &v) { 
d99 3
a101 3
	return lhs.val->rgb_array[0] == rhs.val->rgb_array[0]
	    && lhs.val->rgb_array[1] == rhs.val->rgb_array[1]
	    && lhs.val->rgb_array[2] == rhs.val->rgb_array[2];
d104 1
a104 1
    int friend operator!=(IA_RGB lhs, IA_RGB rhs) {
d107 6
d115 1
a115 5
inline u_char max(IA_RGB op){
    return (op.red()>op.green())?
	((op.red()>op.blue())?op.red():op.blue())
	:((op.green()>op.blue())?op.green():op.blue());
}
a116 1
#endif // IA_RGB_h_
@


1.1
log
@Initial revision
@
text
@d6 6
d14 4
a17 1
//  $Log$
@
