You are here

Use alpha channels directly

If I understand correctly, you can obtain the information by, for each layer, selecting its alpha channel and subtracting the alpha channels of all the layers above it from the selection.

(define (get-boundses image)
  (let ((layers (vector->list (cadr (gimp-image-get-layers image)))))
    (let loop ((sources (reverse layers))
               (boundses '()) )
      (if (null? sources)
        boundses
        (begin
          (gimp-image-select-item image CHANNEL-OP-REPLACE (car sources))
          (unless (null? (cdr sources))
            (map (lambda (x)
              (gimp-image-select-item image CHANNEL-OP-SUBTRACT x) )
              (cdr sources) ))
          (loop (cdr sources)
                (cons (gimp-selection-bounds image) boundses) ))))))

Each of the lists in the resulting 'boundses' is a list comprising (EMPTY? X1 Y1 X2 Y2), where EMPTY? is zero if the respective layer is completely covered by the layers above it.

Subscribe to Comments for "Use alpha channels directly"