Move setting of ioready 'wait' earlier in call chain, to
[python/dscho.git] / Mac / Contrib / ImageHelpers / ExtPixMapWrapper.py
blobac261b5d37be7876c559e7d1eff2e572d16483ad
1 '''
2 A really quick and dirty hack to extend PixMapWrapper
3 They are mere copies of the toImage and fromImage methods.
4 Riccardo Trocca (rtrocca@libero.it)
5 '''
6 from PixMapWrapper import *
7 import Numeric
9 class ExtPixMapWrapper(PixMapWrapper):
11 def toNumeric(self):
13 data = self.tostring()[1:] + chr(0)
14 bounds = self.bounds
15 tmp=Numeric.fromstring(data,Numeric.UnsignedInt8)
16 #tmp.shape=(bounds[3]-bounds[1],bounds[2]-bounds[0],4)
17 tmp.shape=(bounds[2]-bounds[0],bounds[3]-bounds[1],4)
18 return Numeric.transpose(tmp,(1,0,2))
20 def fromNumeric(self,num):
21 s=num.shape
22 x=num.shape[1]
23 y=num.shape[0]
24 #bands=1 Greyscale image
25 #bands=3 RGB image
26 #bands=4 RGBA image
27 if len(s)==2:
28 bands=1
29 num=Numeric.resize(num,(y,x,1))
30 else:
31 bands=num.shape[2]
33 if bands==1:
34 num=Numeric.concatenate((num,num,num),2)
35 bands=3
36 if bands==3:
37 alpha=Numeric.ones((y,x))*255
38 alpha.shape=(y,x,1)
39 num=Numeric.concatenate((num,alpha),2)
41 data=chr(0)+Numeric.transpose(num,(1,0,2)).astype(Numeric.UnsignedInt8).tostring()
42 PixMapWrapper.fromstring(self,data,x,y)