14 March 2020, 23:49 | #1 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,209
|
Conversion of 24bit RGB Image to HAM6
Anyone have a good and quick algorithm for this? ideally one that can uses a fixed 16 colour base palette
|
14 March 2020, 23:50 | #2 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,209
|
or 12bit 0x0RGB format to HAM6 too would also be ideal
|
15 March 2020, 08:12 | #3 |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Simplest algorithm, ignoring dithering, just process each line, walking from left to right picking which pixel is the closest perceived distance to the original pixel from either a colour in the palette, or the previous pixel with HAM offset.
I played with HAM conversions here (including a converter with dithering) https://github.com/alpine9000/amiga_..._ham/README.md |
15 March 2020, 09:29 | #4 |
Registered User
Join Date: Feb 2011
Location: Italy/Rome
Posts: 2,281
|
Just an idea: what about Dynamic Low-res were you can have 32colors for each line?
|
15 March 2020, 11:08 | #5 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,214
|
If the palette is fixed, then this sounds a bit like an application of a Viterbi algorithm to me. Walk the line from left to right, and for each pixel consider four possible alternatives: Pick a color from the palette, or modify red, or green, or blue. Record for each selection the error in terms of color, label the edges of a decision tree with them, continue to the right edge, then backtrace the path with the least possible error. You'll find a lot on google on Viterbi. If the palette is not fixed, a heuristic would be to first select a suitable palette by the k-means algorithm, and then continue from the above. It is then not necessarily the ideal palette, but it should work out.
|
15 March 2020, 12:20 | #6 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,209
|
|
15 March 2020, 13:48 | #7 | |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,209
|
Quote:
|
|
15 March 2020, 13:52 | #8 | |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,209
|
Quote:
Thanks, wil try this too... is their a method for weighting distance on colour perception ? (ie.. green error is more perceivable than red, which is more than blue.. i believe it some where around 35:50:15 in terms of percentage for R:G:B) |
|
15 March 2020, 15:12 | #9 |
Registered User
Join Date: Dec 2014
Location: germany
Posts: 439
|
The wikipedia page on color distance has some useful formulas: https://en.wikipedia.org/wiki/Color_difference
If you cannot afford the square root or a table lookup for it, 3*delta_R + 4*delta_G +2*delta_B gives a cheap approximation. |
15 March 2020, 22:56 | #10 | |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Quote:
|
|
16 March 2020, 08:43 | #11 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
I used 2R, 3G, 1B approximation for my ham8 renderer and it gave good quality and speed.
If you want to convert to ham (regardless if this is ham6 or ham8) you have two ways of doing. The fast way uses static decision method : instead of computing which pixel type you use, this depends on the pixel position. Of course quality is low but it might be enough, depending on the use case. The slow way uses adaptative decision. You compute error for fixed, red, green, blue pixel types. To find out the closest fixed pixel, making 16 computations (64 for ham8 !) is too slow so you can use a 12-bit approximation to read the closest index in a 4096-entry table. You're then left with 4 error level comparisons. |
16 March 2020, 09:05 | #12 |
Registered User
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,544
|
|
16 March 2020, 09:32 | #13 |
Registered User
Join Date: Feb 2010
Location: Espoo / Finland
Posts: 818
|
|
16 March 2020, 10:21 | #14 |
Lemon. / Core Design
Join Date: Mar 2016
Location: Tier 5
Posts: 1,209
|
|
16 March 2020, 11:37 | #15 | |
Registered User
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
|
Quote:
You can find all code for ARGB to HAM6/8 conversion in my source code, but I have to warn you, since it's merged with conditional compilation together with TCdraw an all my other versions and spread over several locations with many dependencies and references. It's very hard to read and understand my confusing code. You will probably not need to care for any alpha channel or transparency, nor to take system, MWB or mouse pointer colors into account. Look for "HAM8imagedrawing" in my source if you are courageously enough to fight with complex chaos. |
|
16 March 2020, 12:48 | #16 |
Registered User
Join Date: Sep 2011
Location: Paris/France
Posts: 274
|
Use my prog it give excellent results
http://aminet.net/package/gfx/conv/DatatypeToHam Sadly it use lots of RAM so run it with WinUAE |
16 March 2020, 13:22 | #17 | ||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
Quote:
But you can find my aga picture viewer from this page if you want to perform speed and quality comparisons. |
||
16 March 2020, 14:13 | #18 | |
Registered User
Join Date: Apr 2005
Location: digital hell, Germany, after 1984, but worse
Posts: 3,365
|
Quote:
http://eab.abime.net/showthread.php?t=64079 Thanks, I have no doubts about the quality and speed of your picture viewer and I know it, although I mostly use TrueColor screens. HAM is just for fun. Last edited by PeterK; 16 March 2020 at 14:18. |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Sculpt animate 4D raw RGB files conversion | christianlucio | support.Apps | 13 | 11 December 2021 14:07 |
Command line image conversion tools | roondar | Coders. General | 16 | 17 August 2021 12:43 |
Image conversion from RGB to indexed color | sparhawk | Graphics | 3 | 15 January 2020 21:53 |
DB25 to DB23 (RGB Connector) DIY Conversion | Nightshft | support.Hardware | 4 | 11 April 2019 13:06 |
Batch conversion of Truecolour images to HAM6 | earok | support.Apps | 0 | 20 May 2015 11:02 |
|
|