Blender Git Loki
Git Commits -> Revision fd94e03
Revision fd94e03 by Jeroen Bakker (master) May 25, 2021, 15:01 (GMT) |
Blenlib: Explicit Colors. Colors are often thought of as being 4 values that make up that can make any color. But that is of course too limited. In C we didn?t spend time to annotate what we meant when using colors. Recently `BLI_color.hh` was made to facilitate color structures in CPP. CPP has possibilities to enforce annotating structures during compilation and can adds conversions between them using function overloading and explicit constructors. The storage structs can hold 4 channels (r, g, b and a). Usage: Convert a theme byte color to a linearrgb premultiplied. ``` ColorTheme4b theme_color; ColorSceneLinear4f<eAlpha::Premultiplied> linearrgb_color = BLI_color_convert_to_scene_linear(theme_color).premultiply_alpha(); ``` The API is structured to make most use of inlining. Most notable are space conversions done via `BLI_color_convert_to*` functions. - Conversions between spaces (theme <=> scene linear) should always be done by invoking the `BLI_color_convert_to*` methods. - Encoding colors (compressing to store colors inside a less precision storage) should be done by invoking the `encode` and `decode` methods. - Changing alpha association should be done by invoking `premultiply_alpha` or `unpremultiply_alpha` methods. # Encoding. Color encoding is used to store colors with less precision as in using `uint8_t` in stead of `float`. This encoding is supported for `eSpace::SceneLinear`. To make this clear to the developer the `eSpace::SceneLinearByteEncoded` space is added. # Precision Colors can be stored using `uint8_t` or `float` colors. The conversion between the two precisions are available as methods. (`to_4b` and `to_4f`). # Alpha conversion Alpha conversion is only supported in SceneLinear space. Extending: - This file can be extended with `ColorHex/Hsl/Hsv` for different representations of rgb based colors. `ColorHsl4f<eSpace::SceneLinear, eAlpha::Premultiplied>` - Add non RGB spaces/storages ColorXyz. Reviewed By: JacquesLucke, brecht Differential Revision: https://developer.blender.org/D10978 |
Commit Details:
Full Hash: fd94e033446c72fb92048a9864c1d539fccde59a
Parent Commit: b046bc5
Lines Changed: +594, -151
2 Added Paths:
/source/blender/blenlib/intern/BLI_color.cc (+55, -0) (View)
/source/blender/blenlib/tests/BLI_color_test.cc (+133, -0) (View)
/source/blender/blenlib/tests/BLI_color_test.cc (+133, -0) (View)
24 Modified Paths:
/source/blender/blenkernel/BKE_attribute_math.hh (+20, -15) (Diff)
/source/blender/blenkernel/intern/attribute_access.cc (+4, -4) (Diff)
/source/blender/blenkernel/intern/attribute_math.cc (+9, -6) (Diff)
/source/blender/blenkernel/intern/geometry_component_mesh.cc (+11, -9) (Diff)
/source/blender/blenlib/BLI_color.hh (+267, -35) (Diff)
/source/blender/blenlib/CMakeLists.txt (+2, -0) (Diff)
/source/blender/draw/intern/draw_cache_impl.h (+0, -1) (Diff)
/source/blender/editors/space_spreadsheet/spreadsheet_cell_value.hh (+1, -1) (Diff)
/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc (+1, -1) (Diff)
/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc (+1, -1) (Diff)
/source/blender/functions/intern/cpp_types.cc (+2, -2) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc (+10, -6) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc (+3, -3) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc (+16, -12) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_curve_map.cc (+4, -3) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc (+1, -1) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc (+8, -8) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc (+4, -3) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_switch.cc (+1, -1) (Diff)
/source/blender/nodes/intern/node_geometry_exec.cc (+3, -2) (Diff)
/source/blender/nodes/intern/node_socket.cc (+2, -2) (Diff)
/source/blender/nodes/intern/type_conversions.cc (+25, -25) (Diff)
/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc (+7, -6) (Diff)
/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc (+4, -4) (Diff)
/source/blender/blenkernel/intern/attribute_access.cc (+4, -4) (Diff)
/source/blender/blenkernel/intern/attribute_math.cc (+9, -6) (Diff)
/source/blender/blenkernel/intern/geometry_component_mesh.cc (+11, -9) (Diff)
/source/blender/blenlib/BLI_color.hh (+267, -35) (Diff)
/source/blender/blenlib/CMakeLists.txt (+2, -0) (Diff)
/source/blender/draw/intern/draw_cache_impl.h (+0, -1) (Diff)
/source/blender/editors/space_spreadsheet/spreadsheet_cell_value.hh (+1, -1) (Diff)
/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc (+1, -1) (Diff)
/source/blender/editors/space_spreadsheet/spreadsheet_layout.cc (+1, -1) (Diff)
/source/blender/functions/intern/cpp_types.cc (+2, -2) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc (+10, -6) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc (+3, -3) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc (+16, -12) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_curve_map.cc (+4, -3) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc (+1, -1) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc (+8, -8) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc (+4, -3) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_switch.cc (+1, -1) (Diff)
/source/blender/nodes/intern/node_geometry_exec.cc (+3, -2) (Diff)
/source/blender/nodes/intern/node_socket.cc (+2, -2) (Diff)
/source/blender/nodes/intern/type_conversions.cc (+25, -25) (Diff)
/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc (+7, -6) (Diff)
/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc (+4, -4) (Diff)