/////////////////////////////////////////////////////////////////////////////// // load a BMP as texture /////////////////////////////////////////////////////////////////////////////// unsigned int ModelGL::loadTextureBmp(const char* fileName) { int chans, x, y; void* buf; Image::Bmp bmp; bmp.read(fileName); x = bmp.getWidth(); y = bmp.getHeight(); chans = bmp.getBitCount() / 8; buf = (void*)bmp.getDataRGB(); // gen texture ID GLuint texture; glGenTextures(1, &texture); // set active texture and configure it glBindTexture(GL_TEXTURE_2D, texture); // select modulate to mix texture with color for shading glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // if wrap is true, the texture wraps over at the edges (repeat) // ... false, the texture ends at the edges (clamp) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // build our texture mipmaps switch(chans) { case 1: gluBuild2DMipmaps(GL_TEXTURE_2D, chans, x, y, GL_LUMINANCE, GL_UNSIGNED_BYTE, buf); break; case 3: gluBuild2DMipmaps(GL_TEXTURE_2D, chans, x, y, GL_RGB, GL_UNSIGNED_BYTE, buf); break; case 4: gluBuild2DMipmaps(GL_TEXTURE_2D, chans, x, y, GL_RGBA, GL_UNSIGNED_BYTE, buf); break; } return texture; }
int main(int argc, char **argv){ mode = 1; cout << "Enter image name : "; cin >> fileName; cout << "===================MODE==================\n"; cout << "(0)shows histogram \n(1)global histogram equalization \n(2)local histogram equalization (window size 3)\n"; cout << "Please enter mode : "; cin >> mode; if (bmp.read(fileName)){ inBuf = bmp.getData(); imageX = bmp.getWidth(); imageY = bmp.getHeight(); }else{ cout << "==============================\n"; cout << "|- Please check image name -|\n"; cout << "==============================\n"; exit(0); } histogram = calculate_histogram(inBuf, imageX, imageY); // hitung histogram if (mode != 0){ if (mode == 1){ strcpy_s(newFileName, "global_equalization_"); strcat_s(newFileName, fileName); perform_histogram_equalization(histogram, imageX, imageY); // histrogram equalization } else{ strcpy_s(newFileName, "local_equalization_"); strcat_s(newFileName, fileName); local_histogram_equalization(histogram, imageX, imageY, WINDOW_SIZE); } bmp.save(newFileName, imageX, imageY, 1, outBuf); // save new image equalHistogram = calculate_histogram(outBuf, imageX, imageY); // new histogram } histoScale = (float)(imageY - 1) / getMaxHistogram(histogram, HISTOGRAM_SIZE); glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(imageX, imageY); glutInitWindowPosition(10, 10); glutCreateWindow("Histogram"); Initialize(); glutDisplayFunc(Draw); glutMainLoop(); return 0; }