Skip to content

Commit

Permalink
mirror camera capture image
Browse files Browse the repository at this point in the history
  • Loading branch information
kryptonbutterfly committed Jan 24, 2024
1 parent f8c5cfb commit 06a0426
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/kryptonbutterfly/totp/misc/Utils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kryptonbutterfly.totp.misc;

import static kryptonbutterfly.math.utils.range.Range.*;

import java.awt.Color;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
Expand Down Expand Up @@ -55,4 +57,17 @@ private static BufferedImage scale(float factor, BufferedImage rawImage)
return new AffineTransformOp(transform, AffineTransformOp.TYPE_BICUBIC)
.filter(rawImage, null);
}

public static final BufferedImage mirror(BufferedImage src)
{
final int width = src.getWidth();
final int height = src.getHeight();
final var result = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);

for (final int y : range(height))
for (final int x : range(width))
result.setRGB(width - x - 1, y, src.getRGB(x, y));

return result;
}
}
3 changes: 2 additions & 1 deletion src/kryptonbutterfly/totp/ui/qrimport/BL.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import kryptonbutterfly.monads.opt.Opt;
import kryptonbutterfly.totp.TinyTotp;
import kryptonbutterfly.totp.misc.ImageLuminanceSource;
import kryptonbutterfly.totp.misc.Utils;
import kryptonbutterfly.util.swing.Logic;
import kryptonbutterfly.util.swing.events.GuiCloseEvent;
import kryptonbutterfly.util.swing.events.GuiCloseEvent.Result;
Expand Down Expand Up @@ -114,7 +115,7 @@ private void scan(QrGui gui)
webcam.open();

final var image = webcam.getImage();
gui.cameraDisplay.setIcon(new ImageIcon(image));
gui.cameraDisplay.setIcon(new ImageIcon(Utils.mirror(image)));
final var result = decode(image);

keepScanning = false;
Expand Down

0 comments on commit 06a0426

Please sign in to comment.