void display() { glClear(GL_COLOR_BUFFER_BIT); glRasterPos2i(0, 0); glDrawPixels(checkImageWidth, checkImageHeight, GL_RGB, GL_UNSIGNED_BYTE, checkImage); int i; GLushort values[histogram_size][3]; glGetHistogram(GL_HISTOGRAM, GL_TRUE, GL_RGB, GL_UNSIGNED_SHORT, values); glBegin(GL_LINE_STRIP); glColor3f(1.0, 0.0, 0.0); for (i = 0; i < histogram_size; i++) glVertex2s(i, values[i][0]); glEnd(); glBegin(GL_LINE_STRIP); glColor3f(0.0, 1.0, 0.0); for (i = 0; i < histogram_size; i++) glVertex2s(i, values[i][1]); glEnd(); glBegin(GL_LINE_STRIP); glColor3f(0.0, 0.0, 1.0); for (i = 0; i < histogram_size; i++) glVertex2s(i, values[i][2]); glEnd(); glFlush(); }
void display(void) { int i; GLushort values[HISTOGRAM_SIZE][3]; glClear(GL_COLOR_BUFFER_BIT); glRasterPos2i(1, 1); glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); glGetHistogram(GL_HISTOGRAM, GL_TRUE, GL_RGB, GL_UNSIGNED_SHORT, values); /* Plot histogram */ glBegin(GL_LINE_STRIP); glColor3f(1.0, 0.0, 0.0); for ( i = 0; i < HISTOGRAM_SIZE; i++ ) glVertex2s(i, values[i][0]); glEnd(); glBegin(GL_LINE_STRIP); glColor3f(0.0, 1.0, 0.0); for ( i = 0; i < HISTOGRAM_SIZE; i++ ) glVertex2s(i, values[i][1]); glEnd(); glBegin(GL_LINE_STRIP); glColor3f(0.0, 0.0, 1.0); for ( i = 0; i < HISTOGRAM_SIZE; i++ ) glVertex2s(i, values[i][2]); glEnd(); glFlush(); }
static int GetHistogram(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag) { GLint compsize; GLenum format, type, target; GLboolean swapBytes, reset; __GLXcontext *cx; ClientPtr client = cl->client; int error; __GLX_DECLARE_SWAP_VARIABLES; char *answer, answerBuffer[200]; GLint width = 0; xGLXSingleReply reply = { 0, }; cx = __glXForceCurrent(cl, tag, &error); if (!cx) { return error; } __GLX_SWAP_INT(pc + 0); __GLX_SWAP_INT(pc + 4); __GLX_SWAP_INT(pc + 8); format = *(GLenum *) (pc + 4); type = *(GLenum *) (pc + 8); target = *(GLenum *) (pc + 0); swapBytes = *(GLboolean *) (pc + 12); reset = *(GLboolean *) (pc + 13); glGetHistogramParameteriv(target, GL_HISTOGRAM_WIDTH, &width); /* * The one query above might fail if we're in a state where queries * are illegal, but then width would still be zero anyway. */ compsize = __glGetTexImage_size(target, 1, format, type, width, 1, 1); if (compsize < 0) return BadLength; glPixelStorei(GL_PACK_SWAP_BYTES, !swapBytes); __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1); __glXClearErrorOccured(); glGetHistogram(target, reset, format, type, answer); if (__glXErrorOccured()) { __GLX_BEGIN_REPLY(0); __GLX_SWAP_REPLY_HEADER(); } else { __GLX_BEGIN_REPLY(compsize); __GLX_SWAP_REPLY_HEADER(); __GLX_SWAP_INT(&width); ((xGLXGetHistogramReply *) &reply)->width = width; __GLX_SEND_VOID_ARRAY(compsize); } return Success; }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBImaging_nglGetHistogramBO(JNIEnv *env, jclass clazz, jint target, jboolean reset, jint format, jint type, jlong values_buffer_offset, jlong function_pointer) { GLvoid *values_address = (GLvoid *)(intptr_t)offsetToPointer(values_buffer_offset); glGetHistogramPROC glGetHistogram = (glGetHistogramPROC)((intptr_t)function_pointer); glGetHistogram(target, reset, format, type, values_address); }
/////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { GLint i; // Looping variable GLint iViewport[4]; // Viewport GLint iLargest; // Largest histogram value static GLubyte invertTable[256][3];// Inverted color table // Do a black and white scaling static GLfloat lumMat[16] = { 0.30f, 0.30f, 0.30f, 0.0f, 0.59f, 0.59f, 0.59f, 0.0f, 0.11f, 0.11f, 0.11f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; static GLfloat mSharpen[3][3] = { // Sharpen convolution kernel {0.0f, -1.0f, 0.0f}, {-1.0f, 5.0f, -1.0f }, {0.0f, -1.0f, 0.0f }}; static GLfloat mEmboss[3][3] = { // Emboss convolution kernel { 2.0f, 0.0f, 0.0f }, { 0.0f, -1.0f, 0.0f }, { 0.0f, 0.0f, -1.0f }}; static GLint histoGram[256]; // Storeage for histogram statistics // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); // Current Raster Position always at bottom left hand corner of window glRasterPos2i(0, 0); glGetIntegerv(GL_VIEWPORT, iViewport); glPixelZoom((GLfloat) iViewport[2] / (GLfloat)iWidth, (GLfloat) iViewport[3] / (GLfloat)iHeight); if(bHistogram == GL_TRUE) // Collect Historgram data { // We are collecting luminance data, use our conversion formula // instead of OpenGL's (which just adds color components together) glMatrixMode(GL_COLOR); glLoadMatrixf(lumMat); glMatrixMode(GL_MODELVIEW); // Start collecting histogram data, 256 luminance values glHistogram(GL_HISTOGRAM, 256, GL_LUMINANCE, GL_FALSE); glEnable(GL_HISTOGRAM); } // Do image operation, depending on rendermode index switch(iRenderMode) { case 5: // Sharpen image glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGB, 3, 3, GL_LUMINANCE, GL_FLOAT, mSharpen); glEnable(GL_CONVOLUTION_2D); break; case 4: // Emboss image glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGB, 3, 3, GL_LUMINANCE, GL_FLOAT, mEmboss); glEnable(GL_CONVOLUTION_2D); glMatrixMode(GL_COLOR); glLoadMatrixf(lumMat); glMatrixMode(GL_MODELVIEW); break; case 3: // Invert Image for(i = 0; i < 255; i++) { invertTable[i][0] = (GLubyte)(255 - i); invertTable[i][1] = (GLubyte)(255 - i); invertTable[i][2] = (GLubyte)(255 - i); } glColorTable(GL_COLOR_TABLE, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, invertTable); glEnable(GL_COLOR_TABLE); break; case 2: // Brighten Image glMatrixMode(GL_COLOR); glScalef(1.25f, 1.25f, 1.25f); glMatrixMode(GL_MODELVIEW); break; case 1: // Just do a plain old image copy default: // This line intentially left blank break; } // Do the pixel draw glDrawPixels(iWidth, iHeight, eFormat, GL_UNSIGNED_BYTE, pImage); // Fetch and draw histogram? if(bHistogram == GL_TRUE) { // Read histogram data into buffer glGetHistogram(GL_HISTOGRAM, GL_TRUE, GL_LUMINANCE, GL_INT, histoGram); // Find largest value for scaling graph down iLargest = 0; for(i = 0; i < 255; i++) if(iLargest < histoGram[i]) iLargest = histoGram[i]; // White lines glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_LINE_STRIP); for(i = 0; i < 255; i++) glVertex2f((GLfloat)i, (GLfloat)histoGram[i] / (GLfloat) iLargest * 128.0f); glEnd(); bHistogram = GL_FALSE; glDisable(GL_HISTOGRAM); } // Reset everyting to default glMatrixMode(GL_COLOR); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glDisable(GL_CONVOLUTION_2D); glDisable(GL_COLOR_TABLE); // Show our hard work... glutSwapBuffers(); }