diff --git a/c/qrcodegen-test.c b/c/qrcodegen-test.c index 76d1d0f..fd57380 100644 --- a/c/qrcodegen-test.c +++ b/c/qrcodegen-test.c @@ -55,8 +55,8 @@ uint8_t reedSolomonMultiply(uint8_t x, uint8_t y); void initializeFunctionModules(int version, uint8_t qrcode[]); int getAlignmentPatternPositions(int version, uint8_t result[7]); bool getModule(const uint8_t qrcode[], int x, int y); -void setModule(uint8_t qrcode[], int x, int y, bool isBlack); -void setModuleBounded(uint8_t qrcode[], int x, int y, bool isBlack); +void setModule(uint8_t qrcode[], int x, int y, bool isDark); +void setModuleBounded(uint8_t qrcode[], int x, int y, bool isDark); int calcSegmentBitLength(enum qrcodegen_Mode mode, size_t numChars); int getTotalBits(const struct qrcodegen_Segment segs[], size_t len, int version); @@ -375,17 +375,17 @@ static void testInitializeFunctionModulesEtc(void) { assert(size == ver * 4 + 17); bool hasLight = false; - bool hasBlack = false; + bool hasDark = false; for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { bool color = qrcodegen_getModule(qrcode, x, y); if (color) - hasBlack = true; + hasDark = true; else hasLight = true; } } - assert(hasLight && hasBlack); + assert(hasLight && hasDark); free(qrcode); numTestCases++; } @@ -432,11 +432,11 @@ static void testGetSetModule(void) { for (int x = 0; x < size; x++) assert(qrcodegen_getModule(qrcode, x, y) == false); } - for (int y = 0; y < size; y++) { // Set all to black + for (int y = 0; y < size; y++) { // Set all to dark for (int x = 0; x < size; x++) setModule(qrcode, x, y, true); } - for (int y = 0; y < size; y++) { // Check all black + for (int y = 0; y < size; y++) { // Check all dark for (int x = 0; x < size; x++) assert(qrcodegen_getModule(qrcode, x, y) == true); } @@ -448,7 +448,7 @@ static void testGetSetModule(void) { setModuleBounded(qrcode, size, 5, false); setModuleBounded(qrcode, 72, size, false); setModuleBounded(qrcode, size, size, false); - for (int y = 0; y < size; y++) { // Check all black + for (int y = 0; y < size; y++) { // Check all dark for (int x = 0; x < size; x++) assert(qrcodegen_getModule(qrcode, x, y) == true); } @@ -456,7 +456,7 @@ static void testGetSetModule(void) { // Set some modules to light setModule(qrcode, 3, 8, false); setModule(qrcode, 61, 49, false); - for (int y = 0; y < size; y++) { // Check most black + for (int y = 0; y < size; y++) { // Check most dark for (int x = 0; x < size; x++) { bool light = (x == 3 && y == 8) || (x == 61 && y == 49); assert(qrcodegen_getModule(qrcode, x, y) != light); diff --git a/c/qrcodegen.c b/c/qrcodegen.c index 7166028..e67a7d3 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -77,8 +77,8 @@ static int finderPenaltyTerminateAndCount(bool currentRunColor, int currentRunLe static void finderPenaltyAddHistory(int currentRunLength, int runHistory[7], int qrsize); testable bool getModule(const uint8_t qrcode[], int x, int y); -testable void setModule(uint8_t qrcode[], int x, int y, bool isBlack); -testable void setModuleBounded(uint8_t qrcode[], int x, int y, bool isBlack); +testable void setModule(uint8_t qrcode[], int x, int y, bool isDark); +testable void setModuleBounded(uint8_t qrcode[], int x, int y, bool isDark); static bool getBit(int x, int i); testable int calcSegmentBitLength(enum qrcodegen_Mode mode, size_t numChars); @@ -414,7 +414,7 @@ testable uint8_t reedSolomonMultiply(uint8_t x, uint8_t y) { /*---- Drawing function modules ----*/ // Clears the given QR Code grid with light modules for the given -// version's size, then marks every function module as black. +// version's size, then marks every function module as dark. testable void initializeFunctionModules(int version, uint8_t qrcode[]) { // Initialize QR Code int qrsize = version * 4 + 17; @@ -449,9 +449,9 @@ testable void initializeFunctionModules(int version, uint8_t qrcode[]) { } -// Draws light function modules and possibly some black modules onto the given QR Code, without changing +// Draws light function modules and possibly some dark modules onto the given QR Code, without changing // non-function modules. This does not draw the format bits. This requires all function modules to be previously -// marked black (namely by initializeFunctionModules()), because this may skip redrawing black function modules. +// marked dark (namely by initializeFunctionModules()), because this may skip redrawing dark function modules. static void drawLightFunctionModules(uint8_t qrcode[], int version) { // Draw horizontal and vertical timing patterns int qrsize = qrcodegen_getSize(qrcode); @@ -512,7 +512,7 @@ static void drawLightFunctionModules(uint8_t qrcode[], int version) { // Draws two copies of the format bits (with its own error correction code) based // on the given mask and error correction level. This always draws all modules of -// the format bits, unlike drawLightFunctionModules() which might skip black modules. +// the format bits, unlike drawLightFunctionModules() which might skip dark modules. static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uint8_t qrcode[]) { // Calculate error correction code and pack bits assert(0 <= (int)mask && (int)mask <= 7); @@ -539,7 +539,7 @@ static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uin setModule(qrcode, qrsize - 1 - i, 8, getBit(bits, i)); for (int i = 8; i < 15; i++) setModule(qrcode, 8, qrsize - 15 + i, getBit(bits, i)); - setModule(qrcode, 8, qrsize - 8, true); // Always black + setModule(qrcode, 8, qrsize - 8, true); // Always dark } @@ -560,7 +560,7 @@ testable int getAlignmentPatternPositions(int version, uint8_t result[7]) { } -// Sets every pixel in the range [left : left + width] * [top : top + height] to black. +// Sets every pixel in the range [left : left + width] * [top : top + height] to dark. static void fillRectangle(int left, int top, int width, int height, uint8_t qrcode[]) { for (int dy = 0; dy < height; dy++) { for (int dx = 0; dx < width; dx++) @@ -573,7 +573,7 @@ static void fillRectangle(int left, int top, int width, int height, uint8_t qrco /*---- Drawing data modules and masking ----*/ // Draws the raw codewords (including data and ECC) onto the given QR Code. This requires the initial state of -// the QR Code to be black at function modules and light at codeword modules (including unused remainder bits). +// the QR Code to be dark at function modules and light at codeword modules (including unused remainder bits). static void drawCodewords(const uint8_t data[], int dataLen, uint8_t qrcode[]) { int qrsize = qrcodegen_getSize(qrcode); int i = 0; // Bit index into the data @@ -587,8 +587,8 @@ static void drawCodewords(const uint8_t data[], int dataLen, uint8_t qrcode[]) { bool upward = ((right + 1) & 2) == 0; int y = upward ? qrsize - 1 - vert : vert; // Actual y coordinate if (!getModule(qrcode, x, y) && i < dataLen * 8) { - bool black = getBit(data[i >> 3], 7 - (i & 7)); - setModule(qrcode, x, y, black); + bool dark = getBit(data[i >> 3], 7 - (i & 7)); + setModule(qrcode, x, y, dark); i++; } // If this QR Code has any remainder bits (0 to 7), they were assigned as @@ -693,17 +693,17 @@ static long getPenaltyScore(const uint8_t qrcode[]) { } } - // Balance of black and light modules - int black = 0; + // Balance of dark and light modules + int dark = 0; for (int y = 0; y < qrsize; y++) { for (int x = 0; x < qrsize; x++) { if (getModule(qrcode, x, y)) - black++; + dark++; } } - int total = qrsize * qrsize; // Note that size is odd, so black/total != 1/2 - // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% - int k = (int)((labs(black * 20L - total * 10L) + total - 1) / total) - 1; + int total = qrsize * qrsize; // Note that size is odd, so dark/total != 1/2 + // Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)% + int k = (int)((labs(dark * 20L - total * 10L) + total - 1) / total) - 1; result += k * PENALTY_N4; return result; } @@ -715,7 +715,7 @@ static int finderPenaltyCountPatterns(const int runHistory[7], int qrsize) { int n = runHistory[1]; assert(n <= qrsize * 3); bool core = n > 0 && runHistory[2] == n && runHistory[3] == n * 3 && runHistory[4] == n && runHistory[5] == n; - // The maximum QR Code size is 177, hence the black run length n <= 177. + // The maximum QR Code size is 177, hence the dark run length n <= 177. // Arithmetic is promoted to int, so n*4 will not overflow. return (core && runHistory[0] >= n * 4 && runHistory[6] >= n ? 1 : 0) + (core && runHistory[6] >= n * 4 && runHistory[0] >= n ? 1 : 0); @@ -724,7 +724,7 @@ static int finderPenaltyCountPatterns(const int runHistory[7], int qrsize) { // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore(). static int finderPenaltyTerminateAndCount(bool currentRunColor, int currentRunLength, int runHistory[7], int qrsize) { - if (currentRunColor) { // Terminate black run + if (currentRunColor) { // Terminate dark run finderPenaltyAddHistory(currentRunLength, runHistory, qrsize); currentRunLength = 0; } @@ -774,13 +774,13 @@ testable bool getModule(const uint8_t qrcode[], int x, int y) { // Sets the module at the given coordinates, which must be in bounds. -testable void setModule(uint8_t qrcode[], int x, int y, bool isBlack) { +testable void setModule(uint8_t qrcode[], int x, int y, bool isDark) { int qrsize = qrcode[0]; assert(21 <= qrsize && qrsize <= 177 && 0 <= x && x < qrsize && 0 <= y && y < qrsize); int index = y * qrsize + x; int bitIndex = index & 7; int byteIndex = (index >> 3) + 1; - if (isBlack) + if (isDark) qrcode[byteIndex] |= 1 << bitIndex; else qrcode[byteIndex] &= (1 << bitIndex) ^ 0xFF; @@ -788,10 +788,10 @@ testable void setModule(uint8_t qrcode[], int x, int y, bool isBlack) { // Sets the module at the given coordinates, doing nothing if out of bounds. -testable void setModuleBounded(uint8_t qrcode[], int x, int y, bool isBlack) { +testable void setModuleBounded(uint8_t qrcode[], int x, int y, bool isDark) { int qrsize = qrcode[0]; if (0 <= x && x < qrsize && 0 <= y && y < qrsize) - setModule(qrcode, x, y, isBlack); + setModule(qrcode, x, y, isDark); } diff --git a/c/qrcodegen.h b/c/qrcodegen.h index fd0ae9c..94aaef9 100644 --- a/c/qrcodegen.h +++ b/c/qrcodegen.h @@ -36,7 +36,7 @@ extern "C" { /* * This library creates QR Code symbols, which is a type of two-dimension barcode. * Invented by Denso Wave and described in the ISO/IEC 18004 standard. - * A QR Code structure is an immutable square grid of black and light cells. + * A QR Code structure is an immutable square grid of dark and light cells. * The library provides functions to create a QR Code from text or binary data. * The library covers the QR Code Model 2 specification, supporting all versions (sizes) * from 1 to 40, all 4 error correction levels, and 4 character encoding modes. @@ -300,7 +300,7 @@ int qrcodegen_getSize(const uint8_t qrcode[]); /* * Returns the color of the module (pixel) at the given coordinates, which is false - * for light or true for black. The top left corner has the coordinates (x=0, y=0). + * for light or true for dark. The top left corner has the coordinates (x=0, y=0). * If the given coordinates are out of bounds, then false (light) is returned. */ bool qrcodegen_getModule(const uint8_t qrcode[], int x, int y); diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 88186e1..538204e 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -466,7 +466,7 @@ void QrCode::drawFormatBits(int msk) { setFunctionModule(size - 1 - i, 8, getBit(bits, i)); for (int i = 8; i < 15; i++) setFunctionModule(8, size - 15 + i, getBit(bits, i)); - setFunctionModule(8, size - 8, true); // Always black + setFunctionModule(8, size - 8, true); // Always dark } @@ -513,10 +513,10 @@ void QrCode::drawAlignmentPattern(int x, int y) { } -void QrCode::setFunctionModule(int x, int y, bool isBlack) { +void QrCode::setFunctionModule(int x, int y, bool isDark) { size_t ux = static_cast(x); size_t uy = static_cast(y); - modules .at(uy).at(ux) = isBlack; + modules .at(uy).at(ux) = isDark; isFunction.at(uy).at(ux) = true; } @@ -676,17 +676,17 @@ long QrCode::getPenaltyScore() const { } } - // Balance of black and light modules - int black = 0; + // Balance of dark and light modules + int dark = 0; for (const vector &row : modules) { for (bool color : row) { if (color) - black++; + dark++; } } - int total = size * size; // Note that size is odd, so black/total != 1/2 - // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% - int k = static_cast((std::abs(black * 20L - total * 10L) + total - 1) / total) - 1; + int total = size * size; // Note that size is odd, so dark/total != 1/2 + // Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)% + int k = static_cast((std::abs(dark * 20L - total * 10L) + total - 1) / total) - 1; result += k * PENALTY_N4; return result; } @@ -793,7 +793,7 @@ int QrCode::finderPenaltyCountPatterns(const std::array &runHistory) cons int QrCode::finderPenaltyTerminateAndCount(bool currentRunColor, int currentRunLength, std::array &runHistory) const { - if (currentRunColor) { // Terminate black run + if (currentRunColor) { // Terminate dark run finderPenaltyAddHistory(currentRunLength, runHistory); currentRunLength = 0; } diff --git a/cpp/QrCode.hpp b/cpp/QrCode.hpp index 55a1ee8..2a1e987 100644 --- a/cpp/QrCode.hpp +++ b/cpp/QrCode.hpp @@ -220,7 +220,7 @@ class QrSegment final { /* * A QR Code symbol, which is a type of two-dimension barcode. * Invented by Denso Wave and described in the ISO/IEC 18004 standard. - * Instances of this class represent an immutable square grid of black and light cells. + * Instances of this class represent an immutable square grid of dark and light cells. * The class provides static factory functions to create a QR Code from text or binary data. * The class covers the QR Code Model 2 specification, supporting all versions (sizes) * from 1 to 40, all 4 error correction levels, and 4 character encoding modes. @@ -314,7 +314,7 @@ class QrCode final { // Private grids of modules/pixels, with dimensions of size*size: - // The modules of this QR Code (false = light, true = black). + // The modules of this QR Code (false = light, true = dark). // Immutable after constructor finishes. Accessed through getModule(). private: std::vector > modules; @@ -363,7 +363,7 @@ class QrCode final { /* * Returns the color of the module (pixel) at the given coordinates, which is false - * for light or true for black. The top left corner has the coordinates (x=0, y=0). + * for light or true for dark. The top left corner has the coordinates (x=0, y=0). * If the given coordinates are out of bounds, then false (light) is returned. */ public: bool getModule(int x, int y) const; @@ -405,7 +405,7 @@ class QrCode final { // Sets the color of a module and marks it as a function module. // Only used by the constructor. Coordinates must be in bounds. - private: void setFunctionModule(int x, int y, bool isBlack); + private: void setFunctionModule(int x, int y, bool isDark); // Returns the color of the module at the given coordinates, which must be in range. diff --git a/java/src/main/java/io/nayuki/qrcodegen/QrCode.java b/java/src/main/java/io/nayuki/qrcodegen/QrCode.java index 1a74fcb..3bd3f4b 100644 --- a/java/src/main/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/src/main/java/io/nayuki/qrcodegen/QrCode.java @@ -32,7 +32,7 @@ import java.util.Objects; /** * A QR Code symbol, which is a type of two-dimension barcode. * Invented by Denso Wave and described in the ISO/IEC 18004 standard. - *

Instances of this class represent an immutable square grid of black and light cells. + *

Instances of this class represent an immutable square grid of dark and light cells. * The class provides static factory functions to create a QR Code from text or binary data. * The class covers the QR Code Model 2 specification, supporting all versions (sizes) * from 1 to 40, all 4 error correction levels, and 4 character encoding modes.

@@ -222,7 +222,7 @@ public final class QrCode { // Private grids of modules/pixels, with dimensions of size*size: - // The modules of this QR Code (false = light, true = black). + // The modules of this QR Code (false = light, true = dark). // Immutable after constructor finishes. Accessed through getModule(). private boolean[][] modules; @@ -273,12 +273,12 @@ public final class QrCode { /** * Returns the color of the module (pixel) at the specified coordinates, which is {@code false} - * for light or {@code true} for black. The top left corner has the coordinates (x=0, y=0). + * for light or {@code true} for dark. The top left corner has the coordinates (x=0, y=0). * If the specified coordinates are out of bounds, then {@code false} (light) is returned. * @param x the x coordinate, where 0 is the left edge and size−1 is the right edge * @param y the y coordinate, where 0 is the top edge and size−1 is the bottom edge * @return {@code true} if the coordinates are in bounds and the module - * at that location is black, or {@code false} (light) otherwise + * at that location is dark, or {@code false} (light) otherwise */ public boolean getModule(int x, int y) { return 0 <= x && x < size && 0 <= y && y < size && modules[y][x]; @@ -405,7 +405,7 @@ public final class QrCode { setFunctionModule(size - 1 - i, 8, getBit(bits, i)); for (int i = 8; i < 15; i++) setFunctionModule(8, size - 15 + i, getBit(bits, i)); - setFunctionModule(8, size - 8, true); // Always black + setFunctionModule(8, size - 8, true); // Always dark } @@ -459,8 +459,8 @@ public final class QrCode { // Sets the color of a module and marks it as a function module. // Only used by the constructor. Coordinates must be in bounds. - private void setFunctionModule(int x, int y, boolean isBlack) { - modules[y][x] = isBlack; + private void setFunctionModule(int x, int y, boolean isDark) { + modules[y][x] = isDark; isFunction[y][x] = true; } @@ -651,17 +651,17 @@ public final class QrCode { } } - // Balance of black and light modules - int black = 0; + // Balance of dark and light modules + int dark = 0; for (boolean[] row : modules) { for (boolean color : row) { if (color) - black++; + dark++; } } - int total = size * size; // Note that size is odd, so black/total != 1/2 - // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% - int k = (Math.abs(black * 20 - total * 10) + total - 1) / total - 1; + int total = size * size; // Note that size is odd, so dark/total != 1/2 + // Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)% + int k = (Math.abs(dark * 20 - total * 10) + total - 1) / total - 1; result += k * PENALTY_N4; return result; } @@ -702,7 +702,7 @@ public final class QrCode { int size = ver * 4 + 17; int result = size * size; // Number of modules in the whole QR Code square result -= 8 * 8 * 3; // Subtract the three finders with separators - result -= 15 * 2 + 1; // Subtract the format information and black module + result -= 15 * 2 + 1; // Subtract the format information and dark module result -= (size - 16) * 2; // Subtract the timing patterns (excluding finders) // The five lines above are equivalent to: int result = (16 * ver + 128) * ver + 64; if (ver >= 2) { @@ -799,7 +799,7 @@ public final class QrCode { // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore(). private int finderPenaltyTerminateAndCount(boolean currentRunColor, int currentRunLength, int[] runHistory) { - if (currentRunColor) { // Terminate black run + if (currentRunColor) { // Terminate dark run finderPenaltyAddHistory(currentRunLength, runHistory); currentRunLength = 0; } diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 115d31d..7cbea57 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -32,7 +32,7 @@ from typing import Callable, Dict, List, Optional, Tuple, Union class QrCode: """A QR Code symbol, which is a type of two-dimension barcode. Invented by Denso Wave and described in the ISO/IEC 18004 standard. - Instances of this class represent an immutable square grid of black and light cells. + Instances of this class represent an immutable square grid of dark and light cells. The class provides static factory functions to create a QR Code from text or binary data. The class covers the QR Code Model 2 specification, supporting all versions (sizes) from 1 to 40, all 4 error correction levels, and 4 character encoding modes. @@ -151,7 +151,7 @@ class QrCode: # the resulting object still has a mask value between 0 and 7. _mask: int - # The modules of this QR Code (False = light, True = black). + # The modules of this QR Code (False = light, True = dark). # Immutable after constructor finishes. Accessed through get_module(). _modules: List[List[bool]] @@ -227,7 +227,7 @@ class QrCode: def get_module(self, x: int, y: int) -> bool: """Returns the color of the module (pixel) at the given coordinates, which is False - for light or True for black. The top left corner has the coordinates (x=0, y=0). + for light or True for dark. The top left corner has the coordinates (x=0, y=0). If the given coordinates are out of bounds, then False (light) is returned.""" return (0 <= x < self._size) and (0 <= y < self._size) and self._modules[y][x] @@ -306,7 +306,7 @@ class QrCode: self._set_function_module(self._size - 1 - i, 8, _get_bit(bits, i)) for i in range(8, 15): self._set_function_module(8, self._size - 15 + i, _get_bit(bits, i)) - self._set_function_module(8, self._size - 8, True) # Always black + self._set_function_module(8, self._size - 8, True) # Always dark def _draw_version(self) -> None: @@ -350,11 +350,11 @@ class QrCode: self._set_function_module(x + dx, y + dy, max(abs(dx), abs(dy)) != 1) - def _set_function_module(self, x: int, y: int, isblack: bool) -> None: + def _set_function_module(self, x: int, y: int, isdark: bool) -> None: """Sets the color of a module and marks it as a function module. Only used by the constructor. Coordinates must be in bounds.""" - assert type(isblack) is bool - self._modules[y][x] = isblack + assert type(isdark) is bool + self._modules[y][x] = isdark self._isfunction[y][x] = True @@ -486,11 +486,11 @@ class QrCode: if modules[y][x] == modules[y][x + 1] == modules[y + 1][x] == modules[y + 1][x + 1]: result += QrCode._PENALTY_N2 - # Balance of black and light modules - black: int = sum((1 if cell else 0) for row in modules for cell in row) - total: int = size**2 # Note that size is odd, so black/total != 1/2 - # Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% - k: int = (abs(black * 20 - total * 10) + total - 1) // total - 1 + # Balance of dark and light modules + dark: int = sum((1 if cell else 0) for row in modules for cell in row) + total: int = size**2 # Note that size is odd, so dark/total != 1/2 + # Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)% + k: int = (abs(dark * 20 - total * 10) + total - 1) // total - 1 result += k * QrCode._PENALTY_N4 return result @@ -602,7 +602,7 @@ class QrCode: def _finder_penalty_terminate_and_count(self, currentruncolor: bool, currentrunlength: int, runhistory: collections.deque) -> int: """Must be called at the end of a line (row or column) of modules. A helper function for _get_penalty_score().""" - if currentruncolor: # Terminate black run + if currentruncolor: # Terminate dark run self._finder_penalty_add_history(currentrunlength, runhistory) currentrunlength = 0 currentrunlength += self._size # Add light border to final run diff --git a/rust/src/lib.rs b/rust/src/lib.rs index dbfb855..2999e29 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -88,7 +88,7 @@ /// /// Invented by Denso Wave and described in the ISO/IEC 18004 standard. /// -/// Instances of this struct represent an immutable square grid of black and light cells. +/// Instances of this struct represent an immutable square grid of dark and light cells. /// The impl provides static factory functions to create a QR Code from text or binary data. /// The struct and impl cover the QR Code Model 2 specification, supporting all versions /// (sizes) from 1 to 40, all 4 error correction levels, and 4 character encoding modes. @@ -126,7 +126,7 @@ pub struct QrCode { // Grids of modules/pixels, with dimensions of size*size: - // The modules of this QR Code (false = light, true = black). + // The modules of this QR Code (false = light, true = dark). // Immutable after constructor finishes. Accessed through get_module(). modules: Vec, @@ -347,7 +347,7 @@ impl QrCode { /// Returns the color of the module (pixel) at the given coordinates, - /// which is `false` for light or `true` for black. + /// which is `false` for light or `true` for dark. /// /// The top left corner has the coordinates (x=0, y=0). If the given /// coordinates are out of bounds, then `false` (light) is returned. @@ -466,7 +466,7 @@ impl QrCode { for i in 8 .. 15 { self.set_function_module(8, size - 15 + i, get_bit(bits, i)); } - self.set_function_module(8, size - 8, true); // Always black + self.set_function_module(8, size - 8, true); // Always dark } @@ -528,8 +528,8 @@ impl QrCode { // Sets the color of a module and marks it as a function module. // Only used by the constructor. Coordinates must be in bounds. - fn set_function_module(&mut self, x: i32, y: i32, isblack: bool) { - *self.module_mut(x, y) = isblack; + fn set_function_module(&mut self, x: i32, y: i32, isdark: bool) { + *self.module_mut(x, y) = isdark; self.isfunction[(y * self.size + x) as usize] = true; } @@ -703,11 +703,11 @@ impl QrCode { } } - // Balance of black and light modules - let black: i32 = self.modules.iter().copied().map(i32::from).sum(); - let total: i32 = size * size; // Note that size is odd, so black/total != 1/2 - // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% - let k: i32 = ((black * 20 - total * 10).abs() + total - 1) / total - 1; + // Balance of dark and light modules + let dark: i32 = self.modules.iter().copied().map(i32::from).sum(); + let total: i32 = size * size; // Note that size is odd, so dark/total != 1/2 + // Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)% + let k: i32 = ((dark * 20 - total * 10).abs() + total - 1) / total - 1; result += k * PENALTY_N4; result } @@ -869,7 +869,7 @@ impl FinderPenalty { // Must be called at the end of a line (row or column) of modules. pub fn terminate_and_count(mut self, currentruncolor: bool, mut currentrunlength: i32) -> i32 { - if currentruncolor { // Terminate black run + if currentruncolor { // Terminate dark run self.add_history(currentrunlength); currentrunlength = 0; } diff --git a/typescript-javascript/qrcodegen.ts b/typescript-javascript/qrcodegen.ts index 77f07bc..2d3e717 100644 --- a/typescript-javascript/qrcodegen.ts +++ b/typescript-javascript/qrcodegen.ts @@ -36,7 +36,7 @@ namespace qrcodegen { /* * A QR Code symbol, which is a type of two-dimension barcode. * Invented by Denso Wave and described in the ISO/IEC 18004 standard. - * Instances of this class represent an immutable square grid of black and light cells. + * Instances of this class represent an immutable square grid of dark and light cells. * The class provides static factory functions to create a QR Code from text or binary data. * The class covers the QR Code Model 2 specification, supporting all versions (sizes) * from 1 to 40, all 4 error correction levels, and 4 character encoding modes. @@ -155,7 +155,7 @@ namespace qrcodegen { // 21 and 177 (inclusive). This is equal to version * 4 + 17. public readonly size: int; - // The modules of this QR Code (false = light, true = black). + // The modules of this QR Code (false = light, true = dark). // Immutable after constructor finishes. Accessed through getModule(). private readonly modules : Array> = []; @@ -232,7 +232,7 @@ namespace qrcodegen { /*-- Accessor methods --*/ // Returns the color of the module (pixel) at the given coordinates, which is false - // for light or true for black. The top left corner has the coordinates (x=0, y=0). + // for light or true for dark. The top left corner has the coordinates (x=0, y=0). // If the given coordinates are out of bounds, then false (light) is returned. public getModule(x: int, y: int): boolean { return 0 <= x && x < this.size && 0 <= y && y < this.size && this.modules[y][x]; @@ -243,7 +243,7 @@ namespace qrcodegen { // Draws this QR Code, with the given module scale and border modules, onto the given HTML // canvas element. The canvas's width and height is resized to (this.size + border * 2) * scale. - // The drawn image is be purely black and light, and fully opaque. + // The drawn image is be purely dark and light, and fully opaque. // The scale must be a positive integer and the border must be a non-negative integer. public drawCanvas(scale: int, border: int, canvas: HTMLCanvasElement): void { if (scale <= 0 || border < 0) @@ -341,7 +341,7 @@ namespace qrcodegen { this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i)); for (let i = 8; i < 15; i++) this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i)); - this.setFunctionModule(8, this.size - 8, true); // Always black + this.setFunctionModule(8, this.size - 8, true); // Always dark } @@ -397,8 +397,8 @@ namespace qrcodegen { // Sets the color of a module and marks it as a function module. // Only used by the constructor. Coordinates must be in bounds. - private setFunctionModule(x: int, y: int, isBlack: boolean): void { - this.modules[y][x] = isBlack; + private setFunctionModule(x: int, y: int, isDark: boolean): void { + this.modules[y][x] = isDark; this.isFunction[y][x] = true; } @@ -566,13 +566,13 @@ namespace qrcodegen { } } - // Balance of black and light modules - let black: int = 0; + // Balance of dark and light modules + let dark: int = 0; for (const row of this.modules) - black = row.reduce((sum, color) => sum + (color ? 1 : 0), black); - const total: int = this.size * this.size; // Note that size is odd, so black/total != 1/2 - // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% - const k: int = Math.ceil(Math.abs(black * 20 - total * 10) / total) - 1; + dark = row.reduce((sum, color) => sum + (color ? 1 : 0), dark); + const total: int = this.size * this.size; // Note that size is odd, so dark/total != 1/2 + // Compute the smallest integer k >= 0 such that (45-5k)% <= dark/total <= (55+5k)% + const k: int = Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1; result += k * QrCode.PENALTY_N4; return result; } @@ -700,7 +700,7 @@ namespace qrcodegen { // Must be called at the end of a line (row or column) of modules. A helper function for getPenaltyScore(). private finderPenaltyTerminateAndCount(currentRunColor: boolean, currentRunLength: int, runHistory: Array): int { - if (currentRunColor) { // Terminate black run + if (currentRunColor) { // Terminate dark run this.finderPenaltyAddHistory(currentRunLength, runHistory); currentRunLength = 0; }