[PATCH] x2: OpenRaster visibility attribute, OpenRaster layer position bugfix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Attached and inlined.

>From 9fc67096c7da7722b38c5f7bf1741795a635d7cd Mon Sep 17 00:00:00 2001
From: Jon Nordby <jononor@xxxxxxxxx>
Date: Thu, 6 May 2010 03:44:01 +0200
Subject: [PATCH 1/2] plug-ins: OpenRaster, fix wrong layer positions

Don't store layer offsets in the PNG, or honor them on loading. The layer
position is given by the OpenRaster layer attributes alone. This caused a bug
where the offsets were applied twice, positioning the layer wrong.
---
plug-ins/pygimp/plug-ins/file-openraster.py | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/plug-ins/pygimp/plug-ins/file-openraster.py
b/plug-ins/pygimp/plug-ins/file-openraster.py
index f4bf6e2..b41fc09 100755
--- a/plug-ins/pygimp/plug-ins/file-openraster.py
+++ b/plug-ins/pygimp/plug-ins/file-openraster.py
@@ -86,7 +86,7 @@ def save_ora(img, drawable, filename, raw_filename):
def store_layer(img, drawable, path):
tmp = os.path.join(tempdir, 'tmp.png')
interlace, compression = 0, 2
- png_chunks = (1, 1, 1, 1, 1) # write all PNG chunks
+ png_chunks = (1, 1, 0, 1, 1) # write all PNG chunks except oFFs(ets)
pdb['file-png-save'](img, drawable, tmp, 'tmp.png',
interlace, compression, *png_chunks)
orafile.write(tmp, path)
@@ -172,7 +172,7 @@ def load_ora(filename, raw_filename):
# import layer, set attributes and add to image
gimp_layer = pdb['gimp-file-load-layer'](img, tmp)
gimp_layer.name = name
- gimp_layer.translate(x, y) # move to correct position
+ gimp_layer.set_offsets(x, y) # move to correct position
gimp_layer.opacity = opac * 100 # a float between 0 and 100
img.add_layer(gimp_layer, layer_no)

--
1.7.0.5

>From fd3be813070a27d1409edabe570ca7a43cf94e93 Mon Sep 17 00:00:00 2001
From: Jon Nordby <jononor@xxxxxxxxx>
Date: Tue, 4 May 2010 12:42:53 +0200
Subject: [PATCH 2/2] plug-ins: OpenRaster visibility layer attribute

---
 plug-ins/pygimp/plug-ins/file-openraster.py |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/plug-ins/pygimp/plug-ins/file-openraster.py
b/plug-ins/pygimp/plug-ins/file-openraster.py
index b41fc09..4c4ae67 100755
--- a/plug-ins/pygimp/plug-ins/file-openraster.py
+++ b/plug-ins/pygimp/plug-ins/file-openraster.py
@@ -35,8 +35,9 @@ def get_layer_attributes(layer):
     x = int(a.get('x', '0'))
     y = int(a.get('y', '0'))
     opac = float(a.get('opacity', '1.0'))
+    visible = a.get('visibility', 'visible') != 'hidden'

-    return path, name, x, y, opac
+    return path, name, x, y, opac, visible


 def thumbnail_ora(filename, thumb_size):
@@ -92,7 +93,7 @@ def save_ora(img, drawable, filename, raw_filename):
         orafile.write(tmp, path)
         os.remove(tmp)

-    def add_layer(x, y, opac, gimp_layer, path):
+    def add_layer(x, y, opac, gimp_layer, path, visible=True):
         store_layer(img, gimp_layer, path)
         # create layer attributes
         layer = ET.Element('layer')
@@ -103,13 +104,14 @@ def save_ora(img, drawable, filename, raw_filename):
         a['x'] = str(x)
         a['y'] = str(y)
         a['opacity'] = str(opac)
+        a['visibility'] = 'visible' if visible else 'hidden'
         return layer

     # save layers
     for lay in img.layers:
         x, y = lay.offsets
         opac = lay.opacity / 100.0 # needs to be between 0.0 and 1.0
-        add_layer(x, y, opac, lay, 'data/%s.png' % lay.name)
+        add_layer(x, y, opac, lay, 'data/%s.png' % lay.name, lay.visible)

     # save thumbnail
     w, h = img.width, img.height
@@ -154,7 +156,7 @@ def load_ora(filename, raw_filename):
         return res

     for layer_no, layer in enumerate(get_layers(stack)):
-        path, name, x, y, opac = get_layer_attributes(layer)
+        path, name, x, y, opac, visible = get_layer_attributes(layer)

         if not path.lower().endswith('.png'):
             continue
@@ -174,6 +176,7 @@ def load_ora(filename, raw_filename):
         gimp_layer.name = name
         gimp_layer.set_offsets(x, y)  # move to correct position
         gimp_layer.opacity = opac * 100  # a float between 0 and 100
+        gimp_layer.visible = visible
         img.add_layer(gimp_layer, layer_no)

         os.remove(tmp)
-- 
1.7.0.5


--
Regards Jon Nordby - www.jonnor.com

Attachment: 0001-plug-ins-OpenRaster-fix-wrong-layer-positions.patch
Description: Binary data

Attachment: 0002-plug-ins-OpenRaster-visibility-layer-attribute.patch
Description: Binary data

_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux