Problems with png

https://attnam.com/topics/Problems-with-png

The Cathedral of Attnam > Other Coding

#1 Nov 2, 2017, 11:58 am Hide

red_kangaroo

I tried to port over some graphics from CLIVAN, so that we can have eg. mangos for the Dark Forest, but I seem to have screwed up. The game now crashes with the following error message:

ivan/Graphics/Item.png is not in indexed color mode!

Would anyone know where I screwed up and what is possible to do to fix this issue?
#2 Nov 2, 2017, 12:50 pm Hide

vasiliy

your image editor prolly converted png to true-color behind your back (your png is 24-bit one). it is not possible to "fix" it, only do it all again, closely watching for conversions. remember, you cannot have non-256-color pngs for I.V.A.N., and png palette should be left intact too!

p.s.: that is, convert 24-bit png back to paletted one won't work as expected.
#3 Nov 2, 2017, 1:01 pm Hide

vasiliy

here's my console utility to copy graphics. it can load paletted png or pcx file, and writes .new.png files. use it like this:

zgfxcopy.exe Item.png destx desty Item.pcx srcx srcy

here, "Item.png" is destination file, "Item.pcx" is source file, "dest" and "src" are destination and source coordinates in pixels, respectively. it will create "Item.new.png" file with 16x16 tile copied, and will try to do color translation for you.

dunno if it will work right with comm. pngs, tho: for some unknown reason comm. fork has palette written backwards, and color translation code may be confused by that.
Attached files
zgfxcopy.7z (332.21 kb)
#4 Nov 2, 2017, 1:14 pm Hide

capristo

Most images, PNG included, have different modes available.

RGB - any color is allowed
Indexed - only a certain limited subset of colors is allowed (defined as the palette)
Grayscale - only shades of gray allowed

You must have saved it in RGB mode
But be careful because even if you switch back to Indexed, the palette may have changed
#5 Nov 2, 2017, 2:11 pm Hide

red_kangaroo

Thank you both, I'll see what I can manage, then.
#6 Nov 2, 2017, 2:28 pm Hide

4zb4

I believe this is why the recommended approach for graphics editing way back when fejoa was working on CLIVAN was to use IrfanView and GraphicsGale, because GraphicsGale automatically detects and uses the colour index of the image, and IrfanView made it easier to save to PCX (?).
Maybe now that IVAN uses PNGs we could just use GraphicsGale by itself?
#7 Nov 2, 2017, 4:28 pm Hide

fejoa

4zb4 wrote
Maybe now that IVAN uses PNGs we could just use GraphicsGale by itself?

Yeah IrfanView and GraphicsGale respect the pallette. You can definitely use GG on just the PNGs now and save them, it even loads the pallette into the pallette window by default. If you're Linux you can run on wine: https://appdb.winehq.org/objectManager.php?sClass=applic...
#8 Nov 3, 2017, 3:48 am Hide

vasiliy

also, mtPaint is nice to work with pngs too.
#9 Nov 3, 2017, 8:52 am Hide

4zb4

I tested it out with Photoshop today, and while you can get it to work and not ruin the image when saving/editing, it's a pain in the ass to do so. You need to export the color table from the image, then load that as a swatch to ensure you don't use colors outside of the index range. Next you change the image mode from "indexed" to "RGB" for editing, and do your stuff. Then you need to convert the mode back to "indexed" and load the color table you exported earlier again to force it to only use the allowed colors. And THEN you save it as PNG.
Photoshop is a bit overkill for editing like this though.