Nein, mit acht Bit. Die Video-Hardware hatte damals nur vier Bit pro Kanal, aber bei der API hat jemand mitgedacht und deshalb war die von Anfang an auf acht Bit pro Kanal ausgelegt.
Dann müssen die imho intern eh mit 24 Bit rechnen, und dann hätten die die Faktoren noch was hochdrehen können.
Magst du dein Code in dem Raum werfen?
Ich würd's gerne vergleichen, da muss ja was anderes passieren.
Ist C#, Konsolen-Projekt
using System;
using System.Collections.Generic;
public class RGB : IEquatable<RGB> {
public int R;
public int G;
public int B;
public RGB (int r, int g, int b) {
(R, G, B) = (r, g, b);
}
public RGB (int htmlcode) {
int b = htmlcode & 255;
int g = (htmlcode >> 8) & 255;
int r = (htmlcode >> 16) & 255;
(R, G, B) = (r, g, b);
}
public string ToString () => "(" + R + "/" + G + "/" + B + ")";
public bool Equals (RGB other) => R == other.R && G == other.G && B == other.B;
[Obsolete ("Nicht Objekte vergleichen", true)]
public override bool Equals (object other) =>
throw new ApplicationException ("Nicht Objekte vergleichen");
public int getSquareDistance (RGB zuFarbe) => getSquareDistance (zuFarbe.R, zuFarbe.G, zuFarbe.B);
public int getSquareDistance (int r, int g, int b) {
int r1 = (this.R - r);
int g1 = (this.G - g);
int b1 = (this.B - b);
var erg = r1 * r1 + g1 * g1 + b1 * b1;
return erg;
}
}
public class FarbListe : List<RGB> {
//public Double getNearestDistance (RGB zuFarbe) => Math.Sqrt(this.Min (x => x.getSquareDistance (zuFarbe)));
public Double getNearestDistance (RGB zuFarbe) {
int minDst = int.MaxValue;
foreach (var item in this) {
minDst = Math.Min (minDst, item.getSquareDistance (zuFarbe));
}
return Math.Sqrt (minDst);
}
public Double getNearestDistance (RGB zuFarbe, RGB ausnahme) {
int minDst = int.MaxValue;
foreach (var item in this) {
if (!item.Equals (ausnahme))
minDst = Math.Min (minDst, item.getSquareDistance (zuFarbe));
}
return Math.Sqrt (minDst);
}
public Double getNearestDistance (int r, int g, int b) {
int minDst = int.MaxValue;
foreach (var item in this) {
minDst = Math.Min (minDst, item.getSquareDistance (r, g, b));
}
return Math.Sqrt (minDst);
}
public RGB getWorstColor () {
RGB worstColor = new (0, 0, 0);
Double worstDistance = 0;
for (int r = 0; r < 256; r++)
for (int g = 0; g < 256; g++)
for (int b = 0; b <= 255; b++) {
Double thisDistance = this.getNearestDistance (r, g, b);
if (worstDistance < thisDistance) {
worstDistance = thisDistance;
worstColor = new (r, g, b);
}
}
return worstColor;
}
}
public class cls_colorDistance {
FarbListe AlleFarben;
private FarbListe loadPepto () {
FarbListe a = new ();
a.Add (new RGB (0, 0, 0));
a.Add (new RGB (255, 255, 255));
a.Add (new RGB (181, 97, 72));
a.Add (new RGB (153, 230, 249));
a.Add (new RGB (193, 97, 201));
a.Add (new RGB (121, 213, 112));
a.Add (new RGB (96, 73, 237));
a.Add (new RGB (247, 255, 108));
a.Add (new RGB (186, 134, 32));
a.Add (new RGB (131, 112, 0));
a.Add (new RGB (231, 154, 132));
a.Add (new RGB (122, 122, 122));
a.Add (new RGB (168, 168, 168));
a.Add (new RGB (192, 255, 185));
a.Add (new RGB (162, 43, 255));
a.Add (new RGB (210, 210, 210));
return a;
}
private FarbListe loadColodore () {
FarbListe a = new ();
a.Add (new RGB (0, 0, 0));
a.Add (new RGB (255, 255, 255));
a.Add (new RGB (150, 40, 46));
a.Add (new RGB (91, 214, 206));
a.Add (new RGB (169, 45, 173));
a.Add (new RGB (65, 185, 54));
a.Add (new RGB (39, 36, 196));
a.Add (new RGB (239, 243, 71));
a.Add (new RGB (169, 72, 21));
a.Add (new RGB (94, 53, 0));
a.Add (new RGB (218, 95, 102));
a.Add (new RGB (71, 71, 71));
a.Add (new RGB (120, 120, 120));
a.Add (new RGB (145, 255, 132));
a.Add (new RGB (104, 100, 255));
a.Add (new RGB (174, 174, 174));
return a;
}
private FarbListe loadWiki () {
FarbListe a = new ();
a.Add (new RGB (0));
a.Add (new RGB (0xffffff));
a.Add (new RGB (0x880000));
a.Add (new RGB (0xaaffee));
a.Add (new RGB (0xcc44cc));
a.Add (new RGB (0x00cc55));
a.Add (new RGB (0x0000aa));
a.Add (new RGB (0xeeee77));
a.Add (new RGB (0xdd8855));
a.Add (new RGB (0x664400));
a.Add (new RGB (0xff7777));
a.Add (new RGB (0x333333));
a.Add (new RGB (0x777777));
a.Add (new RGB (0xaaff66));
a.Add (new RGB (0x0088ff));
a.Add (new RGB (0xbbbbbb));
return a;
}
public cls_colorDistance () {
AlleFarben = loadWiki ();
foreach (var item in AlleFarben) {
System.Console.WriteLine (item.ToString () + AlleFarben.getNearestDistance (item, item));
}
RGB worst = AlleFarben.getWorstColor ();
RGB schorsch = new (0x2755cc);
RGB tuerkis = AlleFarben[3];
System.Console.WriteLine ($"--- Schlechteste Farbe: {worst.ToString ()}");
System.Console.WriteLine ($"Nächter Nachbar von {worst.ToString ()}: {AlleFarben.getNearestDistance (worst)}");
System.Console.WriteLine ($"Nächter Nachbar von {schorsch.ToString ()}: {AlleFarben.getNearestDistance (schorsch)}");
System.Console.WriteLine ("---");
System.Console.WriteLine ($"Distanzen zu {schorsch.ToString ()}");
foreach (var item in AlleFarben) {
System.Console.WriteLine (item.ToString () + Math.Sqrt (item.getSquareDistance (schorsch)));
}
System.Console.WriteLine ("---");
System.Console.WriteLine ("Distanzen zu " + worst.ToString ());
foreach (var item in AlleFarben) {
System.Console.WriteLine (item.ToString () + Math.Sqrt (item.getSquareDistance (worst)));
}
System.Console.WriteLine ("---");
System.Console.WriteLine ($"Speziell Worst <> Tuerkis {tuerkis.ToString ()}: {Math.Sqrt ( tuerkis.getSquareDistance (worst))}");
}
}
Alles anzeigen
Der Output:
(0/0/0)88,33459118601274
(255/255/255)86,68333173107735
(136/0/0)76,02631123499285
(170/255/238)86,68333173107735
(204/68/204)111,476454913134
(0/204/85)150,1399347275734
(0/0/170)139,15099712183164
(238/238/119)72,12489168102785
(221/136/85)51
(102/68/0)74,10128204019145
(255/119/119)51
(51/51/51)74,10128204019145
(119/119/119)108,85311203635843
(170/255/102)72,12489168102785
(0/136/255)160,37767924496225
(187/187/187)86,68333173107735
--- Schlechteste Farbe: (39/255/204)
Nächter Nachbar von (39/255/204): 135,21464417732275
Nächter Nachbar von (39/85/204): 81,99390221229869
---
Distanzen zu (39/85/204)
(0/0/0)224,4147945212169
(255/255/255)279,56573466717987
(136/0/0)241,3503677229434
(170/255/238)217,29473072304353
(204/68/204)165,873445734994
(0/204/85)172,75126627611155
(0/0/170)99,508793581271
(238/238/119)265,0188672528807
(221/136/85)223,35174053496874
(102/68/0)214,1821654573508
(255/119/119)234,59965899378454
(51/51/51)157,19096666157378
(119/119/119)121,57713600837947
(170/255/102)237,62365202142652
(0/136/255)81,99390221229869
(187/187/187)180,54639292990598
---
Distanzen zu (39/255/204)
(0/0/0)328,87991729505165
(255/255/255)221,93918085818015
(136/0/0)340,6611219379165
(170/255/238)135,34031180694095
(204/68/204)249,38724907260195
(0/204/85)135,21464417732275
(0/0/170)260,1960799089794
(238/238/119)217,05989956691678
(221/136/85)247,88303693476084
(102/68/0)283,8203657245195
(255/119/119)269,02973813316623
(51/51/51)255,28219679405768
(119/119/119)179,22332437492616
(170/255/102)166,02710622064097
(0/136/255)135,21464417732275
(187/187/187)163,75896922000945
---
Speziell Worst <> Tuerkis (170/255/238): 135,34031180694095
Alles anzeigen