PDA

View Full Version : image processing in OpenML using GL_ARB_imaging extensio



emack
05-05-2004, 01:29 PM
I am now trying to get a transcoder based on nullxcode to do something useful. My first
task is to switch the red and blue channels of the incoming video stream, for which I wrote the code below.

Of course, it does not work as there is no device context or rendering context set within the nullxcode DLL--if there are any suggested/special settings for these it would be great to know about them.

Is this generally the right way to approach this, or do people use for i/for j/memcpy . . . type loops if they are trying to do channel operations? On p. 104 of the OpenML Spec it indicates that the GL_ARB_imaging extension is used for image processing, but doesn't go into more detail than that.

Thanks,

Eliot

/* Actually transcode an input buffer into an output buffer.
* This is where the real work of a transcoder will occur.
*
* In our case, it's pretty trivial.
*/
static bool
transformBuffer(MLDDopen* pOpen,
MLbyte* inBuf,
MLint32 inSize,
MLDDxcodeParams* inParams,
MLbyte* outBuf,
MLint32 outSize,
MLDDxcodeParams* outParams)
{
bool rval = false;
MLint32 ij=0;
// matrix to swap red and blue chan.
GLfloat colorMatrix[16] = {
0.0, 0.0, 1.0, 0.0,
0.0, 1.0, 0.0, 0.0,
1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0
};

/* Must verify controls in order to catch incompatible settings
* made via mlSendControls()
*/
if (!verifyControls(inParams, outParams)) {
return false;
}

/* Transform away...
*/
if (pOpen->useCopyEngine) {
// Original function--copies data from inBuf to outBuf
// rval = (memcpy(outBuf, inBuf, inSize) ==
outBuf);

// First--to specify raster position transformed to screen
coordinates,
// need to set modelview and projection matrices for simple 2D
rendering.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLfloat) 320, 0.0, (GLfloat) 240);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// More setup
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_COLOR);
glLoadMatrixf(colorMatrix);

glDrawBuffer(GL_FRONT);
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0,0);
glDrawPixels(320,240, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid *)inBuf);
glReadBuffer(GL_FRONT);
glReadPixels(0,0,320,240, GL_RGB, GL_UNSIGNED_BYTE,(GLvoid *)outBuf);
glMatrixMode(GL_MODELVIEW);
// glDrawBuffer(GL_FRONT);
rval = true;
return rval;

} else {
memset(outBuf, 0, outSize);
rval = true;
}
return rval;
}

madmac
02-12-2005, 09:13 AM
I suspect that you have to create your own context, just like in an OpenGL application (try GLUT, and then "downscale" to native calls, only allocating pbuffers - EXT_framebuffer_object will soon help to avoid OS window manager calls for offscreen-rendering).

fjaubert
03-02-2005, 02:50 AM
Perhaps you may want to profile this OpenGL solution vs. the more traditional "for-loop/memcpy" approach you mention. Depending on the architecture, you might find that transferring to an OpenGL board, and especially reading back from the board takes longer than plain memory operations (on many PC graphics boards, ReadPixels is much much slower than WritePixels).