Fixed Undo handling, make sure that the bumpmap is big enough to avoid

2004-02-09  Simon Budig  <simon@gimp.org>

	* plug-ins/script-fu/scripts/add-bevel.scm: Fixed Undo
	handling, make sure that the bumpmap is big enough to
	avoid artefacts.

	Fixes bug #130636.
This commit is contained in:
Simon Budig 2004-02-09 16:41:54 +00:00 committed by Simon Budig
parent 8b6812805d
commit 771e44dca1
2 changed files with 91 additions and 107 deletions

View File

@ -1,3 +1,11 @@
2004-02-09 Simon Budig <simon@gimp.org>
* plug-ins/script-fu/scripts/add-bevel.scm: Fixed Undo
handling, make sure that the bumpmap is big enough to
avoid artefacts.
Fixes bug #130636.
2004-02-09 Michael Natterer <mitch@gimp.org> 2004-02-09 Michael Natterer <mitch@gimp.org>
* app/gui/gui.c (gui_libs_init): added runtime check for * app/gui/gui.c (gui_libs_init): added runtime check for

View File

@ -1,8 +1,8 @@
; The GIMP -- an image manipulation program ; The GIMP -- an image manipulation program
; Copyright (C) 1995 Spencer Kimball and Peter Mattis ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
; ;
; add-bevel.scm version 1.03 ; add-bevel.scm version 1.04
; Time-stamp: <1997-12-16 09:17:24 ard> ; Time-stamp: <2004-02-09 17:07:06 simon>
; ;
; This program is free software; you can redistribute it and/or modify ; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by ; it under the terms of the GNU General Public License as published by
@ -42,77 +42,63 @@
; Nutscrape. ; Nutscrape.
; Changed path (removed "filters/"). ; Changed path (removed "filters/").
; 1.03: adds one-pixel border before bumpmapping, and removes it after. ; 1.03: adds one-pixel border before bumpmapping, and removes it after.
; Got rid of the crop-pixel-border option (no longer reqd). ; Got rid of the crop-pixel-border option (no longer reqd).
; 1.04: Fixed undo handling, ensure that bumpmap is big enough,
; (instead of resizing the image). Removed references to outdated
; bumpmap plugin. (Simon)
; ;
;
; BUMPMAP NOTES:
;
; Bumpmap changed arguments from version 2.02 to 2.03. If you use the
; wrong bumpmap.c this script will either bomb (good) or produce a
; naff image (bad).
;
; As distributed this script expects bumpmap 2.03 (shipped with Gimp 0.99.11)
; or later.
;
; BUGS
;
; Doesn't allow undoing the operation. Why not?
;
; Sometimes (and that's the scary bit) gives bogloads of GTK warnings.
;
(define (script-fu-add-bevel img (define (script-fu-add-bevel img
drawable drawable
thickness thickness
work-on-copy work-on-copy
keep-bump-layer) keep-bump-layer)
(let* ((index 0) (let* ((index 0)
(bevelling-whole-image FALSE) (bevelling-whole-image FALSE)
(greyness 0) (greyness 0)
(thickness (abs thickness)) (thickness (abs thickness))
(type (car (gimp-drawable-type-with-alpha drawable))) (type (car (gimp-drawable-type-with-alpha drawable)))
(image (if (= work-on-copy TRUE) (car (gimp-image-duplicate img)) img)) (image (if (= work-on-copy TRUE) (car (gimp-image-duplicate img)) img))
(pic-layer (car (gimp-image-get-active-drawable image))) (pic-layer (car (gimp-image-get-active-drawable image)))
(width (car (gimp-drawable-width pic-layer))) (offsets (gimp-drawable-offsets pic-layer))
(height (car (gimp-drawable-height pic-layer))) (width (car (gimp-drawable-width pic-layer)))
(old-bg (car (gimp-palette-get-background))) (height (car (gimp-drawable-height pic-layer)))
(bump-layer (car (gimp-layer-new image (old-bg (car (gimp-palette-get-background)))
width ; Bumpmap has a one pixel border on each side
height (bump-layer (car (gimp-layer-new image
GRAY (+ width 2)
"Bumpmap" (+ height 2)
100 GRAY
NORMAL-MODE))) "Bumpmap"
) 100
; NORMAL-MODE)))
)
; If the layer we're bevelling is offset from the image's origin, we ; If the layer we're bevelling is offset from the image's origin, we
; have to do the same to the bumpmap ; have to do the same to the bumpmap
(let ((offsets (gimp-drawable-offsets pic-layer))) (gimp-layer-set-offsets bump-layer (- (car offsets) 1)
(gimp-layer-set-offsets bump-layer (car offsets) (cadr offsets)) (- (cadr offsets) 1))
)
(gimp-image-undo-disable image) ; disable undo on copy, start group otherwise
(if (= work-on-copy TRUE)
(gimp-image-undo-disable image)
(gimp-image-undo-group-start image)
)
;------------------------------------------------------------ ;------------------------------------------------------------
; ;
; Set the selection to the area we want to bevel. ; Set the selection to the area we want to bevel.
; ;
(if (eq? 0 (car (gimp-selection-bounds image))) (if (eq? 0 (car (gimp-selection-bounds image)))
(begin (begin
(set! bevelling-whole-image TRUE) ; ...so we can restore things properly, and crop. (set! bevelling-whole-image TRUE) ; ...so we can restore things properly, and crop.
(gimp-image-resize image (+ width 2) (+ height 2) 1 1) (if (car (gimp-drawable-has-alpha pic-layer))
(if (not (eq? 0 (car (gimp-drawable-has-alpha pic-layer)))) ; Wish I knew Scheme (gimp-selection-layer-alpha pic-layer)
(gimp-selection-layer-alpha pic-layer) (gimp-selection-all image)
(begin )
(gimp-selection-all image) )
) )
)
)
)
; Store it for later. ; Store it for later.
(set! select (car (gimp-selection-save image))) (set! select (car (gimp-selection-save image)))
@ -128,17 +114,18 @@
(set! index 1) (set! index 1)
(while (< index thickness) (while (< index thickness)
(set! greyness (/ (* index 255) thickness)) (set! greyness (/ (* index 255) thickness))
(gimp-palette-set-background (list greyness greyness greyness)) (gimp-palette-set-background (list greyness greyness greyness))
;(gimp-selection-feather image 1) ;Stop the slopey jaggies? ;(gimp-selection-feather image 1) ;Stop the slopey jaggies?
(gimp-edit-bucket-fill bump-layer BG-BUCKET-FILL NORMAL-MODE (gimp-edit-bucket-fill bump-layer BG-BUCKET-FILL NORMAL-MODE
100 0 FALSE 0 0) 100 0 FALSE 0 0)
(gimp-selection-shrink image 1) (gimp-selection-shrink image 1)
(set! index (+ index 1)) (set! index (+ index 1))
) )
; Now the white interior ; Now the white interior
(gimp-palette-set-background '(255 255 255)) (gimp-palette-set-background '(255 255 255))
(gimp-edit-bucket-fill bump-layer BG-BUCKET-FILL NORMAL-MODE 100 0 FALSE 0 0) (gimp-edit-bucket-fill bump-layer BG-BUCKET-FILL NORMAL-MODE
100 0 FALSE 0 0)
;------------------------------------------------------------ ;------------------------------------------------------------
; ;
@ -150,68 +137,57 @@
;(plug-in-gauss-rle 1 image bump-layer thickness TRUE TRUE) ;(plug-in-gauss-rle 1 image bump-layer thickness TRUE TRUE)
; If they're working on the original, let them undo the filter's effects.
; This doesn't work - ideas why not?
(if (= work-on-copy FALSE) (gimp-image-undo-enable image))
; ;
; BUMPMAP INVOCATION: ; BUMPMAP INVOCATION:
; ;
; Use the former with version 2.02 or earlier of bumpmap:
; Use the latter with version 2.03 or later (ambient and waterlevel params)
; (plug-in-bump-map 1 image pic-layer bump-layer 125 45 3 0 0 TRUE FALSE 1)
(plug-in-bump-map 1 image pic-layer bump-layer 125 45 3 0 0 0 0 TRUE FALSE 1) (plug-in-bump-map 1 image pic-layer bump-layer 125 45 3 0 0 0 0 TRUE FALSE 1)
;
; Shave one pixel off each edge
;
(if (= bevelling-whole-image TRUE)
(gimp-image-crop image width height 1 1)
)
(if (= work-on-copy FALSE) (gimp-image-undo-disable image))
;------------------------------------------------------------ ;------------------------------------------------------------
; ;
; Restore things ; Restore things
; ;
(gimp-palette-set-background old-bg) (gimp-palette-set-background old-bg)
(if (= bevelling-whole-image TRUE) (if (= bevelling-whole-image TRUE)
(gimp-selection-none image) ; No selection to start with (gimp-selection-none image) ; No selection to start with
(gimp-selection-load select) (gimp-selection-load select)
) )
; If they started with a selection, they can Select->Invert then ; If they started with a selection, they can Select->Invert then
; Edit->Clear for a cutout. ; Edit->Clear for a cutout.
; clean up ; clean up
(gimp-image-remove-channel image select) (gimp-image-remove-channel image select)
(if (= keep-bump-layer TRUE) (if (= keep-bump-layer TRUE)
(begin (begin
(gimp-image-add-layer image bump-layer 1) (gimp-image-add-layer image bump-layer 1)
(gimp-drawable-set-visible bump-layer 0)) (gimp-drawable-set-visible bump-layer 0))
(gimp-drawable-delete bump-layer) (gimp-drawable-delete bump-layer)
) )
(gimp-image-set-active-layer image pic-layer) (gimp-image-set-active-layer image pic-layer)
(if (= work-on-copy TRUE) (gimp-display-new image)) ; enable undo / end undo group
(if (= work-on-copy TRUE)
(gimp-image-undo-enable image) (begin
(gimp-display-new image)
(gimp-image-undo-enable image)
)
(gimp-image-undo-group-end image)
)
(gimp-displays-flush) (gimp-displays-flush)
) )
) )
(script-fu-register "script-fu-add-bevel" (script-fu-register "script-fu-add-bevel"
_"<Image>/Script-Fu/Decor/Add B_evel..." _"<Image>/Script-Fu/Decor/Add B_evel..."
"Add a bevel to an image" "Add a bevel to an image"
"Andrew Donkin <ard@cs.waikato.ac.nz>" "Andrew Donkin <ard@cs.waikato.ac.nz>"
"Andrew Donkin" "Andrew Donkin"
"1997/11/06" "1997/11/06"
"RGB* GRAY*" "RGB* GRAY*"
SF-IMAGE "Image" 0 SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0 SF-DRAWABLE "Drawable" 0
SF-ADJUSTMENT _"Thickness" '(5 0 30 1 2 0 0) SF-ADJUSTMENT _"Thickness" '(5 0 30 1 2 0 0)
SF-TOGGLE _"Work on Copy" TRUE SF-TOGGLE _"Work on Copy" TRUE
SF-TOGGLE _"Keep Bump Layer" FALSE SF-TOGGLE _"Keep Bump Layer" FALSE
) )