Ejemplo n.º 1
0
static	void	key_press(int keycode, t_frac *frac)
{
	if (keycode == R)
		reroll_color(frac);
	if (keycode == Q)
		blackandwhite(frac);
	if (keycode == W)
		activate_orbit(frac);
	if (keycode == E)
		activate_smooth(frac);
}
Ejemplo n.º 2
0
void processBMP(IMAGE *imagefte, IMAGE *imagedst)
{
  int i,j; // indicadores de posición actual
  PIXEL *pfte,*pdst; // apuntadores para el pixel actual
  PIXEL *v0,*v1,*v2,*v3,*v4,*v5,*v6,*v7; // apuntadores para los pixeles vecinos
  int imageRows, imageCols; // límites para los contadores 

  // copia los encabezados de la imágen fuente a la imágen destino
  memcpy(imagedst, imagefte, sizeof(IMAGE)-sizeof(PIXEL *));
  // obten los límites para los contadores de filas y columnas
  imageRows = imagefte->infoheader.rows;
  imageCols = imagefte->infoheader.cols;

  // reserva la memoria en la imágen destino para los pixeles
  imagedst->pixel = (PIXEL *) malloc(sizeof(PIXEL)*imageRows*imageCols);

  // para cada fila
  for(i = 1; i < imageRows-1; i++)
    // para cada columna
    for(j = 1; j < imageCols-1; j++)
      {
        // encuentra al pixel actual
        pfte = imagefte->pixel+imageCols*i+j;

        // encuentra el pixel destino
        pdst=imagedst->pixel+imageCols*i+j;

        // encuentra a los vecinos
        v0=pfte-imageCols-1;  // renglon arriba a la izquierda
        v1=pfte-imageCols;    // renglon arriba
        v2=pfte-imageCols+1;  // renglon arriba a la derecha
        v3=pfte-1;            // mismo renglon a la izquierda
        v4=pfte+1;            // mismo renglon a la derecha
        v5=pfte+imageCols-1;  // renglon abajo a la izquierda
        v6=pfte+imageCols;    // renglon abajo
        v7=pfte+imageCols+1;  // renglon abajo a la derecha

        // si hay un cambio de tono mayor al DIF entre el pixel fuente y algun vecino
        if(abs(blackandwhite(*pfte)-blackandwhite(*v0))>DIF ||
        abs(blackandwhite(*pfte)-blackandwhite(*v1))>DIF ||
        abs(blackandwhite(*pfte)-blackandwhite(*v2))>DIF ||
        abs(blackandwhite(*pfte)-blackandwhite(*v3))>DIF ||
        abs(blackandwhite(*pfte)-blackandwhite(*v4))>DIF ||
        abs(blackandwhite(*pfte)-blackandwhite(*v5))>DIF ||
        abs(blackandwhite(*pfte)-blackandwhite(*v6))>DIF ||
        abs(blackandwhite(*pfte)-blackandwhite(*v7))>DIF)
        {
          // pinta el pixel de negro
          pdst->red=0;
          pdst->green=0;
          pdst->blue=0;
        }
        else // si no hay cambio
        {
          // pinta el pixel de blanco
          pdst->red=255;
          pdst->green=255;
          pdst->blue=255;
        }
      }
}
Ejemplo n.º 3
0
void *processBMP(void *arg)
{
	printf("Comenzando el thread %i\n", *(int *)arg);
	int i,j;
	int count=0;
	PIXEL *pfte,*pdst;
	PIXEL *v0,*v1,*v2,*v3,*v4,*v5,*v6,*v7;
	int imageRows,imageCols;
	int numThread = *(int *)arg;
	
	imageRows = (&imagenfte)->infoheader.rows;
	imageCols = (&imagenfte)->infoheader.cols;

	
	for(i=1+numThread;i<imageRows-1;i+=NTHREADS)
		for(j=1;j<imageCols-1;j++)
		{
		//printf("Thread %i trabajando\n",numThread);
		pfte=(&imagenfte)->pixel+imageCols*i+j;
		//printf("Punto fuente asignado\n");
		v0=pfte-imageCols-1;
		v1=pfte-imageCols;
		v2=pfte-imageCols+1;
		v3=pfte-1;
		v4=pfte+1;
		v5=pfte+imageCols-1;
		v6=pfte+imageCols;
		v7=pfte+imageCols+1;
		//printf("Puntos asignados\n");
	
		pdst=(&imagendst)->pixel+imageCols*i+j;
		//printf("Punto destino asignado\n");
		if(abs(blackandwhite(*pfte)-blackandwhite(*v0))>DIF ||
			abs(blackandwhite(*pfte)-blackandwhite(*v1))>DIF ||
			abs(blackandwhite(*pfte)-blackandwhite(*v2))>DIF ||
			abs(blackandwhite(*pfte)-blackandwhite(*v3))>DIF ||
			abs(blackandwhite(*pfte)-blackandwhite(*v4))>DIF ||
			abs(blackandwhite(*pfte)-blackandwhite(*v5))>DIF ||
			abs(blackandwhite(*pfte)-blackandwhite(*v6))>DIF ||
			abs(blackandwhite(*pfte)-blackandwhite(*v7))>DIF)
		{
		pdst->red=0;
		pdst->green=0;
		pdst->blue=0;
		}
		else
		{
		pdst->red=255;
		pdst->green=255;
		pdst->blue=255;
		}
	}
}
Ejemplo n.º 4
0
//Thread function
void *threadfunc(void *arg)
{
	THREAD_STRUCT thread = *((THREAD_STRUCT *)arg);//we get the struct that contains the images and the process id
	int i,j;
	PIXEL *v0,*v1,*v2,*v3,*v4,*v5,*v6,*v7;
	PIXEL *pfte,*pdst;

	//start i at process id, and increment in the number of processes it execute so each process execute a segmente of the image matrix
	for(i=thread.id;i<imageRows-1;i+=NTHREADS)	
        {
            pfte=thread.imagefte->pixel+imageCols*i+j;
           
            v0=pfte-imageCols-1;
            v3=pfte-1;
            v5=pfte+imageCols-1;
            v1=pfte-imageCols;
            v6=pfte+imageCols;
            v2=pfte-imageCols+1;
            v4=pfte+1;
            v7=pfte+imageCols+1;
           
            //store a 3x3 matrix at the start of each row
            int tempArray[] = {
                abs(blackandwhite(*pfte)-blackandwhite(*v0)>DIF)
                ,abs(blackandwhite(*pfte)-blackandwhite(*v3)>DIF)
                ,abs(blackandwhite(*pfte)-blackandwhite(*v5)>DIF)
                ,abs(blackandwhite(*pfte)-blackandwhite(*v1)>DIF)
                ,abs(blackandwhite(*v4)-blackandwhite(*pfte)>DIF)//X
                ,abs(blackandwhite(*pfte)-blackandwhite(*v6)>DIF)
                ,abs(blackandwhite(*pfte)-blackandwhite(*v2)>DIF)
                ,abs(blackandwhite(*pfte)-blackandwhite(*v4)>DIF)
                ,abs(blackandwhite(*pfte)-blackandwhite(*v7)>DIF)
            };
           
            for(j=1;j<imageCols-1;j++)
            {
 
                if(j!=1){
                   
                    pfte=thread.imagefte->pixel+imageCols*i+j;
                   	
                   	//as we go through the matrix we only need to to compute the next 3 values of the cols in each row
                    v2=pfte-imageCols+1;
                    v4=pfte+1;
                    v7=pfte+imageCols+1;
                   	
                   	//put the 2nd and 3rd column of our matrix in the 1st and 2nd column, as if we push it to the left
                    tempArray[0] = tempArray[3];
                    tempArray[1] = tempArray[4];
                    tempArray[2] = tempArray[5];
     				
                    tempArray[3] = tempArray[6];
                    tempArray[4] = tempArray[7];
                    tempArray[5] = tempArray[8];
     				
     				         //the 3rd column is assign to the next column right to the pixel pfte
                    tempArray[6] = abs(blackandwhite(*pfte)-blackandwhite(*v2))>DIF;
                    tempArray[7] = abs(blackandwhite(*pfte)-blackandwhite(*v4))>DIF;
                    tempArray[8] = abs(blackandwhite(*pfte)-blackandwhite(*v7))>DIF;
                }
               
                pdst=thread.imagedst->pixel+imageCols*i+j;
                
                if(
                    tempArray[1] || tempArray[6] || tempArray[7] || tempArray[8] ||
                    tempArray[0] || tempArray[2] || tempArray[3] || tempArray[5]
                )
                {
                    pdst->red=0;
                    pdst->green=0;
                    pdst->blue=0;
                }
                else
                {
                    pdst->red=255;
                    pdst->green=255;
                    pdst->blue=255;
                }
            }
        
    }

}
Ejemplo n.º 5
0
/**
*individual thread
*@method threadProcessBMP
*/
DWORD WINAPI threadProcessBMP(LPVOID arg )
{
    struct thread_info *tinfo = arg;
    printf("Thread %d working from %d to %d Row\n",tinfo->nThread,tinfo->fromRow,tinfo->toRow);

    int imageCols= tinfo->imageCols;
    IMAGE *imagefte= tinfo->imagefte;
    IMAGE *imagedst= tinfo->imagedst;
    PIXEL *pfte,*pdst;
    PIXEL *v0,*v1,*v2,*v3,*v4,*v5,*v6,*v7;

    int i,j;
    for( i=tinfo->fromRow ; i<=tinfo->toRow ; i++)
        for(j=1;j< imageCols-1;j++)
        {
          pfte=imagefte->pixel+imageCols*i+j;
          v0=pfte-imageCols-1;
          v1=pfte-imageCols;
          v2=pfte-imageCols+1;
          v3=pfte-1;
          v4=pfte+1;
          v5=pfte+imageCols-1;
          v6=pfte+imageCols;
          v7=pfte+imageCols+1;

          pdst=imagedst->pixel+imageCols*i+j;

          if(abs(blackandwhite(*pfte)-blackandwhite(*v0))>DIF ||
          abs(blackandwhite(*pfte)-blackandwhite(*v1))>DIF ||
          abs(blackandwhite(*pfte)-blackandwhite(*v2))>DIF ||
          abs(blackandwhite(*pfte)-blackandwhite(*v3))>DIF ||
          abs(blackandwhite(*pfte)-blackandwhite(*v4))>DIF ||
          abs(blackandwhite(*pfte)-blackandwhite(*v5))>DIF ||
          abs(blackandwhite(*pfte)-blackandwhite(*v6))>DIF ||
          abs(blackandwhite(*pfte)-blackandwhite(*v7))>DIF)
          {
            pdst->red=0;
            pdst->green=0;
            pdst->blue=0;
          }
          else
          {
            pdst->red=255;
            pdst->green=255;
            pdst->blue=255;
          }


            if(i==2999)
            printf("i=%d, j=%d\n",i,j);
        }

  tinfo->status = 0;
        printf("Thread %d finished\n",tinfo->nThread);
}