diff options
author | Oliver Schinagl <oliver@schinagl.nl> | 2008-01-09 11:31:25 (GMT) |
---|---|---|
committer | Oliver Schinagl <oliver@schinagl.nl> | 2008-01-09 11:31:25 (GMT) |
commit | 4da3ab92496c596274a5efb2304a3e80f927c95a (patch) | |
tree | fa389ec594ba44d50408650ca9492e6d3ad3e051 /Smoke/palette.c | |
parent | f946564b55211d2550488e09c997db75a013d49e (diff) | |
download | 2iv35-4da3ab92496c596274a5efb2304a3e80f927c95a.zip 2iv35-4da3ab92496c596274a5efb2304a3e80f927c95a.tar.gz 2iv35-4da3ab92496c596274a5efb2304a3e80f927c95a.tar.bz2 |
new palettes
Diffstat (limited to 'Smoke/palette.c')
-rw-r--r-- | Smoke/palette.c | 201 |
1 files changed, 119 insertions, 82 deletions
diff --git a/Smoke/palette.c b/Smoke/palette.c index 5a8b9bf..c0fd8b5 100644 --- a/Smoke/palette.c +++ b/Smoke/palette.c @@ -101,23 +101,50 @@ void RGBtoHSV(float r, float g, float b, float *h, float *s, float *v) } +static struct color4f blackandwhite(float value) +{ + struct color4f return_value; + + return_value.r = value; + return_value.g = value; + return_value.b = value; + + return return_value; +} + //rainbow: Implements a color palette, mapping the scalar 'value' to a rainbow color RGB -void rainbow(float value, float *R, float *G, float *B) +static struct colorf4 rainbow(float value) { - const float dx = 0.8f; + struct color4f return_value; + const float dx = 0.8f; + + if (value < 0) { value = 0; } + if (value > 1) { value = 1; } - if (value < 0) value = 0; - if (value > 1) value = 1; + value = (6 - 2 * dx) * value + dx; - value = (6 - 2 * dx) * value + dx; + return_value.r = (float)max(0.0f, (3 - fabs(value - 4.0f) - fabs(value - 5.0f)) / 2.0f); + return_value.b = (float)max(0.0f, (4 - fabs(value - 2.0f) - fabs(value - 4.0f)) / 2.0f); + return_value.g = (float)max(0.0f, (3 - fabs(value - 1.0f) - fabs(value - 2.0f)) / 2.0f); - *R = (float)max(0.0f, (3 - fabs(value - 4.0f) - fabs(value - 5.0f)) / 2.0f); - *G = (float)max(0.0f, (4 - fabs(value - 2.0f) - fabs(value - 4.0f)) / 2.0f); - *B = (float)max(0.0f, (3 - fabs(value - 1.0f) - fabs(value - 2.0f)) / 2.0f); + return return_value; } -void colormap_fire(float value, float *R, float *G, float *B) + +static struct color4f trip_like_i_do(float value) { + struct color4f return_value; + + return_value.r = value; + return_value.g = value; + return_value.b = value; + + return return_value; +} + +static struct color4f colormap_fire(float value) +{ + struct color4f return_value; /* Colormap Fire * A fire effect deals with two parts, first a drop from red to yellow (halfway) * during which time the Red component remains full e.g. 1. The Green component is @@ -125,91 +152,101 @@ void colormap_fire(float value, float *R, float *G, float *B) * point, the Red and Green component (e.g. yellow) have to drop simulataniously * to go from yellow down to black. */ - *B = 0; - *G = 0; - *R = 0; + return_value.r = 0; + return_value.b = 0; + return_value.g = 0; if (value <= (0.01)) { /* whilst value is 0 - 0.5 both red and green equally change to create yellow */ - *R = *G = value; + return_value.r = return_value.g = value; } else { /* whilst value is 0.5 - 1 Red is always fully on while the Green component is * added in steps to go from red to orange to yellow. */ - *G = 0.9f - value; - *R = 0.8f; // not 1, makes red deeper, more intense + return_value.g = 0.9f - value; + return_value.r = 0.8f; // not 1, makes red deeper, more intense } + + return return_value; } -//set_palette: Sets three different types of colormaps -struct color4f set_palette(int colormap_sort, float value, int num_colors) +static struct color4f bluegreenred(float value) { - float R, G, B; - struct color4f return_value; - const int NLEVELS = 7; - - value *= num_colors; - value = (float)(int)(value); - value /= num_colors; - - switch (colormap_sort) - { - case PALETTE_BLACKWHITE: - R = G = B = value; - break; - case PALETTE_RAINBOW: - rainbow(value,&R,&G,&B); - break; - case PALETTE_BANDS: - value *= NLEVELS; value = (float)(int)(value); value/= NLEVELS; - rainbow(value,&R,&G,&B); - break; - case PALETTE_BLUE_GREEN_RED: - if (value < -0.1) - { - R = G = 0; - value -= -0.1f; - value /= 0.9f; - B = -value; - } - else if (value < 0.1) - { - R = B = 0; - value += 0.1f; - value /= 0.2f; - G = value; - } - else - { - value -= 0.1f; - value /= 0.9f; - R = value; - G = B = 0; - } - break; - case PALETTE_WILRIK: - colormap_fire(value, &R, &G, &B); - break; - case PALETTE_OLIVER: - rainbow(value, &R, &G, &B); - break; - case PALETTE_RED: - R = 1.0f; - G = B = 0.0f; - break; - case PALETTE_GREEN: - G = 1.0f; - R = B = 0.0f; - break; - case PALETTE_BLUE: - B = 1.0f; - R = G = 0.0f; - break; + struct color4f return_value; + + return_value.r = 0; + return_value.b = 0; + return_value.g = 0; + + if (value < -0.1) { + value -= -0.1f; + value /= 0.9f; + + return_value.b = -value; + } else if (value < 0.1) { + value += 0.1f; + value /= 0.2f; + + return_value.g = value; + } else { + value -= 0.1f; + value /= 0.9f; + + return_value.r = value; } - return_value.r = R; - return_value.g = G; - return_value.b = B; + return return_value; +} + +//set_palette: Sets three different types of colormaps +struct color4f set_palette(int colormap_sort, float value, int num_colors) +{ + struct color4f return_value; + + return_value.r = 0; + return_value.b = 0; + return_value.g = 0; + + + value *= num_colors; + value = (float)(int)(value); + value /= num_colors; + + switch (colormap_sort) + { + case PALETTE_BLACKWHITE: + return_value = blackandwhite(value); + break; + case PALETTE_RAINBOW: + return_value = rainbow(value); + break; + case PALETTE_BANDS: + value *= 7; + value = (float)(int)(value); + value/= 7; + return_value = rainbow(value); + break; + case PALETTE_BLUE_GREEN_RED: + return_value = bluegreenred(value); + break; + case PALETTE_WILRIK: + return_value = colormap_fire(value); + break; + case PALETTE_OLIVER: + return_value = trip_like_i_do(value); + break; + case PALETTE_RED: + return_value.r = 1.0f; + break; + case PALETTE_GREEN: + return_value.g = 1.0f; + break; + case PALETTE_BLUE: + return_value.b = 1.0f; + break; + default: + break; + } - return return_value; + return return_value; } |