List of usage examples for java.awt Rectangle getMinY
public double getMinY()
From source file:Main.java
/** * Centers a component on its parent./*from ww w. jav a 2 s .c o m*/ * * @param component */ public static void centerInParent(Component component) { Container parent = component.getParent(); if (parent != null) { Rectangle parentBounds = parent.getBounds(); Rectangle dialogBounds = new Rectangle( (int) (parentBounds.getMinX() + parentBounds.getWidth() / 2 - component.getWidth() / 2), (int) (parentBounds.getMinY() + parentBounds.getHeight() / 2 - component.getHeight() / 2), component.getWidth(), component.getHeight()); //dialog.setBounds( dialogBounds ); component.setLocation(dialogBounds.x, dialogBounds.y); } }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java
private static Rectangle2D createHotspot(Rectangle bounds, double x, double y, double xOffset, Size2D blockSize) {//from ww w .ja v a 2s . co m double xx = (x + xOffset + blockSize.width < bounds.getMaxX()) ? (x + xOffset) : (x - xOffset - blockSize.width); double halfHeight = blockSize.height / 2; double yy = (y - halfHeight < bounds.getMinY()) ? (bounds.getMinY()) : (y + halfHeight > bounds.getMaxY()) ? (bounds.getMaxY() - blockSize.height) : (y - halfHeight); return new Rectangle2D.Double(xx, yy, blockSize.width, blockSize.height); }
From source file:de.tor.tribes.ui.views.DSWorkbenchSelectionFrame.java
private void firePerformRegionSelectionEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_firePerformRegionSelectionEvent if (evt.getSource() == jPerformSelection) { Point start = new Point((Integer) jStartX.getValue(), (Integer) jStartY.getValue()); Point end = new Point((Integer) jEndX.getValue(), (Integer) jEndY.getValue()); Rectangle mapDim = ServerSettings.getSingleton().getMapDimension(); if (start.x < mapDim.getMinX() || start.x > mapDim.getMaxX() || start.y < mapDim.getMinY() || start.y > mapDim.getMaxY() || end.x < mapDim.getMinX() || end.x > mapDim.getMaxX() || end.y < mapDim.getMinY() || end.y > mapDim.getMaxY()) { showError("Ungltiger Start- oder Endpunkt"); } else if ((Math.abs(end.x - start.x) * (end.y - start.y)) > 30000) { showError("<html>Die angegebene Auswahl könnte mehr als 10.000 Dörfer umfassen.<br/>" + "Die Auswahl könnte so sehr lange dauern. Bitte verkleinere den gewählten Bereich."); } else {// w w w .j a v a 2s. co m List<Village> selection = DataHolder.getSingleton().getVillagesInRegion(start, end); addVillages(selection); } } jRegionSelectDialog.setVisible(false); }
From source file:at.knowcenter.wag.egov.egiz.pdf.PDFPage.java
/** * Registers a rectangle that bounds the path currently being drawn. * // w w w . j av a 2 s . com * @param bounds * A rectangle depicting the bounds (coordinates originating from * bottom left). * @author Datentechnik Innovation GmbH */ public void registerPathBounds(Rectangle bounds) { if (!bounds.isEmpty()) { logger.debug("Registering path bounds: " + bounds); // vertical start of rectangle (counting from top of page) float upperBoundYPositionFromTop; // vertical end of rectangle (counting from top of page) // this depicts the current end of path-related page content float lowerBoundYPositionFromTop; PDRectangle boundaryBox = this.getCurrentPage().findCropBox(); if (boundaryBox == null) { boundaryBox = this.getCurrentPage().findMediaBox(); } float pageHeight; switch (this.getCurrentPage().findRotation()) { case 90: // CW pageHeight = boundaryBox.getWidth(); upperBoundYPositionFromTop = (float) bounds.getMinX(); lowerBoundYPositionFromTop = (float) bounds.getMaxX(); break; case 180: pageHeight = boundaryBox.getHeight(); upperBoundYPositionFromTop = (float) bounds.getMinY(); lowerBoundYPositionFromTop = (float) bounds.getMaxY(); break; case 270: // CCW pageHeight = boundaryBox.getWidth(); upperBoundYPositionFromTop = pageHeight - (float) bounds.getMaxX(); lowerBoundYPositionFromTop = pageHeight - (float) bounds.getMinX(); break; default: pageHeight = boundaryBox.getHeight(); upperBoundYPositionFromTop = pageHeight - (float) bounds.getMaxY(); lowerBoundYPositionFromTop = pageHeight - (float) bounds.getMinY(); break; } // new maximum ? if (lowerBoundYPositionFromTop > maxPathRelatedYPositionFromTop) { // Is the rectangle (at least partly) located above the footer // line? // (effective page height := page height - footer line) if (upperBoundYPositionFromTop <= effectivePageHeight) { // yes: update current end of path-related page content maxPathRelatedYPositionFromTop = lowerBoundYPositionFromTop; logger.trace("New max path related y position (from top): " + maxPathRelatedYPositionFromTop); } else { // no: rectangle is fully located below the footer line -> // ignore logger.trace("Ignoring path bound below the footer line."); } } } }
From source file:at.knowcenter.wag.egov.egiz.pdfbox2.pdf.PDFPage.java
/** * Registers a rectangle that bounds the path currently being drawn. * //from ww w. j a v a 2s . c om * @param bounds * A rectangle depicting the bounds (coordinates originating from * bottom left). * @author Datentechnik Innovation GmbH */ public void registerPathBounds(Rectangle bounds) { if (!bounds.isEmpty()) { logger.debug("Registering path bounds: " + bounds); // vertical start of rectangle (counting from top of page) float upperBoundYPositionFromTop; // vertical end of rectangle (counting from top of page) // this depicts the current end of path-related page content float lowerBoundYPositionFromTop; PDRectangle boundaryBox = this.getCurrentPage().getCropBox(); if (boundaryBox == null) { boundaryBox = this.getCurrentPage().getMediaBox(); } float pageHeight; switch (this.getCurrentPage().getRotation()) { case 90: // CW pageHeight = boundaryBox.getWidth(); upperBoundYPositionFromTop = (float) bounds.getMinX(); lowerBoundYPositionFromTop = (float) bounds.getMaxX(); break; case 180: pageHeight = boundaryBox.getHeight(); upperBoundYPositionFromTop = (float) bounds.getMinY(); lowerBoundYPositionFromTop = (float) bounds.getMaxY(); break; case 270: // CCW pageHeight = boundaryBox.getWidth(); upperBoundYPositionFromTop = pageHeight - (float) bounds.getMaxX(); lowerBoundYPositionFromTop = pageHeight - (float) bounds.getMinX(); break; default: pageHeight = boundaryBox.getHeight(); upperBoundYPositionFromTop = pageHeight - (float) bounds.getMaxY(); lowerBoundYPositionFromTop = pageHeight - (float) bounds.getMinY(); break; } // new maximum ? if (lowerBoundYPositionFromTop > maxPathRelatedYPositionFromTop) { // Is the rectangle (at least partly) located above the footer // line? // (effective page height := page height - footer line) if (upperBoundYPositionFromTop <= effectivePageHeight) { // yes: update current end of path-related page content maxPathRelatedYPositionFromTop = lowerBoundYPositionFromTop; logger.trace("New max path related y position (from top): " + maxPathRelatedYPositionFromTop); } else { // no: rectangle is fully located below the footer line -> // ignore logger.trace("Ignoring path bound below the footer line."); } } } }
From source file:de.tor.tribes.ui.panels.MinimapPanel.java
/** * Creates new form MinimapPanel/* w ww. jav a2s . c o m*/ */ MinimapPanel() { initComponents(); setSize(300, 300); mMinimapListeners = new LinkedList<>(); mToolChangeListeners = new LinkedList<>(); setCursor(ImageManager.getCursor(iCurrentCursor)); mScreenshotPanel = new ScreenshotPanel(); minimapButtons.put(ID_MINIMAP, new Rectangle(2, 2, 26, 26)); minimapButtons.put(ID_ALLY_CHART, new Rectangle(30, 2, 26, 26)); minimapButtons.put(ID_TRIBE_CHART, new Rectangle(60, 2, 26, 26)); try { minimapIcons.put(ID_MINIMAP, ImageIO.read(new File("./graphics/icons/minimap.png"))); minimapIcons.put(ID_ALLY_CHART, ImageIO.read(new File("./graphics/icons/ally_chart.png"))); minimapIcons.put(ID_TRIBE_CHART, ImageIO.read(new File("./graphics/icons/tribe_chart.png"))); } catch (Exception ignored) { } jPanel1.add(mScreenshotPanel); rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension()); zoomed = false; MarkerManager.getSingleton().addManagerListener(this); TagManager.getSingleton().addManagerListener(this); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); if (!GlobalOptions.isMinimal()) { MinimapRepaintThread.getSingleton().start(); } addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (!showControls && e.getButton() != MouseEvent.BUTTON1) { //show controls Point p = e.getPoint(); p.translate(-5, -5); showControls(p); return; } if (!showControls && iCurrentView == ID_MINIMAP) { Point p = mousePosToMapPosition(e.getX(), e.getY()); DSWorkbenchMainFrame.getSingleton().centerPosition(p.getX(), p.getY()); MapPanel.getSingleton().getMapRenderer().initiateRedraw(MapRenderer.ALL_LAYERS); if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().toFront(); } } else { if (minimapButtons.get(ID_MINIMAP).contains(e.getPoint())) { iCurrentView = ID_MINIMAP; mBuffer = null; showControls = false; MinimapRepaintThread.getSingleton().update(); } else if (minimapButtons.get(ID_ALLY_CHART).contains(e.getPoint())) { iCurrentView = ID_ALLY_CHART; lastHash = 0; showControls = false; updateComplete(); } else if (minimapButtons.get(ID_TRIBE_CHART).contains(e.getPoint())) { iCurrentView = ID_TRIBE_CHART; lastHash = 0; showControls = false; updateComplete(); } } } @Override public void mousePressed(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } if (iCurrentCursor == ImageManager.CURSOR_SHOT || iCurrentCursor == ImageManager.CURSOR_ZOOM) { iXDown = e.getX(); iYDown = e.getY(); } } @Override public void mouseReleased(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } if (rDrag == null) { return; } if (iCurrentCursor == ImageManager.CURSOR_SHOT) { try { BufferedImage i = MinimapRepaintThread.getSingleton().getImage(); double widthFactor = ((double) ServerSettings.getSingleton().getMapDimension().width) / getWidth(); double heightFactor = ((double) ServerSettings.getSingleton().getMapDimension().height) / getHeight(); int x = (int) Math.rint(widthFactor * rDrag.getX()); int y = (int) Math.rint(heightFactor * rDrag.getY()); int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX())); int h = (int) Math.rint(heightFactor * (rDrag.getHeight() - rDrag.getY())); BufferedImage sub = i.getSubimage(x, y, w, h); mScreenshotPanel.setBuffer(sub); jPanel1.setSize(mScreenshotPanel.getSize()); jPanel1.setPreferredSize(mScreenshotPanel.getSize()); jPanel1.setMinimumSize(mScreenshotPanel.getSize()); jPanel1.setMaximumSize(mScreenshotPanel.getSize()); jScreenshotPreview.pack(); jScreenshotControl.pack(); jScreenshotPreview.setVisible(true); jScreenshotControl.setVisible(true); } catch (Exception ie) { logger.error("Failed to initialize mapshot", ie); } } else if (iCurrentCursor == ImageManager.CURSOR_ZOOM) { if (!zoomed) { Rectangle mapDim = ServerSettings.getSingleton().getMapDimension(); double widthFactor = ((double) mapDim.width) / getWidth(); double heightFactor = ((double) mapDim.height) / getHeight(); int x = (int) Math.rint(widthFactor * rDrag.getX() + mapDim.getMinX()); int y = (int) Math.rint(heightFactor * rDrag.getY() + mapDim.getMinY()); int w = (int) Math.rint(widthFactor * (rDrag.getWidth() - rDrag.getX())); if (w >= 10) { rVisiblePart = new Rectangle(x, y, w, w); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); redraw(); zoomed = true; } } else { rVisiblePart = new Rectangle(ServerSettings.getSingleton().getMapDimension()); MinimapRepaintThread.getSingleton().setVisiblePart(rVisiblePart); redraw(); zoomed = false; } MinimapZoomFrame.getSingleton().setVisible(false); } iXDown = 0; iYDown = 0; rDrag = null; } @Override public void mouseEntered(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } switch (iCurrentCursor) { case ImageManager.CURSOR_ZOOM: { MinimapZoomFrame.getSingleton().setVisible(true); } } } @Override public void mouseExited(MouseEvent e) { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } iXDown = 0; iYDown = 0; rDrag = null; } }); addMouseMotionListener(new MouseMotionListener() { @Override public void mouseDragged(MouseEvent e) { if (iCurrentView != ID_MINIMAP) { return; } switch (iCurrentCursor) { case ImageManager.CURSOR_MOVE: { Point p = mousePosToMapPosition(e.getX(), e.getY()); DSWorkbenchMainFrame.getSingleton().centerPosition(p.x, p.y); rDrag = null; break; } case ImageManager.CURSOR_SHOT: { rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY()); break; } case ImageManager.CURSOR_ZOOM: { rDrag = new Rectangle2D.Double(iXDown, iYDown, e.getX(), e.getY()); break; } } } @Override public void mouseMoved(MouseEvent e) { if (iCurrentView == ID_MINIMAP) { switch (iCurrentCursor) { case ImageManager.CURSOR_ZOOM: { if (!MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(true); } int mapWidth = (int) ServerSettings.getSingleton().getMapDimension().getWidth(); int mapHeight = (int) ServerSettings.getSingleton().getMapDimension().getHeight(); int x = (int) Math.rint((double) mapWidth / (double) getWidth() * (double) e.getX()); int y = (int) Math.rint((double) mapHeight / (double) getHeight() * (double) e.getY()); MinimapZoomFrame.getSingleton().updatePosition(x, y); break; } default: { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } } } } Point location = minimapButtons.get(ID_MINIMAP).getLocation(); location.translate(-2, -2); if (!new Rectangle(location.x, location.y, 88, 30).contains(e.getPoint())) { //hide controls showControls = false; repaint(); } } }); addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { if (iCurrentView != ID_MINIMAP) { return; } iCurrentCursor += e.getWheelRotation(); if (iCurrentCursor == ImageManager.CURSOR_DEFAULT + e.getWheelRotation()) { if (e.getWheelRotation() < 0) { iCurrentCursor = ImageManager.CURSOR_SHOT; } else { iCurrentCursor = ImageManager.CURSOR_MOVE; } } else if (iCurrentCursor < ImageManager.CURSOR_MOVE) { iCurrentCursor = ImageManager.CURSOR_DEFAULT; } else if (iCurrentCursor > ImageManager.CURSOR_SHOT) { iCurrentCursor = ImageManager.CURSOR_DEFAULT; } if (iCurrentCursor != ImageManager.CURSOR_ZOOM) { if (MinimapZoomFrame.getSingleton().isVisible()) { MinimapZoomFrame.getSingleton().setVisible(false); } } else { MinimapZoomFrame.getSingleton().setVisible(true); } setCurrentCursor(iCurrentCursor); } }); }
From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java
private void refreshMap() { //ensure that within map range Rectangle mapDim = ServerSettings.getSingleton().getMapDimension(); if (dCenterX < mapDim.getMinX() || dCenterX > mapDim.getMaxX() || dCenterY < mapDim.getMinY() || dCenterY > mapDim.getMaxX()) { //find out where we tried to leaf map and set these valuese to max / min if (dCenterX < mapDim.getMinX()) { dCenterX = (int) mapDim.getMinX(); jCenterX.setText(Integer.toString((int) dCenterX)); } else if (dCenterX > mapDim.getMaxX()) { dCenterX = (int) mapDim.getMaxX(); jCenterX.setText(Integer.toString((int) dCenterX)); }/* ww w. ja v a 2s . c om*/ if (dCenterY < mapDim.getMinY()) { dCenterY = (int) mapDim.getMinY(); jCenterY.setText(Integer.toString((int) dCenterY)); } else if (dCenterY > mapDim.getMaxX()) { dCenterY = (int) mapDim.getMaxX(); jCenterY.setText(Integer.toString((int) dCenterY)); } } double w = (double) MapPanel.getSingleton().getWidth() / GlobalOptions.getSkin().getBasicFieldWidth() * dZoomFactor; double h = (double) MapPanel.getSingleton().getHeight() / GlobalOptions.getSkin().getBasicFieldHeight() * dZoomFactor; MinimapPanel.getSingleton().setSelection((int) Math.floor(dCenterX), (int) Math.floor(dCenterY), (int) Math.rint(w), (int) Math.rint(h)); MapPanel.getSingleton().updateMapPosition(dCenterX, dCenterY, true); }
From source file:org.photovault.dcraw.AHDInterpolateOp.java
@Override public Rectangle mapDestRect(Rectangle src, int srcIndex) { Rectangle ret = null;//from ww w . jav a 2s . co m if (downSample == 1) { ret = new Rectangle((int) src.getMinX() - 3, (int) src.getMinY() - 3, (int) src.getWidth() + 6, (int) src.getHeight() + 6); } else { ret = new Rectangle((int) src.getMinX() * downSample, (int) src.getMinY() * downSample, (int) src.getWidth() * downSample, (int) src.getHeight() * downSample); } return ret; }
From source file:org.photovault.dcraw.AHDInterpolateOp.java
@Override public Rectangle mapSourceRect(Rectangle source, int srcIndex) { Rectangle ret = new Rectangle((int) source.getMinX() + 3, (int) source.getMinY() + 3, (int) source.getWidth() - 6, (int) source.getHeight() - 6); return ret;// www. j a v a2 s . c o m }
From source file:org.photovault.dcraw.AHDInterpolateOp.java
/** * Conpute a rectangle of destination image using AHD interpolation * @param img Array of soruce images (containing just one image in this case * @param dst Raster for the results//from w w w. j a v a 2 s . c o m * @param area Area of dst that needs to be computed */ private void computeRectAHD(PlanarImage[] img, WritableRaster dst, Rectangle area) { log.debug("entry: computeAHD " + area); long entryTime = System.currentTimeMillis(); // RandomIterFactory.create( img[0], area); int minx = Math.max((int) area.getMinX() - 3, 0); int miny = Math.max((int) area.getMinY() - 3, 0); int maxx = Math.min((int) area.getMaxX() + 3, getWidth() - 1); int maxy = Math.min((int) area.getMaxY() + 3, getHeight() - 1); Rectangle enlargedArea = new Rectangle(minx, miny, maxx - minx + 1, maxy - miny + 1); int[][][][] rgb = new int[2][(int) enlargedArea.getWidth()][(int) enlargedArea.getHeight()][3]; int[][][][] lab = new int[2][(int) enlargedArea.getWidth()][(int) enlargedArea.getHeight()][3]; byte[][][] homo = new byte[2][(int) enlargedArea.getWidth()][(int) enlargedArea.getHeight()]; RandomIter riter = RandomIterFactory.create(img[0], enlargedArea); double xyz[] = new double[3]; // Copy the data to temp array for (int y = 0; y < maxy - miny; y++) { for (int x = 0; x < maxx - minx; x++) { int color = fc(y + miny, x + minx); if (color == 3) color = 1; rgb[0][x][y][color] = rgb[1][x][y][color] = (int) (mult[color] * riter.getSample(x + minx, y + miny, 0)); } } // Interpolate green for (int y = 2; y < maxy - miny - 2; y++) { int firstColor = fc(y + miny, minx + 3); int startCol = minx + 3 - (firstColor % 2); for (int x = startCol - minx; x < maxx - minx - 2; x += 2) { int c = fc(y + miny, x + minx); if (c == 3) { c = 1; } int tc = rgb[0][x][y][c]; int eg = rgb[0][x - 1][y][1]; int wg = rgb[0][x + 1][y][1]; int sg = rgb[0][x][y + 1][1]; int ng = rgb[0][x][y - 1][1]; int ec = rgb[0][x - 2][y][c]; int wc = rgb[0][x + 2][y][c]; int sc = rgb[0][x][y + 2][c]; int nc = rgb[0][x][y - 2][c]; // Horizonally int green = 2 * (wg + tc + eg) - (wc + ec); green >>= 2; if (green < 0) green = 0; rgb[0][x][y][1] = green; // Vertically green = 2 * (ng + tc + sg) - (nc + sc); green >>= 2; if (green < 0) green = 0; rgb[1][x][y][1] = green; } } // Interpolate R & B for (int dir = 0; dir < 2; dir++) { for (int y = 3; y < maxy - miny - 3; y++) { for (int x = 3; x < maxx - minx - 3; x++) { int color = fc(y + miny, x + minx); if (color == 1 || color == 3) { // We need to interpolate both red and blue int c = fc(y + 1 + miny, x + minx); int tg = rgb[dir][x][y][1]; int ng = rgb[dir][x][y - 1][1]; int sg = rgb[dir][x][y + 1][1]; int eg = rgb[dir][x + 1][y][1]; int wg = rgb[dir][x - 1][y][1]; int nc = rgb[dir][x][y - 1][c]; int sc = rgb[dir][x][y + 1][c]; int wo = rgb[dir][x - 1][y][2 - c]; int eo = rgb[dir][x + 1][y][2 - c]; int val = tg + ((wo + eo - ng - sg) >> 1); if (val < 0) val = 0; rgb[dir][x][y][2 - c] = val; val = tg + ((nc + sc - ng - sg) >> 1); if (val < 0) val = 0; rgb[dir][x][y][c] = val; } else { /* This pixel is either red or blue so only one of those needs to be interpolated */ int c = 2 - color; int tg = rgb[dir][x][y][1]; int nwg = rgb[dir][x - 1][y - 1][1]; int seg = rgb[dir][x + 1][y + 1][1]; int swg = rgb[dir][x - 1][y + 1][1]; int neg = rgb[dir][x + 1][y - 1][1]; int nwc = rgb[dir][x - 1][y - 1][c]; int nec = rgb[dir][x + 1][y - 1][c]; int swc = rgb[dir][x - 1][y + 1][c]; int sec = rgb[dir][x + 1][y + 1][c]; int val = tg + ((nwc + nec + sec + swc - nwg - neg - swg - seg) >> 2); if (val < 0) val = 0; rgb[dir][x][y][c] = val; } xyz[0] = xyz[1] = xyz[2] = 0.5; // Convert to cielab for (int i = 0; i < 3; i++) { xyz[0] += xyz_cam[0][i] * rgb[dir][x][y][i]; xyz[1] += xyz_cam[1][i] * rgb[dir][x][y][i]; xyz[2] += xyz_cam[2][i] * rgb[dir][x][y][i]; } xyz[0] = cbrt[Math.max(0, (int) Math.min(xyz[0], 65535.0))]; xyz[1] = cbrt[Math.max(0, (int) Math.min(xyz[1], 65535.0))]; xyz[2] = cbrt[Math.max(0, (int) Math.min(xyz[2], 65535.0))]; lab[dir][x][y][0] = Math.max(0, (int) (64.0 * (116.0 * xyz[1] - 16.0))); lab[dir][x][y][1] = 0x8000 + 10 * (int) (64.0 * 500.0 * (xyz[0] - xyz[1])); lab[dir][x][y][2] = 0x8000 + 10 * (int) (64.0 * 200.0 * (xyz[1] - xyz[2])); } } } // Calculate the homogeneity maps int ldiff[][] = new int[2][4]; int abdiff[][] = new int[2][4]; int dx[] = { -1, 1, 0, 0 }; int dy[] = { 0, 0, -1, 1 }; for (int y = 2; y < maxy - miny - 2; y++) { for (int x = 2; x < maxx - minx - 2; x++) { for (int d = 0; d < 2; d++) { for (int i = 0; i < 4; i++) { ldiff[d][i] = Math.abs(lab[d][x][y][0] - lab[d][x + dx[i]][y + dy[i]][0]); int da = lab[d][x][y][1] - lab[d][x + dx[i]][y + dy[i]][1]; int db = lab[d][x][y][1] - lab[d][x + dx[i]][y + dy[i]][1]; abdiff[d][i] = da * da + db * db; } } int leps = Math.min(Math.max(ldiff[0][0], ldiff[0][1]), Math.max(ldiff[1][2], ldiff[1][3])); int abeps = Math.min(Math.max(abdiff[0][0], abdiff[0][1]), Math.max(abdiff[1][2], abdiff[1][3])); for (int d = 0; d < 2; d++) { for (int i = 0; i < 4; i++) { if (ldiff[d][i] <= leps && abdiff[d][i] <= abeps) { homo[d][x][y]++; } } } } } int dstMinx = Math.max((int) area.getMinX(), 5); int dstMiny = Math.max((int) area.getMinY(), 5); int dstMaxy = Math.min((int) area.getMaxY(), getHeight() - 5); int dstMaxx = Math.min((int) area.getMaxX(), getWidth() - 5); for (int row = dstMiny; row < dstMaxy; row++) { for (int col = dstMinx; col < dstMaxx; col++) { int hm0 = 0, hm1 = 0; for (int i = row - miny - 1; i <= row - miny + 1; i++) { for (int j = col - minx - 1; j <= col - minx + 1; j++) { hm0 += homo[0][j][i]; hm1 += homo[1][j][i]; } } if (hm0 < hm1) { dst.setPixel(col, row, rgb[1][col - minx][row - miny]); } else if (hm0 > hm1) { dst.setPixel(col, row, rgb[0][col - minx][row - miny]); } else { for (int i = 0; i < 3; i++) { rgb[0][col - minx][row - miny][i] += rgb[1][col - minx][row - miny][i]; rgb[0][col - minx][row - miny][i] /= 2; } dst.setPixel(col, row, rgb[0][col - minx][row - miny]); } } } long dur = System.currentTimeMillis() - entryTime; log.debug("exit: computeRectAHD in " + dur + "ms"); }