Quickmarch
2009-06-03 19:34:31
Don't know whether it's worth putting it in a plugin, but here it is:
(Delphi code btw ;))
It sorts the colors using RGB by the most white or the least white.
Use like this:
Full source and plugin:
function SortColorsArr(Colors: TIntegerArray; WhiteFirst: Boolean): TIntegerArray;
var
i, c, L: Integer;
R, G, B, M: TIntegerArray;
begin
L := Length(Colors);
SetLength(Result, L);
SetLength(R, L);
SetLength(G, L);
SetLength(B, L);
SetLength(M, L);
for i := 0 to L - 1 do
begin
ColorToRGB(Colors[i], R[i], G[i], B[i]);
M[i] := R[i]+G[i]+B[i];
end;
QuickSort(M, Low(Colors), High(Colors), not(WhiteFirst));
for i := 0 to L - 1 do
for c := 0 to L - 1 do
if ((R[c] + G[c] + B[c]) = M[i]) then
Result[i] := RGBToColor(R[c], G[c], B[c]);
end;
(Delphi code btw ;))
It sorts the colors using RGB by the most white or the least white.
Use like this:
T := SortColorsArr([0, 16777215, 255, 16758374, 15790320, 65536], True);
WriteLn(IntToStr(T[0]));
Full source and plugin: