mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-08 03:19:49 +00:00
1dcb696c35
Fixes various weird issues when palettes have empty slots, and removes unnecessary calculations.
14 lines
443 B
Plaintext
14 lines
443 B
Plaintext
int find_index(vec4 color, int n_of_colors, sampler2D palette_texture) {
|
|
int color_index = 0;
|
|
float smaller_distance = distance(color, texture(palette_texture, vec2(0.0)));
|
|
for (int i = 0; i <= n_of_colors; i++) {
|
|
vec4 palette_color = texelFetch(palette_texture, ivec2(i, 0), 0);
|
|
float dist = distance(color, palette_color);
|
|
if (dist < smaller_distance) {
|
|
smaller_distance = dist;
|
|
color_index = i;
|
|
}
|
|
}
|
|
return color_index;
|
|
}
|