Index: Thuban/UI/baserenderer.py
===================================================================
RCS file: /home/thuban/jail/thubanrepository/thuban/Thuban/UI/baserenderer.py,v
retrieving revision 1.13
diff -u -r1.13 baserenderer.py
--- Thuban/UI/baserenderer.py	22 Nov 2004 11:16:35 -0000	1.13
+++ Thuban/UI/baserenderer.py	20 Jan 2005 16:16:43 -0000
@@ -76,6 +76,13 @@
     """
     del _renderer_extensions[:]
 
+def proj_params_to_str(proj):
+    "Build a string suitable for GDAL describing the given projection"
+    str = ""
+    if proj is not None:
+        for p in proj.GetAllParameters():
+            str += "+" + p + " "
+    return str
 
 #
 #       Base Renderer
@@ -177,35 +184,17 @@
         that methods especially in derived classes have access to the
         map if necessary.
         """
-        # Whether the raster layer has already been drawn. See below for
-        # the optimization this is used for
-        seenRaster = True
-
-        #
-        # This is only a good optimization if there is only one
-        # raster layer and the image covers the entire window (as
-        # it currently does). We note if there is a raster layer
-        # and only begin drawing layers once we have drawn it.
-        # That way we avoid drawing layers that won't be seen.
-        #
-        if Thuban.Model.resource.has_gdal_support():
-            for layer in self.map.Layers():
-                if isinstance(layer, RasterLayer) and layer.Visible():
-                    seenRaster = False
-                    break
 
         for layer in self.map.Layers():
             # if honor_visibility is true, only draw visible layers,
             # otherwise draw all layers
             if not self.honor_visibility or layer.Visible():
                 if isinstance(layer, Layer):
-                    if seenRaster:
-                        for i in self.draw_shape_layer_incrementally(layer):
-                            yield True
+                    for i in self.draw_shape_layer_incrementally(layer):
+                        yield True
                 elif isinstance(layer, RasterLayer) \
                     and Thuban.Model.resource.has_gdal_support():
                     self.draw_raster_layer(layer)
-                    seenRaster = True
                     yield True
                 else:
                     # look it up in the renderer extensions
@@ -370,6 +359,7 @@
         scale = self.scale
         offx, offy = self.offset
         make_point = self.make_point
+
         for part in points:
             result.append([])
             for x, y in part:
@@ -462,50 +452,70 @@
         offx, offy = self.offset
         width, height = self.dc.GetSizeTuple()
 
-        in_proj = ""
-        proj = layer.GetProjection()
-        if proj is not None:
-            for p in proj.GetAllParameters():
-                in_proj += "+" + p + " "
+        in_proj  = proj_params_to_str(layer.GetProjection())
+        out_proj = proj_params_to_str(self.map.GetProjection())
 
-        out_proj = ""
-        proj = self.map.GetProjection()
-        if proj is not None:
-            for p in proj.GetAllParameters():
-                out_proj += "+" + p + " "
+        # True  -- warp the image to the size of the whole screen
+        # False -- only use the bound box of the layer (currently inaccurate)
+        if True: 
+            pmin = [0,height]
+            pmax = [width, 0]
+        else:
+            bb = layer.LatLongBoundingBox()
+            bb = [[[bb[0], bb[1]], [bb[2], bb[3]],],]
+            pmin, pmax = self.projected_points(layer, bb)[0]
+
+        fmin = [max(0, pmin[0]) - offx, offy - min(height, pmin[1])]
+        fmax = [min(width, pmax[0]) - offx, offy - max(0, pmax[1])]
+
+        xmin = fmin[0]/self.scale
+        ymin = fmin[1]/self.scale
+        xmax = fmax[0]/self.scale
+        ymax = fmax[1]/self.scale
 
-        xmin = (0 - offx) / self.scale
-        ymin = (offy - height) / self.scale
-        xmax = (width - offx) / self.scale
-        ymax = (offy - 0) / self.scale
+        width  = int(min(width,  round(fmax[0] - fmin[0] + 1)))
+        height = int(min(height, round(fmax[1] - fmin[1] + 1)))
 
         try:
-            data = ProjectRasterFile(layer.GetImageFilename(),
+            data = [width, height,
+                    ProjectRasterFile(layer.GetImageFilename(),
                                      in_proj, out_proj,
                                      (xmin, ymin, xmax, ymax), "",
                                      (width, height))
+                   ]
         except (IOError, AttributeError, ValueError):
             # Why does this catch AttributeError and ValueError?
             # FIXME: The exception should be communicated to the user
             # better.
             traceback.print_exc()
         else:
-            self.draw_raster_data(data, "BMP")
+            mask = "#030104"
+            #mask = None
+            self.draw_raster_data(fmin[0]+offx, offy-fmax[1], data, "RAW", mask)
+            data = None
+
+    def draw_raster_data(self, x, y, data, format="BMP", mask = None):
+        """Draw the raster image in data onto the DC with the top
+        left corner at (x,y)
 
-    def draw_raster_data(self, data, format="BMP"):
-        """Draw the raster image in data onto the DC
-
-        The raster image data is a string holding the data in the format
-        indicated by the format parameter. The image is assumed to be
-        exactly the size of the dc and to cover it completely.
+        The raster image data is a list holding the image width, height,
+        and data in the format indicated by the format parameter. 
 
         The format parameter is a string with the name of the format.
         The following format names should be used:
 
-          'BMP' -- Windows Bitmap
-          'JPEG' -- Jpeg
-
-        The default format is 'bmp'.
+          'RAW'  -- an array of RGB values (len=3*width*height)
+          'BMP'  -- Windows Bitmap
+          'JPEG' -- JPEG Image
+
+        The default format is 'BMP'.
+
+        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
 
         This method has to be implemented by derived classes. The
         implementation in the derived class should try to support at
