changed (mostly rewritten) to correctly create patterns from drawables

2004-01-10  Michael Natterer  <mitch@gimp.org>

	* plug-ins/script-fu/scripts/select-to-pattern.scm: changed
	(mostly rewritten) to correctly create patterns from drawables
	with or without alpha. Also work correctly with or without a
	currently active selection. Fixes bug #131088.
This commit is contained in:
Michael Natterer 2004-01-10 15:16:58 +00:00 committed by Michael Natterer
parent 5680acaadc
commit 5a85f09261
2 changed files with 46 additions and 51 deletions

View file

@ -1,3 +1,10 @@
2004-01-10 Michael Natterer <mitch@gimp.org>
* plug-ins/script-fu/scripts/select-to-pattern.scm: changed
(mostly rewritten) to correctly create patterns from drawables
with or without alpha. Also work correctly with or without a
currently active selection. Fixes bug #131088.
2004-01-09 Sven Neumann <sven@gimp.org>
* app/gui/tips-dialog.c (tips_dialog_create): don't free the

View file

@ -24,65 +24,53 @@
(define (script-fu-selection-to-pattern image drawable desc filename)
(let* (
(type (car (gimp-drawable-type drawable)))
(old-bg (car (gimp-palette-get-background))))
(set! selection-bounds (gimp-selection-bounds image))
(set! select-offset-x (cadr selection-bounds))
(set! select-offset-y (caddr selection-bounds))
(set! selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
(set! selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
(gimp-image-undo-disable image)
(if (= (car (gimp-selection-is-empty image)) TRUE)
(begin
(gimp-selection-layer-alpha drawable)
(set! active-selection (car (gimp-selection-save image)))
(set! from-selection FALSE))
(begin
(set! from-selection TRUE)
(set! active-selection (car (gimp-selection-save image)))))
(if (= (car (gimp-selection-is-empty image)) TRUE)
(begin
(set! selection-width (car (gimp-drawable-width drawable)))
(set! selection-height (car (gimp-drawable-height drawable))))
(begin
(set! selection-bounds (gimp-drawable-mask-bounds drawable))
(set! select-offset-x (cadr selection-bounds))
(set! select-offset-y (caddr selection-bounds))
(set! selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
(set! selection-height (- (caddr (cddr selection-bounds)) select-offset-y))))
(gimp-edit-copy drawable)
(if (= (car (gimp-drawable-has-alpha drawable)) TRUE)
(set! pattern-draw-type RGBA-IMAGE)
(set! pattern-draw-type RGB-IMAGE))
(set! pattern_draw_type RGB-IMAGE)
(set! pattern-image-type RGB)
(set! pattern_image_type RGB)
(set! pattern-image (car (gimp-image-new selection-width selection-height
pattern-image-type)))
(set! pattern-image (car (gimp-image-new selection-width selection-height pattern_image_type)))
(set! pattern-draw
(car (gimp-layer-new pattern-image selection-width selection-height
pattern-draw-type "Pattern" 100 NORMAL-MODE)))
(set! pattern-draw
(car (gimp-layer-new pattern-image
selection-width
selection-height pattern_draw_type "Pattern" 100 NORMAL-MODE)))
(gimp-drawable-fill pattern-draw TRANSPARENT-FILL)
(gimp-image-add-layer pattern-image pattern-draw 0)
(gimp-image-add-layer pattern-image pattern-draw 0)
(gimp-selection-none pattern-image)
(gimp-edit-copy drawable)
(let ((floating-sel (car (gimp-edit-paste pattern-draw FALSE))))
(gimp-floating-sel-anchor floating-sel))
(let ((floating-sel (car (gimp-edit-paste pattern-draw FALSE))))
(gimp-floating-sel-anchor floating-sel))
(set! data-dir (car (gimp-gimprc-query "gimp_dir")))
(set! filename2 (string-append data-dir
"/patterns/"
filename
(number->string image)
".pat"))
(set! data-dir (car (gimp-gimprc-query "gimp_dir")))
(set! filename2 (string-append data-dir
"/patterns/"
filename
(number->string image)
".pat"))
(file-pat-save 1 pattern-image pattern-draw filename2 "" desc)
(gimp-patterns-refresh)
(gimp-patterns-set-pattern desc)
(file-pat-save 1 pattern-image pattern-draw filename2 "" desc)
(gimp-patterns-refresh)
(gimp-patterns-set-pattern desc)
(gimp-palette-set-background old-bg)
(gimp-image-undo-enable image)
(gimp-image-set-active-layer image drawable)
(gimp-image-delete pattern-image)
(gimp-displays-flush)))
(gimp-image-delete pattern-image)
(gimp-displays-flush))
(script-fu-register "script-fu-selection-to-pattern"
_"<Image>/Script-Fu/Selection/To _Pattern..."
@ -91,7 +79,7 @@
"Cameron Gregory"
"09/02/2003"
"RGB* GRAY*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-STRING _"Pattern Name" "My Pattern"
SF-STRING _"Filename" "mypattern")
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-STRING _"Pattern Name" "My Pattern"
SF-STRING _"Filename" "mypattern")