;; (define (slow-pixellate image drawable block-size) ;; (define (average-color drawable x1 y1 x2 y2) ;; (define (->u8 x) (min (inexact->exact (round x)) 255)) ;; (let* ((width (- x2 x1)) ;; (height (- y2 y1)) ;; (size (* width height))) ;; (let loop ((color #f) ;; (i 0)) ;; (if (< i size) ;; (let* ((row (quotient i width)) ;; (column (remainder i width)) ;; (x (+ x1 column)) ;; (y (+ y1 row)) ;; (color2 (vector->list ;; (cadr (gimp-drawable-get-pixel drawable x y))))) ;; (if color ;; (loop (map + color color2) (+ i 1)) ;; (loop color2 (+ i 1)))) ;; (map (lambda (c) (->u8 (/ c size))) color))))) ;; (let* ((width (car (gimp-drawable-width drawable))) ;; (height (car (gimp-drawable-height drawable))) ;; (rows (ceiling (/ height block-size))) ;; (columns (ceiling (/ width block-size)))) ;; (do ((row 0 (+ row 1))) ;; ((= row rows)) ;; (do ((column 0 (+ column 1))) ;; ((= column columns)) ;; (let* ((x1 (* column block-size)) ;; (y1 (* row block-size)) ;; (x2 (min (+ x1 block-size) width)) ;; (y2 (min (+ y1 block-size) height))) ;; (gimp-image-select-rectangle image CHANNEL-OP-REPLACE ;; x1 y1 ;; block-size block-size) ;; (gimp-context-set-foreground (average-color drawable x1 y1 x2 y2)) ;; (gimp-drawable-edit-fill drawable FILL-FOREGROUND)))))) (define (script-fu-pixellate image drawable blur-radius block-size) (gimp-image-undo-group-start image) (gimp-context-push) (gimp-context-set-defaults) (gimp-progress-set-text "Blurring image...") (plug-in-gauss RUN-NONINTERACTIVE image drawable blur-radius) (gimp-progress-set-text "Pixellating image...") ;; (slow-pixellate image drawable block-size) (plug-in-pixelize RUN-NONINTERACTIVE image drawable block-size) (gimp-context-pop) (gimp-image-undo-group-end image) (gimp-displays-flush)) (script-fu-register "script-fu-pixellate" ; function name "Pixellate" ; menu label "Turns an image into blocks" ; description "Vasilij Schneidermann" ; author "Copyright (C) 2020 Vasilij Schneidermann " ; copyright notice "December 05, 2020" ; creation date "RGB*" ; supported image type SF-IMAGE "Image" FALSE SF-DRAWABLE "Drawable" FALSE SF-ADJUSTMENT "Blur radius" (sf-adjustment 100 0 500 '(step-inc 10) '(page-inc 50) `(type ,SF-SLIDER)) SF-ADJUSTMENT "Block size" (sf-adjustment 48 2 1024 '(step-inc 2) '(page-inc 8) `(type ,SF-SLIDER))) (script-fu-menu-register "script-fu-pixellate" "/Filters/Distorts")