Exemplo n.º 1
0
/* Creates a negative image of the input bitmap file */
int main( int argc, char* argv[] )
{
	UCHAR	r, g, b;
	UINT	width, height;
	UINT	x, y;
	BMP*	bmp;

	/* Check arguments */
	if ( argc != 3 )
	{
		fprintf( stderr, "Usage: %s <input file> <output file>\n", argv[ 0 ] );
		return 0;
	}

	/* Read an image file */
	bmp = BMP_ReadFile( argv[ 1 ] );
	BMP_CHECK_ERROR( stdout, -1 );

	/* Get image's dimensions */
	width = BMP_GetWidth( bmp );
	height = BMP_GetHeight( bmp );

	/* Iterate through all the image's pixels */
	for ( x = 0 ; x < width ; ++x )
	{
		for ( y = 0 ; y < height ; ++y )
		{
			
			/* Get pixel's RGB values */
			BMP_GetPixelRGB( bmp, x, y, &r, &g, &b );

			/* Invert RGB values */
			BMP_SetPixelRGB( bmp, x, y, 255 - r, 255 - g, 255 - b );
		}
	}

	/* Save result */
	BMP_WriteFile( bmp, argv[ 2 ] );
	BMP_CHECK_ERROR( stdout, -2 );


	/* Free all memory allocated for the image */
	BMP_Free( bmp );

	return 0;
}
Exemplo n.º 2
0
/* Creates a blur image of the input bitmap file */
int main( int argc, char* argv[] )
{
	UCHAR	r, g, b;
	UINT	width, height;
	UINT	x, y;
	BMP*	bmp;
	BMP*	bmp_new;
	int 	size;
	int 	count;
	int     i, k, start_i, stop_i, start_k, stop_k;
	int 	r_sum, g_sum, b_sum;
	UCHAR	r_new, g_new, b_new;

	/* Check arguments */
	if ( argc != 4 )
	{
		fprintf( stderr, "Usage: %s <input file> <output file> <blur box size>\n", argv[ 0 ] );
		return 0;
	}

	size = atoi(argv[3]);
	if (size <= 0){
		printf("Please enter a positive integer as the blur box size argument.\n");
		return 0;
	}

	/* Read an image file */
	bmp = BMP_ReadFile( argv[ 1 ] );
	BMP_CHECK_ERROR( stdout, -1 );
	bmp_new = BMP_ReadFile( argv[ 1 ] );
	BMP_CHECK_ERROR( stdout, -1 );

	/* Get image's dimensions */
	width = BMP_GetWidth( bmp );
	height = BMP_GetHeight( bmp );

	/* Iterate through all the image's pixels */
	for ( x = 0 ; x < width ; ++x )
	{
		for ( y = 0 ; y < height ; ++y )
		{
			r_sum = 0;
			g_sum = 0;
			b_sum = 0;
			count = 0;
			/* Get pixel's RGB values */
			start_i = x - size;
			stop_i = x + size;
			start_k = y - size;
			stop_k = y + size;
			for (i = start_i; i <= stop_i; i++){
				for (k = start_k; k <= stop_k; k++){
					if ((i >= 0) && (i < width) && (k >= 0) && (k < height)){
						BMP_GetPixelRGB(bmp, i, k, &r, &g, &b);
						count++;
						r_sum = r_sum + r;
						g_sum = g_sum + g;
						b_sum = b_sum + b;
					}
				}
			}
			r_new = r_sum / count;
			g_new = g_sum / count;
			b_new = b_sum / count;

			/* Invert RGB values */
			BMP_SetPixelRGB( bmp_new, x, y, r_new, g_new, b_new );
		}
	}

	/* Save result */
	BMP_WriteFile( bmp_new, argv[ 2 ] );
	BMP_CHECK_ERROR( stdout, -2 );


	/* Free all memory allocated for the image */
	BMP_Free( bmp );
	BMP_Free( bmp_new );

	return 0;
}
Exemplo n.º 3
0
int separaletras (char * entrada)
{
    UCHAR	r, g, b;
    UINT	width, height;
    UINT	x, y;
    BMP*	bmp;
    BMP*	bmp_BW;
    int conta = 0;

    bmp = BMP_ReadFile( entrada );
    bmp_BW = BMP_ReadFile( entrada );
    BMP_CHECK_ERROR(stdout, -1);
    width = BMP_GetWidth( bmp );
    height = BMP_GetHeight( bmp );
    short Black_White[height][width];
    int colunaDaVez[height - 2*OFFSET_Y];
    int Coluna_Inicio = 0;
    int Coluna_Final  = 0;
    int Linha_Inicio  = 0;
    int Linha_Final   = 0;
    char nomeArquivo[20];

    for( x = 0 ; x < width ; ++x)
    {
        for( y = 0 ; y < height ; ++y)
        {
            BMP_GetPixelRGB( bmp, x, y, &r, &g, &b );
            if((r+g+b) < 384 )
            {
                Black_White[y][x] = 0;
                BMP_SetPixelRGB(bmp_BW, x, y, 0, 0, 0);
            }
            else
            {
                Black_White[y][x] = 1;
                BMP_SetPixelRGB(bmp_BW, x, y, 255, 255, 255);
            }
        }
    }

    for( x = 0 ; x < width ; x++)
    {
        for( y = 0 ; y < height ; y++ )
        {
            if(Black_White[y][x] != Black_White[y][x+1])
            {
                BMP_SetPixelRGB(bmp_BW, x, y, 0,0,0);
            }
            else
            {
                BMP_SetPixelRGB(bmp_BW, x, y, 255, 255, 255);
            }
            if(Black_White[y][x] != Black_White[y+1][x])
            {
                BMP_SetPixelRGB(bmp_BW, x, y, 0, 0, 0);
            }
        }
    }
    int c;
    int numeroArquivo = 0;
    int k,h;

    for( x = OFFSET_X ; x < width-OFFSET_X ; x++)
    {
        for(y = OFFSET_Y ; y < height-OFFSET_Y ; y++)
        {
            BMP_GetPixelRGB(bmp_BW, x, y, &r, &g, &b);

            if(r+g+b > 0)
            {
                colunaDaVez[y-OFFSET_Y] = 0;
            }
            else
            {
                colunaDaVez[y-OFFSET_Y] = 1;
            }
        }
        c = verificaColuna_BW(colunaDaVez, height-2*OFFSET_Y);

        if(c == 0 && Coluna_Inicio != 0)
        {
            sprintf(nomeArquivo, "OUT%d.bmp",numeroArquivo);
            Coluna_Final = x;
            for(k = OFFSET_Y; k < height-OFFSET_Y; k++)
            {
                for(h = Coluna_Inicio ; h < Coluna_Final ; h++)
                {
                    BMP_GetPixelRGB(bmp_BW, h, k, &r, &g, &b);
                    if(r+g+b > 0)
                    {
                        colunaDaVez[h - Coluna_Inicio] = 0;
                    }
                    else
                    {
                        colunaDaVez[h - Coluna_Inicio] = 1;
                    }
                }
                c = verificaColuna_BW(colunaDaVez, Coluna_Final-Coluna_Inicio);
                if(c == 0 && Linha_Inicio != 0)
                {
                    if(k-Linha_Inicio > 10)
                    {
                        Linha_Final = k;

                        BMP_Cut_and_Export(bmp, Coluna_Inicio, Coluna_Final, Linha_Final, Linha_Inicio, nomeArquivo);
                        conta++;
                        Coluna_Final = 0;
                        Coluna_Inicio = 0;
                        Linha_Inicio = 0;
                        Linha_Final = 0;
                        numeroArquivo++;
                        k = h = 200000;
                        break;
                    }
                    else
                    {
                        Linha_Inicio = k;
                    }
                }
                if(c == 1 && Linha_Inicio == 0)
                {
                    Linha_Inicio = k;
                }
            }
        }
        if(c == 1 && Coluna_Inicio == 0)
        {
            Coluna_Inicio = x;
        }

    }
    BMP_CHECK_ERROR( stdout, -1);
    BMP_Free(bmp);
    BMP_Free(bmp_BW);
    return conta;
}
int main(int argc, char **argv)
{
	BMP* bmp;
	unsigned int y,w,h,Nrows,i,j,k,Nchars, charnum,char_w, char_sw, char_bytes,font_size,font_space,firstbyte;
	unsigned char buff[128]; 	//buffer to hold a row of image data
	unsigned char r,g,b;

  if(argc==5)
  {	

	bmp = BMP_ReadFile(argv[4]);
	BMP_CHECK_ERROR(stderr, -1);     

	/* get the height and width of the image. */
        w = BMP_GetWidth(bmp);
        h = BMP_GetHeight(bmp);
	//get font size data
		char_w = atoi(argv[1]);
		char_sw = atoi(argv[2]);
		font_space = atoi(argv[3]);

	//verify font parameters
	//is size of character valid?
	//is number of bytes/character <=128?

	
	//check to make sure the character is not larger than the display
	if ( (char_w >128) || (h>64) )
	{
		fprintf(stderr,"character is too large. max size is 128x64\n");
		return -1;
	}
	
	//calculate the number of rows necessary(each row is 8 pixels tall)
	Nrows = h/8;			//number of whole rows necessary
	if (h%8!=0)
		Nrows++;		//a partial row counts too

	//calculate the number of characters in the image
	Nchars = (w/char_w);

	//calculate # of bytes per character
	char_bytes = Nrows*char_w;

	//calculate total number of bytes for font

	font_size = char_bytes*Nchars+4;	//char_bytes repeated Nchars times +4 for font width,height,short width,space

	//build font
	
	printf("const unsigned int Font[%d] = {0x%.2x, 0x%.2x, 0x%.2x, 0x%.2x,\n",font_size,char_w,h,char_sw,font_space);	//print the array definition

	//now build image data

	firstbyte=0;					//to get the right number of comma's in the array initialization
	for(charnum=0;charnum<Nchars;charnum++)		//loop for each character in the image	
	{	
		for (i=0;i<Nrows;i++)	//loop for each row
		{
			memset(buff,0x00,128);	//clear all bytes in buffer for each new row
			for (j=0;j<char_w;j++)	//loop for each byte in row
			{
				for(k=0;k<8;k++) //loop for each pixel in byte
				{
					//calculate the y coordinate of this bit(x coordinate is j+charnum*char_w)
					y = i*8+k;	
					BMP_GetPixelRGB(bmp,j+charnum*char_w,y,&r,&g,&b);	//get pixel 
					if ((r+g+b) == 0)	//check if pixel is set
					{
						buff[j] |= ((unsigned char)1 << k);		//set the pixel
					}
			 	}
			}
			//output row of data
			for (y=0;y<char_w;y++)
			{		
				if (firstbyte==0)
					printf("0x%.2x",buff[y]); //write w bytes(1 for each x coordinate)
				else
					printf(", 0x%.2x",buff[y]); //write w bytes(1 for each x coordinate)
				firstbyte=1;
			}
		}
		printf("\n");	//print a newline to make the file pretty	
	}
	printf("};\n");		//finish array definition 
  }
  else
  {
	printf("Usage: bmp2header_font [character width in pixels] [short character width in pixels] [spacing in pixels] [infile.bmp] > header.h\n");
	printf("Character width defines how the input image is divided.\nSpacing is the number of pixels between characters when printed.");
	printf("Converts a 24bbp bitmap image with characters in the x direction into a header file array definition\n");
	printf("with the array name of \"Font\"\n");
	printf("any pixel in the source identically equal to 0 is considered set in the font.\n");
  }
	return 0;
}
Exemplo n.º 5
0
/* Creates a negative image of the input bitmap file */
int main( int argc, char* argv[] )
{
	UCHAR	r, g, b;
    int pos = 0;
	int i = 0;
	int startPos = 0;
	int get_x = 0;
	int get_y = 0;
	int thread_num = 0;


    


	/* Check arguments */
	if ( argc != 5 )
	{
		fprintf( stderr, "Usage: %s <input file> <output file>\n", argv[ 0 ] );
		return 0;
	}
    
	/* Read an image file */
	bmp = BMP_ReadFile( argv[ 1 ] );
	BMP_CHECK_ERROR( stdout, -1 );
	/* Get image's dimensions */
	width = BMP_GetWidth( bmp );
	height = BMP_GetHeight( bmp );
	size = width*height;
	box_size = atoi(argv[3]);
	thread_num = atoi(argv[4]);

	if (box_size <= 0){
		printf("sorry, box size cannot be negative or 0\n");
		return 0;
	}

	if (thread_num <= 0){
		printf("sorry, thread number cannot be negative or 0\n");
		return 0;
	}
	interval = size/(thread_num-1);
	// printf("%d\n", size);
	pthread_t thread[thread_num];
	int inter[thread_num];

	/* Iterate through all the image's pixels */
	for ( get_x = 0 ; get_x < width ; get_x++ )
	{
		for ( get_y = 0 ; get_y < height ; get_y++ )
		{
			/* Get pixel's RGB values */
			BMP_GetPixelRGB( bmp, get_x, get_y, &r, &g, &b );

            pos = get_x + get_y*width;
            pixelsR[pos] = r;
            pixelsG[pos] = g;
            pixelsB[pos] = b;
			// BMP_SetPixelRGB( bmp, x, y, 255 - r, 255 - g, 255 - b );
		}
	}

	while (i < thread_num){ 
		inter[i] = startPos;
		i++;
		startPos = startPos + interval;
	}


    i = 0;
	while (i < thread_num){
		pthread_create(&thread[i], NULL, &blur, &inter[i]);
		i++;
	}
	


	i = 0;
	while (i < thread_num){
		pthread_join(thread[i], NULL);
		i++;
	}

	/* Save result */
	BMP_WriteFile( bmp, argv[ 2 ] );
	BMP_CHECK_ERROR( stdout, -2 );


	/* Free all memory allocated for the image */
	BMP_Free( bmp );

	return 0;
}