/*! * Process * Just negative right now... */ void UnMultiply::Process(const LWFilterAccess *fa) { LWFVector out; float *r, *g, *b, *a; int x, y; /* fire up the monitor */ MON_INIT( fa->monitor, fa->height / 8 ); for ( y = 0; y < fa->height; y++ ) { /* get each scanline */ r = fa->getLine( LWBUF_RED, y ); g = fa->getLine( LWBUF_GREEN, y ); b = fa->getLine( LWBUF_BLUE, y ); a = fa->getLine( LWBUF_ALPHA, y ); for ( x = 0; x < fa->width; x++ ) { /* change each pixel value c to 1.0 - c (leave the alpha alone) */ out[ 0 ] = 1.0f - r[ x ]; out[ 1 ] = 1.0f - g[ x ]; out[ 2 ] = 1.0f - b[ x ]; /* set the new value */ fa->setRGB( x, y, out ); fa->setAlpha( x, y, a[ x ] ); } /* once every 8 lines, step the monitor and check for abort */ if (( y & 7 ) == 7 ) if ( MON_STEP( fa->monitor )) return; } MON_DONE( fa->monitor ); }
Process( ConvolveInst *inst, const LWFilterAccess *fa ) { LWFVector out; float *r[ 3 ], *g[ 3 ], *b[ 3 ], *a; float s, k[ 3 ][ 3 ]; int x, y, i; /* make a copy of the kernel, sum the elements */ for ( i = 0, s = 0.0f; i < 9; i++ ) { k[ i / 3 ][ i % 3 ] = inst->kern[ i / 3 ][ i % 3 ]; s += k[ i / 3 ][ i % 3 ]; } /* scale the kernel so that the elements sum to 1.0 */ if ( s != 0.0f ) for ( i = 0; i < 9; i++ ) k[ i / 3 ][ i % 3 ] /= s; /* get the first two scanlines */ for ( i = 0; i < 2; i++ ) { r[ i ] = fa->getLine( LWBUF_RED, i ); g[ i ] = fa->getLine( LWBUF_GREEN, i ); b[ i ] = fa->getLine( LWBUF_BLUE, i ); } /* fire up the monitor */ MON_INIT( fa->monitor, fa->height / 8 ); for ( y = 1; y < fa->height - 1; y++ ) { /* get the next scanline */ r[ 2 ] = fa->getLine( LWBUF_RED, y + 1 ); g[ 2 ] = fa->getLine( LWBUF_GREEN, y + 1 ); b[ 2 ] = fa->getLine( LWBUF_BLUE, y + 1 ); /* apply the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] = b[ 2 ]; /* once every 8 lines, step the monitor and check for abort */ if (( y & 7 ) == 7 ) if ( MON_STEP( fa->monitor )) return; } /* copy the alpha */ for ( y = 0; y < fa->height; y++ ) { a = fa->getLine( LWBUF_ALPHA, y ); for ( x = 0; x < fa->width; x++ ) fa->setAlpha( x, y, a[ x ] ); } MON_DONE( fa->monitor ); }
geoLoad( long version, GlobalFunc *global, LWObjectImport *local, void *serverData ) { static int isurf[ 261 ]; LWFVector pos = { 0.0f }; LWPntID *pntID = NULL; Progress progress; FILE *fp = NULL; struct stat s; char str[ 6 ], *err = NULL; int npts; int i, j; /* check the activation version */ if ( version != LWOBJECTIMPORT_VERSION ) return AFUNC_BADVERSION; /* get the file size */ if ( stat( local->filename, &s )) { local->result = LWOBJIM_BADFILE; return AFUNC_OK; } progress.total = s.st_size; progress.stepsize = progress.total / 20; progress.nextstep = progress.stepsize; /* attempt to open the file */ fp = fopen( local->filename, "r" ); if ( !fp ) { local->result = LWOBJIM_BADFILE; return AFUNC_OK; } /* see whether this is a VideoScape ASCII object file; if not, let someone else try to load it */ fread( str, 1, 4, fp ); if ( strncmp( str, "3DG1", 4 )) { fclose( fp ); local->result = LWOBJIM_NOREC; return AFUNC_OK; } /* initialize the layer */ local->layer( local->data, 1, NULL ); local->pivot( local->data, pos ); /* read the point count */ local->result = LWOBJIM_FAILED; /* assume this until we succeed */ err = "Bad point count."; if ( !read_int( fp, &npts )) goto Finish; if ( npts <= 0 ) goto Finish; /* allocate space to store point IDs */ err = "Couldn't allocate memory for points."; pntID = calloc( npts, sizeof( LWPntID )); if ( !pntID ) goto Finish; /* initialize the progress monitor */ MON_INIT( local->monitor, 20 ); /* read the point list */ for ( i = 0; i < npts; i++ ) { for ( j = 0; j < 3; j++ ) if ( !read_float( fp, &pos[ j ] )) { err = "Couldn't read point."; goto Finish; } if ( !( pntID[ i ] = local->point( local->data, pos ))) { err = "Couldn't create point."; goto Finish; } j = ftell( fp ); if ( j >= progress.nextstep ) { if ( MON_STEP( local->monitor )) { local->result = LWOBJIM_ABORTED; err = NULL; goto Finish; } progress.nextstep += progress.stepsize; } } /* read the polygon list; read_polygon() will set its own failure status and message */ err = NULL; local->result = LWOBJIM_OK; memset( isurf, 0, 261 * sizeof( int )); while ( read_polygon( local, fp, pntID, isurf, 0, &progress )) ; /* create the surface descriptions */ if ( local->result == LWOBJIM_OK ) create_surfs( local, isurf ); /* we're done */ MON_DONE( local->monitor ); local->done( local->data ); Finish: if ( fp ) fclose( fp ); if ( pntID ) free( pntID ); if (( local->result != LWOBJIM_OK ) && err && ( local->failedLen > 0 )) strncpy( local->failedBuf, err, local->failedLen ); return AFUNC_OK; }