[Skencil-commits] r519 - in skencil/branches/skencil-0.6/Plugins: . Filters/Lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Feb 12 00:08:36 CET 2006


Author: bh
Date: 2006-02-12 00:08:36 +0100 (Sun, 12 Feb 2006)
New Revision: 519

Modified:
   skencil/branches/skencil-0.6/Plugins/ChangeLog
   skencil/branches/skencil-0.6/Plugins/Filters/Lib/drawfile.py
   skencil/branches/skencil-0.6/Plugins/Filters/Lib/spritefile.py
Log:
Fix some problems in the drawfile filter because of changes in the
int/long unification introduced in Python 2.4

* Filters/Lib/spritefile.py (spritefile.str2num): Implement in
terms of the module global str2num:
(str2num): New function that was formerly a method with the same
used in spritefile and drawfile.  The implementation is completely
new because the old implementation was incorrect in Python 2.4
because the behavior of the << operator has change a bit.

* Filters/Lib/drawfile.py (drawfile_object.str2num)
(drawfile.str2num): Implement in terms of spritefile.str2num.
(drawfile.new): Convert some hexadecimal constants to decimal so
that they still have the same value in python 2.4 as before.


Modified: skencil/branches/skencil-0.6/Plugins/ChangeLog
===================================================================
--- skencil/branches/skencil-0.6/Plugins/ChangeLog	2006-01-29 19:56:22 UTC (rev 518)
+++ skencil/branches/skencil-0.6/Plugins/ChangeLog	2006-02-11 23:08:36 UTC (rev 519)
@@ -1,3 +1,20 @@
+2006-02-12  Bernhard Herzog  <bh at intevation.de>
+
+	Fix some problems in the drawfile filter because of changes in the
+	int/long unification introduced in Python 2.4
+
+	* Filters/Lib/spritefile.py (spritefile.str2num): Implement in
+	terms of the module global str2num:
+	(str2num): New function that was formerly a method with the same
+	used in spritefile and drawfile.  The implementation is completely
+	new because the old implementation was incorrect in Python 2.4
+	because the behavior of the << operator has change a bit.
+
+	* Filters/Lib/drawfile.py (drawfile_object.str2num)
+	(drawfile.str2num): Implement in terms of spritefile.str2num.
+	(drawfile.new): Convert some hexadecimal constants to decimal so
+	that they still have the same value in python 2.4 as before.
+
 2005-02-14  Bernhard Herzog  <bh at intevation.de>
 
 	* Filters/svgloader.py (rx_trafo): Modify the regular expression

Modified: skencil/branches/skencil-0.6/Plugins/Filters/Lib/drawfile.py
===================================================================
--- skencil/branches/skencil-0.6/Plugins/Filters/Lib/drawfile.py	2006-01-29 19:56:22 UTC (rev 518)
+++ skencil/branches/skencil-0.6/Plugins/Filters/Lib/drawfile.py	2006-02-11 23:08:36 UTC (rev 519)
@@ -33,6 +33,7 @@
 # Tidied up some formatting errors caused by mixing tabs and spaces.
 
 import spritefile, os, string
+import struct
 
 version = '0.13 (Sat 20th October 2001)'
 
@@ -81,15 +82,7 @@
         return s
 
     def str2num(self, size, s):
-    
-        i = 0
-        n = 0
-        while i < size:
-    
-            n = n | (ord(s[i]) << (i*8))
-            i = i + 1
-    
-        return n
+        return spritefile.str2num(size, s)
 
     def decode_double(self, s):
         """Return a floating point number from an IEEE double encoded in a
@@ -1292,9 +1285,18 @@
 
         self.x1 = 0x7fffffff
         self.y1 = 0x7fffffff
-        self.x2 = 0x80000000
-        self.y2 = 0x80000000
 
+        # Note: self.x2 and self.y2 used to be initialized to
+        # 0x80000000.  In Python 2.4 the meaning of that literal has
+        # changed to be always positive instead of being negative on 32
+        # bit platforms.  To avoid problems with that the constants have
+        # been replaced with the decimal version of the interpretation
+        # of 0x80000000 on 32 bit machines.  It's not clear whether that
+        # really is the right solution.  The intention of the value
+        # might have been something like -sys.maxint - 1 instead.
+        self.x2 = -2147483648
+        self.y2 = -2147483648
+
     def number(self, size, n):
     
         # Little endian writing
@@ -1312,17 +1314,9 @@
 
 
     def str2num(self, size, s):
-    
-        i = 0
-        n = 0
-        while i < size:
-    
-            n = n | (ord(s[i]) << (i*8))
-            i = i + 1
-    
-        return n
-    
-    
+        return spritefile.str2num(size, s)
+
+
     def read_group(self, f):
 
         start = f.tell() - 4

Modified: skencil/branches/skencil-0.6/Plugins/Filters/Lib/spritefile.py
===================================================================
--- skencil/branches/skencil-0.6/Plugins/Filters/Lib/spritefile.py	2006-01-29 19:56:22 UTC (rev 518)
+++ skencil/branches/skencil-0.6/Plugins/Filters/Lib/spritefile.py	2006-02-11 23:08:36 UTC (rev 519)
@@ -26,6 +26,22 @@
 
 version = '0.12 (Sun 17th February 2002)'
 
+import struct
+
+def str2num(size, s):
+    """Convert the integer in the string s which has to contain size bytes.
+
+    Allowed sizes are 1, 2 and 4.  1-byte and 2-byte integers as
+    unsigned and 4-byte integers as signed.  All numbers were
+    little-endian.
+    """
+    formats = ("<B", "<H", None, "<i")
+    format = formats[size - 1]
+    if format is None:
+        raise ValueError("Size must be one of 1, 2, or 4")
+    return struct.unpack(format, s)[0]
+
+
 class spritefile_error(Exception):
 
     pass
@@ -119,15 +135,7 @@
 
 
     def str2num(self, size, s):
-    
-        i = 0
-        n = 0
-        while i < size:
-    
-            n = n | (ord(s[i]) << (i*8))
-            i = i + 1
-    
-        return n
+        return str2num(size, s)
 
     def sprite2rgb(self, file, width, height, h_words, first_bit_used, bpp,
                    palette):



More information about the Skencil-commits mailing list