From brett.calcott at gmail.com Mon May 2 15:31:33 2011 From: brett.calcott at gmail.com (Brett Calcott) Date: Mon, 2 May 2011 15:31:33 +0200 Subject: [Pygui] blobedit and py2app Message-ID: Hi, I can't see an answer anywhere to this question: http://mail.python.org/pipermail/pygui/2010-January/000051.html I'm having the same problem, running py2app on blobedit results in an app that doesn't work. From Console, I see this: 02/05/11 15:26:35 [0x0-0x46d46d].org.pythonmac.unspecified.blobedit[6779] from GUI import Application, ScrollableView, Document, Window, FileType, Cursor, rgb 02/05/11 15:26:35 [0x0-0x46d46d].org.pythonmac.unspecified.blobedit[6779] ImportError: No module named GUI For some reason it cannot import GUI. Examining the package, I can see that the library is indeed in there. So I'm not sure why the boot file cannot important it. Any clues? Thanks, Brett -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Sat May 28 10:55:32 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 28 May 2011 20:55:32 +1200 Subject: [Pygui] Convert RGBA to BGRA using standard library? Message-ID: <4DE0B884.10206@canterbury.ac.nz> Can anyone think of an efficient way to convert a string full of RGBA image data to BGRA, using only what's available in the standard library? I'm trying to add a function to PyGUI for creating an Image object from arbitrary data. The problem I'm having is that GDI+ on Windows expects BGRA, whereas most other platforms deal with RGBA. I don't want to require the user to supply the data in different formats on different platforms, so PyGUI needs to be able to convert where necessary. I know the conversion can be done easily using something like PIL or numpy, but I'm after a solution that doesn't depend on any third-party libraries. -- Greg From davecortesi at gmail.com Sat May 28 17:06:33 2011 From: davecortesi at gmail.com (David Cortesi) Date: Sat, 28 May 2011 08:06:33 -0700 Subject: [Pygui] Convert RGBA to BGRA using standard library? (Greg Ewing) Message-ID: > Can anyone think of an efficient way to convert a string > full of RGBA image data to BGRA, using only what's available > in the standard library? > ImageMagick, the venerable graphic toolbox, claims to do this conversion, and there are versions of it that can be loaded as python libs. Follow the links at www.imagemagick.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From manders2k.dev at gmail.com Sat May 28 17:16:57 2011 From: manders2k.dev at gmail.com (Matt Anderson) Date: Sat, 28 May 2011 10:16:57 -0500 Subject: [Pygui] Convert RGBA to BGRA using standard library? (Greg Ewing) In-Reply-To: References: Message-ID: I imagine it's not that hard to roll your own, if you can find out what the details of the formats are. If it's as simple as just swapping the R and B bytes in the string, you could make an array of bytes and do some swapping. If a spec is not readily available, I would try using a library that does the conversion for you on a very small image, and then compare the RGBA and BGRA versions and see if the bit twiddling that needs to be done is obvious (or can be deduced). Matt On May 28, 2011, at 10:06 AM, David Cortesi wrote: > > Can anyone think of an efficient way to convert a string > full of RGBA image data to BGRA, using only what's available > in the standard library? > > ImageMagick, the venerable graphic toolbox, claims to do this conversion, and there are versions of it that can be loaded as python libs. Follow the links at www.imagemagick.org > > _______________________________________________ > Pygui mailing list > Pygui at python.org > http://mail.python.org/mailman/listinfo/pygui -------------- next part -------------- An HTML attachment was scrubbed... URL: From greg.ewing at canterbury.ac.nz Mon May 30 02:05:08 2011 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Mon, 30 May 2011 12:05:08 +1200 Subject: [Pygui] Convert RGBA to BGRA using standard library? In-Reply-To: <4DE2DDA4.4070201@brush.co.nz> References: <4DE0B884.10206@canterbury.ac.nz> <4DE2DDA4.4070201@brush.co.nz> Message-ID: <4DE2DF34.2000302@canterbury.ac.nz> Berwyn Hoyt wrote: > I don't know whether this solution is 'efficient' by your > definition, but it uses standard libraries. It needs to be fast. Any solution that involves a Python loop over the pixels is totally off the radar, sorry. -- Greg From berhoyt+pygui at gmail.com Mon May 30 02:08:51 2011 From: berhoyt+pygui at gmail.com (Berwyn Hoyt) Date: Mon, 30 May 2011 12:08:51 +1200 Subject: [Pygui] Convert RGBA to BGRA using standard library? In-Reply-To: <4DE2DDA4.4070201@brush.co.nz> References: <4DE0B884.10206@canterbury.ac.nz> <4DE2DDA4.4070201@brush.co.nz> Message-ID: Hi Greg, Nice puzzle. I don't know whether this solution is 'efficient' by your definition, but it uses standard libraries. I understand that you just want to swap B and R in an array of bytes formatted like 'RGBARGBA'. For illustration purposes, I'll use this exact string as input data. I have three options. I haven't checked to see which is faster, but the first two options are memory efficient as they use iterators/generators instead of lists: data='RGBARGBA' from itertools import izip, chain pixels=izip(*[iter(data)]*4) # cluster into pixels per docs of zip() new_subpixels = (subpixel for p in pixels for subpixel in (p[2],p[1],p[0],p[3])) new_data = ''.join(new_subpixels) Section option: data='RGBARGBA' from itertools import izip, chain, imap pixels=izip(*[iter(data)]*4) # cluster into pixels per docs of zip() new_pixels = imap(lambda p: (p[2],p[1],p[0],p[3]), pixels) data = ''.join(chain(*new_pixels)) Third option is a slight variation involving zipping and unzipping. It takes more memory because it has to use zip instead of izip, but for all I know it may be faster: data='RGBARGBA' from itertools import izip, chain pixels=zip(*[iter(data)]*4) # cluster into pixels per docs of zip() R,G,B,A = izip(*pixels) # unzip new_pixels = zip(B,G,R,A) # re-zip in different order data = ''.join(chain(*new_pixels)) The last step is flattening the list. Looking up 'flatten' on google will reveal any number of ways to flatten lists and some may be more efficient than this, I don't know. The commented unzip/re-zip steps may be quicker to do with map() and a lambda function, and you may also find that they are a lot. Cheers, Berwyn -- Check out our *winning design* in this Bronchoscope Simulatorfor AirwaySkills ( TVNZ coverageor radio). Berwyn Hoyt, *Electronic Solutions & Business* -- Brush Technology *Ph:* +64 3 741 1204 *Mobile:* +64 21 045 7830 *Web:* brush.co.nz ------------------------ Greg wrote: Can anyone think of an efficient way to convert a string full of RGBA image data to BGRA, using only what's available in the standard library? I'm trying to add a function to PyGUI for creating an Image object from arbitrary data. The problem I'm having is that GDI+ on Windows expects BGRA, whereas most other platforms deal with RGBA. I don't want to require the user to supply the data in different formats on different platforms, so PyGUI needs to be able to convert where necessary. I know the conversion can be done easily using something like PIL or numpy, but I'm after a solution that doesn't depend on any third-party libraries. -------------- next part -------------- An HTML attachment was scrubbed... URL: From berhoyt+pygui at gmail.com Mon May 30 02:12:31 2011 From: berhoyt+pygui at gmail.com (Berwyn Hoyt) Date: Mon, 30 May 2011 12:12:31 +1200 Subject: [Pygui] Convert RGBA to BGRA using standard library? In-Reply-To: <4DE2E09D.8050209@brush.co.nz> References: <4DE0B884.10206@canterbury.ac.nz> <4DE2DDA4.4070201@brush.co.nz> <4DE2DF34.2000302@canterbury.ac.nz> <4DE2E09D.8050209@brush.co.nz> Message-ID: That's why I included the third option which only does C loops on the pixels. On 30/05/2011 12:05 p.m., Greg Ewing wrote: Berwyn Hoyt wrote: I don't know whether this solution is 'efficient' by your definition, but it uses standard libraries. It needs to be fast. Any solution that involves a Python loop over the pixels is totally off the radar, sorry. -- Check out our *winning design* in this Bronchoscope Simulatorfor AirwaySkills ( TVNZ coverageor radio). Berwyn Hoyt, *Electronic Solutions & Business* -- Brush Technology *Ph:* +64 3 741 1204 *Mobile:* +64 21 045 7830 *Web:* brush.co.nz -------------- next part -------------- An HTML attachment was scrubbed... URL: