ham_convert

ham_convert is a freeware (also free for commercial use) graphic converter written by Sebastian Sieczko that can convert a normal jpg/gif/png image to one of the graphic modes of the Commodore Amiga.
It can produce ILBM IFF files (Amiga graphic modes: EHB, HAM6, HAM8, 4/8/16/32/64/128/256-color indexed, PCHG – 4/8/16/32/EHB modes).
This program requires java and should work on any operating system supported by JRE8 or newer (JRE8 is recommended due to JRE11 ui rendering changes).
There are two program versions: stable, and a more frequently updated beta version containing most recent fixes and improvements. Beta version is released to allow users to test newly added features that aren’t yet fully polished to be included in the stable release. This mostly means improved conversion so beta version is recommended for best image quality.

Example HAM6 images are available here.

Contact info (also available in the program – click on the copyright note at the bottom-left of the main window). Please report missing features, incompatibilities, regressions, bugs and any undesired or simply weird behavior. Inclusion of your test pictures and conversion settings will also be really helpful.

I send thanks to the following people who helped me with testing and gave some interesting ideas:
Tomasz Rachwal, cholok

ham_convert 1.3.2

ham_convert 1.3.2

ham_convert 1.3.2 - extra options

ham_convert 1.3.2 – extra options

Features
  • ILBM IFF file generation (HAM6, HAM8, EHB, 4/8/16/32/64/128/256-color modes, DynamicHires-like modes with 2-6 planes as PCHG IFF) with optional lossless compression. Hires and lace flag control is also available.
  • Dithering modes: Bayer, Atkinson, Floyd–Steinberg, Jarvis, Judice, and Ninke, Sierra Lite, 2-row Sierra, 3-row Sierra, Checks (default mode, includes special “lines” and “lines-mixed” versions for HAM6, recommended for interlaced images).
  • Dithering propagation factor selection (5%-100%, most used values: 75%, 85%, 100%, no effect for Bayer and Checks because of lack of error propagation).
  • Dual mode – dual pixel HAM error calculation. This feature exploits dependence of possible set/modify operations of the next pixel on the choice made in current pixel in the same line. Supported in all HAM modes. Testing showed that a two-pixel sequence testing is not enough to react on the coming rapid color change so a more efficient “triple mode” was implemented.
  • Triple mode (HAM6, HAM8) – extension of dual mode with three pixels instead of two. That makes it slower, but much more efficient.
    The principle is to check all possible 3-pixel combinations of HAM operations to better reproduce the source image. Because up to 3 pixels with modify operations are needed to reproduce the source color if all 3 color components differ from the previous pixel in the same line there is a varying “lag” that results in undesired intermediate colors. This lag causes the image to appear slightly blurry horizontally sometimes with garbage pixels at edges called artefacts. Triple mode attempts to better organize set and modify operations to reduce this lag and make resulting image sharper. Use this option for HAM6. Enabled by default since 1.2.2.
    Improved in 1.3.1 beta – added more aggressive variant distributing error more evenly across 3 consecutive pixels (requires LAB error calculation mode).
    Experimental HAM8 version added in 1.3.3 beta.
  • Build-in palette generator using Java Advanced Imaging library. NeuQuant Neural-Net image quantization algorithm is used by default. There are several modes. Mode 0 is a fast single-pass mode for slower computers. Multi-pass modes: 1-safest that doesn’t look great but always gives acceptable result with no side-effects. Other modes eliminate some very similar colors from a bigger palette to make palette more diverse and make room for colors of smaller details that wouldn’t normally appear. Mode 9 is the most aggressive and should be used with caution because it eliminates more colors than other mores and it can make the resulting picture look unnatural.
    Alternative Wu’s color quantizer by Xiaolin Wu is available since 1.3.2 beta.
  • Color reduction is performed only when a source image contains more colors that is allowed in the selected Amiga mode. In OCS modes these colors still need to be converted to 12-bit RGB colorspace, so an image won’t look identical but very close. This allows the user to perform color reduction in a different program and use ham_convert to just save as an iff image.
  • Optional multithreaded HAM6 palette optimization. Attempts to minimize average error by inserting colors from the source image. Unlike previous methods this one performs HAM6 conversion each time to measure how palette modification affects average error. Warning: conversion of a single image might take hours. It was developed before triple mode, LAB colorspace support and wu’s color quantization was added. These features greatly improved image quality and need only a few minutes. Multithreaded HAM6 palette optimization gradually becomes less useful due to its very slow speed.
  • Batch conversion.
  • Importing a palette from a file (JASC palette file format).
  • HAM6 conversion supports more accurrate LAB error calculation mode using CIELAB colorspace instead of RGB. Often produces better results than the old RGB version but is much slower.
    Experimental HAM8 version since 1.3.3 beta.
  • Color mapping in non-HAM indexed modes is performed optionally using a CIEDE2000-based color difference function operating in the CIELAB colorspace.
  • HAM map generation. It’s an image that illustrates what type of operation was used on every pixel of the HAM image. Legend: red – modify red, green – modify green, blue – modify blue, black – set.
  • Error map generation (saved together with the ham map). Brightness represents the color distance between a source color and a calculated color of a ham pixel (normalized to 0-255). Greater distance=brighter pixel.
  • Sample palette files of the various vintage home computers from the 80s like Commodore 64 and Atari 800xl. Use them with the 256-color mode.
  • Notes – fonts may look worse on Linux with OpenJDK, high DPI scaling on Windows 10 requires JRE9 or newer and is not guaranteed to display fully correctly.
Supported modes
  • HAM6 mode – 2 control bits+4 bits of data, 16-color palette, 12-bit color space (Amiga OCS/ECS), multiple dithering methods, checks lines-mixed by default. Note: the most common way to minimize fringing in HAM modes is to oversaturate and overbright the pictures so there are few dark tones close to each other and few tones close to grayscale.
    Recommended options: triple mode, LAB error calculation (aggressive), dithering: checks lines-mixed for 15-bit bitdepth simulation (a dithering method optimized for HAM, Floyd-Steinberg introduces too much HAM fringing due to increased rapid color variability).
  • HAM8 mode – 2 control bits+6 bits of data, 64 color palette, 24-bit color space (Amiga AGA). The only mode supported in the earliest versions of the program. Later work moved into HAM6 and that mode is best supported.
    Recommended options: dual mode.
  • HAM10 mode – 2 control bits+8 bits of data, 256 color palette, 24-bit color space (unfinished Amiga AAA).
  • HAM5 mode – 1 control bit (and 1 hardwired to zero)+4 bits of data, 12-bit color space (Amiga OCS/ECS). Experimental support in 1.3.1 beta. Differences from ham6: red and modify green operations are unavailable resulting in worse quality.
  • 64-color EHB (Extra Half-Brite) mode – 32 colors+the same 32, but with halved brightness, 12-bit color space (Amiga OCS/ECS).
  • OCS/ECS indexed modes – 4-32 colors, 12-bit color space.
  • AGA indexed modes – 64-256 colors, 24-bit color space.
  • Dynamic HiRes – 4/8/16-color palette in hires, 4/8/16/32/64 (EHB) in lores. On pre-AGA Amigas this software mode allowed displaying more than 16 colors in high resolution modes that didn’t support HAM and more than 16 colors at once. PCHG IFF saving is available since 1.3.0 beta (tested viewers: Paint.net – Windows, Visage – Amiga). In 16-color hires mode only max. 7 color changes are supported on real hardware.
    Checks dithering was improved in 1.3.2 beta. New version turned out to be best suited for dynamichires per-line palette changes and is now performs much better that all other dithering types, but is not yet optimized and slow with more than 8 colors per line. It’s recommended for the best quality. Constrained sierra lite is second best in terms of quality.
  • Color bit depth reducer for RGB bit depth reduction (every combination of 1-8 bits per channel).
  • ZX Spectrum mode – 15 colors divided into two palettes: bright1 and bright0. Two colors for every 8×8 pixel block, both from bright1 or both from bright0.
  • ZX Spectrum 8×1 mode available in some ZX Spectrum clones like Timex Sinclair, Pentagon. This mode uses a 8×1 pixel block size to improve the color resolution. The rest is the same as in normal mode.
  • C64 hires and multicolor modes.
  • Commodore Plus/4 hires and multicolor modes.
  • MSX screen2 – 2 colors out of 15 every 8×1 block.
  • VGA fakemode: fake 18-bit hicolor mode used to simulate more than 256 colors at once on a normal VGA card.
  • Sliced variants of HAM and indexed modes – different palette every horizontal line for better color reproduction. Replaced with higher quality DynamicHires modes.
HAM6 conversion steps executed by the program
  • Converting source image to 12-bit RGB
  • Iterational color reduction using Neuquant and similar color removal with configurable strength (pal. gener. mode 0-9, 5 recommended). Starts from 64-color palette, decreases palette size until there are only 16 unique colors.
  • Calculating HAM operation type for each pixel using brute force search with configurable search sequence length (dual mode-2 pixels, triple mode-3 pixels).
    Triple mode (HAM6) – checking 2116 combinations of horizontal 3-pixel groups staring with the current coordinate (out of the 262144-64*64*64 possible combinations only 2116-23*23*4 were determined experimentally to be relevant, out of 23 16 are sets 0-15, modify r-1, r, r+1, g, b-1, b, b+1, where r, g, b are source quantized channel values). Third pixel only needs 4 operations – set closest color, modify r, g, b.
    Finding the lowest error by calculating err(x,y)2+err(x+1,y)2+err(x+2)2 for every combination. Plotting pixel x, y then repeating the same calculation from pixel x+1, y. Effectively results in backward error propagation – err(x+2) is reduced by slightly increasing err(x+1,y) and err(x,y), and err(x+1) is reduced by slightly increasing err(x,y).
  • Optional dithering (checks lines-mixed simulates 15-bit color depth, other types more noticeable and less optimized for HAM).
  • Optional error map and ham operation map saving.
  • Optional IFF image output with lossless compression.
  • PNG image output with lossless compression (all images are saved in the same location as the source image).

Examples
Mielno - original image

Mielno – original image

Mielno - ham8 image on Deluxe Paint 5

Mielno – ham8 iff image (Deluxe Paint 5)

Mielno - ham map (ham8)

Mielno – ham map (ham8)

13 thoughts on “ham_convert

  1. Any chance for Gameboy Color support? It uses 8 palettes, 4 colors per each. Each palette is applied to 8*8 pixel block (tile). Kind of Speccy on steroids since you can have 4 colors per tile and twice as much to choose from. 🙂

    • I can’t promise anything. I will do some research but currently I’m concentrating my work on Amiga modes. Non-Amiga modes aren’t fully implemented and they use an almost brute-force approach to palette generation. Game Boy Color has a palette of 32,768 colors so the number of combinations it too high to check them all. NeuQuant algorithm which I use for color reduction doesn’t work well with less than 16 colors.

      • Oh, I see. I’m not familiar with this stuff so I just asked seeing that there’s support for other 8bit platforms. No problem!

  2. Nice converter! I’ve noticed the IFF saving option being disabled by modes that change the palette on a line by line basis. Would it be hard to implement writing the palette changes as PCHG chunk? Or at least as another simple text format file so it’s possible to convert it to a program/copperlist for the real machine!?

    • I’ve never had time to finish coding the sliced modes. There aren’t fully Amiga-compatible because in reality in 16-color mode not all 16 can be changed and with more colors it gets even worse. According to this document: http://wiki.amigaos.net/wiki/ILBM_IFF_Interleaved_Bitmap#ILBM.PCHG “in laced pictures the changes can only happen on even lines”.
      Number of color changes per line line can be selected in the DynamicHires mode, and in the latest beta version palettes are written to a png image (it was used for debugging but I’ve enabled it in the beta version).
      PCHG IFF support will be added after the current 1.2.0 release.

  3. I have coded a colorcycling effect using palette changes per line starting from a 256 color base palette. I still have problems with horizontal artefacts when the palette changes from one line to the next. I saw in your images there are no such horizontal artefacts. What’s your strategy on minimizing these?

      • The only mode with color changes between lines supported by ham_convert is DynamicHires. Other modes including HAM use single palette. ham_convert is mostly optimized for HAM conversion, DynamicHires conversion still needs more work.
        Color changes calculation (DynamicHires mode):
        -16 unique colors per line.
        -Color changes only every 2 lines (2 successive lines have the same palette).
        for(j=0:number_of_lines-1)
        {
        for(i=0:number_of_changes_per_line-1)
        {
        0.if(j==0)calculate 16-color palette from the source image, else copy palette from line j-2,
        1.prepare 16 palettes with color i,1,...,15 removed (remove 1 color from each one), convert lines j,j+1 of the source image to a new palette and calculate an average color distance between original pixel and converted pixel,
        2.select palette with the lowest average color distance,
        3.swap added color with color at index i,
        3.convert lines j,j+1 of the source image to rgb444 and populate the array with all unique colors,
        4.check all items in the array by putting each one in the empty space of the palette from (2.), convert lines j,j+1 of the source image to a new palette and calculate an average color distance between original pixel and converted pixel,
        5.select palette with the lowest average color distance,
        6.select palette with the lowest error,
        7.convert line to a new palette.
        8.j=j+2
        }
        i=i+1
        }

        More advanced color changes calculation was developed by Trachu for his converter which produces DynamicHires images with less artefacts than ham_convert: https://www.ppa.pl/forum/scena/38042/dynamic-hires-czyli-nowe-otwarcie-mocy-amiga-500

        • Thanks for the detailed explanation! I’ll try it out for future demo projects 🙂 for this particular demo release I ended up skipping the per line color changes as the artefacts were too dirty and the deadline was coming fast.

  4. Ham converter it’s a very beautyful software for project a bitmap graphic.
    I have work for my personal graphics.

Leave a Reply

Your email address will not be published. Required fields are marked *