[EMAIL PROTECTED] (2003-03-22 at 1850.44 +0100):
> I've just completed a Script-Fu script that some people may find quite
> useful (I've missed this functionality myself several times). The
> purpose is to convert a layer's Alpha channel into a mask for editing
> it and later using Apply Layer Mask to put it back. The idea is
> similar to what QuickMask does with selections.

Maybe you can poke at the attached script, a bit old, for reference
see http://groups.yahoo.com/group/gimpi/message/1479 and other posts
about tribes 2 video game. This one does not lose the selection, IIRC.

GSR
 
;;; The GIMP -- an image manipulation program
;;; Copyright (C) 1995 Spencer Kimball and Peter Mattis
;;;
;;; script-fu-alpha-to-mask
;;; Moves the transparency of a layer to the layer mask
;;; Copyright (c) 2001 Guillermo S. Romero
;;; famrom infernal-iceberg.com
;;;
;;; ### License  ###
;;;
;;; 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
;;; the Free Software Foundation; either version 2 of the License, or
;;; (at your option) any later version.
;;; 
;;; 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.
;;; 
;;; You can get a copy of the GNU General Public License from
;;; http://www.gnu.org/, the site of the Free Software Foundation, Inc.
;;;
;;; ### Versions ###
;;;
;;; 1.00.00 Initial release (bug in L,C&P thumbnails?)
;;; 1.01.00 Support for existent mask added (merges transp and mask)
;;;
;;; ### Inline Documentation ###
;;;
;;; # Intro #
;;; Tribes 2, a 3D game, uses RGBA PNGs as skins. The RGB are used for
;;; the colour, and the A for the quantity of environment mapping.
;;; Or at least that is what I have read.
;;;
;;; # Requirements #
;;; This plugin was developed with Gimp 1.2.1 CVS
;;; Check all your plugins and scripts in the DB Browser before reporting bugs
;;; It merges the current layer mask, if any, so you keep all info
;;;
;;; # Parameters #
;;; None the user can play with
;;;
;;; # Debugging and to-do #
;;; Look for ";; @" comments


;; Helper functions from neon-logo.scm
(define (set-pt a index x y)
  (prog1
   (aset a (* index 2) x)
   (aset a (+ (* index 2) 1) y)))

(define (AlphaSpline)
  (let* ((a (cons-array 6 'byte)))
    (set-pt a 0 0 255)
    (set-pt a 1 127 255)
    (set-pt a 2 255 255)
    a))


;; The function
(define (script-fu-alpha-to-mask inImg inDrw)

  ;; Start
  (gimp-undo-push-group-start inImg)

  ;; Merge mask if any
  (set! OrigMask (car (gimp-layer-mask inDrw)))
  (if (not (= OrigMask -1))
      (gimp-image-remove-layer-mask inImg inDrw APPLY))

  ;; Create a new mask
  (set! Mask (car (gimp-layer-create-mask inDrw ALPHA-MASK)))
  (gimp-image-add-layer-mask inImg inDrw Mask)

  ;; Unerase
  (gimp-curves-spline inDrw 4 6 (AlphaSpline))

  ;; End
  (gimp-undo-push-group-end inImg)
  ;; @ The image thumbnail does not update nice
  ;; @ Undo then redo and it refreshes to the right state
  ;; @ Or change to another image and back, to force the refresh too
  ;; @ A refresh call is missing in the C code, maybe fixed for Gimp 1.4
  (gimp-displays-flush))

;; Register!
(script-fu-register "script-fu-alpha-to-mask"
                    _"<Image>/Script-Fu/Utils/Alpha to layer mask"
                    "Moves the transparency of a layer to the layer mask"
                    "Guillermo S. Romero"
                    "2001 Guillermo S. Romero"
                    "2001-04-29"
                    "RGBA GRAYA"
                    SF-IMAGE "Image where to work" 0
                    SF-DRAWABLE "Drawable to modify" 0)
_______________________________________________
Gimp-user mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-user

Reply via email to