mandelbrot

mandelbrot.git
git clone git://git.lenczewski.org/mandelbrot.git
Log | Files | Refs

commit 486a6217433139495d32052b0fc4ee6545c38094
parent 83169cdcb60716016e096d5433cd7de1beacf26b
Author: MikoĊ‚aj Lenczewski <mblenczewski@gmail.com>
Date:   Sun, 19 Jan 2025 12:56:32 +0000

Refactor palette picker slightly

Diffstat:
Msrc/main.c | 18+++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -169,30 +169,34 @@ hsv_to_rgb(float hue, float sat, float val) static inline uint32_t palette(float abs2, uint32_t iters, uint32_t max_iters, enum palette_type type) { - float f = (float) iters / max_iters; - float smooth_iters = (iters + 1) - (logf(logf(sqrtf(abs2))) / M_LN2); - float sf = CLAMP(smooth_iters / max_iters, 0.0f, 1.0f); - float v = 255 * (1 - sf); - switch (type) { case PALETTE_BASIC: return (iters == max_iters) ? pixel(0, 0, 0, 255) : pixel(255, 255, 255, 255); - case PALETTE_MONOCHROME: + case PALETTE_MONOCHROME: { + float f = (float) iters / max_iters; return (iters == max_iters) ? pixel(0, 0, 0, 255) : pixel(f * 255, f * 255, f * 255, 255); + } break; + + case PALETTE_GRAYSCALE: { + float smooth_iters = (iters + 1) - (logf(logf(sqrtf(abs2))) / M_LN2); + float sf = CLAMP(smooth_iters / max_iters, 0.0f, 1.0f); + float v = 255 * (1 - sf); - case PALETTE_GRAYSCALE: return (iters == max_iters) ? pixel(0, 0, 0, 255) : pixel(v, v, v, 255); + } break; case PALETTE_HISTOGRAM: { + float f = (float) iters / max_iters; // TODO: actually implement histogram colouring return (iters == max_iters) ? pixel(0, 0, 0, 255) : pixel(f * 255, f * 255, f * 255, 255); } break; case PALETTE_SMOOTH: { + float smooth_iters = (iters + 1) - (logf(logf(sqrtf(abs2))) / M_LN2); float hue = 0.95 + 20 * smooth_iters; return (iters == max_iters) ? pixel(0, 0, 0, 255) : hsv_to_rgb(hue, 0.8, 1.0);