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)
6 from PixMapWrapper
import *
9 class ExtPixMapWrapper(PixMapWrapper
):
13 data
= self
.tostring()[1:] + chr(0)
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
):
24 #bands=1 Greyscale image
29 num
=Numeric
.resize(num
,(y
,x
,1))
34 num
=Numeric
.concatenate((num
,num
,num
),2)
37 alpha
=Numeric
.ones((y
,x
))*255
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
)