Пример #1
0
bool r100DrawLine3D( void *drv, void *dev, DFBRegion *line )
{
    RadeonDriverData *rdrv = (RadeonDriverData*) drv;
    RadeonDeviceData *rdev = (RadeonDeviceData*) dev;
    float             x1, y1;
    float             x2, y2;
    u32              *v;

    x1 = line->x1;
    y1 = line->y1;
    x2 = line->x2;
    y2 = line->y2;
    if (rdev->matrix) {
        RADEON_TRANSFORM( x1, y1, x1, y1, rdev->matrix, rdev->affine_matrix );
        RADEON_TRANSFORM( x2, y2, x2, y2, rdev->matrix, rdev->affine_matrix );
    }

    v = r100_init_vb( rdrv, rdev, VF_PRIM_TYPE_LINE_LIST, 2, 4 );
    *v++ = f2d(x1);
    *v++ = f2d(y1);
    *v++ = f2d(x2);
    *v++ = f2d(y2);

    return true;
}
Пример #2
0
static void
r300_flush_vb( RadeonDriverData *rdrv, RadeonDeviceData *rdev )
{
     volatile u8 *mmio = rdrv->mmio_base;
    
     EMIT_VERTICES( rdrv, rdev, mmio );
     
     if (DFB_PLANAR_PIXELFORMAT(rdev->dst_format)) {
          DFBRegion clip;
          int       i;
          
          for (i = 0; i < rdev->vb_size; i += 8) {
               rdev->vb[i+0] = f2d(d2f(rdev->vb[i+0])*0.5f);
               rdev->vb[i+1] = f2d(d2f(rdev->vb[i+1])*0.5f);
          }
          
          clip.x1 = rdev->clip.x1 >> 1;
          clip.y1 = rdev->clip.y1 >> 1;
          clip.x2 = rdev->clip.x2 >> 1;
          clip.y2 = rdev->clip.y2 >> 1;
     
          /* Prepare Cb plane */
          radeon_waitfifo( rdrv, rdev, 5 );
          radeon_out32( mmio, R300_RB3D_COLOROFFSET0, rdev->dst_offset_cb );
          radeon_out32( mmio, R300_RB3D_COLORPITCH0, (rdev->dst_pitch>>1) | 
                                                     R300_COLOR_FORMAT_RGB8 );
          radeon_out32( mmio, R300_TX_SIZE_0, ((rdev->src_width/2 -1) << R300_TX_WIDTH_SHIFT)  |
                                              ((rdev->src_height/2-1) << R300_TX_HEIGHT_SHIFT) |
                                              R300_TX_SIZE_TXPITCH_EN );
          radeon_out32( mmio, R300_TX_PITCH_0, (rdev->src_pitch>>1) - 8 );
          radeon_out32( mmio, R300_TX_OFFSET_0, rdev->src_offset_cb ); 
          r300_set_clip3d( rdrv, rdev, &clip );
     
          /* Fill Cb plane */
          EMIT_VERTICES( rdrv, rdev, mmio );
     
          /* Prepare Cr plane */
          radeon_waitfifo( rdrv, rdev, 2 );
          radeon_out32( mmio, R300_RB3D_COLOROFFSET0, rdev->dst_offset_cr );
          radeon_out32( mmio, R300_TX_OFFSET_0, rdev->src_offset_cr );
     
          /* Fill Cr plane */
          EMIT_VERTICES( rdrv, rdev, mmio );
     
          /* Reset */
          radeon_waitfifo( rdrv, rdev, 5 );
          radeon_out32( mmio, R300_RB3D_COLOROFFSET0, rdev->dst_offset );
          radeon_out32( mmio, R300_RB3D_COLORPITCH0, rdev->dst_pitch | 
                                                     R300_COLOR_FORMAT_RGB8 );
          radeon_out32( mmio, R300_TX_SIZE_0, ((rdev->src_width -1) << R300_TX_WIDTH_SHIFT)  |
                                              ((rdev->src_height-1) << R300_TX_HEIGHT_SHIFT) |
                                         R300_TX_SIZE_TXPITCH_EN );
          radeon_out32( mmio, R300_TX_PITCH_0, rdev->src_pitch - 8 );
          radeon_out32( mmio, R300_TX_OFFSET_0, rdev->src_offset ); 
          r300_set_clip3d( rdrv, rdev, &rdev->clip );
     }
int main ()
{
	int i,j, k, l;
	IMAGE im1;
	float **outimage ;
	char filename[512] ;
	
	// <Distance Conversion using Chess Board Distance> program 
	printf ("Sample Program for Filtering \n");

	printf ("Input Image Filename (PGM) = ");
	scanf("%s", filename) ;
	getchar() ;


	//read PGM image
	im1 = Input_PBM (filename);
	if (im1 == 0)
	{
	  printf ("No such file as '%s'\n", filename);
	  exit(0);
	}

	ny = im1->info->ny; nx = im1->info->nx;   // get info of height&width

	inputimage = f2d(ny, nx);  // ny x nx float 2 dimentional array
	outimage = f2d(ny, nx);    // ny x nx float 2 dimentional array

	// copy input image into the array
	for (i=0; i<ny; i++)
	  for (j=0; j<nx; j++)
			inputimage[i][j] = (float)im1->data[i][j] ;

	// <Chess Board Distance  >  processing program
	for (i=0; i<ny; i++)
	  for (j=0; j<nx; j++) {
		  if (inputimage[i][j] == 0) continue;
		  else {
			  outimage[i][j] = getDistance(j, i);
			  printf("%d out of %d\n", i, ny);
		  }
	  }
	int level = 255 / MAX_DISTANCE;
	//from array to image for saving
	for (i=0; i<ny; i++)
	  for (j=0; j<nx; j++)
			im1->data[i][j] = (unsigned char)(outimage[i][j] * level);

	// save processed image as PGM file
	printf ("Output Image Filename (PGM) = ");
	scanf("%s", filename) ;
	getchar() ;

	Output_PBM (im1, filename);
}
int main ()
{
	int i,j, k, l, nx, ny;
	IMAGE im1;
	float **inputimage ;
	float **outimage ;
	char filename[512] ;
	
	// <Median Filter > program 
	printf ("Sample Program for Filtering \n");

	printf ("Input Image Filename (PGM) = ");
	scanf("%s", filename) ;
	getchar() ;


	//read PGM image
	im1 = Input_PBM (filename);
	if (im1 == 0)
	{
	  printf ("No such file as '%s'\n", filename);
	  exit(0);
	}

	ny = im1->info->ny; nx = im1->info->nx;   // get info of height&width

	inputimage = f2d(ny, nx);  // ny x nx float 2 dimentional array
	outimage = f2d(ny, nx);    // ny x nx float 2 dimentional array

	// copy input image into the array
	for (i=0; i<ny; i++)
	  for (j=0; j<nx; j++)
			inputimage[i][j] = (float)im1->data[i][j] ;

	// < Median Filter  >  processing program
	for (i=1; i<ny-1; i++)
	  for (j=1; j<nx-1; j++)
			outimage[i][j] = getMedianValue(inputimage, i, j);


	//from array to image for saving
	for (i=0; i<ny; i++)
	  for (j=0; j<nx; j++)
			im1->data[i][j] = (unsigned char)(outimage[i][j]);

	// save processed image as PGM file
	printf ("Output Image Filename (PGM) = ");
	scanf("%s", filename) ;
	getchar() ;

	Output_PBM (im1, filename);
}
Пример #5
0
void EdgeDetectMarrHill::marr(float s, QImage *img)
{
    int width;
    float **smx;
    int i, j, n;
    float **lgau;

    /* Create a Gaussian and a derivative of Gaussian filter mask  */
    width = 3.35*s + 0.33;
    n = width + width + 1;

    qDebug() << ">>> Suavizando com Gaussiana de tamanho " << n << "x" << n;

    lgau = f2d (n, n);

    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++)
            lgau[i][j] = LoG (distance((float)i, (float)j,
                                        (float)width, (float)width), s);

    /* Convolution of source image with a Gaussian in X and Y directions  */
    smx = f2d (img->width(), img->height());

    qDebug() << ">>> Convolucao com LoG";

    convolution (img, lgau, n, n, smx, img->height(), img->width());

    /* Locate the zero crossings */
    qDebug() << ">>> Passagens por Zero";
    zero_cross (smx, img);

    /* Clear the boundary */
    for (i = 0; i < img->width(); i++) {
        for (j = 0; j <= width; j++)
            img->setPixel(QPoint(i, j), qRgb(0, 0, 0));
        for (j = img->height() - width - 1; j < img->height(); j++)
            img->setPixel(QPoint(i, j), qRgb(0, 0, 0));
    }

    for (j = 0; j < img->height(); j++) {
        for (i = 0; i <= width; i++)
            img->setPixel(QPoint(i, j), qRgb(0, 0, 0));
        for (i = img->width() - width - 1; i < img->width(); i++)
            img->setPixel(QPoint(i, j), qRgb(0, 0, 0));
    }

    free(smx[0]); free(smx);
    free(lgau[0]); free(lgau);
}
Пример #6
0
void imProcessCanny(const imImage* im, imImage* NewImage, float stddev)
{
  int width = 1;
  float **smx,**smy;
  float **dx,**dy;
  int i;
  float gau[MAX_MASK_SIZE], dgau[MAX_MASK_SIZE];

/* Create a Gaussian and a derivative of Gaussian filter mask */
  for(i=0; i<MAX_MASK_SIZE; i++)
  {
    gau[i] = meanGauss ((float)i, stddev);
    if (gau[i] < 0.005)
    {
      width = i;
      break;
    }
    dgau[i] = dGauss ((float)i, stddev);
  }

  smx = f2d (im->height, im->width);
  smy = f2d (im->height, im->width);

/* Convolution of source image with a Gaussian in X and Y directions  */
  seperable_convolution (im, gau, width, smx, smy);

  MAG_SCALE = 0;

/* Now convolve smoothed data with a derivative */
  dx = f2d (im->height, im->width);
  dxy_seperable_convolution (smx, im->height, im->width, dgau, width, dx, 1);
  free(smx[0]); free(smx);

  dy = f2d (im->height, im->width);
  dxy_seperable_convolution (smy, im->height, im->width, dgau, width, dy, 0);
  free(smy[0]); free(smy);

  if (MAG_SCALE)
    MAG_SCALE = 255.0f/(1.4142f*MAG_SCALE);

  /* Non-maximum suppression - edge pixels should be a local max */
  nonmax_suppress (dx, dy, NewImage);

  free(dx[0]); free(dx);
  free(dy[0]); free(dy);
}
void test_function() {
  function<int(int, int)> f2a;
  function<int(int, int)> f2b = add<int>();
  function<int(int, int)> f2c = add<float>();
  function<int(int, int)> f2d(f2b);
  function<int(int, int)> f2e = &add_ints;
  f2c = f2d;
  f2d = &add_ints;
  f2c(1.0, 3);
}
Пример #8
0
bool r100FillTriangle( void *drv, void *dev, DFBTriangle *tri )
{
    RadeonDriverData *rdrv = (RadeonDriverData*) drv;
    RadeonDeviceData *rdev = (RadeonDeviceData*) dev;
    float             x1, y1;
    float             x2, y2;
    float             x3, y3;
    u32              *v;

    x1 = tri->x1;
    y1 = tri->y1;
    x2 = tri->x2;
    y2 = tri->y2;
    x3 = tri->x3;
    y3 = tri->y3;
    if (rdev->matrix) {
        RADEON_TRANSFORM( x1, y1, x1, y1, rdev->matrix, rdev->affine_matrix );
        RADEON_TRANSFORM( x2, y2, x2, y2, rdev->matrix, rdev->affine_matrix );
        RADEON_TRANSFORM( x3, y3, x3, y3, rdev->matrix, rdev->affine_matrix );
    }

    v = r100_init_vb( rdrv, rdev, VF_PRIM_TYPE_TRIANGLE_LIST, 3, 6 );
    *v++ = f2d(x1);
    *v++ = f2d(y1);
    *v++ = f2d(x2);
    *v++ = f2d(y2);
    *v++ = f2d(x3);
    *v++ = f2d(y3);

    return true;
}
Пример #9
0
// evaluate a pong return on the given struct
void multi_ping_eval_pong(ping_struct *ps, fix pong_time)
{	
	int idx;
	fix ping_sum;
	
	// if the ping technically hasn't started,
	if(ps->ping_start < 0L){
		nprintf(("Network","Processing pong for ping which hasn't started yet!\n"));
		return;
	}
	
	// if we still have room to add a ping
	if(ps->num_pings < MAX_PINGS){
		ps->ping_times[ps->ping_add++] = pong_time - ps->ping_start;
		Assertion(ps->ping_times[ps->ping_add-1] > 0L, "Non-positive ping value!");
		ps->num_pings++;
	} 
	// otherwise if we've wrapped around
	else {		
		// increment the place to add the ping time
		if(ps->ping_add >= MAX_PINGS - 1){
			ps->ping_add = 0;
		} else {
			ps->ping_add++;
		}

		ps->ping_times[ps->ping_add] = pong_time - ps->ping_start;
		Assertion(ps->ping_times[ps->ping_add == 0 ? MAX_PINGS - 1 : ps->ping_add - 1] > 0L, "Non-positive ping value!");
	}

	// calculate the average ping time
	ping_sum = 0L;
	for(idx=0;idx<ps->num_pings;idx++){
		ping_sum += ps->ping_times[idx];
	}
	ps->ping_avg = (int)(f2d(1000L * ping_sum) / (double)ps->num_pings);
}
Пример #10
0
static void initPlayer(int p, int clear)
{
   int i, j, k, nok, tries;

   if(clear)
   {
      player[p].angle = 0.0;
      player[p].energy = 0.0;
      player[p].velocity = 10.0;
      player[p].oldVelocity = 10.0;
      player[p].deaths = 0;
      player[p].kills = 0;
      player[p].selfkills = 0;
      player[p].shots = 0;
      player[p].watch = 0;
   }

   player[p].active = 1;
   player[p].currentShot = 0;
   player[p].valid = 0;
   player[p].didShoot = 0;
   player[p].timeout = conf.timeout;
   player[p].timeoutcnt = 0;

   for(i = 0; i < conf.numShots; ++i)
   {
      SimShot* s = &(player[p].shot[i]);
      s->length = 0;
      s->missile.live = 0;
   }

   tries = 0;
   do
   {
      player[p].position.x = 20.0 + (double)rand() / RAND_MAX * (conf.battlefieldW - 40.0);
      player[p].position.y = 20.0 + (double)rand() / RAND_MAX * (conf.battlefieldH - 40.0);

      nok = 0;
      for(i = 0; i < conf.numPlanets; ++i)
      {
         if(distance(player[p].position, planet[i].position) <= (100.0 + planet[i].radius + 4.0))
         {
            nok = 1;
         }
      }
      for(i = 0; i < conf.maxPlayers; ++i)
      {
         if(i == p || !player[i].active) continue;
         if(distance(player[p].position, player[i].position) <= (200.0 + 4.0 + 4.0))
         {
            nok = 1;
         }
      }
      for(i = 0; i < conf.maxPlayers && tries < 2000 && !nok; ++i)
      {
         if(i == p || !player[i].active) continue;
         for(j = 0; j < conf.numShots && !nok; ++j)
         {
            for(k = 0; k < player[i].shot[j].length && !nok; ++k)
            {
               if(distance(player[p].position, f2d(player[i].shot[j].dot[k])) <= 100.0)
               {
                  nok = 1;
               }
            }
         }
      }
      tries++;
   } while (nok);
   if(tries >= 2000)
   {
      printf("Couldn't keep player spawn away from existing shots.\n");
   }
}
Пример #11
0
decltype(auto) *v4 = { 0 }; // expected-error {{cannot form pointer to 'decltype(auto)'}}
decltype(auto) v5 = &overloaded_fn; // expected-error {{could not be resolved}}

auto multi1a = 0, &multi1b = multi1a;
auto multi1c = multi1a, multi1d = multi1b;
decltype(auto) multi1e = multi1a, multi1f = multi1b; // expected-error {{'decltype(auto)' deduced as 'int' in declaration of 'multi1e' and deduced as 'int &' in declaration of 'multi1f'}}

auto f1a() { return 0; }
decltype(auto) f1d() { return 0; }
using Int = decltype(f1a());
using Int = decltype(f1d());

auto f2a(int n) { return n; }
decltype(auto) f2d(int n) { return n; }
using Int = decltype(f2a(0));
using Int = decltype(f2d(0));

auto f3a(int n) { return (n); }
decltype(auto) f3d(int n) { return (n); } // expected-warning {{reference to stack memory}}
using Int = decltype(f3a(0));
using IntLRef = decltype(f3d(0));

auto f4a(int n) { return f(); }
decltype(auto) f4d(int n) { return f(); }
using Int = decltype(f4a(0));
using IntRRef = decltype(f4d(0));

auto f5aa(int n) { auto x = f(); return x; }
auto f5ad(int n) { decltype(auto) x = f(); return x; }
decltype(auto) f5da(int n) { auto x = f(); return x; }
decltype(auto) f5dd(int n) { decltype(auto) x = f(); return x; } // expected-error {{rvalue reference to type 'int' cannot bind to lvalue}}
Пример #12
0
static void
r100_flush_vb( RadeonDriverData *rdrv, RadeonDeviceData *rdev )
{
    volatile u8 *mmio = rdrv->mmio_base;

    EMIT_VERTICES( rdrv, rdev, mmio );

    if (DFB_PLANAR_PIXELFORMAT(rdev->dst_format)) {
        DFBRegion *clip = &rdev->clip;
        bool       s420 = DFB_PLANAR_PIXELFORMAT(rdev->src_format);
        int        i;

        if (DFB_BLITTING_FUNCTION(rdev->accel)) {
            for (i = 0; i < rdev->vb_size; i += 4) {
                rdev->vb[i+0] = f2d(d2f(rdev->vb[i+0])*0.5f);
                rdev->vb[i+1] = f2d(d2f(rdev->vb[i+1])*0.5f);
                if (s420) {
                    rdev->vb[i+2] = f2d(d2f(rdev->vb[i+2])*0.5f);
                    rdev->vb[i+3] = f2d(d2f(rdev->vb[i+3])*0.5f);
                }
            }
        } else {
            for (i = 0; i < rdev->vb_size; i += 2) {
                rdev->vb[i+0] = f2d(d2f(rdev->vb[i+0])*0.5f);
                rdev->vb[i+1] = f2d(d2f(rdev->vb[i+1])*0.5f);
            }
        }

        /* Prepare Cb plane */
        radeon_waitfifo( rdrv, rdev, 5 );
        radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset_cb );
        radeon_out32( mmio, RB3D_COLORPITCH, rdev->dst_pitch/2 );
        radeon_out32( mmio, RE_TOP_LEFT, (clip->y1/2 << 16) |
                      (clip->x1/2 & 0xffff) );
        radeon_out32( mmio, RE_BOTTOM_RIGHT, (clip->y2/2 << 16) |
                      (clip->x2/2 & 0xffff) );
        if (DFB_BLITTING_FUNCTION(rdev->accel)) {
            radeon_out32( mmio, PP_TFACTOR_0, rdev->cb_cop );
            if (s420) {
                radeon_waitfifo( rdrv, rdev, 3 );
                radeon_out32( mmio, PP_TEX_SIZE_0, ((rdev->src_height/2-1) << 16) |
                              ((rdev->src_width/2-1) & 0xffff) );
                radeon_out32( mmio, PP_TEX_PITCH_0, rdev->src_pitch/2 - 32 );
                radeon_out32( mmio, PP_TXOFFSET_0, rdev->src_offset_cb );
            }
        } else {
            radeon_out32( mmio, PP_TFACTOR_1, rdev->cb_cop );
        }

        /* Fill Cb plane */
        EMIT_VERTICES( rdrv, rdev, mmio );

        /* Prepare Cr plane */
        radeon_waitfifo( rdrv, rdev, 2 );
        radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset_cr );
        if (DFB_BLITTING_FUNCTION(rdev->accel)) {
            radeon_out32( mmio, PP_TFACTOR_0, rdev->cr_cop );
            if (s420) {
                radeon_waitfifo( rdrv, rdev, 1 );
                radeon_out32( mmio, PP_TXOFFSET_0, rdev->src_offset_cr );
            }
        } else {
            radeon_out32( mmio, PP_TFACTOR_1, rdev->cr_cop );
        }

        /* Fill Cr plane */
        EMIT_VERTICES( rdrv, rdev, mmio );

        /* Reset */
        radeon_waitfifo( rdrv, rdev, 5 );
        radeon_out32( mmio, RB3D_COLOROFFSET, rdev->dst_offset );
        radeon_out32( mmio, RB3D_COLORPITCH, rdev->dst_pitch );
        radeon_out32( mmio, RE_TOP_LEFT, (clip->y1 << 16) |
                      (clip->x1 & 0xffff) );
        radeon_out32( mmio, RE_BOTTOM_RIGHT, (clip->y2 << 16) |
                      (clip->x2 & 0xffff) );
        if (DFB_BLITTING_FUNCTION(rdev->accel)) {
            radeon_out32( mmio, PP_TFACTOR_0, rdev->y_cop );
            if (s420) {
                radeon_waitfifo( rdrv, rdev, 3 );
                radeon_out32( mmio, PP_TEX_SIZE_0, ((rdev->src_height-1) << 16) |
                              ((rdev->src_width-1) & 0xffff) );
                radeon_out32( mmio, PP_TEX_PITCH_0, rdev->src_pitch - 32 );
                radeon_out32( mmio, PP_TXOFFSET_0, rdev->src_offset );
            }
        } else {
            radeon_out32( mmio, PP_TFACTOR_1, rdev->y_cop );
        }
    }

    rdev->vb_size  = 0;
    rdev->vb_count = 0;
}
Пример #13
0
static void
r100DoTextureTriangles( RadeonDriverData *rdrv, RadeonDeviceData *rdev,
                        DFBVertex *ve, int num, u32 primitive )
{
    volatile u8   *mmio = rdrv->mmio_base;
    int            i;

    radeon_waitfifo( rdrv, rdev, 1 );

    radeon_out32( mmio, SE_VF_CNTL, primitive         |
                  VF_PRIM_WALK_DATA |
                  VF_RADEON_MODE    |
                  (num << VF_NUM_VERTICES_SHIFT) );

    for (; num >= 10; num -= 10) {
        radeon_waitfifo( rdrv, rdev, 60 );
        for (i = 0; i < 10; i++) {
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].x) );
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].y) );
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].z) );
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].w) );
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].s) );
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].t) );
        }
        ve += 10;
    }

    if (num > 0) {
        radeon_waitfifo( rdrv, rdev, num*6 );
        for (i = 0; i < num; i++) {
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].x) );
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].y) );
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].z) );
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].w) );
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].s) );
            radeon_out32( mmio, SE_PORT_DATA0, f2d(ve[i].t) );
        }
    }
}
Пример #14
0
bool r100DrawRectangle3D( void *drv, void *dev, DFBRectangle *rect )
{
    RadeonDriverData *rdrv = (RadeonDriverData*) drv;
    RadeonDeviceData *rdev = (RadeonDeviceData*) dev;
    float             x1, y1;
    float             x2, y2;
    u32              *v;

    x1 = rect->x;
    y1 = rect->y;
    x2 = rect->x+rect->w;
    y2 = rect->y+rect->h;
    if (rdev->matrix) {
        float x, y;

        /* XXX: better LINE_STRIP?! */
        v = r100_init_vb( rdrv, rdev, VF_PRIM_TYPE_LINE_LIST, 8, 16 );
        RADEON_TRANSFORM( x1, y1, x, y, rdev->matrix, rdev->affine_matrix );
        *v++ = f2d(x);
        *v++ = f2d(y);
        RADEON_TRANSFORM( x2, y1, x, y, rdev->matrix, rdev->affine_matrix );
        *v++ = f2d(x);
        *v++ = f2d(y);
        *v++ = f2d(x);
        *v++ = f2d(y);
        RADEON_TRANSFORM( x2, y2, x, y, rdev->matrix, rdev->affine_matrix );
        *v++ = f2d(x);
        *v++ = f2d(y);
        *v++ = f2d(x);
        *v++ = f2d(y);
        RADEON_TRANSFORM( x1, y2, x, y, rdev->matrix, rdev->affine_matrix );
        *v++ = f2d(x);
        *v++ = f2d(y);
        *v++ = f2d(x);
        *v++ = f2d(y);
        RADEON_TRANSFORM( x1, y1, x, y, rdev->matrix, rdev->affine_matrix );
        *v++ = f2d(x);
        *v++ = f2d(y);
    }
    else {
        v = r100_init_vb( rdrv, rdev, VF_PRIM_TYPE_RECTANGLE_LIST, 12, 24 );
        /* top line */
        *v++ = f2d(x1);
        *v++ = f2d(y1);
        *v++ = f2d(x2);
        *v++ = f2d(y1);
        *v++ = f2d(x2);
        *v++ = f2d(y1+1);
        /* right line */
        *v++ = f2d(x2-1);
        *v++ = f2d(y1+1);
        *v++ = f2d(x2);
        *v++ = f2d(y1+1);
        *v++ = f2d(x2);
        *v++ = f2d(y2-1);
        /* bottom line */
        *v++ = f2d(x1);
        *v++ = f2d(y2-1);
        *v++ = f2d(x2);
        *v++ = f2d(y2-1);
        *v++ = f2d(x2);
        *v++ = f2d(y2);
        /* left line */
        *v++ = f2d(x1);
        *v++ = f2d(y1+1);
        *v++ = f2d(x1+1);
        *v++ = f2d(y1+1);
        *v++ = f2d(x1+1);
        *v++ = f2d(y2-1);
    }

    return true;
}
Пример #15
0
bool r100FillRectangle3D( void *drv, void *dev, DFBRectangle *rect )
{
    RadeonDriverData *rdrv = (RadeonDriverData*) drv;
    RadeonDeviceData *rdev = (RadeonDeviceData*) dev;
    float             x1, y1;
    float             x2, y2;
    u32              *v;

    if (rect->w == 1 && rect->h == 1) {
        x1 = rect->x+1;
        y1 = rect->y+1;
        if (rdev->matrix)
            RADEON_TRANSFORM( x1, y1, x1, y1, rdev->matrix, rdev->affine_matrix );

        v = r100_init_vb( rdrv, rdev, VF_PRIM_TYPE_POINT_LIST, 1, 2 );
        *v++ = f2d(x1);
        *v++ = f2d(y1);

        return true;
    }

    x1 = rect->x;
    y1 = rect->y;
    x2 = rect->x+rect->w;
    y2 = rect->y+rect->h;
    if (rdev->matrix) {
        float X1, Y1, X2, Y2, X3, Y3, X4, Y4;

        RADEON_TRANSFORM( x1, y1, X1, Y1, rdev->matrix, rdev->affine_matrix );
        RADEON_TRANSFORM( x2, y1, X2, Y2, rdev->matrix, rdev->affine_matrix );
        RADEON_TRANSFORM( x2, y2, X3, Y3, rdev->matrix, rdev->affine_matrix );
        RADEON_TRANSFORM( x1, y2, X4, Y4, rdev->matrix, rdev->affine_matrix );

        v = r100_init_vb( rdrv, rdev, VF_PRIM_TYPE_TRIANGLE_LIST, 6, 12 );
        *v++ = f2d(X1);
        *v++ = f2d(Y1);
        *v++ = f2d(X2);
        *v++ = f2d(Y2);
        *v++ = f2d(X3);
        *v++ = f2d(Y3);
        *v++ = f2d(X1);
        *v++ = f2d(Y1);
        *v++ = f2d(X3);
        *v++ = f2d(Y3);
        *v++ = f2d(X4);
        *v++ = f2d(Y4);
    }
    else {
        v = r100_init_vb( rdrv, rdev, VF_PRIM_TYPE_RECTANGLE_LIST, 3, 6 );
        *v++ = f2d(x1);
        *v++ = f2d(y1);
        *v++ = f2d(x2);
        *v++ = f2d(y1);
        *v++ = f2d(x2);
        *v++ = f2d(y2);
    }

    return true;
}
Пример #16
0
Файл: e1.c Проект: seigof/Test
int main ()
{
	int i,j, k, l, nx, ny, nx2, ny2, min=0, mini=0, minj=0,sum=0,flag=0;
	BMPIMAGE im, im2;
	float **inputimageR ;
	float **outimageR ;
	float **inputimageG ;
	float **outimageG ;
	float **inputimageB ;
	float **outimageB ;
	float **inputtempateR ;
	float **outtempateR ;
	float **inputtempateG ;
	float **outtempateG ;
	float **inputtempateB ;
	float **outtempateB ;
	
	char filename[512] ;
	char filename2[512] ;
	
	
	printf ("Sample Program for Filtering \n");
	
	printf ("Input Image Filename (BMP) = ");
	scanf("%s", filename) ;
	getchar() ;
	
	
	
	//BMP画像を指定したファイルから読み込む
	im = Input_BMP (filename);
	if (im == 0)
	{
		printf ("No such file as '%s'\n", filename);
		exit(0);
	}
	
	ny = im->height; nx = im->width;   // 画像のサイズを読み込んだ画像情報から獲得
	
	inputimageR = f2d(ny, nx);  // ny行 nx列のfloat型の2次元配列を確保
	outimageR = f2d(ny, nx);    // ny行 nx列のfloat型の2次元配列を確保
	inputimageG = f2d(ny, nx);  // ny行 nx列のfloat型の2次元配列を確保
	outimageG = f2d(ny, nx);    // ny行 nx列のfloat型の2次元配列を確保
	inputimageB = f2d(ny, nx);  // ny行 nx列のfloat型の2次元配列を確保
	outimageB = f2d(ny, nx);    // ny行 nx列のfloat型の2次元配列を確保
	
	printf ("Input Pattern Image Filename (BMP) = ");
	scanf("%s", filename2) ;
	getchar() ;
	
	im2 = Input_BMP (filename2);
	if (im2 == 0)
	{
		printf ("No such file as '%s'\n", filename2);
		exit(0);
	}
	
	ny2 = im2->height; nx2 = im2->width;   // 画像のサイズを読み込んだ画像情報から獲得
	
	inputtempateR = f2d(ny2, nx2);  // ny2行 nx2列のfloat型の2次元配列を確保
	outtempateR = f2d(ny2, nx2);    // ny2行 nx2列のfloat型の2次元配列を確保
	inputtempateG = f2d(ny2, nx2);  // ny2行 nx2列のfloat型の2次元配列を確保
	outtempateG = f2d(ny2, nx2);    // ny2行 nx2列のfloat型の2次元配列を確保
	inputtempateB = f2d(ny2, nx2);  // ny2行 nx2列のfloat型の2次元配列を確保
	outtempateB = f2d(ny2, nx2);    // ny2行 nx2列のfloat型の2次元配列を確保
	
	//画像の画素値をfloat型の2次元配列にコピー(処理のため)
	for (i=0; i<ny; i++)
	for (j=0; j<nx; j++)
	inputimageR[i][j] = (float)im->red[i][j] ;
	for (i=0; i<ny; i++)
	for (j=0; j<nx; j++)
	inputimageG[i][j] = (float)im->green[i][j] ;
	for (i=0; i<ny; i++)
	for (j=0; j<nx; j++)
	inputimageB[i][j] = (float)im->blue[i][j] ;
	
	for (i=0; i<ny2; i++)
	for (j=0; j<nx2; j++)
	inputtempateR[i][j] = (float)im2->red[i][j] ;
	for (i=0; i<ny2; i++)
	for (j=0; j<nx2; j++)
	inputtempateG[i][j] = (float)im2->green[i][j] ;
	for (i=0; i<ny2; i++)
	for (j=0; j<nx2; j++)
	inputtempateB[i][j] = (float)im2->blue[i][j] ;
	
	//フィルタリングの処理プログラム
	//同じ処理をRGBそれぞれについて繰り返している
	int ssdR=0;
	int ssdG=0;
	int ssdB=0;
	flag = 0;
	for (i=1; i<ny-ny2; i++){
		for (j=1; j<nx-nx2; j++){
			sum=0;
			ssdR=0;
			ssdG=0;
			ssdB=0;
			outimageR[i][j] = 0.0;
			outimageG[i][j] = 0.0;
			outimageB[i][j] = 0.0;
			for (k=1; k<ny2; k++){
				for (l=1; l<nx2; l++){
					ssdR += ((inputimageR[i + k][j + l] - inputtempateR[k][l]) * (inputimageR[i + k][j + l] - inputtempateR[k][l]));
					ssdG += ((inputimageG[i + k][j + l] - inputtempateG[k][l]) * (inputimageG[i + k][j + l] - inputtempateG[k][l]));
					ssdB += ((inputimageB[i + k][j + l] - inputtempateB[k][l]) * (inputimageB[i + k][j + l] - inputtempateB[k][l]));
				}
			}
			sum = ssdR + ssdG + ssdB;
			if((sum < min) || (flag == 0)){
				min = sum;
				mini = i;
				minj = j;
				flag = 1;
			}
			if(min == 0)
			break;
			
		}
	}
	
	//float型の2次元配列からIMAGE構造体データにコピー(セーブするため)
	//コピーする前に,0以下の値は0に,255以上の値は255にしている.
	//同じ処理をRGBそれぞれについて繰り返している
	for (i=0; i<ny; i++){
		for (j=0; j<nx; j++){
			if (outimageB[i][j]>255.0) outimageB[i][j]=255.0;
			if (outimageB[i][j]<0.0) outimageB[i][j]=0.0;
			
			im->blue[i][j] = (unsigned char)(inputimageB[i][j]);
		}
	}
	for (i=0; i<ny; i++){
		for (j=0; j<nx; j++){
			if (outimageR[i][j]>255.0) outimageR[i][j]=255.0;
			if (outimageR[i][j]<0.0) outimageR[i][j]=0.0;
			
			im->red[i][j] = (unsigned char)(inputimageR[i][j]);
		}
	}
	for (i=0; i<ny; i++){
		for (j=0; j<nx; j++){
			if (outimageG[i][j]>255.0) outimageG[i][j]=255.0;
			if (outimageG[i][j]<0.0) outimageG[i][j]=0.0;
			
			im->green[i][j] = (unsigned char)(inputimageG[i][j]);
		}
	}
	for (i=0; i<ny; i++){
		for (j=0; j<nx; j++){
			if ((i == mini) && (j ==minj)){
				for (k=0; k<ny2; k++)
				for (l=0; l<nx2; l++){
					im->blue[i+k][j+l] = (unsigned char)(inputtempateB[k][l]);	
					im->red[i+k][j+l] = (unsigned char)(inputtempateR[k][l]);
					im->green[i+k][j+l] = (unsigned char)(inputtempateG[k][l]);
					if((k==0)||(l==0)||(k==ny2-1)||(l==nx2-1)){
						im->blue[i+k][j+l] = 255;	
						im->red[i+k][j+l] = 255;
						im->green[i+k][j+l] = 255;
					}
				}
				break;	
			}
		}
	}
	
	//BMP画像としてファイルにセーブ
	printf ("Output Image Filename (BMP)  = ");
	scanf("%s", filename) ;
	getchar() ;
	Output_BMP (im, filename);
}
Пример #17
0
bool r100StretchBlit( void *drv, void *dev, DFBRectangle *sr, DFBRectangle *dr )
{
    RadeonDriverData *rdrv = (RadeonDriverData*) drv;
    RadeonDeviceData *rdev = (RadeonDeviceData*) dev;
    float             x1, y1;
    float             x2, y2;
    float             s1, t1;
    float             s2, t2;
    u32              *v;

    if (rdev->blittingflags & DSBLIT_DEINTERLACE) {
        sr->y /= 2;
        sr->h /= 2;
    }

    s1 = sr->x;
    t1 = sr->y;
    s2 = sr->x+sr->w;
    t2 = sr->y+sr->h;
    if (rdev->blittingflags & DSBLIT_ROTATE180) {
        float tmp;
        tmp = s2;
        s2 = s1;
        s1 = tmp;
        tmp = t2;
        t2 = t1;
        t1 = tmp;
    }

    x1 = dr->x;
    y1 = dr->y;
    x2 = dr->x+dr->w;
    y2 = dr->y+dr->h;
    if (rdev->matrix) {
        float X1, Y1, X2, Y2, X3, Y3, X4, Y4;

        RADEON_TRANSFORM( x1, y1, X1, Y1, rdev->matrix, rdev->affine_matrix );
        RADEON_TRANSFORM( x2, y1, X2, Y2, rdev->matrix, rdev->affine_matrix );
        RADEON_TRANSFORM( x2, y2, X3, Y3, rdev->matrix, rdev->affine_matrix );
        RADEON_TRANSFORM( x1, y2, X4, Y4, rdev->matrix, rdev->affine_matrix );

        v = r100_init_vb( rdrv, rdev, VF_PRIM_TYPE_TRIANGLE_LIST, 6, 24 );
        *v++ = f2d(X1);
        *v++ = f2d(Y1);
        *v++ = f2d(s1);
        *v++ = f2d(t1);
        *v++ = f2d(X2);
        *v++ = f2d(Y2);
        *v++ = f2d(s2);
        *v++ = f2d(t1);
        *v++ = f2d(X3);
        *v++ = f2d(Y3);
        *v++ = f2d(s2);
        *v++ = f2d(t2);
        *v++ = f2d(X1);
        *v++ = f2d(Y1);
        *v++ = f2d(s1);
        *v++ = f2d(t1);
        *v++ = f2d(X3);
        *v++ = f2d(Y3);
        *v++ = f2d(s2);
        *v++ = f2d(t2);
        *v++ = f2d(X4);
        *v++ = f2d(Y4);
        *v++ = f2d(s1);
        *v++ = f2d(t2);
    }
    else {
        v = r100_init_vb( rdrv, rdev, VF_PRIM_TYPE_RECTANGLE_LIST, 3, 12 );
        *v++ = f2d(x1);
        *v++ = f2d(y1);
        *v++ = f2d(s1);
        *v++ = f2d(t1);
        *v++ = f2d(x2);
        *v++ = f2d(y1);
        *v++ = f2d(s2);
        *v++ = f2d(t1);
        *v++ = f2d(x2);
        *v++ = f2d(y2);
        *v++ = f2d(s2);
        *v++ = f2d(t2);
    }

    return true;
}