Skip to content

Commit

Permalink
Fix RGB values within valid range (Refs #29)
Browse files Browse the repository at this point in the history
- Fix Lagange and Bezier interpolation functions.
- Ensure that the RGB values are within the valid range of 0 to 255.
  • Loading branch information
gha3mi committed Feb 14, 2024
1 parent 9ba6816 commit a96eb9f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/colormap_class.f90
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,9 @@ pure function bezier(colors, levels) result(map)
map_r(i,:) = map_r(i,:) + real(colors(j+1,:), wp)*&
real(factorial(order), wp)/(real(factorial(j), wp)*real(factorial(order-j), wp)) * t**j * (1.0_wp-t)**(order-j)
end do
map(i,:) = scale_real_int(map_r(i,:), 0, 255) ! Scale to integer RGB range
map(i,1) = min(255, max(0, nint(map_r(i,1))))
map(i,2) = min(255, max(0, nint(map_r(i,2))))
map(i,3) = min(255, max(0, nint(map_r(i,3))))
end do
end function bezier

Expand Down Expand Up @@ -992,7 +994,9 @@ pure function lagrange(colors, levels) result(map)
map_r(i,2) = dot_product(lagrange_poly(t,order+1), real(colors(:,2), wp))
map_r(i,3) = dot_product(lagrange_poly(t,order+1), real(colors(:,3), wp))
end do
map(i,:) = scale_real_int(map_r(i,:), 0, 255) ! Scale to integer RGB range
map(i,1) = min(255, max(0, nint(map_r(i,1))))
map(i,2) = min(255, max(0, nint(map_r(i,2))))
map(i,3) = min(255, max(0, nint(map_r(i,3))))
end do
end function lagrange

Expand Down

0 comments on commit a96eb9f

Please sign in to comment.