[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Image file formats with palettes
On Wed, Aug 04, 2004 at 08:08:56PM -0000, Zak Arntson wrote:
> I'm trying to read images from a file, and use palette swapping/shifting.
> So far the only format I can find that supports palettes is gif. I'm
> creating images in MSPaint, which is limiting me to jpg, gif, bmp, tiff
> and png. I'd _love_ to use png, but I can't get it to work without loading
> a dummy gif and using convert().
>
> My question is then: Is there a way to convert a surface to one with a
> palette without resorting to gifs? I've tried stuff like:
>
> img = pygame.Surface((40,40), HWPALETTE)
>
> But it's not working. Which makes sense, I mean, I'm not identifying what
> _kind_ of palette I'd like.
>
> Thanks in advance!
>
> ---
> Zak Arntson
> www.harlekin-maus.com - Games - Lots of 'em
Try using paletized pngs (use GIMP or ImageMagick to convert to indexed
color, then save).
(If you want to do it without using a tool like GIMP or ImageMagick, you
could try:
- making a surface
- making code to map colors to a palette
- loading a palette from somewhere
- mapping each pixel onto the pallete (and storing in the mapped surface
that you made previously)