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 float shade = 0.0f;
78 bool filmic_tonemap = false;
79 bool aces_tonemap = false;
80 bool agx_tonemap = false;
81};
82
84{
85 glm::vec3 grass = {0.38f, 0.44f, 0.29f};
86 glm::vec3 dry = {0.60f, 0.58f, 0.42f};
87 glm::vec3 soil = {0.64f, 0.55f, 0.43f};
88 glm::vec3 sediment = {0.80f, 0.76f, 0.68f};
89 glm::vec3 rock = {0.53f, 0.50f, 0.46f};
90 glm::vec3 ridge = {0.71f, 0.70f, 0.68f};
91 glm::vec3 snow = {0.94f, 0.95f, 0.97f};
92 float rock_talus = 0.003f;
93 float rock_edge = 0.15f;
94 float strata = 0.35f;
95 float streaks = 0.8f;
96 int streak_length = 60;
97 float flow = 0.8f;
98 float flow_width = 0.5f;
99 float deposition = 0.5f;
100 float snow_line = 0.85f;
101 float snow_amount = 0.f;
102 uint32_t seed = 0;
103 float noise_scale = 1.f;
104 float color_noise = 1.f;
105 float detail = 1.f;
106 float cavity = 0.6f;
107 int ir_region = 50;
108};
109
117enum Cmap : int; // highmap/colormap.hpp
118
135void apply_hillshade(Texture &img,
136 const Array &array,
137 float vmin = 0.f,
138 float vmax = 1.f,
139 float exponent = 1.f);
140
159void apply_hillshade(std::vector<uint8_t> &img,
160 const Array &array,
161 float vmin = 0.f,
162 float vmax = 1.f,
163 float exponent = 1.f,
164 bool is_img_rgba = false);
165
185void color_adjust(Array &r,
186 Array &g,
187 Array &b,
188 ColorAdjust param,
189 glm::ivec2 dither_seed);
190
212 const Array &g,
213 const Array &b,
214 const glm::vec3 &color,
215 float tolerance = 0.f);
216
233Texture colorize(const Array &array,
234 float vmin,
235 float vmax,
236 int cmap,
237 bool hillshading,
238 bool reverse = false,
239 const Array *p_noise = nullptr);
240
259Texture colorize(const Array &array,
260 float vmin,
261 float vmax,
262 const std::vector<float> &positions,
263 const std::vector<glm::vec3> &colormap_colors,
264 bool reverse = false,
265 const Array *p_noise = nullptr);
266
304 const Array &a2,
305 const glm::vec2 range1,
306 const glm::vec2 range2,
307 const std::vector<float> &positions1,
308 const std::vector<float> &positions2,
309 const std::vector<glm::vec3> &colormap_colors1,
310 const std::vector<glm::vec3> &colormap_colors2,
311 MixMethod method = MM_SQRT_AVG,
312 bool reverse1 = false,
313 bool reverse2 = false,
314 const Array *p_noise1 = nullptr,
315 const Array *p_noise2 = nullptr);
316
325Texture colorize_grayscale(const Array &array);
326
336Texture colorize_histogram(const Array &array);
337
377Texture colorize_slope_height_heatmap(const Array &array, int cmap);
378
396Texture colorize_vec2(const Array &array1, const Array &array2);
397
419Array luminance(const Texture &tex);
420
441Texture mix(const Texture &tex1,
442 const Texture &tex2,
443 MixMethod method = MM_SQRT_AVG);
444
459Texture mix(const Texture &tex1,
460 const Texture &tex2,
461 const Array &mask,
462 MixMethod method = MM_SQRT_AVG,
463 float gain = 1.f);
464
471Texture mix(const std::vector<const Texture *> &texs,
472 MixMethod method = MM_SQRT_AVG);
473
489Texture mix_normal_map(const Texture &nmap_base,
490 const Texture &nmap_detail,
491 float detail_scaling,
492 NormalMapBlendingMethod blending_method);
493
504glm::vec3 shade_color(const glm::vec3 &color, float t);
505
516void shade_color(Texture &tex, const Array &factor);
517
533 const Array &z,
534 int ir,
535 float strength = 1.0f);
536
555 const Array &z,
556 const Array *p_deposition = nullptr,
557 const Array *p_snow_depth = nullptr,
559 const BBox2D &bbox = BBox2D::unit(),
560 const Array *p_noise = nullptr,
562
563} // namespace hmap
564
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:31
Abstract communicator interface providing MPI-style collective directives for single-source SPMD Arra...
Definition communicator_interface.hpp:60
static SingleArrayComm & instance()
Definition communicator.cpp:78
A class to represent a multi-channel texture using planar hmap::Array storage.
Definition texture.hpp:37
Definition opencv.hpp:20
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:254
Texture terrain_texture(const Array &z, const Array *p_deposition=nullptr, const Array *p_snow_depth=nullptr, const TerrainTextureParams &params=TerrainTextureParams(), const BBox2D &bbox=BBox2D::unit(), const Array *p_noise=nullptr, ICommunicator &comm=SingleArrayComm::instance())
Generate a procedural terrain texture from elevation and surface analysis.
Definition terrain_texture.cpp:25
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:725
glm::vec3 shade_color(const glm::vec3 &color, float t)
Adjust color by shading parameter t clamped to [0, 1].
Definition color_adjust.cpp:34
Texture colorize_vec2(const Array &array1, const Array &array2)
Combine two arrays into a colored image.
Definition colorize.cpp:508
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:43
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:34
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:115
void shade_topographic_residual(Texture &tex, const Array &z, int ir, float strength=1.0f)
Apply shade_color to a Texture based on topographic residuals of an elevation array.
Definition color_adjust.cpp:161
Texture colorize_grayscale(const Array &array)
Convert an array to a grayscale image.
Definition colorize.cpp:416
void gain(Array &array, float factor, const Array *p_mask)
Apply a gain correction to the array elements.
Definition filters.cpp:251
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:561
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:461
Texture colorize_histogram(const Array &array)
Convert an array to a histogram-based grayscale image.
Definition colorize.cpp:424
Array luminance(const Texture &tex)
Compute luminance from a Texture.
Definition colorize.cpp:555
Axis-aligned 2D bounding box in world coordinates.
Definition bbox2d.hpp:25
static constexpr BBox2D unit()
Definition bbox2d.hpp:39
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:80
float shade
Definition colorize.hpp:77
bool aces_tonemap
Definition colorize.hpp:79
float contrast
Definition colorize.hpp:72
bool filmic_tonemap
Definition colorize.hpp:78
float exposure
Definition colorize.hpp:71
float gamma
Definition colorize.hpp:75
float in_max
Definition colorize.hpp:70
Definition colorize.hpp:84
float rock_edge
Definition colorize.hpp:93
float color_noise
Definition colorize.hpp:104
float streaks
Definition colorize.hpp:95
glm::vec3 grass
Definition colorize.hpp:85
float snow_line
Definition colorize.hpp:100
glm::vec3 dry
Definition colorize.hpp:86
int streak_length
Definition colorize.hpp:96
float strata
Definition colorize.hpp:94
float detail
Definition colorize.hpp:105
glm::vec3 rock
Definition colorize.hpp:89
glm::vec3 snow
Definition colorize.hpp:91
uint32_t seed
Definition colorize.hpp:102
float noise_scale
Definition colorize.hpp:103
int ir_region
Definition colorize.hpp:107
float flow
Definition colorize.hpp:97
float deposition
Definition colorize.hpp:99
float flow_width
Definition colorize.hpp:98
float snow_amount
Definition colorize.hpp:101
glm::vec3 sediment
Definition colorize.hpp:88
glm::vec3 soil
Definition colorize.hpp:87
float cavity
Definition colorize.hpp:106
float rock_talus
Definition colorize.hpp:92
glm::vec3 ridge
Definition colorize.hpp:90
Header file for the Texture class.