hi,

I guess you could try converting it into an 8bit surface, and then saving
that.

You could do it with surf array fairly quickly I think...

something like:
    red = rgb_im[:,:,0:1]
    surf_red = pygame.image.fromstring(red, size, 'P')
    pygame.image.save(surf_red, "red.png")

You might need to change the pallete of the image to one where the colors
are grey scale.


cheers,


On Wed, Oct 7, 2009 at 3:43 AM, Ian Mallett <[email protected]> wrote:

> Hello,
>
> I'm trying to debug a weird FBO/depth problem, and it would be great to
> have screenshots of the depth.  My current method does not work:
>
> def ScreenSurf(rect=AUTO,type=RGB,framebuffer=0):
>     if rect == AUTO:
>         size = glGetFloatv(GL_VIEWPORT)
>         size = [int(round(size[2])),int(round(size[3]))]
>         rect = [0,0,size[0],size[1]]
>     glPixelStorei(GL_PACK_ROW_LENGTH,0)
>     glPixelStorei(GL_PACK_SKIP_ROWS,0)
>     glPixelStorei(GL_PACK_SKIP_PIXELS,0)
>     if type==RGBA:
>         glPixelStorei(GL_PACK_ALIGNMENT,4)
>     elif type==RGB:
>         glPixelStorei(GL_PACK_ALIGNMENT,1)
>     elif type==DEPTH:
>         glPixelStorei(GL_PACK_ALIGNMENT,2)
>     try:
>         data =
> glReadPixels(rect[0],rect[1],rect[2],rect[3],type,GL_UNSIGNED_BYTE)
>         print len(data)
>     except:
>         previous = glGetIntegerv(GL_READ_BUFFER)
>         glReadBuffer(GL_COLOR_ATTACHMENT0_EXT+framebuffer)
>         data =
> glReadPixels(rect[0],rect[1],rect[2],rect[3],type,GL_UNSIGNED_BYTE)
>         glReadBuffer(previous)
>     if type==RGBA:
>         return pygame.image.fromstring(data,(rect[2],rect[3]),'RGBA',1)
>     elif type==RGB:
>         return pygame.image.fromstring(data,(rect[2],rect[3]),'RGB',1)
>     elif type==DEPTH:
>         #What goes here?
>
> The surface that is returned is then saved (pygame.image.save()).
>
> The issue is that in the case of depth, data is of length x*y.  In the case
> of RGB color, it is 3*rect[2]*rect[3].  In the case of RGBA, it is
> 4*rect[2]*rect[3].  PyGame doesn't know how to convert it (there's no
> pygame.image.fromstring(data,size,'R',1), for instance).  What's a decent
> way to save the depth as an image?
>
> Thanks,
> Ian
>

Reply via email to