delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/21/14:16:32

From: "John Dough" <noone AT nowhere DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: What is a good palette for 8-Bit Grafix?
Date: Thu, 21 Oct 1999 15:50:36 +0200
Organization: Adamastor
Lines: 95
Message-ID: <7un5pf$lcs$1@news.adamastor.ac.za>
References: <7uhdij$sfb$1 AT rohrpostix DOT uta4you DOT at> <380D499C DOT F017D7D8 AT snetch DOT cpg DOT com DOT au> <380E052C DOT 11DC03E9 AT gtcom DOT net>
NNTP-Posting-Host: n90.narga.sun.ac.za
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Krogg wrote in message <380E052C DOT 11DC03E9 AT gtcom DOT net>...
>Michael Abbott aka frEk wrote:
>>
>> Heya
>>
>> What immediately comes to mind is using a palette sort of truecolor
like... ie.
>> Instead of for example the hicolor 5-5-5 palette, within 8 bits you use a
3-3-2
>> palette which means 3 bits of red, 3 for green, 2 for blue...
>> Short program:
>>
>BLA BLA BLA...sorry,you was making my head hurt.
>
>Lookhere feller,since you seem to know so much about
>colors and stuff,why dont you answer me this:
>suppose i gots an 8 bit palette that has some
>colors in it like so:
>
>,--r g b
>|  | | |
>0--0,0,0
>1--1,7,9
>2--2,8,9
>3--5,1,2
>4--7,8,3
>
>and
>
>i also gots a pixel on my screen that wants to
>be as close to 1,6,2 as it can be,but can only
>choose from the existin palette of colors.
>
>what would be a good way of figurin out what
>color i allready gots what is closer to the
>color i wants than the rest of them colors i
>allready got?
>
>and fer trivia porposes witch of them colors
>up there is closest to 1,6,2 ?
>
>
>to everyone else
>I reckon this is off topic kinda,but this fella seems
>like he knows a thing or 2 about colors so i felt like
>i had to ask while i hads me a chance.



Well, sure pardner! A nice yun feller like yerself deserves all th' help it
can git!

To find the existing colour that is closest to the colour that you want, you
have to calculate the distance between the colour that you want and each
colour that you have.
Here's what I mean with "the distance between":  look at the r, g and b
values as the x, y and z components of a point in 3d space. Now you can
calculate how close two colours are to each other, just like you would
calculate how close two 3d points are to each other. How do you calculate
the distance between two 3d points? The distance is sqrt((x1-x2)^2 +
(y1-y2)^2 + (z1-z2)^2).  (The squareroot of the sum of the squares of the
difference between the x, y and z components). So you would look at each
colour you have and calculate the distance between it and the one you want,
and so find the closest colour.

The example you gave:
,--r g b
|  | | |
0--0,0,0
1--1,7,9
2--2,8,9
3--5,1,2
4--7,8,3
And you're looking for 1, 6, 2.
Distance between your colour and
0:
sqrt((1-0)^2 + (6-0)^2 + (2-0)^2) = sqrt(41)
1:
sqrt((1-1)^2 + (6-7)^2 + (2-9)^2) = sqrt(50)
2:
sqrt((1-2)^2 + (6-8)^2 + (2-9)^2) = sqrt(54)
3:
sqrt((1-5)^2 + (6-1)^2 + (2-2)^2) = sqrt(41)
4:
sqrt((1-7)^2 + (6-8)^2 + (2-3)^2) = sqrt(41)

Mmm. So we have three potential colours that are equally close. A rather
unlikely event, but which one you use doesn't really matter. Your algorith
will probably return the first of the three as the closest, which is fine.
You will also notice that the sqrt operation is not really neccassary. You
should drop it to speed up your operations a bit.



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019