I'm trying to copy a layer from one image to another.  Below is a
fragment of the code to do this; new-image has already been created
with the same base type as the old-image.

    (set! new-layer 
         (car (gimp-layer-new new-image
                              (car (gimp-drawable-width old-layer))
                              (car (gimp-drawable-height old-layer))
                              (car (gimp-drawable-type old-layer))
                              (car (gimp-layer-get-name old-layer))
                              (car (gimp-layer-get-opacity old-layer))
                              (car (gimp-layer-get-mode old-layer)))))
    (gimp-layer-set-preserve-trans new-layer (car (gimp-layer-get-preserve-trans 
old-layer)))
    (gimp-layer-set-visible new-layer (car (gimp-layer-get-visible old-layer)))

    ;; Add the layer to the image copy.  Then tweak the position to correspond to the
    ;; position in the old image.
    (gimp-image-add-layer new-image new-layer -1)
    (gimp-selection-all new-image)
    (gimp-edit-clear new-layer)
    (gimp-selection-all old-image)
    (gimp-edit-copy old-layer)
    (gimp-floating-sel-anchor (car (gimp-edit-paste new-layer 1)))
    (apply gimp-layer-set-offsets (append (list new-layer)
                                          (gimp-drawable-offsets old-layer)))

I've taken the above and stepped through it one line at a time from
the SIOD console.  When I do the (gimp-floating-sel-anchor ...) the
layer is misaligned compared to the original.  The
gimp-layer-set-offsets does nothing.  Once the selection is anchored,
that's where it stays.  The layer I'm copying is the same size as the
canvas and the same size as the background layer.

I also tried this interactively by selecting the whole canvas, copying
the layer and pasting it into the new layer in the new image.  It does
the same thing, i.e., the layer is not ending up aligned the same as
the original.

What am I doing wrong?

roland
-- 
                       PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD                             RL Enterprises
[EMAIL PROTECTED]                     76-15 113th Street, Apt 3B
[EMAIL PROTECTED]                       Forest Hills, NY 11375


Here is the entire function which is being called, in case the above
is not enough to show what is happening.

(define (astro-image-copy old-image background-only)
  (let* ((width (car (gimp-image-width old-image)))
         (height (car (gimp-image-height old-image)))
         ;; Create new image with same dimensions and type as original.
         (new-image (car (gimp-image-new width height (car (gimp-image-base-type 
old-image)))))
         (layer-array (cadr (gimp-image-get-layers old-image)))
         (layer-count (length layer-array))
         old-layer new-layer)
    ;; Start working on the new image, discard undo information.
    (gimp-image-undo-disable new-image)
    (while (> layer-count 0)
           (set! layer-count (- layer-count 1))
           (set! old-layer (aref layer-array layer-count))
           ;; Create a new layer for the image copy with properties identical to those 
in the
           ;; old image
           (set! new-layer 
                 (car (gimp-layer-new new-image
                                      (car (gimp-drawable-width old-layer))
                                      (car (gimp-drawable-height old-layer))
                                      (car (gimp-drawable-type old-layer))
                                      (car (gimp-layer-get-name old-layer))
                                      (car (gimp-layer-get-opacity old-layer))
                                      (car (gimp-layer-get-mode old-layer)))))
           (gimp-layer-set-preserve-trans new-layer (car 
(gimp-layer-get-preserve-trans old-layer)))
           (gimp-layer-set-visible new-layer (car (gimp-layer-get-visible old-layer)))
           
           ;; Add the layer to the image copy.  Then tweak the position to correspond 
to the
           ;; position in the old image.
           (gimp-image-add-layer new-image new-layer -1)
           (gimp-selection-all new-image)
           (gimp-edit-clear new-layer)
           (gimp-selection-all old-image)
           (gimp-edit-copy old-layer)
           (gimp-floating-sel-anchor (car (gimp-edit-paste new-layer 1)))
           (apply gimp-layer-set-offsets (append (list new-layer)
                                                 (gimp-drawable-offsets old-layer)))
           
           ;; If the background-only flag is non-nil, quit after copying the bottom 
layer.
           (if background-only
               (set! layer-count 0)))
    
    ;; Enable undo tracking and return the new image.
    (gimp-image-undo-enable new-image)
    new-image))
_______________________________________________
Gimp-developer mailing list
[EMAIL PROTECTED]
http://lists.xcf.berkeley.edu/mailman/listinfo/gimp-developer

Reply via email to