scripts/applications/gimp/agw.scm

140 lines
5.0 KiB
Scheme

(define author "Alison Gray Watson")
(define license "Public domain")
(define path "<Image>/:>")
(define (agw-vec-list vl)
(vector->list (cadr vl)))
(define (agw-p67-font)
(for-each
(lambda (im)
(let ((dr (car (gimp-image-get-active-drawable im))))
(unless (eq? (gimp-image-base-type im) RGB)
(gimp-image-convert-rgb im))
(gimp-drawable-desaturate dr DESATURATE-LUMINANCE)
(gimp-image-convert-indexed
im
CONVERT-DITHER-NONE
CONVERT-PALETTE-CUSTOM
0 ; num-cols (ign.)
FALSE ; alpha-dither
FALSE ; remove-unused
"p67 palette")))
(agw-vec-list (gimp-image-list))))
(define (agw-overwrite-all)
(for-each
(lambda (im)
(let ((dr (car (gimp-image-get-active-drawable im)))
(fn (car (gimp-image-get-filename im))))
(gimp-file-save RUN-NONINTERACTIVE im dr fn fn)))
(agw-vec-list (gimp-image-list))))
(define (agw-overlay-all fn mode)
(for-each
(lambda (im)
(let ((ly (car (gimp-file-load-layer RUN-NONINTERACTIVE im fn))))
(gimp-image-insert-layer im ly 0 -1)
(gimp-layer-set-mode ly mode)
(gimp-image-merge-down im ly CLIP-TO-IMAGE)))
(agw-vec-list (gimp-image-list))))
(define (agw-destructure im)
(for-each
(lambda (dr)
(when (gimp-item-is-drawable dr)
(plug-in-colortoalpha RUN-NONINTERACTIVE im dr (car (gimp-context-get-foreground)))))
(agw-vec-list (gimp-image-get-layers im))))
(define (agw-export-font start dir pfx sfx im)
(letrec ((num (string->number start 16))
(pre (string-append dir "/" pfx))
(fnc (lambda (ls n)
(let* ((dr (car ls))
(nx (cdr ls))
(dr? (gimp-item-is-drawable dr))
(fnm (string-append pre (number->string n 16) sfx)))
(when dr?
(gimp-file-save RUN-NONINTERACTIVE im dr fnm fnm))
(unless (null? nx)
(fnc nx (if dr? (succ n) n)))))))
(fnc (agw-vec-list (gimp-image-get-layers im)) num)))
(define (agw-240p-ify im1)
(let ((ly1 (car (gimp-image-get-active-layer im1)))
(dr1 (car (gimp-image-get-active-drawable im1)))
(im2 (car (gimp-image-duplicate im1)))
(w (inexact->exact
(floor (/ (car (gimp-image-width im1))
(/ (car (gimp-image-height im1)) 240))))))
(gimp-context-set-interpolation INTERPOLATION-NONE)
(gimp-image-scale im1 w 240)
(plug-in-threshold-alpha RUN-NONINTERACTIVE im1 dr1 128)
(gimp-context-set-interpolation INTERPOLATION-CUBIC)
(gimp-image-scale im2 w 240)
(let ((ly2 (car (gimp-layer-new-from-drawable
(car (gimp-image-get-active-drawable im2))
im1))))
(gimp-image-insert-layer im1 ly2 0 -1)
(gimp-image-select-rectangle im1 CHANNEL-OP-REPLACE 0 0 w 240)
(gimp-image-select-item im1 CHANNEL-OP-SUBTRACT ly1)
(gimp-drawable-edit-clear ly2)
(gimp-image-select-rectangle im1 CHANNEL-OP-SUBTRACT 0 0 w 240)
(gimp-image-merge-down im1 ly2 CLIP-TO-BOTTOM-LAYER)
(plug-in-autocrop RUN-NONINTERACTIVE im1
(car (gimp-image-get-active-drawable im1)))
(gimp-image-delete im2))))
(define (agw-threshold-all)
(for-each
(lambda (im)
(plug-in-threshold-alpha RUN-NONINTERACTIVE im (car (gimp-image-get-active-drawable im)) 128)
(plug-in-autocrop RUN-NONINTERACTIVE im (car (gimp-image-get-active-drawable im))))
(agw-vec-list (gimp-image-list))))
(script-fu-register
"agw-p67-font"
"P67 Font" "Converts open images to a project67 font"
author license "2021" "")
(script-fu-register
"agw-overwrite-all"
"Overwrite All Open" "Overwrites all currently open images"
author license "2021" "")
(script-fu-register
"agw-overlay-all"
"Overlay All Open" "Overlays all currently open images with another image"
author license "2021" ""
SF-FILENAME "File" ""
SF-ENUM "Mode" '("LayerMode" "normal"))
(script-fu-register
"agw-destructure"
"Destructure" "Deletes foreground color from all layers"
author license "2021" ""
SF-IMAGE "Image" 0)
(script-fu-register
"agw-export-font"
"Export Layers" "Exports all layers with hex names"
author license "2021" ""
SF-STRING "Start Number (Hex)" "21"
SF-DIRNAME "Output Directory" "/tmp"
SF-STRING "Prefix (Optional)" ""
SF-STRING "Suffix (Required)" ".png"
SF-IMAGE "Image" 0)
(script-fu-register
"agw-240p-ify"
"240p-ify" "Crunches an image to 240p smoothly"
author license "2022" ""
SF-IMAGE "Image" 0)
(script-fu-register
"agw-threshold-all"
"Threshold All" "Crunches all of the open images"
author license "2022" "")
(script-fu-menu-register "agw-p67-font" path)
(script-fu-menu-register "agw-overwrite-all" path)
(script-fu-menu-register "agw-overlay-all" path)
(script-fu-menu-register "agw-destructure" path)
(script-fu-menu-register "agw-export-font" path)
(script-fu-menu-register "agw-240p-ify" path)
(script-fu-menu-register "agw-threshold-all" path)