Пример #1
0
void GBMapView::OnSave()
{
  CString filename;

  if(theApp.captureFormat == 0)
    filename = "map.png";
  else
    filename = "map.bmp";

  LPCTSTR exts[] = {".png", ".bmp" };
  CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME);
  CString filter = theApp.winLoadFilter(IDS_FILTER_PNG);

  FileDlg dlg(this,
              filename,
              filter,
              theApp.captureFormat ? 2 : 1,
              theApp.captureFormat ? "BMP" : "PNG",
              exts,
              "",
              title,
              true);

  if(dlg.DoModal() == IDCANCEL) {
    return;
  }

  if(dlg.getFilterIndex() == 2)
    saveBMP(dlg.GetPathName());
  else
    savePNG(dlg.GetPathName());
}
Пример #2
0
void TileViewer::save()
{
    char captureBuffer[2048];

    if(captureFormat == 0)
        strcpy(captureBuffer, "tiles.png");
    else
        strcpy(captureBuffer, "tiles.bmp");

    char *exts[] = {".png", ".bmp" };

    FileDlg dlg(getHandle(),
                (char *)captureBuffer,
                (int)sizeof(captureBuffer),
                (char *)winLoadFilter(IDS_FILTER_PNG),
                captureFormat ? 2 : 1,
                captureFormat ? "BMP" : "PNG",
                exts,
                (char *)NULL,
                (char *)winResLoadString(IDS_SELECT_CAPTURE_NAME),
                TRUE);

    BOOL res = dlg.DoModal();
    if(res == FALSE) {
        DWORD res = CommDlgExtendedError();
        return;
    }

    if(captureFormat)
        saveBMP(captureBuffer);
    else
        savePNG(captureBuffer);
}
/** Cleanup fxn for saving bitmaps **/
void ModelerView::endDraw()
{
	if ((bmp_name == NULL) || (!save_bmp)) return;
	glFinish();
	saveBMP(bmp_name);
	save_bmp = false;
}
Пример #4
0
void GBOamView::save()
{
  CString captureBuffer;

  if(theApp.captureFormat == 0)
    captureBuffer = _T("oam.png");
  else
    captureBuffer = _T("oam.bmp");

  LPCTSTR exts[] = {_T(".png"), _T(".bmp") };

  CString filter = theApp.winLoadFilter(IDS_FILTER_PNG);
  CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME);

  FileDlg dlg(this,
              captureBuffer,
              filter,
              theApp.captureFormat ? 2 : 1,
              theApp.captureFormat ? _T("BMP") : _T("PNG"),
              exts,
              _T(""),
              title,
              true);

  if(dlg.DoModal() == IDCANCEL) {
    return;
  }
  captureBuffer = dlg.GetPathName();

  if(dlg.getFilterIndex() == 2)
    saveBMP(captureBuffer);
  else
    savePNG(captureBuffer);
}
Пример #5
0
void GBTileView::OnSave() 
{
  CString captureBuffer;

  if(theApp.captureFormat == 0)
    captureBuffer = "tiles.png";
  else
    captureBuffer = "tiles.bmp";

  LPCTSTR exts[] = {".png", ".bmp" };

  CString filter = theApp.winLoadFilter(IDS_FILTER_PNG);
  CString title = winResLoadString(IDS_SELECT_CAPTURE_NAME);

  FileDlg dlg(this,
              captureBuffer,
              filter,
              theApp.captureFormat ? 2 : 1,
              theApp.captureFormat ? "BMP" : "PNG",
              exts,
              "",
              title,
              true);

  if(dlg.DoModal() == IDCANCEL) {
    return;
  }

  captureBuffer = dlg.GetPathName();

  if(theApp.captureFormat)
    saveBMP(captureBuffer);
  else
    savePNG(captureBuffer);  
}
Пример #6
0
int main()
{
  // variables para manejo de tiempo
  struct timeval start_ts;
  struct timeval stop_ts;
  struct timeval elapsed_time;

  int res; // variable de resultado de procesos
  
  char namedest[100]; // variable para el nombre del destino

  // obtener el tiempo inicial
  gettimeofday(&start_ts, NULL);

  // generar los nombres de los archivos fuente y destino
  strcpy(namedest, strtok(filename,"."));
  strcat(filename,".bmp");
  strcat(namedest,"_secuencial.bmp");

  printf("Archivo fuente %s\n",filename);
  printf("Archivo destino %s\n",namedest);

  // cargar el archivo en memoria
  res = loadBMP(filename, &imagenfte);
  // verificar el cargado
  if(res == -1)
  {
    fprintf(stderr, "Error al abrir imagen\n");
    exit(1);
  }

  printf("Procesando imagen de: Renglones = %d, Columnas =%d\n", imagenfte.infoheader.rows, imagenfte.infoheader.cols);
  // ejecutar el procesamiento
  processBMP(&imagenfte, &imagendst);

  // 
  res = saveBMP(namedest, &imagendst);
  // verificar la escritura
  if(res == -1)
  {
    fprintf(stderr, "Error al escribir imagen\n");
    exit(1);
  }

  // obtener el tiempo final
  gettimeofday(&stop_ts, NULL);

  // calcular e imprimir tiempo
  timersub(&stop_ts, &start_ts, &elapsed_time);

  printf("------------------------------\n");
  printf("TIEMPO TOTAL, %ld.%ld segundos\n",elapsed_time.tv_sec, elapsed_time.tv_usec);
}
Пример #7
0
bool FileManager::saveImage(const QString &fileName, const byte fileType)
{
	QString eName = getExtensionName(fileName);
	if(eName.toLower() == "bmp")
	{
		return saveBMP(fileName, fileType);
	}
	else if(eName.toLower() == "png")
	{
		return savePNG(fileName);
	}
	return false;
}
Пример #8
0
void imageIO::saveImage(char* filename, unsigned char dataArray[], int size) {
	std::string strFilename = std::string(filename);
	std::vector <unsigned char> buffer;

	printf("%s", "Saving File as: ");
	printf("%s \n", filename);

	if (strFilename.substr(strFilename.length() - 4) == ".bmp") {
		saveBMP(filename, imageWidth, imageHeight, dataArray);
	}
	else if (strFilename.substr(strFilename.length() - 4) == ".png") {

		buffer.insert(buffer.begin(), dataArray, dataArray + size);
		savePNG(filename, buffer);
	}
}
Пример #9
0
int main()
{
  clock_t t_inicial,t_final;
  IMAGE imagefte;//Imagen fuente
  IMAGE imagedst;//Imagen destino

  //file name
  char namedest[80];
  strcpy(namedest,strtok(filename,"."));
  strcat(filename,".bmp");
  strcat(namedest,"_P.bmp");
  printf("Source file: %s\n",filename);
  printf("Target file: %s\n",namedest);

  t_inicial=clock();

  //load
  if(loadBMP(filename,&imagefte)==-1)
  {
    fprintf(stderr,"ERROR: Couldn't open image\n");
    exit(1);
  }

  printf("\nProcessing image: ROWS= %d, COLUMNS= %d\n\n",imagefte.infoheader.rows,imagefte.infoheader.cols);

  //process
  processBMP(&imagefte,&imagedst);

  //save
  puts("Saving...");
  if(saveBMP(namedest,&imagedst)==-1)
  {
    fprintf(stderr,"Error al escribir imagen\n");
    exit(1);
  }


  t_final=clock();
  printf("------------------------------\n");
  printf("Tiempo %3.6f segundos\n",((float) t_final- (float)t_inicial)/ CLOCKS_PER_SEC);

}
Пример #10
0
int main()
{
  	int res;
  	long long start_ts;
  	long long stop_ts;
  	long long elapsed_time;
  	struct timeval ts;

  	gettimeofday(&ts, NULL);
  	start_ts = ts.tv_sec * 1000000 + ts.tv_usec;//start time

  	strcpy(namedest,strtok(filename,"."));

  	strcat(filename,".bmp"); 
  	strcat(namedest,"_P.bmp"); 
  	printf("Archivo fuente %s\n",filename); 
  	printf("Archivo destino %s\n",namedest);
  	res=loadBMP(filename,&imagenfte); 
  	if(res==-1)
  	{
  		fprintf(stderr,"Error al abrir imagen\n");
  		exit(1); 
  	}
  	
  	printf("Procesando imagen de: Renglones = %d, Columnas = %d\n",imagenfte.infoheader.rows,imagenfte.infoheader.cols);
  	processBMP(&imagenfte,&imagendst);

  	res=saveBMP(namedest,&imagendst); 
  	if(res==-1)
  	{
  		fprintf(stderr,"Error al escribir imagen\n");
  		exit(1); 
  	}

  	gettimeofday(&ts, NULL);
  	stop_ts = ts.tv_sec * 1000000 + ts.tv_usec; //end time
  	elapsed_time = stop_ts - start_ts;

  	printf("Tiempo = %4.2f segundos\n",(float)elapsed_time/1000000);//elapsed time

}
Пример #11
0
int main()
{
	int res, i, j;
	clock_t t_inicial,t_final;
	char namedest[80];

	t_inicial=clock();

	strcpy(namedest,strtok(filename,"."));
	
	strcat(filename,".bmp");
	strcat(namedest,"_P.bmp");
	printf("Archivo fuente %s\n",filename);
	printf("Archivo destino %s\n",namedest);

	res=loadBMP(filename,&imagenfte);

	if(res==-1)
	{
		fprintf(stderr,"Error al abrir imagen\n");
		exit(1);
	}
	
	printf("Procesando imagen de: Renglones = %d, Columnas = %d\n",imagenfte.infoheader.rows,imagenfte.infoheader.cols);
	
	//start paralelizar
	printf("Paralelizando usando %i threads\n", NTHREADS);
	threadID = (int *) malloc(sizeof(int)*NTHREADS);
	pthread_t threads[NTHREADS];
	
	memcpy(&imagendst, &imagenfte, sizeof(IMAGE)-sizeof(PIXEL *));
	printf("Imagen fuente copiada a imagen destino\n");
	int imageRows = (&imagenfte)->infoheader.rows;
	int imageCols = (&imagenfte)->infoheader.cols;
	(&imagendst)->pixel=(PIXEL *)malloc(sizeof(PIXEL)*imageRows*imageCols);
	printf("Memoria para pixeles en imagen destino creada\n");

	for(i=0;i<NTHREADS;i++)
	{
		printf("Creando thread %i\n", i);
		threadID[i] = i;
		printf("Thread %i creado\n", threadID[i]);
		pthread_create(&threads[i], NULL, processBMP, (void *)&threadID[i]);
	}

	for(j=0; j<NTHREADS; j++)
	{
		pthread_join(threads[j], NULL);
	}
	//end paralelizar
	
	res=saveBMP(namedest,&imagendst);
	if(res==-1)
	{
		fprintf(stderr,"Error al escribir imagen\n");
		exit(1);
	}
	t_final=clock();
	
	printf("Tiempo %3.6f segundos\n",((float) t_final- (float)t_inicial)/CLOCKS_PER_SEC);
}
Пример #12
0
int main()
{
	int res, i, j;
	clock_t t_inicial,t_final;
	char namedest[80];

	t_inicial=clock();

	strcpy(namedest,strtok(filename,"."));
	
	strcat(filename,".bmp");
	strcat(namedest,"_P.bmp");
	printf("Archivo fuente %s\n",filename);
	printf("Archivo destino %s\n",namedest);

	res=loadBMP(filename,&imagenfte);

	if(res==-1)
	{
		fprintf(stderr,"Error al abrir imagen\n");
		exit(1);
	}
	
	printf("Procesando imagen de: Renglones = %d, Columnas = %d\n",imagenfte.infoheader.rows,imagenfte.infoheader.cols);
	
	//start paralelizar
	printf("Paralelizando usando %i threads\n", NTHREADS);
	threadID = (int *) malloc(sizeof(int)*NTHREADS);
	
	memcpy(&imagendst, &imagenfte, sizeof(IMAGE)-sizeof(PIXEL *));
	int imageRows = (&imagenfte)->infoheader.rows;
	int imageCols = (&imagenfte)->infoheader.cols;
	int status=0;
	(&imagendst)->pixel=(PIXEL *)malloc(sizeof(PIXEL)*imageRows*imageCols);
	
	int pids[NTHREADS];
	char *stack;
	stack = malloc(STACK_SIZE*NTHREADS);
	
	for(i=1;i<NTHREADS+1;i++)
	{
		//printf("Creando thread %i\n", i-1);
		threadID[i-1] = i-1;
		//printf("Thread %i creado\n", threadID[i-1]);
		pids[i-1] = clone(processBMP,stack + STACK_SIZE*i,CLONE_FS|CLONE_FILES|CLONE_VM,(void*)&threadID[i-1]);
	}

	for(j=0;j<NTHREADS;j++)
	{
		waitpid(pids[j], &status, __WALL);
	}
	
	//end paralelizar
	
	res=saveBMP(namedest,&imagendst);
	if(res==-1)
	{
		fprintf(stderr,"Error al escribir imagen\n");
		exit(1);
	}
	t_final=clock();
	
	printf("Tiempo %3.6f segundos\n",((float) t_final- (float)t_inicial)/CLOCKS_PER_SEC);
}
Пример #13
0
int main(int argc, char *argv[])
{
  int width, height, maxiter, flag;
  double x[2], y[2], c[2];
  char *image, *stats;

  int comm_sz, my_rank;

  double t1, t2, delta;
  
  // Get and parse the program parameters
  getParams(argv, &flag, c, x, y, &width, &height, &maxiter, &image, &stats);

  // Allocate space for the image
  int *iterations = (int*)malloc( sizeof(int) * width * height );
  assert(iterations != NULL);
  
  // Start MPI
  MPI_Init(NULL, NULL);
  MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  
  // Begin process timer
  t1 = MPI_Wtime();
  
  /* compute set */
  int maxCount = parallelJulia(x, width, y, height, c, flag, maxiter, iterations, my_rank, comm_sz, MPI_COMM_WORLD);

  // Stop timer and compute time elapse
  t2 = MPI_Wtime();
  delta = t2 - t1;

  if (my_rank == 0)
  {
    /* save our picture for the viewer */
    printf("\nMaster process %d creating image...\n", my_rank);
    saveBMP(image, iterations, width, height);
    printf("\nFinished image creation\n");
  }

  // Wait for all processes to finish Julia computations
  MPI_Barrier(MPI_COMM_WORLD);

  // Open stats file
  MPI_File statsFile;

  if (MPI_File_open(MPI_COMM_WORLD, stats, MPI_MODE_CREATE|MPI_MODE_WRONLY, MPI_INFO_NULL, &statsFile) == MPI_SUCCESS) 
  {
    // Generate statistic string
    char message[100];
    sprintf(message, "process %d: max iterations reached = %d, time elapsed = %lf\n", my_rank, maxCount, delta);
  
    MPI_File_write_ordered(statsFile, message, strlen(message), MPI_CHAR, MPI_STATUS_IGNORE);

    MPI_File_close(&statsFile);
  }
  else printf("Problem opening file on process %d\n", my_rank);

  // Close MPI environment
  MPI_Finalize();
  
  // Free reserved memory
  free(iterations);

  return 0;
}
Пример #14
0
void
TextureLoader::save( const std::string& _path,
					 const FILE_FORMAT _fileFormat )
{
	// argument checks
	if ( _path.empty() )
		GEM_ERROR( "Path argument is empty." );


	// cant save empty file
	if ( !isLoaded_ )
		return;


	// local variables
	FILE_FORMAT fileFormat = _fileFormat;
	std::string path = _path;


	// split path
	std::string dir, name, ext;
	splitPath( path, &dir, &name, &ext );


	// Tell the user that we are trying to save the file
	GEM_CONSOLE( "Saving texture " + name + (ext.empty() ? "" : ".") + ext );


	// First determine file-type
	if ( fileFormat == FILE_FORMAT_NONE )
	{
		if ( ext == "bmp" )
		{
			fileFormat = FILE_FORMAT_BMP;
		}
		else if ( ext == "pfm" )
		{
			fileFormat = FILE_FORMAT_PFM;
		}
	}


	// activate the right file loader depending on file type
	try
	{
		switch ( fileFormat )
		{
		case FILE_FORMAT_BMP:
			saveBMP( path );
			break;
		case FILE_FORMAT_PFM:
			savePFM( path );
			break;
		default:
			GEM_THROW( "Unsupported file type ." + ext );
		}
	}
	catch( const std::exception& e )
	{
		GEM_ERROR( e.what() );
	}
}
Пример #15
0
bool Bitmap::saveImage(const char* filename)
{
	if (extensionUpper(filename) == "BMP") return saveBMP(filename);
	if (extensionUpper(filename) == "EXR") return saveEXR(filename);
	return false;
}
Пример #16
0
int main(int argc, char **argv)
{
	//Initialize MPI
	MPI_Init(NULL, NULL);

	int whoAmI;
	MPI_Comm_rank(MPI_COMM_WORLD, &whoAmI);

    // Set up problem
    printf("Setting up problem...\n");
	fflush(stdout);
    double *A = (double*)malloc(sizeof(double)*(M*N)*(M*N));
    double *b = (double*)malloc(sizeof(double)*(M*N));
    double *x = (double*)malloc(sizeof(double)*(M*N));
    
    setupProblem(A, b, M, N);
    memset(x, (char)0, sizeof(double)*M*N);
    
	if (0 == whoAmI)
	{
		printf("ok\n");
		fflush(stdout);
	}

    // [Debug] Uncomment next line of code for printing a matrix/vector to a file.
    // Attention: Only do this for small matrices (i.e. M,N <= 8)!
    //printMatrixToFile("A.dat", A, M, N);
    
	if(0 == whoAmI)
	{
		printf("Solving...\n");
		fflush(stdout);
		//resetTime();
	}
    unsigned int iteration;
    for (iteration = 0; iteration < MAX_ITERATIONS; )
    {
		//visualize first, to see initial solution:
		if(0 == whoAmI)
		{
			printf("iterations: %d\n", iteration);
			fflush(stdout);
        
			// visualize
			unsigned char *pixels;
			visualizeMap(x, &pixels, M*N);
        
			// save bitmap
			printf("Saving bitmap...");
			fflush(stdout);
			char filename[64];
			sprintf(filename, "images/heatmap%d.bmp", iteration);
			if (!saveBMP(filename, pixels, M, N, 0))
			{
				printf("fail!\n");
				fflush(stdout);
				return 1;
			}
			else
			{
				printf("ok\n");
				fflush(stdout);
			}
			free(pixels);
		}
		
        // solve
        unsigned int iterationsDone = jacobi_solve(A, b, x, M*N, 10, 0.001);
        if (iterationsDone < 10) break;
        else iteration += iterationsDone;
    }
	if(0 == whoAmI)
	{
		//double timeNeededForSolving = getTime();
		//printf("End of computation!\nTime needed for solving: %fs\n", timeNeededForSolving);
	}
    
    free(A);
    free(b);
    free(x);

	MPI_Finalize();
   
    return 0;
}
Пример #17
0
int main(int argc, char *argv[])
{
  //mpi stuff
  int my_rank, p;
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  MPI_Comm_size(MPI_COMM_WORLD, &p);


  //julia stuff
  long int width, height, maxiter;
  int flag;
  // double x, xr, y, yr, c[2];
  char *image, *image_ext;
  long prec = 160;
  mpf_t xr_i, xr_f, yr_i, yr_f, x_center, y_center, zoom, c[2];
  mpf_set_default_prec (prec); 
  mpf_init (xr_i);
  mpf_init (xr_f);
  mpf_init (yr_i);
  mpf_init (yr_f);
  mpf_init (x_center);
  mpf_init (y_center);
  mpf_init (zoom);
  mpf_init (c[0]);
  mpf_init (c[1]);
  getParams(argv, &flag, c, &x_center, &y_center, &xr_i, &yr_i, &xr_f, &yr_f, &width, &height, &maxiter, &zoom, &image, &image_ext);
  int i = 0;
  
  while (1){
    // Process 0 is responsible for saving the image
    if(my_rank == 0){
      float *iterations = (float*)malloc( sizeof(float) * width * height );
      assert(iterations);
      printf ("Processing image %i\n", i);
      /* compute set */
      julia(x_center, xr_i, width, y_center, yr_i, height, c, flag, maxiter, iterations, my_rank, p, MPI_COMM_WORLD);
    
   	
      /* save our picture for the viewer */
      char currentImage [50];
      sprintf (currentImage, "%s%d%s", image, i, image_ext);
      printf ("currentImage: %s\n", currentImage);
      gmp_printf ("fixed point mpf %.*Ff with %d digits\n", prec, xr_i, prec);
      gmp_printf ("fixed point mpf %.*Ff with %d digits\n", prec, yr_i, prec);
      saveBMP(currentImage, iterations, width, height);
      printf ("Finished image %i\n", i);
      //printf("saving image took: %lf seconds\n", MPI_Wtime() - t0);
      //printf("max iterations hit: %ld /%ld\n", maxCount, maxiter);
      
      free(iterations);
    }
    else{
      julia(x_center, xr_i, width, y_center, yr_i, height, c, flag, maxiter, NULL, my_rank, p, MPI_COMM_WORLD);
    }
    mpf_div(xr_i, xr_i, zoom);
    mpf_div(yr_i, yr_i, zoom);
    i++;
    //check if xr_i < xr_f OR yr_i < yr_f
    if (mpf_cmp(xr_i, xr_f)<=0 || mpf_cmp(yr_i, yr_f)<=0){
      break;
    }

    // Only process image 0 to i-1
    /*
    if (i > 7){
      break;
    }
    */
  }
  MPI_Finalize();
  return 0;
}
Пример #18
0
int main(int argc, char** argv)
{  
  // Computation parameters
  int maxiter, maxIterStart, maxIterEnd;
  int iterStep;
  int flag;
  int comm_sz, my_rank;
  time_t t1, t2;
  double delta, maxTime;
  int i;
  int *iterations;

  // Video parameters
  unsigned long int width, height;
  int frames, curframe;
  int startframe, endframe;
  int fps, vidLen;
  float zoomx, zoomy;
  mpf_t framezoomx, framezoomy;

  // File name variables
  char *filename;
  char filenum [10];
  char *fileext = ".bmp";
  char *image = "";

  // GMP Floats
  mpf_t cr, ci;
  mpf_init(cr);
  mpf_init(ci);

  mpf_t xcent, ycent;
  mpf_init(xcent);
  mpf_init(ycent);

  mpf_t xrInit, yrInit, xrFin, yrFin;
  mpf_init(xrInit);
  mpf_init(yrInit);
  mpf_init(xrFin);
  mpf_init(yrFin);

  // Get and parse the program parameters and set GMP precision
  getParams(argv, &flag, &cr, &ci, &xcent, &ycent, &xrInit, &yrInit, &xrFin, &yrFin, &width, &height, &maxIterStart, &maxIterEnd, &filename, &fps, &vidLen, &startframe, &endframe);
  mpf_set_default_prec(mpf_get_prec(cr));

  // Calculate number of frames in the video
  frames = fps * vidLen;

  // Calculate number of iterations to add per frame
  iterStep = ceil((2*(double)maxIterEnd - 2*(double)maxIterStart) / (double)frames);

  // Calculate zoom rate based on the number of frames; since the first frame is not zoomed
  // in on, we calculate zoom with frame count (totalframes - 1)
  // x and y zoom are calculated separately to avoid stretching images
  zoomx = pow((float)mpf_get_d(xrInit) / (float)mpf_get_d(xrFin), 1.0/((float)frames - 1));
  mpf_init(framezoomx);
  mpf_set_d(framezoomx, (double)zoomx);

  zoomy = pow((float)mpf_get_d(yrInit) / (float)mpf_get_d(yrFin), 1.0/((float)frames - 1));
  mpf_init(framezoomy);
  mpf_set_d(framezoomy, (double)zoomy);

  /* Start MPI */
  MPI_Init(NULL, NULL);
  MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

  // Debugging output
  int n = 35;
  if (my_rank == 0)
  {
    gmp_printf ("x = %+.*Ff\n", n, xcent);
    gmp_printf ("xr Init = %+.*Ff\n", n, xrInit);
    gmp_printf ("xr Fin = %+.*Ff\n\n", n, xrFin);

    gmp_printf ("y = %+.*Ff\n", n, ycent);
    gmp_printf ("yr Init = %+.*Ff\n", n, yrInit);
    gmp_printf ("yr Fin = %+.*Ff\n\n", n, yrFin);

    printf("Height = %ld\t", height);
    printf("Width = %ld\n", width);
    printf("maxiterStart = %d\t", maxIterStart);
    printf("maxiterEnd = %d\t", maxIterEnd);
    printf("iterStep = %d\n\n", iterStep);

    gmp_printf ("Zoom x (GMP) = %+.*Ff\n", n, framezoomx);
    gmp_printf ("Zoom y (GMP) = %+.*Ff\n", n, framezoomy);
    printf("frames = %d\n\n", frames);
  }

  // Divide frames among processes
  startframe = startframe - 1; // Offset frame divisions
  endframe = endframe - 1;
  frames = endframe - startframe + 1; // Total frames + 1 to include end bound

  int totalframes = frames / comm_sz;
  if (my_rank < (frames % comm_sz)) totalframes++;
  printf("Process %d processess %d frames\n", my_rank, totalframes);

  // Start timer
  time(&t1);

  /* Start OpenMP */
  #pragma omp parallel shared(width, height, xcent, ycent, xrInit, yrInit, maxIterStart, iterStep, framezoomx, framezoomy) private(i, iterations, filenum, image, curframe, maxiter)
  {
    /* Variables and memory declared in this section are private to each thread */

    // Allocate space for the image
    iterations = (int*)calloc( width * height, sizeof(int) );
    assert(iterations != NULL);
 
    // Allocate space for the filenames
    image = malloc(strlen(filename) + 5 + strlen(fileext));

    // GMP variables to stored distance from center point in
    mpf_t xmin, xmax, ymin, ymax;
    mpf_init(xmin);
    mpf_init(xmax);
    mpf_init(ymin);
    mpf_init(ymax);

    /* Start OpenMP parallel FOR */
    #pragma omp for
    for ( i = 0; i < totalframes; i++ )
    {
      curframe = my_rank + (i * comm_sz) + startframe;
      maxiter = maxIterStart + (iterStep * curframe);
      printf("Process %d working on frame %d with thread %d\n", my_rank, curframe + 1, omp_get_thread_num());

      // xmin, xmax, ymin and ymax
      if (curframe == 0)
      {
        // Do not zoom for the first image
        mpf_sub(xmin, xcent, xrInit);
        mpf_add(xmax, xcent, xrInit);

        mpf_sub(ymin, ycent, yrInit);
        mpf_add(ymax, ycent, yrInit);
      }
      else
      {
        // Radius is calculated as r = rinit / (zoom^frame#)
        mpf_pow_ui(xmax, framezoomx, (unsigned long int)curframe);
        mpf_div(xmax, xrInit, xmax);
        mpf_pow_ui(ymax, framezoomy, (unsigned long int)curframe);
        mpf_div(ymax, yrInit, ymax);

        mpf_sub(xmin, xcent, xmax);
        mpf_add(xmax, xcent, xmax);
        mpf_sub(ymin, ycent, ymax);
        mpf_add(ymax, ycent, ymax);
      }

      /* Compute Julia set */
      GMPJulia(xmin, xmax, width, width, 0, ymin, ymax, height, height, 0, cr, ci, flag, maxiter, iterations);

      /* Save image as a bitmap (.bmp) */
      sprintf(filenum, "%05d", curframe + 1);

      strcpy(image, filename);
      strcat(image, filenum);
      strcat(image, fileext);  

      printf("\nProcess %d creating frame %d on thread %d...", my_rank, curframe + 1, omp_get_thread_num());
      saveBMP(image, iterations, width, height);
    }

    // Free thread-reserved memory
    free(iterations);
    free(image);
    mpf_clear(xmin);
    mpf_clear(xmax);
    mpf_clear(ymin);
    mpf_clear(ymax);
  }

  // Stop timer and calculate elapsed time
  time(&t2);
  delta = difftime(t2, t1);

  MPI_Reduce(&delta, &maxTime, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);

  if (my_rank == 0) printf("Computation time = %lf\n", maxTime);

  // Close MPI environment
  MPI_Finalize();

  // Free reserved memory
  //mpf_clears(cr, ci, x, y, xr, yr, xmin, xmax, ymin, ymax, (mpf_t *) 0);
  mpf_clear(cr);
  mpf_clear(ci);
  mpf_clear(xcent);
  mpf_clear(ycent);
  mpf_clear(xrInit);
  mpf_clear(yrInit);
  mpf_clear(xrFin);
  mpf_clear(yrFin);
  mpf_clear(framezoomx);
  mpf_clear(framezoomy);

   return 0;
}