[PYGAME - SOLVED] Problem with headless window

This topic is 2630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello, I am trying to make an application that will run a simulation on a headless server. In short, it does the following: 1. load an image from the database 2. display a text as an overlay on top of the image 3. capture the 'screen' and save the image back to the database The problem is that when saving the image back to the database I loose a lot of colors! But only when running the simulation headless.Here is the part where I initialize pygame and tell to create a headless application: os.environ["SDL_VIDEODRIVER"] = "dummy" pygame.init() pygame.display.set_mode((1,1)) Here is the part where I create the 'screen' buffer GS._SCREEN = pygame.Surface((640, 480)).convert()The main algorithm is something like this:def MainLoop(): GS._SCREEN.fill([255,0,0]) # clear the buffer GS._SCREEN.blit(sprite, (0,0)) # display something on the buffer pygame.image.save(GS._SCREEN, "path/to/directory") #save the image back in the database pygame.display.flip()http://www.box.net/files#/files/0/f/104328302/1/f_968101145 <- This is how the image should look likehttp://www.box.net/files#/files/0/f/104328302/1/f_968100995 <- This is how it actually looks after it is saved. As you can see it has less colors.REMARK: if am not using a headless window, the image is saved CORRECTLY!Here is the whole code:import pygameimport os# initialize headless pygameos.environ["SDL_VIDEODRIVER"] = "dummy"pygame.init()pygame.display.set_mode((1,1))# create image bufferSCREEN = pygame.Surface((640, 480)).convert()# load a simple imagesprite = pygame.image.load("Assets/Sprite/spriteTest.jpg").convert()# display it on the bufferSCREEN.blit(sprite, (0,0))# save the buffer pygame.image.save(SCREEN, "Assets/Output/spriteResult.jpg")Regards,Florea Stefan.

EDIT: It turns out that the error was in the pygame.image.load(). It did not load correctly the images. Perhaps it is a pygame bug.
If I use a different loading mechanism(PIL or OpenCV) everything works as expected.
My guess is that when using a headless application, the mechanims inside pygame.image.load() changes

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• Forum Statistics

• Total Topics
633759
• Total Posts
3013715
×