Created
March 10, 2023 18:26
-
-
Save UuuNyaa/c884563cdf18ea784851b2e08434e6dc to your computer and use it in GitHub Desktop.
Color correction for GIMP Script-Fu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (string-replace strIn strReplace strReplaceWith) | |
| (let* ( | |
| (curIndex 0) | |
| (replaceLen (string-length strReplace)) | |
| (replaceWithLen (string-length strReplaceWith)) | |
| (inLen (string-length strIn)) | |
| (result strIn) | |
| ) | |
| ;loop through the main string searching for the substring | |
| (while (<= (+ curIndex replaceLen) inLen) | |
| ;check to see if the substring is a match | |
| (if (substring-equal? strReplace result curIndex (+ curIndex replaceLen)) | |
| (begin | |
| ;create the result string | |
| (set! result (string-append (substring result 0 curIndex) strReplaceWith (substring result (+ curIndex replaceLen) inLen))) | |
| ;now set the current index to the end of the replacement. it will get incremented below so take 1 away so we don't miss anything | |
| (set! curIndex (-(+ curIndex replaceWithLen) 1)) | |
| ;set new length for inLen so we can accurately grab what we need | |
| (set! inLen (string-length result)) | |
| ) | |
| ) | |
| (set! curIndex (+ curIndex 1)) | |
| ) | |
| (string-append result "") | |
| ) | |
| ) | |
| (define (correct-color input) | |
| (let* ( | |
| (img (car (gimp-file-load 1 input input))) | |
| (layer (car (gimp-image-get-active-layer img))) | |
| (output (string-replace input ".png" ".jpg")) | |
| ) | |
| (gimp-drawable-hue-saturation layer HUE-RANGE-ALL 0 0 100 0) | |
| (gimp-drawable-hue-saturation layer HUE-RANGE-RED 0 0 -5 0) | |
| ;; (gimp-drawable-hue-saturation layer HUE-RANGE-BLUE 0 0 -50 0) | |
| ;; (gimp-drawable-hue-saturation layer HUE-RANGE-YELLOW 0 0 -50 0) | |
| (gimp-drawable-hue-saturation layer HUE-RANGE-MAGENTA 0 0 -10 0) | |
| (gimp-curves-spline layer HISTOGRAM-VALUE 10 #(32 0 80 80 160 180 240 250 255 255)) | |
| ;; (gimp-display-new img) | |
| (file-jpeg-save RUN-NONINTERACTIVE img layer output output 0.99 0.01 1 0 "" 0 1 0 0) | |
| (gimp-image-delete img) | |
| ) | |
| ) | |
| (for-each correct-color | |
| (map | |
| (lambda (x) (string-append "/path/to/" x)) | |
| '( | |
| "test.png" | |
| ) | |
| ) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment