_A Memory-Constrained Image Processing Architecture_ by Mayur Patel Example 1: #include #include #include int main ( int argc, char *argv[] ) { SGIReader in( "test.rgb" ); Contraster contrasted( &in, 1.3 ); SGIWriter out( "out.rgb", (InputImage *)&contrasted, in.getArea(), UChar); return ( 0 ); } Example 2: #ifndef TYPESEPER #define TYPESEPER ; #endif #ifndef TYPEENDOFLIST #define TYPEENDOFLIST ; #endif TYPEMACRO( float, Float ) TYPESEPER TYPEMACRO( int, Int ) TYPEENDOFLIST #ifdef TYPESEPER #undef TYPESEPER #endif #ifdef TYPEENDOFLIST #undef TYPEENDOFLIST #endif #ifdef TYPEMACRO #undef TYPEMACRO #endif Example 3: (a) enum Type { #define TYPESEPER , #define TYPEENDOFLIST #define TYPEMACRO( type, label ) label #include }; (b) void addition( Type opType, void *pDest, void *pOp1, void *pOp2 ) { switch( opType ) { #define TYPEMACRO( type, label ) \ case( label ) : \ *(( type * ) pDest ) = \ ( type ) *pOp1 + ( type ) *pOp2; \ break; #include default: break; }; return; } Listing One // File: Contraster.h -- (c) 1996 Mayur Patel #ifndef Contraster_CLASS #define Contraster_CLASS #include #include class Contraster : public InputImage { public: Contraster( InputImage *pIn, float rLumFactor, float rGreyPoint = 0.5 ); ~Contraster( void ); int fillTile( ImageTile *pWriteHere ); protected: InputImage *_pHost; float _rLumFactor; float _rGrey; }; #endif Listing Two // File: Contraster.C -- (c) 1996 Mayur Patel #include #include Contraster::Contraster( InputImage *pIn, float rLumFactor, float rGrey ) : InputImage( Real ) { _pHost = pIn; if ( _pHost ) _pHost->registerReference(); _rLumFactor = rLumFactor; _rGrey = rGrey; } Contraster::~Contraster( void ) { if ( _pHost ) _pHost->unregisterReference(); return; } int Contraster::fillTile( ImageTile *pWriteHere ) { int iRet = 0; ImageTile *pTile; unsigned long lLoop; register float *pSrc; register float *pDest; if ( _pHost && pWriteHere ) { pTile = _pHost->newTile( pWriteHere->getArea() ); if ( pTile ) { assert( getType() == pWriteHere->getType() ); pTile->typecast( Real ); pSrc = (float *) pTile->getBuffer(); pDest = (float *) pWriteHere->getBuffer(); lLoop = pWriteHere->getArea().width * pWriteHere->getArea().height; while ( lLoop ) { lLoop--; // contrast enhance: *pDest = _rGrey + (( *pSrc - _rGrey ) * _rLumFactor ); // clamp over-exposure & under-exposure: *pDest = ( *pDest < 0.0 ) ? ( 0.0 ) : ( *pDest ); *pDest = ( *pDest > 1.0 ) ? ( 1.0 ) : ( *pDest ); pDest++; pSrc++; } pTile->deleteTile(); } } return ( iRet ); }