From aeb1e61aa753beacf442763f0df23af8fb9c781c Mon Sep 17 00:00:00 2001 From: amoibos Date: Sun, 11 Jan 2015 23:29:47 +0100 Subject: [PATCH] let python do the endian stuff --- PIL/_binary.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/PIL/_binary.py b/PIL/_binary.py index 51ce45a79..89a05a46f 100644 --- a/PIL/_binary.py +++ b/PIL/_binary.py @@ -11,6 +11,8 @@ # See the README file for information on usage and redistribution. # +from struct import unpack, pack + if bytes is str: def i8(c): return ord(c) @@ -34,7 +36,7 @@ def i16le(c, o=0): c: string containing bytes to convert o: offset of bytes to convert in string """ - return i8(c[o]) | (i8(c[o+1]) << 8) + return unpack("H", c[o:o+2]) def i32be(c, o=0): - return ((i8(c[o]) << 24) | (i8(c[o+1]) << 16) | - (i8(c[o+2]) << 8) | i8(c[o+3])) + return unpack(">I", c[o:o+4]) # Output, le = little endian, be = big endian def o16le(i): - return o8(i) + o8(i >> 8) + return pack("> 8) + o8(i >> 16) + o8(i >> 24) + return pack("> 8) + o8(i) + return pack(">H", i) def o32be(i): - return o8(i >> 24) + o8(i >> 16) + o8(i >> 8) + o8(i) + return pack(">I", i) # End of file