From 65e395d41be6abbeb177b7fd939af34bc8874032 Mon Sep 17 00:00:00 2001 From: Bartosz Firyn Date: Tue, 24 Jun 2014 18:19:14 +0000 Subject: [PATCH] Fix performance issue on Widnows when image is mirrored, refs #227 --- .../com/github/sarxos/webcam/WebcamPanel.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamPanel.java b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamPanel.java index 0448b75e..dce9d033 100644 --- a/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamPanel.java +++ b/webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamPanel.java @@ -264,12 +264,27 @@ public void paintImage(WebcamPanel owner, BufferedImage image, Graphics2D g2) { gr.setColor(Color.BLACK); gr.fillRect(0, 0, pw, ph); + int sx1, sx2, sy1, sy2; // source rectangle coordinates + int dx1, dx2, dy1, dy2; // destination rectangle coordinates + + dx1 = x; + dy1 = y; + dx2 = x + w; + dy2 = y + h; + if (mirrored) { - x = x + w; - w = -w; + sx1 = iw; + sy1 = 0; + sx2 = 0; + sy2 = ih; + } else { + sx1 = 0; + sy1 = 0; + sx2 = iw; + sy2 = ih; } - gr.drawImage(image, x, y, w, h, null); + gr.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null); } finally { if (gr != null) {