From 593ff051bf6606d5075ec61ba92db4737287575c Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sun, 26 Aug 2018 00:01:00 +0000 Subject: [PATCH] Clarified and simplified some code. --- src/io/nayuki/fastqrcodegen/QrCode.java | 4 ++-- src/io/nayuki/fastqrcodegen/QrCodeGeneratorDemo.java | 11 +++-------- src/io/nayuki/fastqrcodegen/QrTemplate.java | 3 ++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/io/nayuki/fastqrcodegen/QrCode.java b/src/io/nayuki/fastqrcodegen/QrCode.java index 6fed91e..a4d623f 100644 --- a/src/io/nayuki/fastqrcodegen/QrCode.java +++ b/src/io/nayuki/fastqrcodegen/QrCode.java @@ -185,8 +185,8 @@ public final class QrCode { BufferedImage result = new BufferedImage((size + border * 2) * scale, (size + border * 2) * scale, BufferedImage.TYPE_INT_RGB); for (int y = 0; y < result.getHeight(); y++) { for (int x = 0; x < result.getWidth(); x++) { - boolean val = getModule(x / scale - border, y / scale - border); - result.setRGB(x, y, val ? 0x000000 : 0xFFFFFF); + boolean color = getModule(x / scale - border, y / scale - border); + result.setRGB(x, y, color ? 0x000000 : 0xFFFFFF); } } return result; diff --git a/src/io/nayuki/fastqrcodegen/QrCodeGeneratorDemo.java b/src/io/nayuki/fastqrcodegen/QrCodeGeneratorDemo.java index d9b1c21..03920e2 100644 --- a/src/io/nayuki/fastqrcodegen/QrCodeGeneratorDemo.java +++ b/src/io/nayuki/fastqrcodegen/QrCodeGeneratorDemo.java @@ -28,11 +28,9 @@ package io.nayuki.fastqrcodegen; import java.awt.image.BufferedImage; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Arrays; import java.util.List; import javax.imageio.ImageIO; @@ -64,11 +62,8 @@ public final class QrCodeGeneratorDemo { ImageIO.write(img, "png", imgFile); // Write image to file String svg = qr.toSvgString(4); // Convert to SVG XML code - try (Writer out = new OutputStreamWriter( - new FileOutputStream("hello-world-QR.svg"), - StandardCharsets.UTF_8)) { - out.write(svg); // Create/overwrite file and write SVG data - } + Files.write(new File("hello-world-QR.svg").toPath(), + svg.getBytes(StandardCharsets.UTF_8)); } diff --git a/src/io/nayuki/fastqrcodegen/QrTemplate.java b/src/io/nayuki/fastqrcodegen/QrTemplate.java index cbc50ff..97a4fbd 100644 --- a/src/io/nayuki/fastqrcodegen/QrTemplate.java +++ b/src/io/nayuki/fastqrcodegen/QrTemplate.java @@ -174,7 +174,8 @@ final class QrTemplate { // Draw two copies for (int i = 0; i < 18; i++) { int bit = (bits >>> i) & 1; - int a = size - 11 + i % 3, b = i / 3; + int a = size - 11 + i % 3; + int b = i / 3; darkenFunctionModule(a, b, bit); darkenFunctionModule(b, a, bit); }