Create colormap from Lagrange interpolation of control colors
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | colors(:,:) | |||
| integer, | intent(in), | optional | :: | levels |
pure function lagrange(colors, levels) result(map) integer, intent(in) :: colors(:,:) integer, intent(in), optional :: levels integer, allocatable :: map(:,:) integer :: order, i, j, n, levels_ real(wp) :: t, r, g, b real(wp), allocatable :: L(:) ! Set default value for levels if (present(levels)) then levels_ = levels else levels_ = 256 end if ! Order of the Lagrange interpolation. order = size(colors, 1) - 1 if (order < 1) error stop "Error: At least two control colors are required for Lagrange interpolation." allocate(map(levels_, 3)) n = order + 1 do i = 1, levels_ t = real(i-1, wp) / real(levels_-1, wp) L = lagrange_poly(t, n) r = 0.0_wp g = 0.0_wp b = 0.0_wp do j = 1, n r = r + L(j) * real(colors(j,1), wp) g = g + L(j) * real(colors(j,2), wp) b = b + L(j) * real(colors(j,3), wp) end do map(i,1) = min(255, max(0, nint(r))) map(i,2) = min(255, max(0, nint(g))) map(i,3) = min(255, max(0, nint(b))) end do end function lagrange