; Original version : Elias ; ; 0.1a Raymond Ostertag 2004/10 ; - changed menu entry ; vim: expandtab : tabstop=3 : shiftwidth=3 : smarttab ; plot a pixel with color (r, g, b) at position (x, y) to drawable (draw) (define (plot draw x y r g b) (set! pixel (cons-array 3 'byte)) (aset pixel 0 r) (aset pixel 1 g) (aset pixel 2 b) (gimp-drawable-set-pixel draw x y 3 pixel) (gimp-drawable-update draw x y 1 1) ) (define (layers-to-grid orig-image orig-draw width height x-gap y-gap max-line) (set! n (car (gimp-image-get-layers orig-image))) (set! grid-width (if (< n max-line) n max-line)) (set! grid-height (trunc (/ (- (+ n grid-width) 1) grid-width))) (set! new-width (- (* grid-width (+ width x-gap)) x-gap)) (set! new-height (- (* grid-height (+ height y-gap)) y-gap)) ; create new image, with layer and drawable (set! image (car (gimp-image-new new-width new-height RGB))) (set! layer (car (gimp-layer-new image new-width new-height RGBA-IMAGE "Layer" 100 NORMAL-MODE))) (gimp-image-add-layer image layer -1) (set! draw (car (gimp-image-get-active-drawable image))) (gimp-edit-clear draw) (set! layers (cadr (gimp-image-get-layers orig-image))) (set! i n) (set! y 0) (while (and (< y new-height) (> i 0)) (set! x 0) (while (and (< x new-width) (> i 0)) (set! i (+ -1 i)) (gimp-image-set-active-layer orig-image (aref layers i)) (set! orig-draw (car (gimp-image-get-active-drawable orig-image))) ; copy rect out of orig (gimp-rect-select orig-image 0 0 width height REPLACE 0 0) (gimp-edit-copy orig-draw) (gimp-selection-none orig-image) ; paste into current layer (set! sel (car (gimp-edit-paste draw 1))) (gimp-layer-set-offsets sel x y) (gimp-floating-sel-anchor sel) (set! x (+ x (+ width x-gap))) ) (set! y (+ y (+ height y-gap))) ) (gimp-display-new image) ) (define (grid-to-layers orig-image orig-draw width height x-gap y-gap max-line) ; create new image (set! image (car (gimp-image-new width height RGB))) (set! orig-width (car (gimp-image-width orig-image))) (set! orig-height (car (gimp-image-height orig-image))) (gimp-image-undo-group-start orig-image) (set! y 0) (while (< y orig-height) (set! x 0) (while (< x orig-width) ; create, add and activate layer (set! layer (car (gimp-layer-new image width height RGBA-IMAGE "Layer" 100 NORMAL-MODE))) (gimp-image-add-layer image layer -1) (gimp-image-set-active-layer image layer) (set! draw (car (gimp-image-get-active-drawable image))) (gimp-edit-clear draw) ; copy rect out of orig (gimp-rect-select orig-image x y width height REPLACE 0 0) (gimp-edit-copy orig-draw) (gimp-selection-none orig-image) ; paste into current layer (set! sel (car (gimp-edit-paste draw 1))) (gimp-layer-set-offsets sel 0 0) (gimp-floating-sel-anchor sel) (set! x (+ (+ x width) x-gap)) ) (set! y (+ (+ y height) y-gap)) ) (gimp-image-undo-group-end orig-image) (gimp-display-new image) ) (define (script-fu-layergrid orig-image orig-draw width height x-gap y-gap max-line direction) (if (= direction 0) (layers-to-grid orig-image orig-draw width height x-gap y-gap max-line) (grid-to-layers orig-image orig-draw width height x-gap y-gap max-line) ) ) (script-fu-register "script-fu-layergrid" _"/Script-Fu/Utils/LayerGrid..." "Transforms layers into a grid, or a grid into layers." "Elias " "" "2003-11-13" "*" SF-IMAGE "Input Image" 0 SF-DRAWABLE "Input Drawable" 0 SF-ADJUSTMENT "Picture Width" '(32 1 1000 1 10 0 1) SF-ADJUSTMENT "Picture Height" '(32 1 1000 1 10 0 1) SF-ADJUSTMENT "Gap Width" '(0 0 1000 1 10 0 1) SF-ADJUSTMENT "Gap Height" '(0 0 1000 1 10 0 1) SF-ADJUSTMENT "Max pictures in row " '(8 1 1000 1 10 0 1) SF-OPTION "Direction" '("Layers->Grid" "Grid->Layers") )