X16PngConverter - now for Windows, Linux and macOS

Johan Kårlin
Posts: 292
Joined: Wed Jun 03, 2020 11:33 am
Location: Kalmar, Sweden

X16PngConverter - now for Windows, Linux and macOS

Post by Johan Kårlin »

New functionality in version 1.2 - Support for macOS and Linux.


This is a cross-platform console application (the user interface is text-based) for Windows, macOS, and Linux. It will convert PNG images to a format that the video controller (VERA) of the Commander X16 can read. Images can also be converted to the X16 Graphics Format (BMX). Both indexed images (which contain a palette) and full-color images are supported. The original file can contain an image or several tiles or sprites with max 256 colors. For conversion of images, the width of the image must be 320 or 640 pixels. Height has no restrictions. For conversion to tiles or sprites, the width and height of each tile/sprite must be specified.

Colors
Bits per pixel (BPP) in the generated file will depend on how many colors the conversion results in. The number of colors might be reduced because the color depth of VERA is limited to 12 bits. In other words, several 32-bit colors in the original image might be converted to the same 12-bit color. Semitransparent colors (0 < alpha < 255) will be treated as solid colors.

Transparency
The first color of the palette might be transparent when rendered by VERA. For example, this is when a sprite is rendered in front of a layer. Therefore it can be crucial which color in the original image will receive index 0 in the generated palette. The selection is made in the following way:
  1. If the original image is indexed (has a palette), the color with index 0 in the original will also receive index 0 in the converted image.
  2. If the user has explicitly stated which color should be the first, this color will receive index 0.
  3. If nothing above applies, the color of the top left pixel will receive index 0.
Output
At least two files will be generated: a binary file with image data and the palette in binary format or the format of assembly source code or BASIC. As a bonus a BASIC program that displays the image/tiles/sprites can be generated.

Installation
Just run the executable file for your system. The files are large because they are self-contained, i.e. the .NET runtime and used libraries are included. This means you don't have to have .NET installed on your computer.

Syntax
X16PngConverter [-help] [FILENAME] {-image|-tiles|-sprites} [-height] [-width] [-palette] [-transparent] [-demo].

Options
  • (No arguments) : Displays this text.
  • -help/-h : Same as above if it is the first argument.
  • FILENAME : If the name of the file is the only argument, the original image will be analyzed to see if conversion is possible and in that case which options that are possible.
  • -bmx|-image|-tiles|-sprites: Set conversion mode (mandatory). For images, the width must be either 320 or 640 pixels.
    -bmx will output a file in the X16 Graphics Format (BMX).
    -image will output two files, one file with raw image data, and a file containing the palette (see -palette below).
  • -height/-h : Set height of tiles or sprites (not used when converting to a bitmap image). Valid values for tile mode are 8 and 16, for sprites 8, 16, 32 and 64.
  • -width/-w : Set width of tiles or sprites, (not used when converting to a bitmap image). Valid values are the same as for height.
  • -palette/-p : Set file format for the destination file that contains the palette. Valid values are:
    bin - a binary file
    asm - text file containing assembly source code)
    bas - text file containing BASIC DATA statements).
    If this option is omitted, all three files will be created.
  • -transparent/-t : Set which color that will have index 0 in the generated palette. The value must be a 32-bit hexadecimal value in the following format: $AARRGGBB where A = alpha, R = red, G = green and B = blue.
  • -demo/-d : Generate a demo program in BASIC. This can be loaded to the emulator by using the -bas option. For example: x16emu -bas mysprites_demo.txt. To run it immediately add the option -run. Using this option will cause a binary palette file to be created.
Examples
  • X16PngConverter : Display help text.
  • X16PngConverter image.png : Analyse image and see if it is possible to convert.
    X16PngConverter image.png -bmx : Convert to the X16 Graphics format (BMX).
  • X16PngConverter image.png -image : Convert to a bitmap image (width must be 320 or 640 pixels).
  • X16PngConverter image.png -tiles -h 16 -w 16 : Convert to tiles with a width and height of 16 pixels.
  • X16PngConverter image.png -image -p asm : Convert to sprites and output palette only as a file with assembly source code.
  • X16PngConverter image.png -image -t $ff88aacc : Convert image with the specified (potentially transparent) color as the first in the generated palette.
  • X16PngConverter image.png -image -demo : Convert image and generate a BASIC demo program named image_demo.txt.
Releases
V 1.0 - Dec 1 2021. First official release.
V 1.1 - Dec 5 2023. Support for converting images to the X16 Graphics Format (BMX).
V 1.2 - July 1 2024. Support for macOS and Linux besides Windows.

Download the latest release here: https://github.com/joolin1/x16-png-conv ... tag/v1.2.0

screenshot.png
screenshot.png (96.24 KiB) Viewed 12164 times
turaco.png
turaco.png (40.55 KiB) Viewed 8704 times
stockholm.png
stockholm.png (56.26 KiB) Viewed 8704 times
#R47 - Converted images are compatible with release 46 of the emulator and KERNAL.
Attachments
samples.zip
(159.29 KiB) Downloaded 426 times
Last edited by Johan Kårlin on Mon Jul 01, 2024 3:39 pm, edited 6 times in total.
kimmi9413
Posts: 3
Joined: Sat Apr 01, 2023 6:29 pm

Heart Re: X16PngConverter

Post by kimmi9413 »

Thank you for this tool.
Works fine. And the demo option is a nice starting point for beginners like me :)
User avatar
Kevin Murphy Games
Posts: 15
Joined: Tue Feb 21, 2023 2:42 pm

Re: X16PngConverter

Post by Kevin Murphy Games »

Looks like a really useful tool.

Thankyou.
yock1960
Posts: 136
Joined: Tue Nov 16, 2021 8:42 pm

Re: X16PngConverter

Post by yock1960 »

This is AWESOME!!! Thanks!
Johan Kårlin
Posts: 292
Joined: Wed Jun 03, 2020 11:33 am
Location: Kalmar, Sweden

Re: X16PngConverter - support for the new X16 Graphics Format

Post by Johan Kårlin »

X16PngConverter now supports the new X16 Graphics Format (BMX). If you use the "-demo" option, a BASIC program is generated that can load and display the image.
Johan Kårlin
Posts: 292
Joined: Wed Jun 03, 2020 11:33 am
Location: Kalmar, Sweden

Re: X16PngConverter - now for Windows, Linux and macOS

Post by Johan Kårlin »

X16PngConverter has become a cross-platform application. It now supports Linux and macOS, not only Windows.
User avatar
ahenry3068
Posts: 1136
Joined: Tue Apr 04, 2023 9:57 pm

Re: X16PngConverter - now for Windows, Linux and macOS

Post by ahenry3068 »

Was looking at your screen. I've got my own convertor I've written (Its under Graphics Apps) .. Was looking at your screen. There's no reason to limit images to a 320 or 640 width. For 8 bit ".BIN's" you can load them into RAM and display them with GRAPH_draw_image. You just have to pass it the proper width and height parameters (It does of course have to fit on the 320x240 screen). Also BMX has no Height/Width restrictions as part of the spec. Though so far the implementations i've seen for decoders (mine included) Only support 320 or less width and 240 or less Height.
Johan Kårlin
Posts: 292
Joined: Wed Jun 03, 2020 11:33 am
Location: Kalmar, Sweden

Re: X16PngConverter - now for Windows, Linux and macOS

Post by Johan Kårlin »

Thanks for pointing this out. Yes it is an unnecessary restriction, especially when considering the existence of GRAPH_Draw_Image. I will change it in next version.
funkheld
Posts: 322
Joined: Mon Feb 26, 2024 11:11 am

Re: X16PngConverter - now for Windows, Linux and macOS

Post by funkheld »

the png images must all be created with the rgb color from the x16 color format, otherwise they are not correct...or are they?

thanks.
greetings
Johan Kårlin
Posts: 292
Joined: Wed Jun 03, 2020 11:33 am
Location: Kalmar, Sweden

Re: X16PngConverter - now for Windows, Linux and macOS

Post by Johan Kårlin »

No, it is not necessary. The colors of the PNG image will be converted to X16 colors, in other words the 8-bit values (0-255) will be approximated with the closest 4-bit value (0-15). Have a look at the example in one of the screen dumps that I have attached in the first post in this thred. There you can see the original colors listed beside the resulting X16 colors.
Post Reply