summaryrefslogtreecommitdiffstats
path: root/Smoke/colormap.c
blob: e4a49010f1b64162db8de288803a6a584f436db7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#ifdef G_OS_WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#endif

#include <math.h>


#include <rfftw.h>
#include "fluids.h"

#include "funcs.h"
#include "palette.h"

#include "colormap.h"


static int colormap_colormap = PALETTE_BLACKWHITE;

static int colormap_num_colors = PALETTE_MAXCOLORS;

static float colormap_alpha = 0.9f;

static int colormap_scaling = FALSE;

static int colormap_clamping = FALSE;

static float colormap_scale_min = 0.0f;
static float colormap_scale_max = 1.0f;

static float colormap_clamp_min = 0.0f;
static float colormap_clamp_max = 1.0f;

static int colormap_autoscaling = FALSE;

static fftw_real *colormap_frame;


void colormap_set_num_colors(int num_colors)
{
  colormap_num_colors = num_colors;
}

int colormap_get_num_colors(void)
{
  return colormap_num_colors;
}

void colormap_set_colormap(int colormap)
{
  colormap_colormap = colormap;
}

int colormap_get_colormap(void)
{
  return colormap_colormap;
}

void colormap_set_alpha(float alpha)
{
  colormap_alpha = alpha;
}

float colormap_get_alpha(void)
{
  return colormap_alpha;
}

void colormap_set_scaling(int scaling)
{
  colormap_scaling = scaling;
}

int colormap_get_scaling(void)
{
  return colormap_scaling;
}

void colormap_set_clamping(int clamping)
{
  colormap_clamping = clamping;
}

int colormap_get_clamping(void)
{
  return colormap_clamping;
}

void colormap_set_scale_min(float min_scale)
{
  if (colormap_scaling) {
    colormap_scale_min = min_scale;
  }
}

float colormap_get_scale_min(void)
{
  return colormap_scale_min;
}

void colormap_set_scale_max(float max_scale)
{
  if (colormap_scaling) {
    colormap_scale_max = max_scale;
  }
}

float colormap_get_scale_max(void)
{
  return colormap_scale_max;
}

void colormap_set_clamp_min(float min_clamp)
{
  if (colormap_clamping) {
    colormap_clamp_min = min_clamp;
  }
}

float colormap_get_clamp_min(void)
{
  return colormap_clamp_min;
}

void colormap_set_clamp_max(float max_clamp)
{
  if (colormap_clamping) {
    colormap_clamp_max = max_clamp;
  }
}

float colormap_get_clamp_max(void)
{
  return colormap_clamp_max;
}

void colormap_set_autoscaling(int autoscaling)
{
  colormap_autoscaling = autoscaling;
}

int colormap_get_autoscaling(void)
{
  return colormap_autoscaling;
}

void colormap_set_frame(fftw_real *frame)
{
  colormap_frame = frame;
}

fftw_real *colormap_get_frame(void)
{
  return colormap_frame;
}


static float remap(float value)
{
	value -= colormap_scale_min;
	value /= (colormap_scale_max - colormap_scale_min);

	return value;
}

static float clamp(float value)
{
  if (value < colormap_clamp_min) value = colormap_clamp_min;
  if (value > colormap_clamp_max) value = colormap_clamp_max;

  return value;
}

struct color4f colormap_get_color(float value)
{
  struct color4f return_value;

  value = colormap_clamping ? clamp(value) : value;
  value = colormap_scaling ? remap(value) : value;

  return_value = set_palette(colormap_colormap, value, colormap_num_colors);
  return_value.a = colormap_alpha;

  return return_value;
}

void renderer_reset_scaling(void)
{
  colormap_scale_min = 0.0f;
  colormap_scale_max = 1.0f;
}

void renderer_reset_clamping(void)
{
  colormap_clamp_min = 0.0f;
  colormap_clamp_max = 1.0f;
}