/* 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; }
GLFont *glFontLoad(char *fontfile) { GLFont *font = NULL; BMPFile *bmp = NULL; bmp = BMP_Load(fontfile); if (!bmp) return NULL; font = calloc(1, sizeof(GLFont)); if (!font) { BMP_Destroy(&bmp); return NULL; } font->textureID = makeTexture(BMP_GetWidth(bmp), BMP_GetHeight(bmp), BMP_GetPixelArray(bmp)); BMP_Destroy(&bmp); font->base = makeFontList(font->textureID); return font; }
// Load a texture and store its handle in "handle" bool terrain::load_texture(const char *filename, GLuint *handle) { BMP *bitmap; // Load the texture by reading a bmp file bitmap = BMP_ReadFile(filename); // Return false and show an error message if the file // could not be loaded if (BMP_GetError() != BMP_OK) { std::cout<<BMP_GetErrorDescription()<<std::endl; return false; } // Get a pointer to the bitmap data unsigned char* data = BMP_GetImageData(bitmap); // Generate one texture and store its ID in "handle" glGenTextures(1, handle); // Bind the texture glBindTexture(GL_TEXTURE_2D, *handle); // Enable linear blending between different mipmapping levels glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Clamp the texture at the borders glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); // Transfer the image data to the graphics card. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BMP_GetWidth(bitmap), BMP_GetHeight(bitmap), 0, GL_RGB, GL_UNSIGNED_BYTE, data); // Not needed anymore free(data); BMP_Free(bitmap); // Unbind texture glBindTexture(GL_TEXTURE_2D, 0); return true; }
// Return the height of the height map int terrain::get_heightmap_height() const { return BMP_GetHeight(heightmap); }
/* 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; }
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; }
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; }
/* 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; }
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; }