Log In  

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

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

P#145217 2024-03-31 06:38 ( Edited 2024-04-08 03:34)

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!

P#145266 2024-03-31 17:09

@CaptManiac
The save button is in the menu

P#145267 2024-03-31 17:17

@Cutievirus

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

P#145578 2024-04-03 14:34
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

P#145580 2024-04-03 15:07

Hooray, thanks!

P#145715 2024-04-04 20:49

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

P#145874 2024-04-06 03:13 ( Edited 2024-04-06 03:14)

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!

P#145920 2024-04-06 19:09

@369369369
I'm not getting any crashes on my end, maybe it's something about the png you're feeding it?

@Mushkrat
The memory location for the palette is mentioned in this document
https://www.lexaloffle.com/dl/docs/picotron_gfx_pipeline.html#Display_Palettes

P#145983 2024-04-07 16:06
1

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

P#145984 2024-04-07 16:27

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!

P#145990 2024-04-07 18:17 ( Edited 2024-04-07 18:34)

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.

P#145994 2024-04-07 21:07

[Please log in to post a comment]