General Category => Programming => Topic started by: zhulien on 03:34, 04 October 21
Hi,has anyone written logic for PNG loading on a CPC,or better still... in PHP taking a PNG file and converting it to CPC (Mode 1 is preferable, but possibly mode 0).
Something like this but in PHP, not GO
I've done something in JAVA that accepts any 160x200 image and converts it into a SCR file (MODE 0). Very simplistic and not much more than a script. I can post the source code if that helps to understand the process.
I had a program (not written by me) that converted BMP to CPC. I'll see if I can find that.
Edit: Found it: https://www.cpcwiki.eu/index.php/ConvImgCPC
Quote from: zhulien on 03:34, 04 October 21Something like this but in PHP, not GOYou can run the martine shell executable from PHP.
El CPC Paint included on JavaCPC works quite well.
EDITO: Oh, I missed the PHP part of thew request :picard:
I have put in place some image processing for PNG to an output, the output i can write whatever i choose - either a CPC sprite in a given mode.
This is only a POC, it is doing the first bit consisting of a bit of my code and another service.
I was thinking if Open Street Maps is available for CPC, it could be useful for some games. I have specifically locked the coordinates, for now but you can play with the zoom level.
It is retrieving a PNG, but ultimately it would have the option to retrieve a CPC-compatible sprite. I have fixed the tile size to 200x200pixels which fits nicely in Mode 1. I am thinking Mode 1 has enough colours to make the map recognisable still.
https://8bitology.net/poc/cpcmap/cpcmap.php?zoom=16 (zoom is valid between 0 and 19).
The terrain option uses a different 3rd party service again that likely I cannot redevelop.
https://8bitology.net/poc/cpcmap/cpcmap.php?zoom=15&style=terrain (zoom is valid between 0 and 15)
btw, if i were to make a game, I would either use Mode 1 with the map to the right or left leaving 120 pixels for menus, scoring, statuses etc (thinking Red Alert on a global scale)... or a vertical orientation like Arkanoid could work too. Being Vertical would make it easier to switch between tiles of eg: streets (4 colours) vs terrain (16 colours) with a split mode for scores etc.
Once converted to CPC sprite and compressed (RLE?) then the file sizes should be very small, and the M4 can quickly transfer them to SD Card for CPC's local caching.
https://8bitology.net/poc/cpcmap/cpcmap.php?zoom=8&style=terrain (https://8bitology.net/poc/cpcmap/cpcmap.php?zoom=8&class=bbc_linktarget=_blankrel=noopener) (perhaps terrain would look better in mode 0?)
The 3rd image below is equivalent to the 200x200 one, but double-width pixels of mode 0 (on CPC it would be 100x200).
To map RGB values from a PNG to the CPC pallet, what would be a good algorithm for colour reduction?