Log In  


Cart #pngframe-3 | 2024-04-08 | Embed ▽ | License: CC4-BY-NC-SA
27

Import PNG images and generate optimal palette

Can import png to fit picotron default palette, custom palette imported through hex file, or custom palette generated for the png file.

For best results, reduce the png to 64 or fewer colors in an external program such as gimp. This isn't required, but will save you some time waiting for the palette to generate and will allow you to use dithering.

If the imported png has less than the "max colors" value and is set to generate palette, the generation step can be used and the image's colors can be used as-is.

The generated palette is also sorted to attempt to fit the current palette. Colors in the generated palette are moved to the location of similar colors on the loaded palette. For example, black will attempt to stay black, and white will attempt to stay white.

If generate palette is turned off, the image will be made to fit the current palette (either picotron's default palette or an imported hex palette)

Lab color space can be selected for more accurate color matching, but increases generation time. The selected color space affects both palette generation and color sorting.

After generating you can save the image as a userdata pod. The generated palette is attached as metadata so the image can be opened in Paint with the correct palette.

See also pancelor's unrelated but similar cart, import png

Update 1.1

Added seed field so the generated palette can be deterministic
Added ability to import pal files exported from OkPal

Update 1.2

Added "palette format" option to choose whether the palette in the metadata will be in hex format (text) or pal format (userdata).
Added "keep colors" field. Specify a number of colors that will be left unchanged when generating the palette. If set to 32, the generated palette will occupy only the second half of the palette
Added ability to re-open previously saved images (pod files)
Added ability to save and open gfx files, and to save pal and hex files.
Improved color sorting
Added ability to copy generated image with ctrl+c, it can be pasted into the gfx editor

27


1

Very nice! I love taking photos and converting them with this to see the results. You say:
"After generating you can save the image as a userdata pod. The generated palette is attached as metadata so the image can be opened in Paint with the correct palette."

How do you do this (save as userdata pod)? Thanks!


@CaptManiac
The save button is in the menu


@Cutievirus

Sorry for the noob question, but how can I use the generated palette in my code?


1

@saguizin
the palette is exported as metadata in hex format (a list a hexadecimal values separated by newlines)
the metadata is returned as the second value from fetch

content, meta = fetch(filename)
palette = meta.palette

you can look at PalMan for an example of how to apply the hex file.

I’m considering also adding an option to export the palette in pal format (Like OkPal uses) but for now it only exports hex format


Hooray, thanks!


It's crashing Picotron each time I drop a png in it


Hey! How did you find out that memory location for defining the RGB values for the palette? I haven't seen anything on the wiki or the manual about that!



1

I believe it crashes if the image is larger than 480x270.


I can confirm I just gave it a larger image.
Maybe checking if the image is of a proper size and then showing an error message could be beneficial.
Also I couldn't find a way to copy the image into the sprite editor so I just used importpng :(
But besides that, it's great that your cart lets you change the palette to view the image properly, good job on this one!


I tried with a 1280x720 image and aside from taking a while to generate and being too big to fit on the screen it worked fine for me, I think it still must be something else.

I'm running the latest version of picotron (v0.1.0e) on windows 11, and so far every png file I've thrown at it has worked, and fake png files (any other file renamed to png) produce error messages as expected but don't crash picotron.



[Please log in to post a comment]