From 7a2e4c98667b65fbbdb7f7501ed74e3244c71bd0 Mon Sep 17 00:00:00 2001 From: withgod Date: Sun, 7 Jun 2009 18:40:12 +0900 Subject: [PATCH] implements IceCtroller **Texture methods --- pyweb/mumble/MumbleCtlIce.py | 38 ++++++++++++++++++++++++++++++++---- pyweb/mumble/mctl.py | 7 ++++--- pyweb/settings.py | 4 ++-- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/pyweb/mumble/MumbleCtlIce.py b/pyweb/mumble/MumbleCtlIce.py index a1ac494..c9d33e8 100755 --- a/pyweb/mumble/MumbleCtlIce.py +++ b/pyweb/mumble/MumbleCtlIce.py @@ -164,11 +164,41 @@ class MumbleCtlIce(MumbleCtlBase): self._getIceServerObject(srvid).setACL(id, acls, groups, inherit) - - def getTexture(self, srvid, mumbleid): - print self._getIceServerObject(srvid).getTexture(mumbleid) - #return Image.fromstring( "RGBA", ( 600, 60 ), self._getIceServerObject(srvid).getTexture(mumbleid)); + texture = self._getIceServerObject(srvid).getTexture(mumbleid) + if len(texture) == 0: + raise ValueError( "No Texture has been set." ); + # this returns a list of bytes. + decompressed = decompress( texture ); + # iterate over 4 byte chunks of the string + imgdata = ""; + for idx in range( 0, len(decompressed), 4 ): + # read 4 bytes = BGRA and convert to RGBA + # manual wrote getTexture returns "Textures are stored as zlib compress()ed 600x60 32-bit RGBA data." + # http://mumble.sourceforge.net/slice/Murmur/Server.html#getTexture + # but return values BGRA X( + bgra = unpack( "4B", decompressed[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", ( 600, 60 ), imgdata); + + def setTexture(self, srvid, mumbleid, infile): + # open image, convert to RGBA, and resize to 600x60 + img = Image.open( infile ).convert( "RGBA" ).transform( ( 600, 60 ), Image.EXTENT, ( 0, 0, 600, 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] ); + # compress using zlib + compressed = compress( bgrastring ); + # pack the original length in 4 byte big endian, and concat the compressed + # data to it to emulate qCompress(). + texture = pack( ">L", len(bgrastring) ) + compressed; + # finally call murmur and set the texture + self._getIceServerObject(srvid).setTexture(mumbleid, texture) @staticmethod def setUnicodeFlag(data): diff --git a/pyweb/mumble/mctl.py b/pyweb/mumble/mctl.py index bef6362..71f22de 100755 --- a/pyweb/mumble/mctl.py +++ b/pyweb/mumble/mctl.py @@ -97,7 +97,7 @@ if __name__ == "__main__": x = int(sys.argv[1]) dbusCtl = MumbleCtlDbus() iceCtl = MumbleCtlIce() - + """ print "equal test ---" print "getBootedServers [%s]" % (dbusCtl.getBootedServers() == iceCtl.getBootedServers()) print "getChannels [%s]" % (dbusCtl.getChannels(x) == iceCtl.getChannels(x)) @@ -108,6 +108,7 @@ if __name__ == "__main__": print "getAllConf(x) [%s]" % (dbusCtl.getAllConf(x) == iceCtl.getAllConf(x)) print "getRegisteredPlayers(x) [%s]" % (dbusCtl.getRegisteredPlayers(x) == iceCtl.getRegisteredPlayers(x)) print "getTexture(2, 30) [%s]" % (dbusCtl.getTexture(2, 30) == iceCtl.getTexture(2, 30)) - - #print iceCtl.getTexture(2, 30).__class__ + """ + dbusCtl.getTexture(2, 30).__class__ + iceCtl.getTexture(2, 30).__class__ #print dbusCtl.getTexture(2, 30).__class__ diff --git a/pyweb/settings.py b/pyweb/settings.py index 03f26d3..0843a9a 100755 --- a/pyweb/settings.py +++ b/pyweb/settings.py @@ -56,8 +56,8 @@ if not MUMBLE_DJANGO_ROOT or not exists( MUMBLE_DJANGO_ROOT ): DEBUG = True TEMPLATE_DEBUG = DEBUG -#DAOTYPE='ice' -DAOTYPE='dbus' +DAOTYPE='ice' +#DAOTYPE='dbus' ADMINS = ( # ('Your Name', 'your_email@domain.com'),