English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 10 March 2016, 01:42   #1
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 881
HAM conversion

I have been re-learning how to program an amiga (See my progress here). When I got up to displaying a HAM image I decided to create a utility to convert png files to raw HAM bitplane and palette data. (I am cross developing on a MAC, testing in Win/FS-UAE/SAE so didn't have any programs that could do HAM conversion).

I couldn't really find much source code out there for doing HAM conversions, so wrote a simple converter myself.

The source code is available in my github repository if anyone is interested. It's pretty simple, and in no-way is the best HAM converter out there, but I thought people might find it interesting.

I would love any tips people have on algorithms for HAM conversion, or pointers to open source code that does a similar thing.

One funny feature my program has, is a brute force attack for finding the base HAM palette. It basically tries 65536 different palette combinations and compares the difference between the generated HAM image and the original. This is obviously very slow, but the results are not so bad.

Here is a sample low-res screenshot from an image I converted. This was done using the brute force palette algorithm and also has floyd steinberg dithering applied:



I think I have a bug somewhere that seems to increase the color intensity the image compared to the original, but I haven't really spent much time investigating that yet.

When I next spend time on this I will probably have a go at doing a sliced ham conversion.
alpine9000 is offline  
Old 10 March 2016, 10:37   #2
thellier
Registered User
 
Join Date: Sep 2011
Location: Paris/France
Posts: 274
Nice :-)

>source code out there for doing HAM conversions,

See my source here (unoptimized but efficient)
http://aminet.net/package/gfx/conv/DatatypeToHam

Alain Thellier
thellier is offline  
Old 10 March 2016, 10:50   #3
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
You can use my picture viewer to directly convert png to ham. It needs AGA, though, because this is HAM8 conversion only. But it's damned fast for what it does. So far only ADPro gave a significantly better visual result
My viewer also has a ham fringe reduction system to display very large images without too much fringing to the left (you see, these horror color lines when scrolling ham images).
Source code is available on request.
meynaf is offline  
Old 11 March 2016, 00:13   #4
invent
pixels
 
invent's Avatar
 
Join Date: May 2014
Location: Australia
Age: 52
Posts: 476
If we had a few (24bit images) to test, I'd be happy to try out a few programs.

I did recently convert some 24bit images to Ham6 with reasonable results. Experimenting with adding some dithering in the conversion via various tools. (PPaint, Brilliance, Photoshop, GraphX, Web Image Guru)

Adding the dither helped remove some of the banding issues.
invent is offline  
Old 11 March 2016, 00:24   #5
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
It looks really good!

Quote:
Originally Posted by alpine9000 View Post
I think I have a bug somewhere that seems to increase the color intensity the image compared to the original, but I haven't really spent much time investigating that yet.
This often happens when you have a source image in gamma space, like a photograph, to which you apply filters that are essentially linear combinations. The solution is to de-gamma first to get the source data into linear space, filter, and apply gamma again, but I'm not sure it's that easy to solve here, where you're dithering to HAM6.
Leffmann is offline  
Old 11 March 2016, 09:04   #6
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 881
Quote:
Originally Posted by thellier View Post
Nice :-)

See my source here (unoptimized but efficient)
http://aminet.net/package/gfx/conv/DatatypeToHam

Alain Thellier
Thanks! I will definitely check it out.

Quote:
Originally Posted by meynaf View Post
You can use my picture viewer to directly convert png to ham. It needs AGA, though, because this is HAM8 conversion only. But it's damned fast for what it does. So far only ADPro gave a significantly better visual result
My viewer also has a ham fringe reduction system to display very large images without too much fringing to the left (you see, these horror color lines when scrolling ham images).
Source code is available on request.
Currently my converter only runs on unix (I don't yet have an amiga). Figured there is no need to write something for the amiga because I guessed there are already heaps of great options. But definitely interested in any tips you can give on how to improve my algorithms.

Quote:
Originally Posted by invent View Post
If we had a few (24bit images) to test, I'd be happy to try out a few programs.

I did recently convert some 24bit images to Ham6 with reasonable results. Experimenting with adding some dithering in the conversion via various tools. (PPaint, Brilliance, Photoshop, GraphX, Web Image Guru)

Adding the dither helped remove some of the banding issues.
As it's currently only a unix command line program not sure if you're able to run it?. It's tricky to test unless you have a mac. I'd be interested to try running my program against pre-dithered images however, so if you have anything that is pre-dithered i'd love to have it.

Quote:
Originally Posted by Leffmann View Post
It looks really good!
This often happens when you have a source image in gamma space, like a photograph, to which you apply filters that are essentially linear combinations. The solution is to de-gamma first to get the source data into linear space, filter, and apply gamma again, but I'm not sure it's that easy to solve here, where you're dithering to HAM6.
Thanks for the tip. I have seen a couple of hints of people applying a gamma factor to the dithered pixels, I will look into it.
alpine9000 is offline  
Old 11 March 2016, 09:10   #7
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 881
Tried running it interlaced:

Unsure how it would look on a real amiga. On UAE the horizontal is obviously doubled to match the increase in vertical pixels, hence the 640x512 res screenshot.



Trying to buy an amiga Harder than I thought it would be.
alpine9000 is offline  
Old 11 March 2016, 09:22   #8
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by alpine9000 View Post
But definitely interested in any tips you can give on how to improve my algorithms.
Can't give you any tip without knowing what your algorithms are


Quote:
Originally Posted by alpine9000 View Post
Unsure how it would look on a real amiga.
Quite good if using a good monitor. HAM artifacts are less visible due to the natural anti-aliasing of CRT monitors. UAE's filters may make things better, even though i didn't investigate in this area.


Quote:
Originally Posted by alpine9000 View Post
On UAE the horizontal is obviously doubled to match the increase in vertical pixels, hence the 640x512 res screenshot.
Can you share your original true color image so that i can make a few tests with it ?

EDIT: Found the image on your GitHub. Now having a closer look...

Last edited by meynaf; 11 March 2016 at 09:35.
meynaf is offline  
Old 11 March 2016, 09:48   #9
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 881
Quote:
Originally Posted by meynaf View Post
Can't give you any tip without knowing what your algorithms are

Quite good if using a good monitor. HAM artifacts are less visible due to the natural anti-aliasing of CRT monitors. UAE's filters may make things better, even though i didn't investigate in this area.

Can you share your original true color image so that i can make a few tests with it ?
Source code to my converter is here:

https://github.com/alpine9000/amiga_...tools/imagecon

Images are in the "assets" folder of the main repository:

https://github.com/alpine9000/amiga_examples/

Direct links:

320x256: (This is the one I used for the non interlaced conversions above)

https://raw.githubusercontent.com/al...ssets/gigi.png

320x512: (Used for the interlaced example)

https://raw.githubusercontent.com/al...gi_320x512.png

640x512: (Only used to create the above)

https://raw.githubusercontent.com/al...gi_640x512.png
alpine9000 is offline  
Old 11 March 2016, 10:06   #10
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Looks nice in 640x512 HAM8. Maybe darker than the original, though.

meynaf is offline  
Old 11 March 2016, 10:09   #11
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 881
Quote:
Originally Posted by meynaf View Post
Looks nice in 640x512 HAM8. Maybe darker than the original, though.
Sure does

Almost 20k colors! I think the original only had 35k from memory.
alpine9000 is offline  
Old 11 March 2016, 10:27   #12
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
It may be possible that the image suffers more from 640x512 to 320x256 downsampling than from color quantization, f.e. the hair looks quite pixelated. The eye is more sensitive to details than to colors anyway.
meynaf is offline  
Old 11 March 2016, 10:50   #13
pandy71
Registered User
 
Join Date: Jun 2010
Location: PL?
Posts: 2,743
Quote:
Originally Posted by alpine9000 View Post
What kind of resampling was used to create those pictures?
I ask due highly visible aliasing problem (and missing data) - consider to apply some AA processing before colour quantization - also HAM results may be better (less abrupt signal) http://avisynth.nl/index.php/Externa...#Anti-aliasing - this mostly for video processing but most of them give excellent results also with pictures - highly recommended!
Be careful with dithering as most of typical dithering methods is not applicable to HAM directly - general dithering assume that pixels are independent where HAM due its lossy coding can't provide this requirement - as such good dithering algorithm need to have information how error will be propagated in line. To simplify this stage you may assume creating regular structure from CLUT pixels (like each 4th pixels is from CLUT) - this will limit error propagation only to at max 3 pixels and also those pictures can be pre-calculated to remove/minimize fringes.
From my perspective algorithm for color selection should apply weighting (corresponding to eye perception), calculation should be performed in linear space (most of RGB sources as pointed Leffmann is non-linear and should be linearised - inverted Gamma before processing), you may also consider to perform some calculations in different than RGB color space (of course at the end of process chain you need to convert to RGB) http://www.imagemagick.org/Usage/col...cs/#processing .
As HAM is limited only in horizontal direction processing can be optimized for single line and as such significantly simplified (error dithering in vertical direction have no penalty). To improve picture consistency i would assume anyway at least two - few lines need to be analysed at the same time.
You may consider adaptive approach with PSNR as feedback or better something like SSIM http://en.wikipedia.org/wiki/Structural_similarity to select best method.

Last edited by pandy71; 11 March 2016 at 14:11.
pandy71 is offline  
Old 11 March 2016, 11:20   #14
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 881
Well spotted guys.

I was using a pixel editor to do the downscaling.

Tried using something better:



quite different compared to the previous one:



@pandy71 - thanks for those links. You have given me lots of homework there
alpine9000 is offline  
Old 29 March 2016, 06:02   #15
invent
pixels
 
invent's Avatar
 
Join Date: May 2014
Location: Australia
Age: 52
Posts: 476
Hi Everyone.

Hopefully the following test/process will be useful.

First the Ham-8, 640x512 IFF image.
Top image has no dither applied (photoshop)
Bottom image has 1 percent Uniform Dither.



Tools used:

Amiga - True Brilliance
Mac - Photoshop, Graphic Converter 9
PC - AmigaForever 2016

First I Sourced the highest resolution/quality image of Gigi (3000x2000 pixels)
File here: http://static.fanpage.it/wp-content/...-484696837.jpg

Process:
Photoshop (Mac)
- Image Interpolation: set to Bicubic Automatic
- Imported into Photoshop (via File/Place)
- Scaled to 107% to best match size of largest test image (640x512)
- Exported at 24bit PNG - 640x512

Graphic Converter (Mac)
- Open Exported PNG file
- Exported as IFF file (Compression RLE)

Parallels Desktop (PC - Windows 10)
- Amiga Forever 2016 Plus Edition
- Open True Brilliance
- Open IFF file
- Save IFF file _TB.iff

Issues:
- Getting any format into True Brilliance, tried various programs such as XnConvert (but only exports as Greyscale IFF files), in discussion with software company at moment trying to resolve it.




Image of all files in zip

All images including Photoshop and 3000x2000 image source.

Google Drive (22MB) Zip file


Other Notes:

- I used AmigaForever to export screen capture images from Brilliance (raw files)

Last edited by invent; 29 March 2016 at 06:17.
invent is offline  
Old 29 March 2016, 07:02   #16
amiman99
Registered User
 
amiman99's Avatar
 
Join Date: Sep 2009
Location: San Antonio, TX USA
Age: 50
Posts: 1,184
These HAM-8 images look very nice.
This brings back some memories when I first saw the Newtek HAM-6 image the "Lady w Scarf", WOW that image looked good on my TV! Memories.
amiman99 is offline  
Old 29 March 2016, 11:54   #17
pandy71
Registered User
 
Join Date: Jun 2010
Location: PL?
Posts: 2,743
Quote:
Originally Posted by invent View Post
Hi Everyone.

Hopefully the following test/process will be useful.

First the Ham-8, 640x512 IFF image.
Top image has no dither applied (photoshop)
Bottom image has 1 percent Uniform Dither.)
Uniform dither shall be at least TPDF (HPTPDF better) with level at least 2 LSB and finally it have no sense (is suboptimal) in case of HAM as HAM is lossy compression (from same reason there is no sense to dither pictures before JPEG encoding).
Proper dithering for HAM must efficiently use CLUT (very important for HAM-6) and efficiently deal delta coding (i.e. way how HAM works - only one delta on one of components allowed at once).
pandy71 is offline  
Old 29 March 2016, 13:33   #18
invent
pixels
 
invent's Avatar
 
Join Date: May 2014
Location: Australia
Age: 52
Posts: 476
Hi Amiman99, I was also trying to see if it's possible to find higher quality images that were used back in the Amiga Ham-6 days and the possibility of making them better quality.

Hi Pandy71, all good information you post, I will note that some info you post goes beyond my knowledge at the moment but is definitely informative, thankyou

My intention for the test images was to see what the cleanest image I could produce without some of the banding (at the sacrifice of file size). It was tempting to combine only some dithering/with transparency on some areas that needed it such as the highlighted sections in the following image zoomed in sections.

invent is offline  
Old 29 March 2016, 14:40   #19
pandy71
Registered User
 
Join Date: Jun 2010
Location: PL?
Posts: 2,743
Problem with HAM is that HAM is lossy model of tha data compression - normal approach to pictures and well known algorithms are designed for non lossy model - in case of HAM using those methods may give suboptimal results as error will be pushed beyond due inherent HAM fringing - HAM error propagate in one direction - from left to right.
http://www.imagemagick.org/Usage/quantize/#colors
http://www.imagemagick.org/Usage/quantize/#dither_error
http://www.imagemagick.org/Usage/qua...ordered-dither
Only ordered dithering (and maybe Ulichney matrix) may prevent such situation or algorithm need to trace HAM distortions (so error feedback to quantizer must be after HAM encoding and HAM decoding).
CLUT selection may be done with http://www.cs.berkeley.edu/~dcoetzee/downloads/scolorq/ or perhaps http://members.ozemail.com.au/~dekker/NEUQUANT.HTML
Rest of conversion is unique for Amiga.
Also proper processing assume operations in linear space (i.e. normal RGB is not linear - it is after gamma correction and as such inverted gamma must be applied to RGB and this unavoidable lead to increased bit depth - usually for 8 bits 12 - 16 bit is OK).
http://www.imagemagick.org/Usage/resize/#techniques
Also different color space (different than RGB may give better results).
pandy71 is offline  
Old 20 February 2019, 22:22   #20
AJO_MoonTurtle
Registered User
 
Join Date: Feb 2019
Location: Chippewa Falls, WI
Posts: 4
I was wondering if there was a PNG/BMP to Amiga graphics converter for Windows?

I was thinking of an Amiga equivalent to Atari Image Workshop or Buckshot.

And I don't mean one that has to be run within an emulator
AJO_MoonTurtle is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ham videos Zooup1972 support.Apps 17 19 April 2015 00:35
Amiga HAM Si-Pie Amiga scene 12 13 November 2008 23:50
HAM pictures jviper New to Emulation or Amiga scene 2 24 March 2006 01:03
HAM Demo Frazor request.Demos 2 06 August 2003 14:36

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:14.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09956 seconds with 13 queries