summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-05-10 19:07:03 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-05-10 19:16:42 -0400
commit8062ba4eb5bbde70aa73368f7e3d400cfde2eea8 (patch)
treed4a230ccd2cea4221d8c59cb3f89d26ec24ca88e /main.c
parent1ad60a81f71665ce3a2e1412cc3704b0b5f028bf (diff)
downloadkd-forest-8062ba4eb5bbde70aa73368f7e3d400cfde2eea8.tar.xz
Allow all possible bit-depths, not just multiples of three.
Diffstat (limited to 'main.c')
-rw-r--r--main.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/main.c b/main.c
index af518ea..5b604d4 100644
--- a/main.c
+++ b/main.c
@@ -11,7 +11,7 @@
// Number of trailing zero bits on each color chanel, set to zero for all
// 24-bit images
-#define ZERO_BITS 0
+#define BIT_DEPTH 24
// Whether to sort by hue
#define HUE_SORT 1
@@ -117,18 +117,22 @@ remove_non_boundary(kd_forest_t *kdf, kd_node_t *node, unsigned int width, unsig
int
main(void)
{
- const unsigned int jump = 1U << ZERO_BITS;
- const unsigned int width = 1U << ((24 - 3*ZERO_BITS + 1)/2); // Round up
- const unsigned int height = 1U << ((24 - 3*ZERO_BITS)/2); // Round down
+ const unsigned int width = 1U << (BIT_DEPTH + 1)/2; // Round up
+ const unsigned int height = 1U << (BIT_DEPTH)/2; // Round down
const unsigned int size = width*height;
printf("Generating a %ux%u image (%u pixels)\n", width, height, size);
+ // From least to most perceptually important
+ const unsigned int bskip = 1U << (24 - BIT_DEPTH)/3;
+ const unsigned int rskip = 1U << (24 - BIT_DEPTH + 1)/3;
+ const unsigned int gskip = 1U << (24 - BIT_DEPTH + 2)/3;
+
// Generate all the colors
uint32_t *colors = xmalloc(size*sizeof(uint32_t));
- for (unsigned int b = 0, i = 0; b < 0x100; b += jump) {
- for (unsigned int g = 0; g < 0x100; g += jump) {
- for (unsigned int r = 0; r < 0x100; r += jump, ++i) {
+ for (unsigned int b = 0, i = 0; b < 0x100; b += bskip) {
+ for (unsigned int g = 0; g < 0x100; g += gskip) {
+ for (unsigned int r = 0; r < 0x100; r += rskip, ++i) {
colors[i] = (r << 16) | (g << 8) | b;
}
}
@@ -177,8 +181,7 @@ main(void)
size_t max_size = 0;
// Do multiple passes to get rid of artifacts in HUE_SORT mode
- const unsigned int passes = 24 - 3*ZERO_BITS;
- for (unsigned int i = 1, progress = 0; i <= passes; ++i) {
+ for (unsigned int i = 1, progress = 0; i <= BIT_DEPTH; ++i) {
unsigned int stripe = 1 << i;
for (unsigned int j = stripe/2 - 1; j < size; j += stripe, ++progress) {