コード例 #1
0
ファイル: histogram.c プロジェクト: MichaelHe1125/GLUT
void init(void)
{
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   glClearColor(0.0, 0.0, 0.0, 0.0);

   glHistogram(GL_HISTOGRAM, HISTOGRAM_SIZE, GL_RGB, GL_FALSE);
   glEnable(GL_HISTOGRAM);
}
コード例 #2
0
ファイル: 10_histogram.c プロジェクト: c14006078/opengl
void init(void) {
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_FLAT);
    makeCheckImage();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glHistogram(GL_HISTOGRAM, histogram_size, GL_RGB, GL_FALSE);
    glEnable(GL_HISTOGRAM);
}
コード例 #3
0
ファイル: g_render.c プロジェクト: aosm/X11
void __glXDisp_Histogram(GLbyte *pc)
{
	glHistogram( 
		*(GLenum   *)(pc + 0),
		*(GLsizei  *)(pc + 4),
		*(GLenum   *)(pc + 8),
		*(GLboolean *)(pc + 12)
	);
}
コード例 #4
0
ファイル: histogram.c プロジェクト: MichaelHe1125/GLUT
void keyboard(unsigned char key, int x, int y)
{
   static GLboolean sink = GL_FALSE;
    
   switch (key) {
      case 's' :
	  sink = !sink;
	  glHistogram(GL_HISTOGRAM, HISTOGRAM_SIZE, GL_RGB, sink);
	  break;
	  
      case 27:
         exit(0);
   }
   glutPostRedisplay();
   
}
コード例 #5
0
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_ARBImaging_nglHistogram(JNIEnv *env, jclass clazz, jint target, jint width, jint internalformat, jboolean sink, jlong function_pointer) {
    glHistogramPROC glHistogram = (glHistogramPROC)((intptr_t)function_pointer);
    glHistogram(target, width, internalformat, sink);
}
コード例 #6
0
ファイル: Rendering.cpp プロジェクト: artulec88/GameEngine
/**
 * If enabled, histogram incoming RGBA color values.
 * See https://www.opengl.org/sdk/docs/man3/xhtml/glHistogram.xml
 */
void rendering::ReadHistogramParameter()
{
	if (supportedOpenGLLevel > 300)
	{
		INFO_LOG_RENDERING("Histogram not supported in OpenGL version higher than 3.0");
		CheckErrorCode(__FUNCTION__, "Initializing histogram parameters");
		return;
	}
	const auto histogramEnabled = GET_CONFIG_VALUE_RENDERING("GL_HISTOGRAM_ENABLED", 0);
	if (histogramEnabled == 0)
	{
		glDisable(GL_HISTOGRAM);
		DEBUG_LOG_RENDERING("GL_HISTOGRAM disabled");
		CheckErrorCode(__FUNCTION__, "Initializing histogram parameters");
		return;
	}

	glEnable(GL_HISTOGRAM);

	auto histogramTargetStr = GET_CONFIG_VALUE_STR_RENDERING("GL_HISTOGRAM_TARGET", "GL_HISTOGRAM");
	GLenum histogramTarget;
	if (histogramTargetStr == "GL_HISTOGRAM") { histogramTarget = GL_HISTOGRAM; }
	else if (histogramTargetStr == "GL_PROXY_HISTOGRAM") { histogramTarget = GL_PROXY_HISTOGRAM; }
	else /* GL_HISTOGRAM is default */
	{
		ERROR_LOG_RENDERING("Invalid enum \"", histogramTargetStr, "\" given for the histogram target parameter. Using default GL_HISTOGRAM");
		histogramTargetStr = "GL_HISTOGRAM";
		histogramTarget = GL_HISTOGRAM;
	}

	const auto histogramWidth = GET_CONFIG_VALUE_RENDERING("GL_HISTOGRAM_WIDTH", 16); // must be a power of 2

	auto histogramInternalFormatStr = GET_CONFIG_VALUE_STR_RENDERING("GL_HISTOGRAM_INTERNAL_FORMAT", "GL_ALPHA");
	GLenum histogramInternalFormat;
	if (histogramInternalFormatStr == "GL_ALPHA") { histogramInternalFormat = GL_ALPHA; }
	else if (histogramInternalFormatStr == "GL_ALPHA4") { histogramInternalFormat = GL_ALPHA4; }
	else if (histogramInternalFormatStr == "GL_ALPHA8") { histogramInternalFormat = GL_ALPHA8; }
	else if (histogramInternalFormatStr == "GL_ALPHA12") { histogramInternalFormat = GL_ALPHA12; }
	else if (histogramInternalFormatStr == "GL_ALPHA16") { histogramInternalFormat = GL_ALPHA16; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE") { histogramInternalFormat = GL_LUMINANCE; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE4") { histogramInternalFormat = GL_LUMINANCE4; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE8") { histogramInternalFormat = GL_LUMINANCE8; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE12") { histogramInternalFormat = GL_LUMINANCE12; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE16") { histogramInternalFormat = GL_LUMINANCE16; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE_ALPHA") { histogramInternalFormat = GL_LUMINANCE_ALPHA; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE4_ALPHA4") { histogramInternalFormat = GL_LUMINANCE4_ALPHA4; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE6_ALPHA2") { histogramInternalFormat = GL_LUMINANCE6_ALPHA2; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE8_ALPHA8") { histogramInternalFormat = GL_LUMINANCE8_ALPHA8; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE12_ALPHA4") { histogramInternalFormat = GL_LUMINANCE12_ALPHA4; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE12_ALPHA12") { histogramInternalFormat = GL_LUMINANCE12_ALPHA12; }
	else if (histogramInternalFormatStr == "GL_LUMINANCE16_ALPHA16") { histogramInternalFormat = GL_LUMINANCE16_ALPHA16; }
	else if (histogramInternalFormatStr == "GL_R3_G3_B2") { histogramInternalFormat = GL_R3_G3_B2; }
	else if (histogramInternalFormatStr == "GL_RGB") { histogramInternalFormat = GL_RGB; }
	else if (histogramInternalFormatStr == "GL_RGB4") { histogramInternalFormat = GL_RGB4; }
	else if (histogramInternalFormatStr == "GL_RGB5") { histogramInternalFormat = GL_RGB5; }
	else if (histogramInternalFormatStr == "GL_RGB8") { histogramInternalFormat = GL_RGB8; }
	else if (histogramInternalFormatStr == "GL_RGB10") { histogramInternalFormat = GL_RGB10; }
	else if (histogramInternalFormatStr == "GL_RGB12") { histogramInternalFormat = GL_RGB12; }
	else if (histogramInternalFormatStr == "GL_RGB16") { histogramInternalFormat = GL_RGB16; }
	else if (histogramInternalFormatStr == "GL_RGBA") { histogramInternalFormat = GL_RGBA; }
	else if (histogramInternalFormatStr == "GL_RGBA2") { histogramInternalFormat = GL_RGBA2; }
	else if (histogramInternalFormatStr == "GL_RGBA4") { histogramInternalFormat = GL_RGBA4; }
	else if (histogramInternalFormatStr == "GL_RGB5_A1") { histogramInternalFormat = GL_RGB5_A1; }
	else if (histogramInternalFormatStr == "GL_RGBA8") { histogramInternalFormat = GL_RGBA8; }
	else if (histogramInternalFormatStr == "GL_RGB10_A2") { histogramInternalFormat = GL_RGB10_A2; }
	else if (histogramInternalFormatStr == "GL_RGBA12") { histogramInternalFormat = GL_RGBA12; }
	else if (histogramInternalFormatStr == "GL_RGBA16") { histogramInternalFormat = GL_RGBA16; }
	else /* GL_RGBA is default */
	{
		ERROR_LOG_RENDERING("Invalid enum \"", histogramInternalFormatStr, "\" given for the histogram internal format. Using default GL_RGBA");
		histogramInternalFormatStr = "GL_RGBA";
		histogramInternalFormat = GL_RGBA;
	}

	const auto histogramSink = GET_CONFIG_VALUE_RENDERING("GL_HISTOGRAM_SINK", false);
	glHistogram(histogramTarget, histogramWidth, histogramInternalFormat, histogramSink);

	if (histogramSink)
	{
		INFO_LOG_RENDERING("GL_HISTOGRAM enabled with target = \"", histogramTargetStr, "\", width = ", histogramWidth, ", internal format = \"", histogramInternalFormatStr, "\" and enabled sink");
	}
	else
	{
		INFO_LOG_RENDERING("GL_HISTOGRAM enabled with target = \"", histogramTargetStr, "\", width = ", histogramWidth, ", internal format = \"", histogramInternalFormatStr, "\" and disabled sink");
	}
	CheckErrorCode(__FUNCTION__, "Initializing histogram parameters");
}
コード例 #7
-1
///////////////////////////////////////////////////////////////////////        
// 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();
    }