English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 14 February 2020, 16:03   #1
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,437
Question Converting a given palette to Extra Half-Brite

I've been wondering lately how you'd properly convert colours to an EHB specific palette. For non-EHB I can think of several approaches, but for EHB I'm kind of stumped on how to deal with the half-bright colours.

Are there any good algorithms available for this (including source)?
I did try to find some on EAB, but my search-fu was not particularly good so I found lots of threads on EHB in general.
roondar is offline  
Old 15 February 2020, 13:10   #2
Solo Kazuki
Registered User
 
Solo Kazuki's Avatar
 
Join Date: Sep 2004
Location: Poland
Posts: 1,305
To reduction colours in specific picture, i was using PPaint, which have good palette reduction parameters.

But i suppose it's for overall work, not one picture?
Solo Kazuki is offline  
Old 15 February 2020, 13:50   #3
chb
Registered User
 
Join Date: Dec 2014
Location: germany
Posts: 439
I used (for another color reduction problem, not EHB) a modified k-means algorithm, where I substituted the euclidean distance by a custom distance function. I guess in the case of EHB, the centers would be your 32 direct palette colors, but when computing the distance to a pixel color, you'd use the min of the distance to the direct color and the associated half brite color.

It's a bit of a sloppy approach, because all the convergence theorems etc. for k-means assume euclidean distance, but for me it worked reasonably well. K-means is quite slow, however, so it's rather not well suited if you want to write something running on the Amiga.
chb is offline  
Old 15 February 2020, 14:06   #4
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,437
Quote:
Originally Posted by Solo Kazuki View Post
To reduction colours in specific picture, i was using PPaint, which have good palette reduction parameters.

But i suppose it's for overall work, not one picture?
Well, I want to convert a whole bunch of pictures (on the order of 200-300). I suppose I could use PPaint for it, but I thought it might be simple to just make a small program that does it manually.

I also had a look at http://tool.anides.de/ but that doesn't actually convert to EHB. It claims to do so, but the results are identical to the 32 colour version it generates
Quote:
Originally Posted by chb View Post
I used (for another color reduction problem, not EHB) a modified k-means algorithm, where I substituted the euclidean distance by a custom distance function. I guess in the case of EHB, the centers would be your 32 direct palette colors, but when computing the distance to a pixel color, you'd use the min of the distance to the direct color and the associated half brite color.

It's a bit of a sloppy approach, because all the convergence theorems etc. for k-means assume euclidean distance, but for me it worked reasonably well. K-means is quite slow, however, so it's rather not well suited if you want to write something running on the Amiga.
This makes me wonder how the old Amiga programs did this. I can't imagine them using something this slow.

Anyway, I must confess my own ideas where considerably simpler. I was looking at something more along the lines of modifying existing code like https://rosettacode.org/wiki/Color_quantization/C

Perhaps it's more efficient to select an existing program and scripting around it so it can do the slew of images I want to try. Which leads to the obvious question: which program is the best bet here. Probably an Amiga one, as I don't suppose modern programs support EHB output in any meaningful way.
roondar is offline  
Old 15 February 2020, 17:47   #5
chb
Registered User
 
Join Date: Dec 2014
Location: germany
Posts: 439
If you want to use an existing program, then there's also hamconvert
which, despite the name, supports EHB and has a batch mode.

PS: Rosetta code has an example of color quantization using k-means - unfortunately it is written in J, which at least for my eyes looks quite similar to banging your head on the keyboard. But it's very short!

Last edited by chb; 15 February 2020 at 17:53.
chb is offline  
Old 15 February 2020, 21:02   #6
Hewitson
Registered User
 
Hewitson's Avatar
 
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 41
Posts: 3,773
Wow. J looks almost as bad as Brainf**k. Completely unreadable and unusable language.
Hewitson is offline  
Old 15 February 2020, 22:51   #7
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,437
Yeah, J is something else. Give me 68000 assembly any day over that!

I'll be checking out HAMconvert. See if that actually does create 64 colour images when converting to EHB
roondar is offline  
Old 15 February 2020, 23:21   #8
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 882
You can see here where I gave it a go to create an EHB converter:

https://github.com/alpine9000/amiga_...r/011.ehb_mode

I didn't really expend much effort at the time as EHB wasn't something I really saw myself using much.
alpine9000 is offline  
Old 15 February 2020, 23:32   #9
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,437
Thanks, I'll check it out!
roondar is offline  
Old 17 February 2020, 03:46   #10
Hewitson
Registered User
 
Hewitson's Avatar
 
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 41
Posts: 3,773
alpine9000, do you have any ideas how the code could be improved to make better use of EHB?

Not necessarily asking you to actually make the changes, I'm happy to have a play around with it.
Hewitson is offline  
Old 17 February 2020, 08:53   #11
Antiriad_UK
OCS forever!
 
Antiriad_UK's Avatar
 
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 418
The pic to raw converter I use (KingCon by Hannibal/Lemon.) has a EHB conversion option. Not sure what it does but I can run a picture through it and spit out the raw + dc.w palette data if you have a test picture handy?
Antiriad_UK is offline  
Old 17 February 2020, 09:22   #12
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 882
Quote:
Originally Posted by Hewitson View Post
alpine9000, do you have any ideas how the code could be improved to make better use of EHB?

Not necessarily asking you to actually make the changes, I'm happy to have a play around with it.
I am pretty sure my code just picks the “best” 32 colour palette, then does a quantisation of the original image with the 32 colour + 32 half bright colours.

Off the top of my head, I guess two ways to improve it would be picking the base palette with the intelligence that half bright colours exist and also taking advantage of the half bright colours in a more sophisticated way (like being used in a dithering algorithm for example).
alpine9000 is offline  
Old 17 February 2020, 10:41   #13
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,437
I'm going to be using hamconvert for now (which is a very nice tool, by the way). Writing a proper colour quantisation algorithm for EHB is probably going to take more time than I want to spend on it at the moment.

As for the why I'd want to.. Well, I've always been fascinated by EHB and don't always like the "HAM look". So I want to experiment a bit with images converted to EHB instead and see how that ends up.

Last edited by roondar; 17 February 2020 at 11:08.
roondar is offline  
Old 17 February 2020, 13:05   #14
invent
pixels
 
invent's Avatar
 
Join Date: May 2014
Location: Australia
Age: 53
Posts: 476
Hi Roonar, I remember converting Rygar graphics to HalfBright mode. One of my approaches was to go to the export gif option in photoshop and here you can lock colours. Another setting first needs to happen, that is display most commonly used colours first, from this I’d then try to Eliminate colours that are very close in rbg value. The aim of course was to get 64 colour palette exported.

Other option was to import the arcade graphics as a 256 colour image into Brilliance and let it convert. Happy to share what I came up with.

By the way if you want any of us to experiment with converting graphics with a particular palette in mind please share the file

Good luck and look forward to seeing what you come up with
invent is offline  
Old 19 February 2020, 16:48   #15
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,437
Once I have something, I'll be sure to share it. But it may be a while yet
roondar is offline  
Old 20 February 2020, 16:23   #16
NorthWay
Registered User
 
Join Date: May 2013
Location: Grimstad / Norway
Posts: 853
I'd like to see a dynamic/sliced EHB converter/viewer for OCS...
NorthWay is offline  
Old 21 February 2020, 00:04   #17
invent
pixels
 
invent's Avatar
 
Join Date: May 2014
Location: Australia
Age: 53
Posts: 476
Thought I'd post the experimentation of HalfBright for Rygar, If nothing else was an interesting process of reducing arcade colours (256?) down to 64.

The example at top left of the lava enemy shows 3 colours replaced using the darker versions., considering its only two red colours in the 32 colour palette it works pretty well.
Attached Thumbnails
Click image for larger version

Name:	Screenshot 2020-02-21 08.57.57.jpg
Views:	363
Size:	234.1 KB
ID:	66262  
invent is offline  
Old 24 February 2020, 19:40   #18
TCH
Newbie Amiga programmer
 
TCH's Avatar
 
Join Date: Jun 2012
Location: Front of my A500+
Age: 38
Posts: 372
Perhaps you can use my image converter? (http://bgafc.t-hosting.hu/prgv.php?p=2)
If you have a palette which you want to convert into EHB, then you can just save an image with it and convert it with the converter.
TCH is offline  
Old 05 July 2020, 15:18   #19
ImmortalA1000
Registered User
 
Join Date: Feb 2009
Location: london/england
Posts: 1,347
I used HAMconvert to do some SF2 arcade full widescreen mockups in EHB and they look fantastic. And if you was actually going to try and code it you would actually use the copper at least once and edit the arcade palette a bit (like Dhalsim's graduated floor of stone and carpet) for better colour reduction and even on SCART RGB you would be hard pressed to tell arcade images and EHB images displayed in Dpaint 4 by your A1200

I would upload them but if you saw them you would probably go to the founder of US Gold's mansion and do illegal things to him, which I don't condone!
ImmortalA1000 is offline  
Old 11 July 2020, 06:33   #20
AmigaHope
Registered User
 
Join Date: Sep 2006
Location: New Sandusky
Posts: 944
Stupid and definitely-not-optimal algorithm I came up with a long time ago that seemed to work pretty well:

Work in HSV space. Find median brightness value, quantize brightest half to 32 colors with your favorite palette-reduction algorithm, quantize darkest half to 32 colors too. Arrange results in 3D HSV space. Find nearest neighbors in HSV space between both sets with V*2 for second set, average all values between nearest neighbors (then dividing V by 2 again for the halfbrite set). Take this as your final palette and requantize original image to it. This produces pretty good pictures as long as the brighter colors do not have wildly different hues from the darker colors.

Last edited by AmigaHope; 12 July 2020 at 09:52.
AmigaHope 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
Query about Extra Half-Brite (EHB) Foebane Amiga scene 15 13 September 2015 12:18
Lost half of my harddrive...? Firestone support.Hardware 12 28 August 2013 08:05
THROW IN 2nd HALF: Announced TheFoxSoft Retrogaming General Discussion 4 24 April 2012 10:37
Can only view half a scanned page tim_calladine AMR data problems 9 01 October 2008 17:22

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 06:55.

Top

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