/** * Draw the given polygon, filled with the specified colour. * * @param p The polygon to draw. * @param col The colour to fill the polygon with. */ public void drawPolygonFilled(Polygon p, final Q col) { // clip to the frame p = p.intersect(this.targetImage.getBounds().asPolygon()); this.drawPolygon(p, col); if (p.getNumInnerPoly() == 1) { ScanRasteriser.scanFill( p.points, new ScanLineListener() { @Override public void process(final int x1, final int x2, final int y) { ImageRenderer.this.drawHorizLine(x1, x2, y, col); } }); } else { // final ConnectedComponent cc = new ConnectedComponent(p); // cc.process(new BlobRenderer<Q>(this.targetImage, col)); final int minx = Math.max(0, (int) Math.round(p.minX())); final int maxx = Math.min((int) Math.round(p.maxX()), targetImage.getWidth() - 1); final int miny = Math.max(0, (int) Math.round(p.minY())); final int maxy = Math.min((int) Math.round(p.maxY()), targetImage.getHeight() - 1); final Pixel tmp = new Pixel(); for (tmp.y = miny; tmp.y <= maxy; tmp.y++) { for (tmp.x = minx; tmp.x <= maxx; tmp.x++) { if (p.isInside(tmp)) this.targetImage.setPixel(tmp.x, tmp.y, col); } } } }
/** * Draw into this image the provided image at the given coordinates. Parts of the image outside * the bounds of this image will be ignored. * * @param image The image to draw. * @param x The x-coordinate of the top-left of the image * @param y The y-coordinate of the top-left of the image */ public void drawImage(final I image, final int x, final int y) { final int stopx = Math.min(this.targetImage.getWidth(), x + image.getWidth()); final int stopy = Math.min(this.targetImage.getHeight(), y + image.getHeight()); final int startx = Math.max(0, x); final int starty = Math.max(0, y); for (int yy = starty; yy < stopy; yy++) for (int xx = startx; xx < stopx; xx++) this.targetImage.setPixel(xx, yy, image.getPixel(xx - x, yy - y)); }
/** * Draw into this image the provided image at the given coordinates ignoring certain pixels. Parts * of the image outside the bounds of this image will be ignored. Pixels in the ignore list will * be stripped from the image to draw. * * @param image The image to draw. * @param x The x-coordinate of the top-left of the image * @param y The y-coordinate of the top-left of the image * @param ignoreList The list of pixels to ignore when copying the image */ public void drawImage( final I image, final int x, final int y, @SuppressWarnings("unchecked") final Q... ignoreList) { final int stopx = Math.min(this.targetImage.getWidth(), x + image.getWidth()); final int stopy = Math.min(this.targetImage.getHeight(), y + image.getHeight()); final int startx = Math.max(0, x); final int starty = Math.max(0, y); for (int yy = starty; yy < stopy; yy++) for (int xx = startx; xx < stopx; xx++) { final Q val = image.getPixel(xx - x, yy - y); if (Arrays.binarySearch(ignoreList, val, this.targetImage.getPixelComparator()) < 0) this.targetImage.setPixel(xx, yy, val); } }