Sign in to follow this  

[PYGAME - SOLVED] Problem with headless window

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:[code] os.environ["SDL_VIDEODRIVER"] = "dummy" pygame.init() pygame.display.set_mode((1,1))[/code] Here is the part where I create the 'screen' buffer[code] GS._SCREEN = pygame.Surface((640, 480)).convert()[/code]The main algorithm is something like this:[code]def MainLoop(): GS._SCREEN.fill([255,0,0]) # clear the buffer GS._SCREEN.blit(sprite, (0,0)) # display something on the buffer, "path/to/directory") #save the image back in the database pygame.display.flip()[/code][url=""][/url] <- This is how the image should look like[url=""][/url] <- 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:[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, "Assets/Output/spriteResult.jpg")[/code]Regards,Florea Stefan.

[b]EDIT: [/b]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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this