示例#1
0
/*!
 * 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 );

}
示例#2
0
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 kernel */

      for ( x = 1; x < fa->width - 1; x++ ) {
         out[ 0 ] = r[ 1 ][ x ] * k[ 1 ][ 1 ]
            + r[ 0 ][ x - 1 ] * k[ 0 ][ 0 ]
            + r[ 0 ][ x     ] * k[ 0 ][ 1 ]
            + r[ 0 ][ x + 1 ] * k[ 0 ][ 2 ]
            + r[ 1 ][ x - 1 ] * k[ 1 ][ 0 ]
            + r[ 1 ][ x + 1 ] * k[ 1 ][ 2 ]
            + r[ 2 ][ x - 1 ] * k[ 2 ][ 0 ]
            + r[ 2 ][ x     ] * k[ 2 ][ 1 ]
            + r[ 2 ][ x + 1 ] * k[ 2 ][ 2 ];

         out[ 1 ] = g[ 1 ][ x ] * k[ 1 ][ 1 ]
            + g[ 0 ][ x - 1 ] * k[ 0 ][ 0 ]
            + g[ 0 ][ x     ] * k[ 0 ][ 1 ]
            + g[ 0 ][ x + 1 ] * k[ 0 ][ 2 ]
            + g[ 1 ][ x - 1 ] * k[ 1 ][ 0 ]
            + g[ 1 ][ x + 1 ] * k[ 1 ][ 2 ]
            + g[ 2 ][ x - 1 ] * k[ 2 ][ 0 ]
            + g[ 2 ][ x     ] * k[ 2 ][ 1 ]
            + g[ 2 ][ x + 1 ] * k[ 2 ][ 2 ];

         out[ 2 ] = b[ 1 ][ x ] * k[ 1 ][ 1 ]
            + b[ 0 ][ x - 1 ] * k[ 0 ][ 0 ]
            + b[ 0 ][ x     ] * k[ 0 ][ 1 ]
            + b[ 0 ][ x + 1 ] * k[ 0 ][ 2 ]
            + b[ 1 ][ x - 1 ] * k[ 1 ][ 0 ]
            + b[ 1 ][ x + 1 ] * k[ 1 ][ 2 ]
            + b[ 2 ][ x - 1 ] * k[ 2 ][ 0 ]
            + b[ 2 ][ x     ] * k[ 2 ][ 1 ]
            + b[ 2 ][ x + 1 ] * k[ 2 ][ 2 ];

         /* set the new pixel value */

         fa->setRGB( x, y, out );
      }

      /* shift bottom two scanlines up by one */

      r[ 0 ] = r[ 1 ];  r[ 1 ] = r[ 2 ];
      g[ 0 ] = g[ 1 ];  g[ 1 ] = g[ 2 ];
      b[ 0 ] = b[ 1 ];  b[ 1 ] = 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 );
}
示例#3
0
文件: load.c 项目: DimondTheCat/xray
static int read_polygon( LWObjectImport *local, FILE *fp, LWPntID *pntID,
   int *isurf, int isDetail, Progress *progress )
{
   static int vert[ 200 ];
   static LWPntID vID[ 200 ];
   LWPolID polID;
   int vscolor, nvert, ndet, i;
   char tag[ 40 ], *err = NULL;


   /* read the vertex count */

   if ( !read_int( fp, &nvert ))
      if ( feof( fp )) return 0;  else goto Fail;

   err = "Bad vertex count.";
   if ( nvert <= 0 || nvert > 200 ) goto Fail;

   /* read the vertices--these index the point list */

   err = "Couldn't read polygon.";

   for ( i = 0; i < nvert; i++ )
      if ( !read_int( fp, &vert[ i ] )) goto Fail;

   /* read the VideoScape color code */

   if ( !read_int( fp, &vscolor )) goto Fail;
   ++isurf[ vscolor ];

   /* get the surface name for this color code */

   get_surf( vscolor, tag, NULL, 0 );

   /* create the polygon */

   for ( i = 0; i < nvert; i++ )
      vID[ i ] = pntID[ vert[ i ]];

   polID = local->polygon( local->data, LWPOLTYPE_FACE, 0, nvert, vID );
   local->polTag( local->data, polID, LWPTAG_SURF, tag );

   /* update the progress monitor */

   i = ftell( fp );
   if ( i >= progress->nextstep ) {
      if ( MON_STEP( local->monitor )) {
         local->result = LWOBJIM_ABORTED;
         return 0;
      }
      progress->nextstep += progress->stepsize;
   }

   /* if this polygon has no detail polygons, we're done */

   if ( vscolor >= 0 ) return 1;

   /* read the detail polygon count--details can't have details */

   if ( isDetail || !read_int( fp, &ndet )) goto Fail;

   /* read the detail polygons recursively */

   for ( i = 0; i < ndet; i++ )
      if ( !read_polygon( local, fp, pntID, isurf, 1, progress ))
         if ( local->result == LWOBJIM_ABORTED ) return 0;
         else goto Fail;

   return 1;

Fail:
   local->result = LWOBJIM_FAILED;
   if ( !err )
      err = "Unexpected end of file.";
   if ( local->failedLen > 0 )
      strncpy( local->failedBuf, err, local->failedLen );

   return 0;
}
示例#4
0
文件: load.c 项目: DimondTheCat/xray
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;
}