Re : putting an NSImage into a movie frame
Re : putting an NSImage into a movie frame
- Subject: Re : putting an NSImage into a movie frame
- From: Seungoh Ryu <email@hidden>
- Date: Thu, 28 Jun 2001 14:37:43 -0400
A while ago, I had a similar question.
I guess I had a bit more problem since I was trying to take a picture
from NSOpenGLiew and dump it onto a QT movie.
After spending a few frustrative days, I arrived at the following,
rather inelegant solution:
Clues given by Kenneth Dyke <email@hidden> regarding the pixel map
manipulation was critical.
I still believe there must be better ways to do it, but this was the
best I could.
It works for me, and for jk <email@hidden>.
Hope somebody take up this and improve on it, since there seems many
people interested in doing similar task. The best will of course be for
Apple to make a nice
OpenGL-QT-Cocoa API .
I attach three bits of code, which is
1) to extract rgb bits from openGl using glReadPixels
2) then pass the array to a function in QT portion of the code
3) which converts (rearrange) it into a pixmap attached to a GWorld,
which
can then be used as source for QT
So far, it works for me though I am uncomfortable with the last portion,
where I
manually fiddle with the pixmap of a GWorld,
If you come up with a better, or more elegant solution, please let me
know.
Seungoh Ryu
-- a physicist with unhealthy interest in programming
===================================
// a method (in NSOpenGL code) to be used to extract the RGBA bits
-(void) readPixels:(unsigned char *)pixie
{
NSRect bounds = [self bounds];
glReadBuffer(GL_FRONT_LEFT);
[[self openGLContext] makeCurrentContext];
glClearColor(0.0, 0.0, 0.0,0.0);
glReadPixels(0, 0, (GLsizei)(bounds.size.width),
(GLsizei)(bounds.size.height), GL_RGBA, GL_UNSIGNED_BYTE, pixie);
[NSOpenGLContext clearCurrentContext];
}
// segment from openGL portion of the code to be used to extract RGBA
bits from
// OpenGL and pass it to the QT portion
width = (int)(bounds.size.width);
height = (int)(bounds.size.height);
pixie = (unsigned char *)malloc(width * height * 4);
[[self myOpenGLView] readPixels:pixie];
[myMovieMaker copyAnImageIntoMovie:pixie withRect:[[self
myOpenGLView] bounds]];
free(pixie);
// segment from the QuickTime portion of the code
// fill in the pixmap of a GWorld (pixels) to be used in various QT
calls
PixMapHandle pmh;
unsigned char *pixels;
pmh = GetPortPixMap(theGWorld); // get the handle to the
destination pixmap
LockPixels (pmh);
pixels = GetPixBaseAddr(pmh); // get the ptr to the pixmap data
region
skip = (**pmh).rowBytes & 0x7FFF; // two byte number with the last
bit screened out
// printf ("source bytesPerRow = %d, width = %d\n",
(**pmh).rowBytes & 0x7FFF, width);
// destination pixels expect ARGB while the source pixmap data has
RGBA
// since it was filled by glReadPixel with RGBA
// hence the switching in the indices
for(j=0;j<height;j++)
for(i=0;i<width;i++)
{
pixels[i*4+ j*skip] =pixie[((height-1-j)*4*width+i*4)+3]; //
alpha
pixels[i*4+1+ j*skip]=pixie[((height-1-j)*4*width+i*4)]; //red
pixels[i*4+2+ j*skip]=pixie[((height-1-j)*4*width+i*4)+1]; //
green
pixels[i*4+3+j*skip] = pixie[((height-1-j)*4*width+i*4)+2]; //
blue
}
On Wednesday, June 20, 2001, at 05:57 AM, jk wrote:
Hi there,
I was wondering if you ever ended up getting any responses to your
question about exporting an OpenGL frame in OSX into QuickTime.
I've run into the same problem: I have raw pixel information that
I need placed into a PixMap for use in QuickTime.
Let me know if you've found a solution!
--
this is a .sig about a superhero named jonny, it's called jonny's .sig!