Looking for a <modern image format> to bitmap tool (python, preferably)

handy tools that can assist in the development of new software
Post Reply
thoughstar
Posts: 12
Joined: Wed Jul 15, 2020 10:43 am
Location: Oslo, Norway
Contact:

Looking for a <modern image format> to bitmap tool (python, preferably)

Post by thoughstar » Wed Jul 22, 2020 10:53 pm

Hi,

I'm looking for a tool, preferably python (but anything that will compile on a mac/linux/wsl will do) that takes
as input a PNG/BMP/JPG/GIF/RAW and a RISC OS screen mode and outputs a bitmap with colours that closely match the "default" palette for said mode (e.g. 13).

Does such a thing exist? Or what is the preferred method for converting a bunch of files to something that can easily be stmfd'd to screen memory?

Tor

User avatar
kieranhj
Posts: 921
Joined: Sat Sep 19, 2015 11:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Looking for a <modern image format> to bitmap tool (python, preferably)

Post by kieranhj » Wed Jul 22, 2020 11:09 pm

I’ve got a png2arc Python script but it only works for MODE 9 and requires input PNG images with <= 16 colours. It does spit out a separate 64 byte file with the colour palette values at least.

https://github.com/kieranhj/stniccc-arc ... png2arc.py

It’s been on my list to do a MODE 13 version for a while but not got around to it. Probably worth asking Sarah Walker what she used for Horizon & Reach demos.
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

VectorEyes
Posts: 378
Joined: Fri Apr 13, 2018 2:48 pm
Contact:

Re: Looking for a <modern image format> to bitmap tool (python, preferably)

Post by VectorEyes » Wed Jul 22, 2020 11:19 pm

If you can stand an hour or two of learning how to use it, then Imagemagick will do exactly this sort of thing. You can give it one image which is the 'source', another image which contains all the colours in your target palette, and it will spit out an image that contains only target palette colours. Plus you get a lot of control over the dithering options.

It's usable from the command line and has bindings for python, C# and probably a vast amount of other languages.

I found this page very useful when I was working out how to use it to generate and/or preprocess images for our latest BBC Master demo:

http://www.imagemagick.org/Usage/quantize/

If you search for 'Dither using Pre-Defined Color Maps' on that page you'll find the example of how to quantise an image to a specified set of colours.

VectorEyes
Posts: 378
Joined: Fri Apr 13, 2018 2:48 pm
Contact:

Re: Looking for a <modern image format> to bitmap tool (python, preferably)

Post by VectorEyes » Wed Jul 22, 2020 11:25 pm

Oh, when you say 'to bitmap' do you mean to a sequence of bytes that matches the Archimedes screen memory layout for the appropriate screen mode? Obviously Imagemagick won't help with that directly, but you can use it to extract specified pixels from the image in <scripting language of choice> and then reconstruct the 'bitmap' to another file. Personally I'm a bit fan of using C# plus Magick.NET (very easy to knock up little command-line tools for image-manipulation and image creation!)

User avatar
kieranhj
Posts: 921
Joined: Sat Sep 19, 2015 11:11 pm
Location: Farnham, Surrey, UK
Contact:

Re: Looking for a <modern image format> to bitmap tool (python, preferably)

Post by kieranhj » Wed Jul 22, 2020 11:27 pm

Thanks. That would still be really useful actually as you’d end up with a PNG just containing the correct 256 colours for MODE 13. It would be easy to extend the above Python script to output the correct byte encoding for loading directly into MODE 13 screen buffer.

I don’t really want to be reinventing the wheel when it comes to dithering etc. when all this has been done many times and by people that know it much better than I.
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

Post Reply

Return to “development tools”