From c709294181ff2cce376f54e4aefe83f52028f630 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Fri, 26 Feb 2010 00:26:04 +0100 Subject: [PATCH] adapt getTexture to work with the new texture format. 1.2.2 is buggy, so textures won't work with that version. fixes #79 --- pyweb/mumble/MumbleCtlIce.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/pyweb/mumble/MumbleCtlIce.py b/pyweb/mumble/MumbleCtlIce.py index e0568be..24a7e29 100644 --- a/pyweb/mumble/MumbleCtlIce.py +++ b/pyweb/mumble/MumbleCtlIce.py @@ -138,8 +138,11 @@ def MumbleCtlIce( connstring, slicefile=None, icesecret=None ): elif murmurversion[:2] == (1, 2) and murmurversion[:3] < 2: return MumbleCtlIce_120( connstring, meta ); - else: + elif murmurversion[:3] == 2: return MumbleCtlIce_122( connstring, meta ); + + elif murmurversion[:3] == 3: + return MumbleCtlIce_123( connstring, meta ); class MumbleCtlIce_118(MumbleCtlBase): @@ -500,27 +503,28 @@ class MumbleCtlIce_120(MumbleCtlIce_118): class MumbleCtlIce_122(MumbleCtlIce_120): @protectDjangoErrPage def getTexture(self, srvid, mumbleid): + raise ValueError( "This method is buggy in 1.2.2, sorry dude." ); + + @protectDjangoErrPage + def setTexture(self, srvid, mumbleid, infile): + img = open( infile, "rb" ) + self._getIceServerObject(srvid).setTexture(mumbleid, img) + + +class MumbleCtlIce_123(MumbleCtlIce_120): + @protectDjangoErrPage + def getTexture(self, srvid, mumbleid): + import sys texture = self._getIceServerObject(srvid).getTexture(mumbleid) if len(texture) == 0: raise ValueError( "No Texture has been set." ); - imgdata = "" - for idx in range( 0, len(texture)-4, 4 ): - bgra = unpack( "4B", texture[idx:idx+4] ); - imgdata += pack( "4B", bgra[2], bgra[1], bgra[0], bgra[3] ); - # return an 600x60 RGBA image object created from the data - return Image.fromstring( "RGBA", ( 88, 60 ), imgdata ); + from StringIO import StringIO + return Image.open( StringIO( texture ) ) @protectDjangoErrPage def setTexture(self, srvid, mumbleid, infile): # open image, convert to RGBA, and resize to 600x60 - img = Image.open( infile ).convert( "RGBA" ).transform( ( 88, 60 ), Image.EXTENT, ( 0, 0, 88, 60 ) ); - # iterate over the list and pack everything into a string - bgrastring = ""; - for ent in list( img.getdata() ): - # ent is in RGBA format, but Murmur wants BGRA (ARGB inverse), so stuff needs - # to be reordered when passed to pack() - bgrastring += pack( "4B", ent[2], ent[1], ent[0], ent[3] ); - # finally call murmur and set the texture - self._getIceServerObject(srvid).setTexture(mumbleid, bgrastring) + img = open( infile, "rb" ) + self._getIceServerObject(srvid).setTexture(mumbleid, img)