示例#1
0
int perform_convolution(FILE *in, FILE *out, float sigma, int kx, int ky, const char *comment, BOOL binary) {
  int ux = 0, uy = 0;
  float **u = ip_load_image(in, &ux, &uy, NULL);

  if (!u)
    return 4;

  float **kernel = gaussian_kernel(kx, ky, sigma);

  if (!kernel) {
    ip_deallocate_image(ux, uy, u);
    return 5;
  }

  // TODO Schummlung entfernen
  dummies(u, ux, uy);
  float **v = convolve(ux + 2, uy + 2, u, kx, ky, kernel);

  ip_deallocate_image(ux, uy, u);
  ip_deallocate_image(kx, ky, kernel);

  if (!v)
    return 6;

  ip_save_image(out, ux, uy, v, comment, binary);

  ip_deallocate_image(ux, uy, v);

  return 0;
}
void lindiff 

     (long     nx,        /* image dimension in x direction */ 
      long     ny,        /* image dimension in y direction */
      float    ht,        /* time step size, 0 < ht <= 0.25 */
      float    hx,        /* pixel size in x direction */
      float    hy,        /* pixel size in y direction */
      float    **u)       /* input: original image;  output: smoothed */

/* 
 linear diffusion subroutine for du/dt = div(grad(u))
*/

{
long    i, j;       /* loop variables */
float   rx, ry;     /* mesh ratios */
float   **f;        /* copy of input image u */
      

/* ---- allocate storage for f ---- */

alloc_matrix (&f, nx+2, ny+2);


/* ---- copy u into f ---- */

for (i=1; i<=nx; i++)
 for (j=1; j<=ny; j++)
     f[i][j] = u[i][j];


/* ---- create dummy boundaries for f by mirroring ---- */

dummies (f, nx, ny);


/* ---- diffusive averaging ---- */

rx = ht / (hx * hx);
ry = ht / (hy * hy);
for (i=1; i<=nx; i++)
 for (j=1; j<=ny; j++)
     {
/*
 SUPPLEMENT CODE
*/
	 u[i][j] = (1 - 2 * rx - 2 * ry) * f[i][j] + rx * f[i + 1][j] + rx * f[i - 1][j] + ry * f[i][j + 1] + ry * f[i][j - 1];
     }


/* ---- disallocate storage for f ---- */

disalloc_matrix (f, nx+2, ny+2);

return;

} /* lindiff */
示例#3
0
int main(int argc, char * argv[])
{
	if(argc != 2)
	{
		puts("No file detected");
		exit(0);
	}
	FILE * fp;
	char * snitch = NULL;
	time_t tiem = 0;
	uint8_t verbosity = 0;
	uint8_t NameOffset = 9+PLAYER_N;
	struct Planet TheirPlanet = {NULL,NULL,0,0,0};
	struct Resource TheirResource = {0,0,0};
	struct Fleet TheirFleet = {0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	struct Defense TheirDefense = {0,0,0,0,0,0,0,0,0,0};
	struct Building TheirBuildings = {0,0,0,0,0,0,0,0};
	struct Research TheirResearch = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

	fp = fopen(argv[1],"r");
	if(fp == NULL)
	{
		puts("Null or nonexistent file");
		exit(0);
	}

	snitch = whosaidthat(&fp);
	get_tango(&fp, &TheirPlanet);
	puts("Calling function...");
	tiem = r_time(&fp);
	TheirPlanet.Owner = losersname(&fp,NameOffset);
	booty(&fp, &TheirResource);
	verbosity = get_verbosity(&fp);
	if(verbosity == 1)
	{
		verbosity += dummies(&fp,&TheirFleet);
	}
	if(verbosity == 2)
	{
		verbosity += bunker(&fp,&TheirDefense);
	}
	if(verbosity == 3)
	{
		verbosity += shanty(&fp,&TheirBuildings);
	}
	if(verbosity == 4)
	{
		edumucation(&fp,&TheirResearch);
	}

/*	printf("Metal: %lu\nCrystal: %lu\nDeuterium: %lu\n",TheirResource.Metal,TheirResource.Crystal,TheirResource.Deuterium);
*/	printf("%llu\n",(long long)tiem);
	puts(snitch);

	fclose(fp);
	return 0;
}