FloreaStefan 0 Newbie Poster

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_code((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/f...2/1/f_968101145 <- This is how the image should look like

http://www.box.net/f...2/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 pygame
import os

# initialize headless pygame
os.environ["SDL_VIDEODRIVER"] = "dummy"
pygame.init()
pygame.display.set_mode((1,1))

# create image buffer
SCREEN = pygame.Surface((640, 480)).convert()

# load a simple image
sprite = pygame.image.load("Assets/Sprite/spriteTest.jpg").convert()

# display it on the buffer
SCREEN.blit(sprite, (0,0))

# save the buffer 
pygame.image.save(SCREEN, "Assets/Output/spriteResult.jpg")

Regards,
Florea Stefan.