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