Convert the region of the agg buffer bounded by bbox to a wx.Bitmap.  If
    bbox is None, the entire buffer is converted.

    Note: agg must be a backend_agg.RendererAgg instance.
425598
def _convert_agg_to_wx_bitmap(agg, bbox):
    
    if bbox is None:
        # agg => rgba buffer -> bitmap
        return wx.BitmapFromBufferRGBA(int(agg.width), int(agg.height),
            agg.buffer_rgba())
    else:
        # agg => rgba buffer -> bitmap => clipped bitmap
        return _WX28_clipped_agg_as_bitmap(agg, bbox)
478640
def getBitmap(self):
        
        return PlatformManager.getBitmapFromRect(self.x, self.y, self.w, self.h)
1270188
public byte[] getRL2Image( Geometry geom, String geomEpsg, int width, int height ) throws Exception {
        String sql;
        String rasterName = getName();
        if (geomEpsg != null) {
            sql = "select GetMapImageFromRaster('" + rasterName + "', ST_Transform(ST_GeomFromText('" + geom.toText() + "', "
                    + geomEpsg + "), " + srid + ") , " + width + " , " + height
                    + ", 'default', 'image/png', '#ffffff', 0, 80, 1 )";
        } else {
            sql = "select GetMapImageFromRaster('" + rasterName + "', ST_GeomFromText('" + geom.toText() + "') , " + width + " , "
                    + height + ", 'default', 'image/png', '#ffffff', 0, 80, 1 )";
        }

        return database.execOnConnection(mConn -> {
            try (IHMStatement stmt = mConn.createStatement()) {
                IHMResultSet resultSet = stmt.executeQuery(sql);
                if (resultSet.next()) {
                    byte[] bytes = resultSet.getBytes(1);
                    return bytes;
                }
            }
            return null;
        });
    }
1034959
def set_bg(self, r, g, b):
        
        self.img_bg = (r, g, b)
        self.redraw(whence=0)
753463
def render(self, bbox, width=None, height=None):
        
        width = width or self.tilesize
        height = height or self.tilesize
        self._prepare_rendering(bbox, width=width, height=height)

        # Render image with default Agg renderer
        tmpfile = NamedTemporaryFile(delete=False)
        im = mapnik.Image(width, height)
        mapnik.render(self._mapnik, im)
        im.save(tmpfile.name, 'png256')  # TODO: mapnik output only to file?
        tmpfile.close()
        content = open(tmpfile.name, 'rb').read()
        os.unlink(tmpfile.name)
        return content
115518
def world_to_image(bbox, size):
    """"""

    px_per_unit = (float(size[0])/bbox.width, float(size[1])/bbox.height)
    return lambda x,y: ((x-bbox.xmin) * px_per_unit[0], size[1] - (y-bbox.ymin)*px_per_unit[1])
785154
public static void getScreenShotABGR(ByteBuffer bgraBuf, BufferedImage out) {
        WritableRaster wr = out.getRaster();
        DataBufferByte db = (DataBufferByte) wr.getDataBuffer();

        byte[] cpuArray = db.getData();

        // copy native memory to java memory
        bgraBuf.clear();
        bgraBuf.get(cpuArray);
        bgraBuf.clear();

        int width = wr.getWidth();
        int height = wr.getHeight();

        // flip the components the way AWT likes them
        for (int y = 0; y < height / 2; y++) {
            for (int x = 0; x < width; x++) {
                int inPtr = (y * width + x) * 4;
                int outPtr = ((height - y - 1) * width + x) * 4;

                byte b1 = cpuArray[inPtr + 0];
                byte g1 = cpuArray[inPtr + 1];
                byte r1 = cpuArray[inPtr + 2];
                byte a1 = cpuArray[inPtr + 3];

                byte b2 = cpuArray[outPtr + 0];
                byte g2 = cpuArray[outPtr + 1];
                byte r2 = cpuArray[outPtr + 2];
                byte a2 = cpuArray[outPtr + 3];

                cpuArray[outPtr + 0] = a1;
                cpuArray[outPtr + 1] = b1;
                cpuArray[outPtr + 2] = g1;
                cpuArray[outPtr + 3] = r1;

                cpuArray[inPtr + 0] = a2;
                cpuArray[inPtr + 1] = b2;
                cpuArray[inPtr + 2] = g2;
                cpuArray[inPtr + 3] = r2;
            }
        }
    }
724777
def bbox(self):
        """"""
        bbs = [seg.bbox() for seg in self._segments]
        xmins, xmaxs, ymins, ymaxs = list(zip(*bbs))
        xmin = min(xmins)
        xmax = max(xmaxs)
        ymin = min(ymins)
        ymax = max(ymaxs)
        return xmin, xmax, ymin, ymax
1122410
def region(self, rect):
        
        box = (int(rect[0]), int(rect[1]), int(rect[0]) + int(rect[2]),
               int(rect[1]) + int(rect[3]))
        if box[2] > self.img.size[0] or box[3] > self.img.size[1]:
            raise errors.RectangleError("Region out-of-bounds")
        self.img = self.img.crop(box)
        return self
669250
def zoom_bbox(self, bbox):
        
        try:
            bbox.transform(self.map.srs)
        except gdal.GDALException:
            pass
        else:
            self.map.zoom_to_box(mapnik.Box2d(*bbox.extent))
523529
private BufferedImage to24Bit3ComponentRGB(int[][] decoded, int width, int height) {
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
        byte[] imageBuffer = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();

        for (int i = 0; i < imageBuffer.length / 3; i++) {
            // Convert to RGB (BGR)
            imageBuffer[i * 3 + 2] = (byte) decoded[0][i];
            imageBuffer[i * 3 + 1] = (byte) decoded[1][i];
            imageBuffer[i * 3] = (byte) decoded[2][i];
        }

        return image;
    }
789473
public void accept(PainterVisitor visitor, Object group, Bbox bounds, boolean recursive) {
		// First place the image at the correct location:
		image.setBounds(new Bbox(getUpperLeftCorner().getX(), getUpperLeftCorner().getY(), getWidth(), getHeight()));

		// Then draw:
		if (parent != null) {
			map.getVectorContext().drawImage(parent, getId(), image.getHref(), image.getBounds(),
					(PictureStyle) image.getStyle());
		} else {
			map.getVectorContext().drawImage(group, getId(), image.getHref(), image.getBounds(),
					(PictureStyle) image.getStyle());
		}
		map.getVectorContext().setCursor(parent, getId(), Cursor.POINTER.getValue());
	}
817760
private MappeableContainer toBitmapIfNeeded() {
    int sizeAsRunContainer = MappeableRunContainer.serializedSizeInBytes(this.nbrruns);
    int sizeAsBitmapContainer = MappeableBitmapContainer.serializedSizeInBytes(0);
    if (sizeAsBitmapContainer > sizeAsRunContainer) {
      return this;
    }
    return toBitmapContainer();
  }
1208951
public int filterRGB(int pX, int pY, int pARGB) {
        // Get color components
        int r = pARGB >> 16 & 0xFF;
        int g = pARGB >> 8 & 0xFF;
        int b = pARGB & 0xFF;

        // Scale to new contrast
        r = LUT[r];
        g = LUT[g];
        b = LUT[b];

        // Return ARGB pixel, leave transparency as is
        return (pARGB & 0xFF000000) | (r << 16) | (g << 8) | b;
    }
578734
public Bitmap getDrawingBitmap() {
        /*
         * Layer manager only starts drawing a new bitmap when the last one is swapped (taken to
         * the screen). This ensures that the layer manager draws not too many frames. (only as
         * much as can get displayed).
         */
        synchronized (this.allowSwap) {
            this.allowSwap.waitDisabled();
            Bitmap b = this.lmBitmap.lock();
            if (b != null) {
                b.setBackgroundColor(this.displayModel.getBackgroundColor());
            }
            return b;
        }
    }
940751
def tiles_from_bbox(self, geometry, zoom):
        
        validate_zoom(zoom)
        return self.tiles_from_bounds(geometry.bounds, zoom)
469002
def _slice_area_from_bbox(self, src_area, dst_area, ll_bbox=None,
                              xy_bbox=None):
        """"""
        if ll_bbox is not None:
            dst_area = AreaDefinition(
                'crop_area', 'crop_area', 'crop_latlong',
                {'proj': 'latlong'}, 100, 100, ll_bbox)
        elif xy_bbox is not None:
            dst_area = AreaDefinition(
                'crop_area', 'crop_area', 'crop_xy',
                src_area.proj_dict, src_area.x_size, src_area.y_size,
                xy_bbox)
        x_slice, y_slice = src_area.get_area_slices(dst_area)
        return src_area[y_slice, x_slice], y_slice, x_slice