458 |
# True -- warp the image to the size of the whole screen |
# True -- warp the image to the size of the whole screen |
459 |
# False -- only use the bound box of the layer (currently inaccurate) |
# False -- only use the bound box of the layer (currently inaccurate) |
460 |
if True: |
if True: |
461 |
|
#if False: |
462 |
pmin = [0,height] |
pmin = [0,height] |
463 |
pmax = [width, 0] |
pmax = [width, 0] |
464 |
else: |
else: |
466 |
bb = [[[bb[0], bb[1]], [bb[2], bb[3]],],] |
bb = [[[bb[0], bb[1]], [bb[2], bb[3]],],] |
467 |
pmin, pmax = self.projected_points(layer, bb)[0] |
pmin, pmax = self.projected_points(layer, bb)[0] |
468 |
|
|
469 |
fmin = [max(0, pmin[0]) - offx, offy - min(height, pmin[1])] |
#print bb |
470 |
fmax = [min(width, pmax[0]) - offx, offy - max(0, pmax[1])] |
#print pmin, pmax |
471 |
|
|
472 |
|
fmin = [max(0, min(pmin[0], pmax[0])) - offx, |
473 |
|
offy - min(height, max(pmin[1], pmax[1]))] |
474 |
|
|
475 |
|
fmax = [min(width, max(pmin[0], pmax[0])) - offx, |
476 |
|
offy - max(0, min(pmin[1], pmax[1]))] |
477 |
|
|
478 |
xmin = fmin[0]/self.scale |
xmin = fmin[0]/self.scale |
479 |
ymin = fmin[1]/self.scale |
ymin = fmin[1]/self.scale |
484 |
height = int(min(height, round(fmax[1] - fmin[1] + 1))) |
height = int(min(height, round(fmax[1] - fmin[1] + 1))) |
485 |
|
|
486 |
try: |
try: |
487 |
data = [width, height, |
options = 0 |
488 |
ProjectRasterFile(layer.GetImageFilename(), |
options = options | layer.MaskType() |
489 |
in_proj, out_proj, |
|
490 |
(xmin, ymin, xmax, ymax), "", |
project_params = (layer.GetImageFilename(), in_proj, out_proj, |
491 |
(width, height)) |
(xmin, ymin, xmax, ymax), "", (width, height), |
492 |
] |
options) |
493 |
except (IOError, AttributeError, ValueError): |
|
494 |
|
data = (width, height, apply(ProjectRasterFile, project_params)) |
495 |
|
|
496 |
|
except (MemoryError, IOError, AttributeError, ValueError): |
497 |
# Why does this catch AttributeError and ValueError? |
# Why does this catch AttributeError and ValueError? |
498 |
# FIXME: The exception should be communicated to the user |
# FIXME: The exception should be communicated to the user |
499 |
# better. |
# better. |
500 |
traceback.print_exc() |
traceback.print_exc() |
501 |
else: |
else: |
502 |
mask = "#030104" |
self.draw_raster_data(fmin[0]+offx, offy-fmax[1], data, "RAW") |
|
#mask = None |
|
|
self.draw_raster_data(fmin[0]+offx, offy-fmax[1], data, "RAW", mask) |
|
503 |
data = None |
data = None |
504 |
|
|
505 |
def draw_raster_data(self, x, y, data, format="BMP", mask = None): |
def draw_raster_data(self, x, y, data, format="BMP"): |
506 |
"""Draw the raster image in data onto the DC with the top |
"""Draw the raster image in data onto the DC with the top |
507 |
left corner at (x,y) |
left corner at (x,y) |
508 |
|
|
509 |
The raster image data is a list holding the image width, height, |
The raster image data is a tuple of the form |
510 |
and data in the format indicated by the format parameter. |
(width, height, (image_data, mask_data, alpha_data)) |
511 |
|
|
512 |
|
holding the image width, height, image data, mask data, and alpha data. |
513 |
|
mask_data may be None if a mask should not be used. alpha_data may |
514 |
|
also be None. If both are not None mask overrides alpha. If |
515 |
|
format is 'RAW' the data will be RGB values and the mask |
516 |
|
will be in XMB format. Otherwise, both kinds |
517 |
|
of data are assumed to be in the format specified in format. |
518 |
|
|
519 |
The format parameter is a string with the name of the format. |
The format parameter is a string with the name of the format. |
520 |
The following format names should be used: |
The following format names should be used: |
525 |
|
|
526 |
The default format is 'BMP'. |
The default format is 'BMP'. |
527 |
|
|
|
The mask parameter determines how a mask (if any) is applied |
|
|
to the image. mask can have the following values: |
|
|
|
|
|
o None -- no mask is used |
|
|
o Any object accepted by wxBitmap.SetMaskColour() |
|
|
o A one-bit image the same size as the image data |
|
|
|
|
528 |
This method has to be implemented by derived classes. The |
This method has to be implemented by derived classes. The |
529 |
implementation in the derived class should try to support at |
implementation in the derived class should try to support at |
530 |
least the formats specified above and may support more. |
least the formats specified above and may support more. |