Пример #1
0
/* carrega uma nova cena */
int load_cb(void) {
  char* filename = get_file_name();  /* chama o dialogo de abertura de arquivo */
  char buffer[30];

  if (filename==NULL) return 0;

  /* Le a cena especificada */
  scene = sceLoad( filename );
  if( scene == NULL ) return IUP_DEFAULT;

  sceGetCamera( scene, &camera );
  camGetEye( camera, eye );
  camGetScreenWidth( camera, &width );
  camGetScreenHeight( camera, &height );
  yc=0;

  if (image) imgDestroy(image);
  image = imgCreate( width, height );
  IupSetfAttribute(label, "TITLE", "%3dx%3d", width, height);
  sprintf(buffer,"%3dx%3d", width, height);
  IupSetAttribute(canvas,IUP_RASTERSIZE,buffer);
  IupSetFunction (IUP_IDLE_ACTION, (Icallback) idle_cb);
  start_time  = clock(); 
  return IUP_DEFAULT;
}
Пример #2
0
/* carrega uma nova cena */
int load_cb(void) {
	char* filename = get_file_name();  /* chama o dialogo de abertura de arquivo */
	char buffer[30];

	if (filename==NULL) return 0;

	/* Le a cena especificada */
	scene = sceLoad( filename );
	if( scene == NULL ) return IUP_DEFAULT;

	camera = sceGetCamera( scene );
	eye = camGetEye( camera );
	width = camGetScreenWidth( camera );
	height = camGetScreenHeight( camera );
	yc=0;

	if (image) imgDestroy(image);
	image = imgCreate( width, height );
	IupSetfAttribute(label, "TITLE", "%3dx%3d", width, height);
	sprintf(buffer,"%3dx%3d", width, height);
	IupSetAttribute(canvas,IUP_RASTERSIZE,buffer);
	IupSetFunction (IUP_IDLE_ACTION, (Icallback) idle_cb);
	start_time  = clock(); 

	IupGLMakeCurrent(canvas);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT);
	glEnd();
	glFlush();
	IupGLSwapBuffers(canvas);  /* change the back buffer with the front buffer */

	return IUP_DEFAULT;
}
int main(int argc, char *argv[]) {
	init_imgproc();
	Viewer *view = viewOpen(200, 200, "Sails");
	Image *img = imgFromBitmap(argv[1]);
	
	for (int x = 0; x < img -> width; x++) {
		for (int y = 0; y < img -> height; y++) {
			char * pixel = imgGetPixel(img, x, y);
			char red = pixel[2];
			char green = pixel[1];
			char blue = pixel[0];
			
			if (red > green && red > blue) {
				imgSetPixel(img, x, y, 255, 0, 0);
			} else if (green > red && green > blue) {
				imgSetPixel(img, x, y, 0, 255, 0);
			} else {
				imgSetPixel(img, x, y, 0, 0, 255);
		
			}
		}
	}

	viewDisplayImage(view, img);
	waitTime(5000); 
	imgDestroy(img);
	viewClose(view);
	quit_imgproc();
	return 0;
}
Пример #4
0
void Colony::printDebugImage()
{
    static int step = 0;
    Image* img = _environment->getPheromoneImage();//imgCreate( _environment->getWidth(), _environment->getHeight(), 3 );

    int nAnts = _ants.size();
    for (int i = 0; i < nAnts; ++i)
    {
        Ant* ant = _ants[i];
        if (_ants[i]->isAlive())
        {
            // each ant has a color
            //imgSetPixel3f( img, ant->_position.x, ant->_position.y, 1.0f - i/(float)nAnts, (0.0f + i) / nAnts, 0.0f );
            
            //all ants are red
            imgSetPixel3f( img, ant->_position.x, ant->_position.y, 1,0,0 );
        }
        else
        {
            imgSetPixel3f( img, ant->_position.x, ant->_position.y, 0.0f, 0.0f, 1.0f );
        }
    }

    char filename[100];
    sprintf( filename, "debugImages/debugImage%04d.bmp", ++step );
    imgWriteBMP( filename, img );
    imgDestroy( img );
}
Пример #5
0
int binary_cb(void)
{
	Image* tmp = gc.image;
	if (tmp != NULL){
		IupSetfAttribute(gc.msgbar, "TITLE", "Grey scale image ...");
		gc.image = imgGrey(tmp);
		repaint_cb(gc.canvas);   /* repaint canvas */
		imgDestroy(tmp);
		tmp = gc.image;
		gc.image = imgBinary(tmp);
		repaint_cb(gc.canvas);   /* repaint canvas */
		imgDestroy(tmp);
		IupSetfAttribute(gc.msgbar, "TITLE", "Binary image ...");
	}
     return IUP_DEFAULT;
}
Пример #6
0
void Colony::generateProbabilityImages()
{
     Image* vis = _environment->getVisibilityImage(); imgWriteBMP( (char*)"gammaone.bmp", vis );
     
     Image* visGammaDown = imgCopy( vis );
     imgGamma( visGammaDown, 0.5f ); imgWriteBMP( (char*)"gammadown.bmp", visGammaDown );
     Image* gammaDownProb = generateProbabilityImage( visGammaDown );
     imgDestroy( visGammaDown );
     _probabilityDistributions.push_back( gammaDownProb );
     
     Image* visGammaUp = imgCopy( vis );
     imgGamma( visGammaUp, 1.5f ); imgWriteBMP( (char*)"gammaup.bmp", visGammaUp );
     Image* gammaUpProb = generateProbabilityImage( visGammaUp );
     imgDestroy( visGammaUp );
     _probabilityDistributions.push_back( gammaUpProb );
     
     Image* prob = generateProbabilityImage( vis );
     imgDestroy( vis );
     _probabilityDistributions.push_back( prob );
}
Пример #7
0
int dilate_cb(void)
{
	Image *tmp = gc.image;
	
	if(tmp == NULL || imgGetDimColorSpace(tmp) != 1) {

		IupSetfAttribute(gc.msgbar, "TITLE", "Image doesn't exist or not binary");
		return IUP_DEFAULT;
	}

	IupSetfAttribute(gc.msgbar, "TITLE", "Image dilatating ...");
	gc.image = imgDilatation(tmp);
	repaint_cb(gc.canvas);   /* repaint canvas */
	imgDestroy(tmp);
	IupSetfAttribute(gc.msgbar, "TITLE", "Image dilatated ...");

	return IUP_DEFAULT;
}
Пример #8
0
int change_cb(void) {

	Image *tmp = gc.image;
	
	if(tmp == NULL || imgGetDimColorSpace(tmp) != 1) {

		IupSetfAttribute(gc.msgbar, "TITLE", "Image doesn't exist or not binary");
		return IUP_DEFAULT;
	}

	IupSetfAttribute(gc.msgbar, "TITLE", "Changing binary colors ...");
	gc.image = imgChangeBinary(tmp);
	repaint_cb(gc.canvas);   /* repaint canvas */
	imgDestroy(tmp);
	IupSetfAttribute(gc.msgbar, "TITLE", "Binary colors changed ...");

	return IUP_DEFAULT;
}
Пример #9
0
void Colony::printDebugImage()
{
    static int step = 0;
    Image* imgIn = _environment->getPheromoneImage();
    imgNormalize( imgIn, 2 );
    
    Image* img = imgCreate( _environment->getWidth(), _environment->getHeight(), 3 );
    
    for (int x = 0; x < _environment->getWidth(); ++x)
    {
        for (int y = 0; y < _environment->getHeight(); ++y)
        {
            float lum = imgGetPixelf( imgIn, x, y );
            imgSetPixelf( img, x, y, lum );
        }
    }  
    
    int nAnts = _ants.size();
    for (int i = 0; i < nAnts; ++i)
    {
        Ant* ant = _ants[i];
        if (ant->isAlive())
        {
            // each ant has a color
            imgSetPixel3f( img, ant->_position.x, ant->_position.y, 1.0f - i/(float)nAnts, (0.0f + i) / nAnts, 0.0f );
            
            //all ants are red
            //imgSetPixel3f( img, ant->_position.x, ant->_position.y, 1,0,0 );
        }
        else
        {
            imgSetPixel3f( img, ant->_position.x, ant->_position.y, 0.0f, 0.0f, 1.0f );
        }
    }

    
    //postProcessing( &img );
    char filename[150];
    sprintf( filename, "debugImg/debugImage%04d.bmp", ++step );
    imgWriteBMP( filename, img );
    imgDestroy( img );
}
Пример #10
0
Colony::Colony(Image* image, DirectionalField* directionalFied)
{
    if (imgGetDimColorSpace( image ) != 1)
    {
        Image* aux = imgGrey( image );
        imgDestroy( image );
        image = aux;
        aux = 0;
    }
    
    // Normalize image
    //imgNormalize( image, 2 );
    
    // Apply gaussian filter for noise reduction
    //imgGauss( image );
    
    imgWriteBMP( (char*)"debugImg/inputAfterGaussian.bmp", image );
    
    _environment = new Environment( INITIAL_PHEROMONE, MIN_PHEROMONE, EVAPORATION_RATE, image, directionalFied );
    
    generateProbabilityImages();
}
Пример #11
0
int load_cb(void)
{
	char* file_name = IupSelectFile("File Selection","*.bmp","Load a BMP file");
    if (!file_name) {
        IupSetfAttribute(gc.msgbar, "TITLE", "Selection failed"); 
		return IUP_DEFAULT;
	}

	if (gc.image!=NULL) imgDestroy(gc.image);
   
	gc.image=imgReadBMP(file_name);  /* loads the image */
	if (gc.image!=NULL) {
	   gc.width = imgGetWidth(gc.image);
	   gc.height = imgGetHeight(gc.image);
	   IupCanvasResize(gc.canvas,gc.dialog,gc.width,gc.height);
	   repaint_cb(gc.canvas);
       IupSetfAttribute(gc.msgbar, "TITLE", "%s", strip_path_from_filename(file_name));

	} else
	   IupSetfAttribute(gc.msgbar, "TITLE", "Can't open %s", strip_path_from_filename(file_name)); 

	return IUP_DEFAULT;
}
Пример #12
0
int main(int argc, char * argv[])
{
	init_imgproc();
	clock_t start = clock();
	pid_t pid;
	int fdr, fdw;
	fdr = open("/dev/xillybus_read_32", O_RDONLY);				//get descriptor from PL output
	fdw = open("/dev/xillybus_write_32", O_WRONLY);				//get descriptor from PL input
	if ((fdr < 0) || (fdw < 0)) 
	{
	    perror("Failed to open Xillybus device file(s)");
	    exit(1);
	}
  	pid = fork();

	if (pid < 0) 
	{
		perror("Failed to fork()");
		exit(1);
	}

	if (pid)													//child process
	{
		close(fdr);
		uint32_t *tologic;
		char *buf;
		int rc, donebytes;
		Image * img = imgFromBitmap("lena.bmp");
	  	int pixel_count = img->width*img->height;
		uint32_t bytes_count = pixel_count*sizeof(uint32_t);
		tologic = malloc(bytes_count);
		if (!tologic) 
		{
			fprintf(stderr, "Failed to allocate memory\n");
			exit(1);
		}
		uint32_t x, y;
		for(x = 0; x < img->width; x++)
		{
			for(y = 0; y < img->height; y++)
			{
				tologic[x*(img->height)+y] = *((uint32_t *)(imgGetPixel(img, x, y))) >> 8;
			}
		}
		buf = (char *) tologic;
		donebytes = 0;
		while (donebytes < bytes_count)							//loop care about writing all bytes to PL
		{
			rc = write(fdw, buf + donebytes, bytes_count - donebytes);
			if ((rc < 0) && (errno == EINTR)) continue;
			if (rc <= 0) 
			{
				perror("write() failed");
				exit(1);
			}
			donebytes += rc;
		}
		imgDestroy(img);
		close(fdw);
		return 0;
	} 
	else 														//parent process
	{