1. pygame
  2. pygame
  3. pygame
  4. Issues


Issue #65 open

deriving surface from other surfaces sometimes does not work

René Dudfield
created an issue

== Gummbum Uhhh, 2011-02-22 07:50:51 -0800

{{{ Created attachment 40 Small demo program and PNG image


The constructor usage pygame.Surface((width,height),flags=0,Surface) seems to return a valid surface, but blitting or drawing to the derived surface doesn't do anything visible to the surface. Just guessing from the behavior, this seems to occur when the source bpp differs from that of the display.

In the following snippet, 'image.png' is an 8-bpp image and the display is 32-bpp:

im1 = pygame.image.load('image.png') r = im1.get_rect() im2 = pygame.surface.Surface(r.size,0,im1)

im2 now seems to be broken. Blitting does not work...

im2.blit(im1, (0,0), r)

And even things like im2.fill() do not work.

See attached image and sample program. This happened to me once before with a different PNG file. I did not collect the details at that time. Hope this is enough info to zero right in on the issue. }}}

Attachments: [[http://www.pygame.org/old_bug_attachments/40/test.zip| test.zip]]

== Gummbum Uhhh, 2011-02-22 07:59:19 -0800

{{{ In contrast with the attached demo program, I've been successfully using the following and similar workarounds:

r = im1.get_rect() flags = im1.get_flags() bitsize = im1.get_bitsize() im2 = self.pygame.Surface(r.size, flags, bitsize) im2.blit(im1, (0,0), r)

Although I usually use this with tilesheets, so r would define a sub-region of the source image in those cases. }}}

Comments (6)

  1. René Dudfield reporter
    • changed status to open


    'works for me' on OSX with latest pygame from tip.

    I modified the program in test.py a little so that it prints information about the surfaces.

    Can anyone else get this to fail for them?

    """hit space to see a "bad" surface on screen"""
    import pygame
    from pygame.locals import *
    screen = pygame.display.set_mode((400,400))
    def test1():
        """make surfaces same format as display"""
        im1 = pygame.surface.Surface((24,28))
        im2 = pygame.surface.Surface((24,28), 0, im1)
        im2.blit(im1, (0,0), im1.get_rect())
        return im1,im2
    def test2():
        """make 8-bp surfaces from image"""
        im1 = pygame.image.load('mini2x.png')
        ## this seems to make an unusable surface
        im2 = pygame.surface.Surface((24,28), 0, im1)
        ## proof1: this does not work
        im2.blit(im1, (0,0), (0,0,24,28))
        ## proof2: even this does not work
        return im1,im2
    test = 1
    print ('test1')
    im1,im2 = test1()
    while 1:
        for e in pygame.event.get():
            if e.type == KEYDOWN:
                test += 1
                if test % 2:    
                    print ('test1')
                    im1,im2 = test1()
                    print ('test2')
                    im1,im2 = test2()
                print "get_flags im1,2:", im1.get_flags(), im2.get_flags()
                print "get_losses im1,2:", im1.get_losses(), im2.get_losses()
                print "get_masks im1,2:", im1.get_masks(), im2.get_masks()
        screen.blit(im1, (0,0))
        screen.blit(im2, (0,30))
  2. Log in to comment