예제 #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;
}
예제 #2
0
파일: blur1.c 프로젝트: msv4109/CodeSample
/* 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;
}
예제 #3
0
void* blur(void* p){
	UCHAR avgR, avgG, avgB;
	int x = 0;
	int y = 0;
	int sumR = 0;
	int sumG = 0;
	int sumB = 0;
	int startX = 0;
	int startY = 0;
	int endX = 0;
	int endY = 0;
	int count = 0;
	int tempPos = *(int*)p;
    int tempY = 0;
    int pos = 0;
    int nextPos = tempPos + interval;


    while (tempPos < nextPos && tempPos < size){

            count = 0;
            sumR = 0;
            sumG = 0;
            sumB = 0;
            y = tempPos/width;
            x = tempPos%width;


            // check for boundaries
			if (x - box_size < 0){
				startX = 0;
			} else {
				startX = x - box_size;
			}

			if (y - box_size < 0){
				startY = 0;
			} else {
				startY = y - box_size;
			}

			if (x + box_size >= width){
				endX = width - 1;
			} else {
				endX = x + box_size;
			}

			if (y + box_size >= height){
				endY = height - 1;
			} else {
				endY = y + box_size;
			}

			while (startX <= endX){
				tempY = startY;
				while (tempY <= endY){
					pos = startX + tempY*width;
					sumR += pixelsR[pos];
					sumG += pixelsG[pos];
					sumB += pixelsB[pos];
					tempY ++;
					count++;
				}
				startX ++;
			}

			avgR = sumR/count;
			avgG = sumG/count;
			avgB = sumB/count;



            pthread_mutex_lock(&lock);
			BMP_SetPixelRGB( bmp, x, y, avgR, avgG, avgB );
			pthread_mutex_unlock(&lock);

			tempPos++;
    }

    return NULL;


}
예제 #4
0
파일: main.c 프로젝트: diogolabres/MLP
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;
}
예제 #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;
}