2006-12-09 21:33:38 +00:00
|
|
|
; GIMP - The GNU Image Manipulation Program
|
1997-11-24 22:05:25 +00:00
|
|
|
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
2006-10-16 01:08:54 +00:00
|
|
|
;
|
1997-11-24 22:05:25 +00:00
|
|
|
; Selection to Image
|
|
|
|
; Copyright (c) 1997 Adrian Likins
|
|
|
|
; aklikins@eos.ncsu.edu
|
|
|
|
;
|
2013-01-27 17:52:38 +02:00
|
|
|
; Takes the Current selection and saves it as a separate image.
|
1997-11-24 22:05:25 +00:00
|
|
|
;
|
|
|
|
;
|
2009-01-17 22:28:01 +00:00
|
|
|
; This program is free software: you can redistribute it and/or modify
|
1997-11-24 22:05:25 +00:00
|
|
|
; it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
; the Free Software Foundation; either version 3 of the License, or
|
1997-11-24 22:05:25 +00:00
|
|
|
; (at your option) any later version.
|
2006-10-16 01:08:54 +00:00
|
|
|
;
|
1997-11-24 22:05:25 +00:00
|
|
|
; This program is distributed in the hope that it will be useful,
|
|
|
|
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
; GNU General Public License for more details.
|
2006-10-16 01:08:54 +00:00
|
|
|
;
|
1997-11-24 22:05:25 +00:00
|
|
|
; You should have received a copy of the GNU General Public License
|
2018-07-11 23:27:07 +02:00
|
|
|
; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
(define (script-fu-selection-to-image image drawable)
|
2006-10-16 01:08:54 +00:00
|
|
|
(let* (
|
|
|
|
(draw-type (car (gimp-drawable-type-with-alpha drawable)))
|
2021-04-20 17:47:11 +02:00
|
|
|
(image-type (car (gimp-image-get-base-type image)))
|
2006-10-16 01:08:54 +00:00
|
|
|
(selection-bounds (gimp-selection-bounds image))
|
|
|
|
(select-offset-x (cadr selection-bounds))
|
|
|
|
(select-offset-y (caddr selection-bounds))
|
|
|
|
(selection-width (- (cadr (cddr selection-bounds)) select-offset-x))
|
|
|
|
(selection-height (- (caddr (cddr selection-bounds)) select-offset-y))
|
2008-01-15 05:15:08 +00:00
|
|
|
(active-selection 0)
|
|
|
|
(from-selection 0)
|
|
|
|
(new-image 0)
|
|
|
|
(new-draw 0)
|
2006-10-16 01:08:54 +00:00
|
|
|
)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2004-09-23 11:16:23 +00:00
|
|
|
(gimp-context-push)
|
2011-11-09 02:42:34 -05:00
|
|
|
(gimp-context-set-defaults)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
1999-10-17 00:07:55 +00:00
|
|
|
(gimp-image-undo-disable image)
|
2006-10-16 01:08:54 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
(if (= (car (gimp-selection-is-empty image)) TRUE)
|
2006-10-16 01:08:54 +00:00
|
|
|
(begin
|
2011-11-05 20:13:02 +01:00
|
|
|
(gimp-image-select-item image CHANNEL-OP-REPLACE drawable)
|
2006-10-16 01:08:54 +00:00
|
|
|
(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)))
|
|
|
|
)
|
|
|
|
)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
Fix #6026, SF scripts use v3 API for multilayer gimp-edit-copy, -cut, -paste.
Why: in v3 the signature for gimp-edit-foo PDB procedures changed to support multilayer selection.
This finishes the task for ScriptFu scripts in the GIMP repo.
This is not a complete list, since some calls were changed incidentally by prior commits.
You can grep for "edit-copy" etc. in script-fu/scripts to find instances.
This also makes incidental changes, to script calls to plug-in-tile,
which now also has a changed signature to support multilayer.
The changes are simple code transformations.
The changes to gimp-edit-paste calls are more complex,
a mixed bag of a few lines transformed to more lines.
I did not try to understand the larger logic of the changed plugins.
I did not test the changed plugins functionally.
I used a harness to call each changed plugin with improvised parameters,
only checking that the test plugin did not throw runtime errors,
not checking that they produced correct images.
As noted in the issue, this might be undone if the original signatures
for gimp-edit-foo are restored as convenience functions.
2022-05-06 16:40:19 -04:00
|
|
|
(gimp-edit-copy 1 (vector drawable))
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2004-09-23 11:16:23 +00:00
|
|
|
(set! new-image (car (gimp-image-new selection-width
|
2006-10-16 01:08:54 +00:00
|
|
|
selection-height image-type)))
|
2004-09-23 11:16:23 +00:00
|
|
|
(set! new-draw (car (gimp-layer-new new-image
|
2006-10-16 01:08:54 +00:00
|
|
|
selection-width selection-height
|
2017-01-09 20:37:30 +01:00
|
|
|
draw-type "Selection" 100 LAYER-MODE-NORMAL)))
|
2011-03-02 02:55:43 -05:00
|
|
|
(gimp-image-insert-layer new-image new-draw 0 0)
|
2017-01-09 20:37:30 +01:00
|
|
|
(gimp-drawable-fill new-draw FILL-BACKGROUND)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
Fix #6026, SF scripts use v3 API for multilayer gimp-edit-copy, -cut, -paste.
Why: in v3 the signature for gimp-edit-foo PDB procedures changed to support multilayer selection.
This finishes the task for ScriptFu scripts in the GIMP repo.
This is not a complete list, since some calls were changed incidentally by prior commits.
You can grep for "edit-copy" etc. in script-fu/scripts to find instances.
This also makes incidental changes, to script calls to plug-in-tile,
which now also has a changed signature to support multilayer.
The changes are simple code transformations.
The changes to gimp-edit-paste calls are more complex,
a mixed bag of a few lines transformed to more lines.
I did not try to understand the larger logic of the changed plugins.
I did not test the changed plugins functionally.
I used a harness to call each changed plugin with improvised parameters,
only checking that the test plugin did not throw runtime errors,
not checking that they produced correct images.
As noted in the issue, this might be undone if the original signatures
for gimp-edit-foo are restored as convenience functions.
2022-05-06 16:40:19 -04:00
|
|
|
(let* (
|
|
|
|
(pasted (gimp-edit-paste new-draw FALSE))
|
|
|
|
(num-pasted (car pasted))
|
|
|
|
(floating-sel (aref (cadr pasted) (- num-pasted 1)))
|
|
|
|
)
|
2006-10-16 01:08:54 +00:00
|
|
|
(gimp-floating-sel-anchor floating-sel)
|
|
|
|
)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
1999-10-17 00:07:55 +00:00
|
|
|
(gimp-image-undo-enable image)
|
2022-08-02 16:40:08 -04:00
|
|
|
(gimp-image-set-selected-layers image 1 (vector drawable))
|
1999-12-19 17:19:51 +00:00
|
|
|
(gimp-display-new new-image)
|
2004-09-23 11:16:23 +00:00
|
|
|
(gimp-displays-flush)
|
|
|
|
|
2006-10-16 01:08:54 +00:00
|
|
|
(gimp-context-pop)
|
|
|
|
)
|
|
|
|
)
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
(script-fu-register "script-fu-selection-to-image"
|
2006-10-16 01:08:54 +00:00
|
|
|
_"To _Image"
|
|
|
|
_"Convert a selection to an image"
|
|
|
|
"Adrian Likins <adrian@gimp.org>"
|
|
|
|
"Adrian Likins"
|
|
|
|
"10/07/97"
|
|
|
|
"RGB* GRAY*"
|
|
|
|
SF-IMAGE "Image" 0
|
|
|
|
SF-DRAWABLE "Drawable" 0
|
|
|
|
)
|