fortplot_colors Module

Color parsing and management for matplotlib-compatible color syntax

Supports: - Hex colors: #FF0000, #F00 - RGB tuples: (1.0, 0.5, 0.0), (255, 128, 0) - Named colors: red, blue, green, etc. - Single letters: r, g, b, c, m, y, k, w - RGBA with alpha channel support - Performance optimization through caching



Derived Types

type, public ::  color_t

Components

Type Visibility Attributes Name Initial
real(kind=wp), public :: r = 0.0_wp
real(kind=wp), public :: g = 0.0_wp
real(kind=wp), public :: b = 0.0_wp
real(kind=wp), public :: a = 1.0_wp
logical, public :: valid = .false.

Functions

public function is_valid_color(color_str) result(is_valid)

Check if color string is valid without full parsing

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: color_str

Return Value logical

public function get_cache_hit_rate() result(hit_rate)

Get cache hit rate for performance monitoring

Arguments

None

Return Value real(kind=wp)

public function validate_color_for_backend(color_str, backend) result(is_valid)

Validate color for specific backend constraints

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: color_str
character(len=*), intent(in) :: backend

Return Value logical


Subroutines

public subroutine parse_color(color_str, rgb, success)

Parse matplotlib-compatible color string to RGB values [0,1]

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: color_str
real(kind=wp), intent(out) :: rgb(3)
logical, intent(out) :: success

public subroutine parse_color_rgba(color_str, rgba, success)

Parse color string to RGBA values [0,1] including alpha channel

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: color_str
real(kind=wp), intent(out) :: rgba(4)
logical, intent(out) :: success

public subroutine clear_color_cache()

Clear the color cache

Arguments

None

public subroutine parse_colors_bulk(color_specs, rgb_results, success_flags)

Parse multiple colors efficiently

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: color_specs(:)
real(kind=wp), intent(out) :: rgb_results(:,:)
logical, intent(out) :: success_flags(:)

public subroutine rgb_to_hsv(rgb, hsv)

Convert RGB to HSV color space

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: rgb(3)
real(kind=wp), intent(out) :: hsv(3)

public subroutine rgb_to_lab(rgb, lab)

Convert RGB to LAB color space (simplified implementation)

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: rgb(3)
real(kind=wp), intent(out) :: lab(3)

public subroutine apply_colormap_to_array(values, colormap, rgb_mapped)

Apply colormap to array of values efficiently

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: values(:)
character(len=*), intent(in) :: colormap
real(kind=wp), intent(out) :: rgb_mapped(:,:)