Color quantization: Difference between revisions

Updated D entry
m (Removed duplicate task template)
(Updated D entry)
Line 143:
cast(ubyte)round(c.b));
 
enum addRGB = (in Col c1, in Col c2) pure nothrow @nogc =>
Col(c1.r + c2.r, c1.g + c2.g, c1.b + c2.b);
 
Line 152:
}
 
enum minC = (in Col c1, in Col c2) pure nothrow @nogc =>
Col(min(c1.r, c2.r), min(c1.g, c2.g), min(c1.b, c2.b));
 
enum maxC = (in Col c1, in Col c2) pure nothrow @nogc =>
Col(max(c1.r, c2.r), max(c1.g, c2.g), max(c1.b, c2.b));
 
Line 181:
}
 
enum fCmp = (in float a, in float b) pure nothrow @nogc =>
(a > b) ? 1 : (a < b ? -1 : 0);
 
Axis largestAxis(in Col c) pure nothrow @nogc {
immutable int r1 = fCmp(c.r, c.g);
immutable int r2 = fCmp(c.r, c.b);
Line 196:
in Col vol, Col[] pixels)
pure nothrow {
bool delegate(immutable Col) pure nothrow @nogc partFunc;
final switch (largestAxis(vol)) {
case Axis.R: partFunc = c1 => c1.r < c.r; break;
Line 207:
}
 
uint RGB2uint(in RGB c) pure nothrow @nogc {
return c.r | (c.g << 8) | (c.b << 16);
}
 
enum uintToRGB = (in uint c) pure nothrow @nogc =>
RGB(c & 0xFF, (c >> 8) & 0xFF, (c >> 16) & 0xFF);