Anonymous user
Color quantization: Difference between revisions
Improved names in second D entry
(Updated second D entry) |
(Improved names in second D entry) |
||
Line 288:
import std.exception: enforce;
import std.array: empty;
enum ON_INHEAP = 1;
Line 324 ⟶ 323:
} while (line.length && line[0] == '#');
//immutable
▲ immutable size = line.split.to!(uint[2]);
auto img = imageNew(size[0], size[1]);
enforce(fIn.readln.strip == "255");
Line 355 ⟶ 351:
}
struct
uint alloc, n;
OctreeNode** buf;
}
int
pure nothrow @safe @nogc
in {
assert(a != null);
assert(b != null);
} out(result) {
assert(result ==
} body {
if (a.nKids < b.nKids)
Line 377 ⟶ 374:
}
void downHeap(
in {
assert(h != null);
Line 388 ⟶ 385:
if (m >= h.n)
break;
if (m + 1 < h.n &&
m++;
if (
break;
Line 403 ⟶ 400:
}
void upHeap(
in {
assert(h != null);
Line 412 ⟶ 409:
while (n > 1) {
auto prev = h.buf[n / 2];
if (
break;
Line 424 ⟶ 421:
}
void
in {
assert(h != null);
Line 450 ⟶ 447:
}
OctreeNode* popHeap(
in {
assert(h != null);
Line 470 ⟶ 467:
}
OctreeNode*
ref OctreeNode[] pool) nothrow @nogc
out(result) {
assert(result != null);
Line 494 ⟶ 491:
}
void
out {
assert(
} body {
auto
while (
auto p =
free(
}
}
OctreeNode*
nothrow @nogc
in {
assert(root != null);
assert(pix != null);
assert(!pool.
} out(result) {
assert(result != null);
Line 525 ⟶ 522:
!!(pix[2] & bit);
if (!root.kids[i])
root.kids[i] =
root = root.kids[i];
Line 537 ⟶ 534:
}
OctreeNode*
in {
assert(p != null);
Line 575 ⟶ 572:
}
void errorDiffuse(Image* im,
in {
assert(im != null);
Line 686 ⟶ 683:
} body {
auto pix = im.pix.ptr;
OctreeNode[] pool;
auto root =
for (uint i = 0; i < im.w * im.h; i++, pix += 3)
while (heap.n > nColors + 1)
foreach (immutable i; 1 .. heap.n) {
Line 712 ⟶ 709:
}
pool.
heap.buf.free;
}
|