Example #1
0
void preparaletras()
{
    BMP* bmp, * nbmp;
    int i;

    for(i = 0; i < 3; i++)
    {
        char ca[10];
        snprintf(ca, sizeof(ca), "OUT%d.bmp", i);
        bmp = BMP_ReadFile(ca);
        bmp = BMP_Gray(bmp);
        nbmp = BMP_Resized(bmp, 20);
        BMP_WriteFile(nbmp, ca);
        BMP_ExtraiEntradas(nbmp, "entradaletras.txt");
        BMP_Free( bmp );
        BMP_Free( nbmp );
    }

    for(i = 3; i < 7; i++)
    {
        char ca[10];
        snprintf(ca, sizeof(ca), "OUT%d.bmp", i);
        bmp = BMP_ReadFile(ca);
        bmp = BMP_Gray(bmp);
        nbmp = BMP_Resized(bmp, 20);
        BMP_WriteFile(nbmp, ca);
        BMP_ExtraiEntradas(nbmp, "entradanumeros.txt");
        BMP_Free( bmp );
        BMP_Free( nbmp );
    }
}
Example #2
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;
}
Example #3
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;
}
Example #4
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;
}
Example #5
0
int main() {
    static const char* cubeNames[CC_FACE_NUM] = {
            "TOP.bmp",
            "LEFT.bmp",
            "FRONT.bmp",
            "RIGHT.bmp",
            "BACK.bmp",
            "DOWN.bmp"
    };

    struct cc_context ctx;

    unsigned int i = 0;
    unsigned int j = 0;

    unsigned char rr;
    unsigned char gg;
    unsigned char bb;

    BMP *bmpCube[CC_FACE_NUM];

    unsigned int   width  = 0;
    unsigned int   height = 0;
    unsigned short depth  = 0;

    BMP *output = NULL;

    unsigned int pano_width  = 0;
    unsigned int pano_height = 0;

    const struct cc_coord* coord = NULL;

    // Read the 6 input images
    for (i = 0; i < CC_FACE_NUM; ++i) {
        bmpCube[i] = BMP_ReadFile(cubeNames[i]);

        if (BMP_GetError() != BMP_OK) {
            return 1;
        }
    }

    // Get image's dimensions
    width  = (unsigned int)BMP_GetWidth( bmpCube[0]);
    height = (unsigned int)BMP_GetHeight(bmpCube[0]);
    depth  = BMP_GetDepth( bmpCube[0]);

    // The input images must be square
    if (width != height) {
        return 1;
    }

    /*
       Initialise the algorithm:
         the width of each input is 640 pixel,
         the vertical view portion is PI (180 degrees),
         the horizontal view portion is 2*PI (360 degress).

       In this case, the output image size will be calculated accordingly.
       There is another more detailed init function you can play with.
     */
    cc_init(&ctx, width, M_PI*2.0, M_PI);

    // Generate the mapping from panorama to cubic
    cc_gen_map(&ctx);

    // Access the dimension of the panorama image
    pano_width  = ctx.px_pano_h;
    pano_height = ctx.px_pano_v;

    // Create the panorama output image
    output = BMP_Create(pano_width, pano_height, depth);

    // Map the pixels from the panorama back to the source image
    for (i = 0; i < pano_width; ++i) {
        for (j = 0; j < pano_height; ++j) {
            // Get the corresponding position of (i, j)
            coord = cc_get_coord(&ctx, i, j);

            // Access the pixel
            BMP_GetPixelRGB(bmpCube[coord->face], (unsigned long)coord->x, (unsigned long)coord->y, &rr, &gg, &bb);

            // Write the pixel to the panorama
            BMP_SetPixelRGB(output, i, j, rr, gg, bb);
        }
    }

    // Write the output file
    BMP_WriteFile(output, "PANO.bmp");

    // Release memory
    BMP_Free(output);

    for (i = 0; i < CC_FACE_NUM; ++i) {
        BMP_Free(bmpCube[i]);
    }

    cc_close(&ctx);

    return 0;
}