Post Reply 
 
Thread Rating:
  • 45 Votes - 3.24 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Image Processing Algorithms
Author Message
mudlord Offline
not banned.
*****

Posts: 507
Joined: Feb 2009
Reputation: 5
Post: #1
Image Processing Algorithms
I am currently investigating certain image processing/scaling algorithms.

For example: http://board.byuu.org/viewtopic.php?f=10&t=203
The effect could very easily be done with a vertex and pixel shader (using a vertex shader, calculate the velocity of a pixel, and then blur accordingly), but thats not the point.

I am interested in using scaling/image processing algorithms, that are written in software, for rendering hardware rendered 3D images, for processing with the CPU. No shaders, no nothing, except raw CPU processing. Attached is a example that uses such a approach. The scene is captured into a buffer, not a texture, and post processed, and drawn back purely in software. Speed is a issue and I ask for assistance in accelerating glReadPixel operations.

I am also asking for sources such as HQXX/2xsai as well as references for Lanczos/Mitchell scaling/resampling algorithms
Updated.

Added a plasma background, should be more useful for detecting artifacts.
I added a basic software bloom filter. Still, same performance issues with glReadPixels remains....

Considering turning this app into a OGL benchmark for filters. Would be nice to add Kega filters.


Attached File(s)
.zip  glsandbox.zip (Size: 29.9 KB / Downloads: 57)
(This post was last modified: 08-16-2009 11:37 AM by mudlord.)
08-15-2009 08:52 PM
Visit this user's website Find all posts by this user Quote this message in a reply
mudlord Offline
not banned.
*****

Posts: 507
Joined: Feb 2009
Reputation: 5
Post: #2
RE: Image Processing Algorithms
Heheheh, ran into a interesting optimization problem.....

Code:
void post_process_cpu()
{
    glPushMatrix();
    glLoadIdentity();
    glTranslatef(0.0,0.0f,-4.0f);
    glColor3f(1.0f,1.0f,1.0f);
    //RGB-888, 32 bits
        GLuint scratchtex;
    int bufsize = window_width * window_height * 4;
    int pitch = window_width*4;
    unsigned char* ImageBuffer = (unsigned char*)malloc(bufsize);

    glDisable(GL_TEXTURE_2D);
    glReadPixels ( 0, 0, window_width, window_height, GL_RGBA,     GL_UNSIGNED_BYTE, (unsigned char*)ImageBuffer);

    //do 2xSai/HQ2X/bloom/whatever on ImageBuffer

    glEnable(GL_TEXTURE_2D);
    glGenTextures(1, &scratchtex);
    glBindTexture(GL_TEXTURE_2D, scratchtex);
    glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    glTexImage2D( GL_TEXTURE_2D, 0, 3, window_width, window_height, 0,
    GL_RGBA, GL_UNSIGNED_BYTE, ImageBuffer);
    
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-1.0f, -1.0f,  1.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f( 1.0f, -1.0f,  1.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f( 1.0f,  1.0f,  1.0f);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(-1.0f,  1.0f,  1.0f);
    glEnd();

    glBindTexture(GL_TEXTURE_2D, 0);
    glDeleteTextures(1, &scratchtex);

    free(ImageBuffer);
    glDisable(GL_TEXTURE_2D);
    glPopMatrix();
}

I know, unoptimized.

As I said, I worked out a way.
Render the scene into a 512*512 viewport, then copy the texture. However, for some odd reason, I do not know, the texture in the rendered scene is off centre, by exactly half (only half the image is displayed). Any help with the usage of glViewport and the tex coords would be great. Unfortunately, I lost the code in the past thats perfect for scaling textures according to aspect ratio, viewport size and texture size.
08-17-2009 01:10 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: