// Program: 3055 // Author: Manuel J. A. Eugster ( e0126312@student.tuwien.ac.at ) // FileId: $Id: RGBSystem.java,v 1.1.1.1 2001/12/10 18:56:04 heder Exp $ import java.lang.*; import RGBVector; import RGBRectangle; // CLASS: // Red Green Blue Color space. // public class RGBSystem { private RGBVector vRGBSpace; // Red Green Blue Color space private RGBVector vRGBReduce; // Red Green Blue reduction relation // METHOD: // Constructor. Standard red, blue, green values (255). // public RGBSystem() { this.vRGBSpace = new RGBVector( 255, 255, 255 ); } // METHOD: // Constructor. Possible to set other red, green, blue // values. // public RGBSystem( int iR, int iG, int iB ) { this.vRGBSpace = new RGBVector( iR, iG, iB ); } // METHOD: // Set color reduction // public void setReduction( int iRedR, int iRedG, int iRedB ) { this.vRGBReduce = new RGBVector( iRedR, iRedG, iRedB ); return; } // METHOD: // Creates the rectangle around the real point. // public RGBRectangle createRect( int iR, int iG, int iB ) { RGBVector vPoint = new RGBVector( iR, iG, iB ); // Real point int [] iRGBReduced = {-1, -1, -1, -1, -1, -1}; // Reduced points for ( int i = 0; i < 3; i++ ) { int iUBorder = 0; int iLBorder = 0; int j = 0; do { iUBorder = ( int ) Math.round( ( vRGBSpace.getCoord( i ) / vRGBReduce.getCoord( i ) ) * j ); j++; } while ( vPoint.getCoord( i ) > iUBorder ); iLBorder = ( int ) Math.round( ( vRGBSpace.getCoord( i ) / vRGBReduce.getCoord( i ) ) * ( j - 2 ) ); if ( Math.abs( vPoint.getCoord( i ) - iUBorder ) < Math.abs( vPoint.getCoord( i ) - iLBorder ) ) { iRGBReduced[i] = iUBorder; iRGBReduced[i + 3] = iLBorder; } else { iRGBReduced[i] = iLBorder; iRGBReduced[i + 3] = iUBorder; } } return( new RGBRectangle( vPoint, iRGBReduced ) ); } }