Image Unit Processing Interface. INFO: This is a mirror from GitHub. github.com/sona-tau/iupi

Added color value invert.

Added function that takes an RGB color, converts it to HSV, inverts its "value" parameter and converts it back to RGB. Also fixed a modulo error.

authored by

Sebastián Ramírez and committed by
GitHub
8773524a fbc5ca15

+5 -3
+5 -3
src/main.rkt
··· 62 62 (bin-op-builder c1 c2 -)) 63 63 64 64 ; Invert the luminosity of a color 65 - (define (color-value-invert [c : RGBColor]) : RGBColor 66 - c) 65 + (define (color-value-invert [c1 : RGBColor]) : RGBColor 66 + (type-case HSVColor (rgb->hsv c1) 67 + [(hsvcolor h1 s1 v1) 68 + (let [(h2 h1) (s2 s1) (v2 (- 1 v1))] (hsv->rgb [hsvcolor h2 s2 v2]))])) 67 69 68 70 ; Invert each RGB value of a color 69 71 (define (color-linear-invert [c : RGBColor]) : RGBColor ··· 135 137 (l (/ (+ x+ x-) 2)) 136 138 (h [cond 137 139 [(= c 0) 0] 138 - [(= v r) (* 60 (modulo (/ (- g b) c) 6))] 140 + [(= v r) (* 60 (modulo (round (/ (- g b) c)) 6))] 139 141 [(= v g) (* 60 (+ (/ (- b r) c) 2))] 140 142 [(= v b) (* 60 (+ (/ (- r g) c) 4))] 141 143 [else 0]])