144 |
|
|
145 |
return ret |
return ret |
146 |
|
|
147 |
def draw_raster_data(self, layer, x,y, data, format = 'BMP'): |
def draw_raster_data(self, x,y, data, format = 'BMP', opacity=1.0): |
148 |
|
|
149 |
mask = None |
mask = None |
150 |
alpha = None |
alpha = None |
168 |
else: |
else: |
169 |
stream = cStringIO.StringIO(image_data) |
stream = cStringIO.StringIO(image_data) |
170 |
image = wxImageFromStream(stream, raster_format_map[format]) |
image = wxImageFromStream(stream, raster_format_map[format]) |
171 |
|
|
172 |
if mask_data is not None: |
if mask_data is not None: |
173 |
stream = cStringIO.StringIO(mask_data) |
stream = cStringIO.StringIO(mask_data) |
174 |
mask = wxImageFromStream(stream, raster_format_map[format]) |
mask = wxImageFromStream(stream, raster_format_map[format]) |
176 |
elif alpha_data is not None: |
elif alpha_data is not None: |
177 |
stream = cStringIO.StringIO(alpha_data) |
stream = cStringIO.StringIO(alpha_data) |
178 |
alpha = wxImageFromStream(stream, raster_format_map[format]) |
alpha = wxImageFromStream(stream, raster_format_map[format]) |
179 |
alpha = alpha.GetData()[:] # XXX: do we need to copy this? |
alpha = alpha.GetData() #[:] # XXX: do we need to copy this? |
180 |
|
elif image.HasAlpha(): |
181 |
|
alpha = image.GetAlphaData() |
182 |
|
|
183 |
# |
# |
184 |
# if we are using the alpha_data then scale down the alpha values |
# scale down the alpha values the opacity level using a string |
185 |
# by the layer's opacity using a string translation table |
# translation table for efficiency. |
186 |
# |
# |
187 |
if alpha is not None: |
if alpha is not None: |
188 |
lo = layer.Opacity() |
if opacity == 0: |
|
if lo == 0: |
|
189 |
return |
return |
190 |
elif lo == 1: |
elif opacity == 1: |
191 |
a = alpha |
a = alpha |
192 |
else: |
else: |
193 |
tr = [int(i*lo) for i in range(256)] |
tr = [int(i*opacity) for i in range(256)] |
194 |
table = array.array('B', tr).tostring() |
table = array.array('B', tr).tostring() |
195 |
a = alpha.translate(table) |
a = alpha.translate(table) |
196 |
|
|