///////////////////////////////////////////////////////////
// File: ilut.cpp
// Description: ImageLut - lookup table
//
// Author: C Dare-Edwards
// Copyright Conrad Dare-Edwards 1997
#include "stdafx.h"
#include "isystem.hpp"
#include "ilut.hpp"
#include <math.h>
// convert a byte stream through lookup table
void
ImageLut::Lookup( BYTE* buffer, int length ) const
{
// pass buffer through lut
while( length-- ) *buffer++ = m_luttable[ *buffer ];
}
// convert a single byte through lookup table
BYTE&
ImageLut::operator[] ( BYTE nIndex )
{
IASSERT( nIndex < BYTE_SIZE);
return( m_luttable[nIndex] );
}
// Scale between two points
BOOL
ImageLut::ScaleTo(const ImagePoint& from,
const ImagePoint& to)
{
int width = to.x - from.x;
int height = to.y - from.y;
// catch errors
if( from.y+ height >= getRange() ||
from.x+width >= getRange() || width <= 0 )
{
IASSERT( FALSE ); // alert we got problems
return ( FALSE ); // exit stage left
}
float addy = ((float)height / (float)width);
// slope across to to.x to.y
for( int i = 0; i <= abs(width); i++ )
{
m_luttable [ i+from.x] = from.y + (int)(addy*i);
}
return TRUE;
}
//End of File