HighMap library (C++)
Loading...
Searching...
No Matches
colorize.hpp
Go to the documentation of this file.
1/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
18#pragma once
19#include <cstdint>
20#include <map>
21#include <string>
22#include <vector>
23
24#include "highmap/array.hpp"
25#include "highmap/texture.hpp"
27
28namespace hmap
29{
30
49
58
59static std::map<std::string, int> normal_map_blending_method_as_string = {
60 {"Linear", NMAP_LINEAR},
61 {"Partial derivative", NMAP_DERIVATIVE},
62 {"Unreal Developer Network", NMAP_UDN},
63 {"Unity", NMAP_UNITY},
64 {"Whiteout", NMAP_WHITEOUT},
65};
66
68{
69 float in_min = 0.0f;
70 float in_max = 1.0f;
71 float exposure = 0.0f;
72 float contrast = 1.0f;
73 float saturation = 1.0f;
74 float temperature = 0.0f;
75 float gamma = 1.f;
76 float dither_amp = 0.f;
77 bool filmic_tonemap = false;
78 bool aces_tonemap = false;
79 bool agx_tonemap = false;
80};
81
89enum Cmap : int; // highmap/colormap.hpp
90
107void apply_hillshade(Texture &img,
108 const Array &array,
109 float vmin = 0.f,
110 float vmax = 1.f,
111 float exponent = 1.f);
112
131void apply_hillshade(std::vector<uint8_t> &img,
132 const Array &array,
133 float vmin = 0.f,
134 float vmax = 1.f,
135 float exponent = 1.f,
136 bool is_img_rgba = false);
137
157void color_adjust(Array &r,
158 Array &g,
159 Array &b,
160 ColorAdjust param,
161 glm::ivec2 dither_seed);
162
184 const Array &g,
185 const Array &b,
186 const glm::vec3 &color,
187 float tolerance = 0.f);
188
205Texture colorize(const Array &array,
206 float vmin,
207 float vmax,
208 int cmap,
209 bool hillshading,
210 bool reverse = false,
211 const Array *p_noise = nullptr);
212
231Texture colorize(const Array &array,
232 float vmin,
233 float vmax,
234 const std::vector<float> &positions,
235 const std::vector<glm::vec3> &colormap_colors,
236 bool reverse = false,
237 const Array *p_noise = nullptr);
238
276 const Array &a2,
277 const glm::vec2 range1,
278 const glm::vec2 range2,
279 const std::vector<float> &positions1,
280 const std::vector<float> &positions2,
281 const std::vector<glm::vec3> &colormap_colors1,
282 const std::vector<glm::vec3> &colormap_colors2,
283 MixMethod method = MM_SQRT_AVG,
284 bool reverse1 = false,
285 bool reverse2 = false,
286 const Array *p_noise1 = nullptr,
287 const Array *p_noise2 = nullptr);
288
297Texture colorize_grayscale(const Array &array);
298
308Texture colorize_histogram(const Array &array);
309
349Texture colorize_slope_height_heatmap(const Array &array, int cmap);
350
368Texture colorize_vec2(const Array &array1, const Array &array2);
369
391Array luminance(const Texture &tex);
392
413Texture mix(const Texture &tex1,
414 const Texture &tex2,
415 MixMethod method = MM_SQRT_AVG);
416
432Texture mix(const Texture &tex1,
433 const Texture &tex2,
434 const Array &mask,
435 MixMethod method = MM_SQRT_AVG,
436 float gain = 1.f);
437
444Texture mix(const std::vector<const Texture *> &texs,
445 MixMethod method = MM_SQRT_AVG);
446
462Texture mix_normal_map(const Texture &nmap_base,
463 const Texture &nmap_detail,
464 float detail_scaling,
465 NormalMapBlendingMethod blending_method);
466
467} // namespace hmap
468
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:32
A class to represent a multi-channel texture using planar hmap::Array storage.
Definition texture.hpp:37
Definition algebra.hpp:23
Texture colorize_bivariate(const Array &a1, const Array &a2, const glm::vec2 range1, const glm::vec2 range2, const std::vector< float > &positions1, const std::vector< float > &positions2, const std::vector< glm::vec3 > &colormap_colors1, const std::vector< glm::vec3 > &colormap_colors2, MixMethod method=MM_SQRT_AVG, bool reverse1=false, bool reverse2=false, const Array *p_noise1=nullptr, const Array *p_noise2=nullptr)
Colorize two scalar fields into a Texture using two custom colormaps and a color mixing method.
Definition colorize.cpp:243
Array color_match_mask(const Array &r, const Array &g, const Array &b, const glm::vec3 &color, float tolerance=0.f)
Create a mask of pixels matching a target color within a tolerance.
Definition color_match_mask.cpp:12
Texture mix_normal_map(const Texture &nmap_base, const Texture &nmap_detail, float detail_scaling, NormalMapBlendingMethod blending_method)
Blend two normal maps into a single output normal map.
Definition colorize.cpp:714
Texture colorize_vec2(const Array &array1, const Array &array2)
Combine two arrays into a colored image.
Definition colorize.cpp:497
void color_adjust(Array &r, Array &g, Array &b, ColorAdjust param, glm::ivec2 dither_seed)
Apply color correction and tonemapping to RGB arrays.
Definition color_adjust.cpp:31
void apply_hillshade(Texture &img, const Array &array, float vmin=0.f, float vmax=1.f, float exponent=1.f)
Apply hillshading to a Tensor image.
Definition colorize.cpp:27
Texture colorize(const Array &array, float vmin, float vmax, int cmap, bool hillshading, bool reverse=false, const Array *p_noise=nullptr)
Apply colorization to an array.
Definition colorize.cpp:108
Texture colorize_grayscale(const Array &array)
Convert an array to a grayscale image.
Definition colorize.cpp:405
void gain(Array &array, float factor, const Array *p_mask)
Apply a gain correction to the array elements.
Definition filters.cpp:198
NormalMapBlendingMethod
Definition colorize.hpp:51
@ NMAP_UDN
Definition colorize.hpp:54
@ NMAP_UNITY
Definition colorize.hpp:55
@ NMAP_WHITEOUT
Definition colorize.hpp:56
@ NMAP_DERIVATIVE
Definition colorize.hpp:53
@ NMAP_LINEAR
Definition colorize.hpp:52
Cmap
Enumeration for different colormap types.
Definition colormaps.hpp:83
MixMethod
Methods for mixing/blending texture colors.
Definition colorize.hpp:44
@ MM_MIXBOX
Physical pigment-based mixing (Mixbox).
Definition colorize.hpp:47
@ MM_SQRT_AVG
Square-root average mixing.
Definition colorize.hpp:46
@ MM_LINEAR
Linear RGB mixing.
Definition colorize.hpp:45
Texture mix(const Texture &tex1, const Texture &tex2, MixMethod method=MM_SQRT_AVG)
Mix two textures into an output texture.
Definition colorize.cpp:550
Texture colorize_slope_height_heatmap(const Array &array, int cmap)
Colorizes a slope height heatmap based on the gradient norms of a given array.
Definition colorize.cpp:450
Texture colorize_histogram(const Array &array)
Convert an array to a histogram-based grayscale image.
Definition colorize.cpp:413
Array luminance(const Texture &tex)
Compute luminance from a Texture.
Definition colorize.cpp:544
Definition colorize.hpp:68
float in_min
Definition colorize.hpp:69
float dither_amp
Definition colorize.hpp:76
float temperature
Definition colorize.hpp:74
float saturation
Definition colorize.hpp:73
bool agx_tonemap
Definition colorize.hpp:79
bool aces_tonemap
Definition colorize.hpp:78
float contrast
Definition colorize.hpp:72
bool filmic_tonemap
Definition colorize.hpp:77
float exposure
Definition colorize.hpp:71
float gamma
Definition colorize.hpp:75
float in_max
Definition colorize.hpp:70
Header file for the Texture class.