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