![]() |
CanScan
|
Thread-safe singleton to hold a shared QR code BufferedImage.
More...
Collaboration diagram for fr.softsf.canscan.ui.EncodedImage:Public Member Functions | |
| void | drawFinderPatterns (Graphics2D g, int matrixWidth, CommonFields config) |
| Renders the three QR code finder patterns at the corners using the specified style. | |
| void | drawLogoIfPresent (Graphics2D g, CommonFields config) throws IOException |
| Draws the logo at the center of the QR code if a valid logo file is provided. | |
| void | drawSquareFinderPatternAtPixel (Graphics2D g, double x, double y, double diameter, Color qrColor, Color bgColor) |
| Draws a standard square QR code finder pattern at the specified pixel coordinates. | |
| void | freeQrOriginal () |
| Releases the current QR code image and its resources. | |
| BufferedImage | generateImage (String data, CommonFields config) throws WriterException, IOException |
| Generates a QR code image with optional logo and styling. | |
| BufferedImage | getQrOriginal () |
| Retrieves a defensive copy of the QR code image. | |
| void | updateQrOriginal (BufferedImage newImage) |
| Updates the QR code image using a defensive copy. | |
Private Member Functions | |
| BufferedImage | createDefensiveCopy (BufferedImage sourceImage) |
| Creates a defensive copy of the source image. | |
| BitMatrix | createMatrix (String text, int margin) throws WriterException |
| Creates a QR code matrix for the given text. | |
| void | drawModule (Graphics2D g, int x, int y, double moduleSizeX, double moduleSizeY, CommonFields config) |
| Draws a single QR code module at the specified coordinates with configured size and shape. | |
| void | drawModules (Graphics2D g, BitMatrix matrix, CommonFields config) |
| Renders all QR code modules onto the provided graphics context. | |
| void | drawRoundedFinderPatternAtPixel (Graphics2D g, double x, double y, double diameter, Color qrColor, Color bgColor) |
| Draws a QR code finder pattern with rounded corners at the specified pixel coordinates. | |
| long | estimateImageMemoryMB (int size) |
| Estimates the memory required to create a BufferedImage. | |
| void | fillBackground (Graphics2D g, int size, Color bgColor) |
| Fills the entire QR code area with the specified background color. | |
| long | getAvailableMemoryMB () |
| Gets the available memory in the JVM with safety margin for image generation. | |
| boolean | isInBottomLeftPattern (int x, int y, int matrixHeight, int margin) |
| Checks if coordinates are within the bottom-left position pattern. | |
| boolean | isInPositionPattern (int x, int y, int matrixWidth, int matrixHeight, int margin) |
| Determines whether the given coordinates fall within any of the three QR code position patterns. | |
| boolean | isInTopLeftPattern (int x, int y, int margin) |
| Checks if coordinates are within the top-left position pattern. | |
| boolean | isInTopRightPattern (int x, int y, int matrixWidth, int margin) |
| Checks if coordinates are within the top-right position pattern. | |
| boolean | shouldSkipModule (int x, int y, BitMatrix matrix, ModuleContext ctx) |
| Determines whether a QR code module should be skipped during rendering. | |
| void | validateMemoryForImageSize (int size) |
| Validates that sufficient memory is available to generate a square image of the given size. | |
Private Attributes | |
| final Object | imageLock = new Object() |
| BufferedImage | qrOriginal |
Static Private Attributes | |
| static final int | AVAILABLE_MEMORY_TO_GENERATE_IMAGE = 50 |
| static final String | BG_COLOR = "bgColor" |
| static final int | BYTES_PER_KILOBYTE = 1024 |
| static final String | CONFIG = "config" |
| static final double | DEFAULT_GAP_BETWEEN_LOGO_AND_MODULES = 0.9 |
| static final String | DRAW_MODULES = "drawModules" |
| static final String | DRAW_ROUNDED_FINDER_PATTERN_AT_PIXEL |
| static final String | DRAW_SQUARE_FINDER_PATTERN_AT_PIXEL |
| static final String | GENERATE_QR_CODE_IMAGE = "generateQrCodeImage" |
| static final String | MATRIX = "matrix" |
| static final String | SHOULD_SKIP_MODULE = "shouldSkipModule" |
Thread-safe singleton to hold a shared QR code BufferedImage.
All access is synchronized for thread safety.
|
private |
Creates a defensive copy of the source image.
| sourceImage | The image to copy (must not be null). |
|
private |
Creates a QR code matrix for the given text.
| text | The string to encode in the QR code. |
| margin | The outer margin of the QR code in modules. |
| WriterException | If encoding fails. |
| void fr.softsf.canscan.ui.EncodedImage.drawFinderPatterns | ( | Graphics2D | g, |
| int | matrixWidth, | ||
| CommonFields | config ) |
Renders the three QR code finder patterns at the corners using the specified style.
| g | The graphics context for rendering. |
| matrixWidth | Width of the QR code matrix. |
| config | Configuration containing size, colors, module shape, and margin. |
Here is the call graph for this function:| void fr.softsf.canscan.ui.EncodedImage.drawLogoIfPresent | ( | Graphics2D | g, |
| CommonFields | config ) throws IOException |
Draws the logo at the center of the QR code if a valid logo file is provided.
The logo is scaled to fit within 90% of the designated white box area, which is determined by the QR code size and configured image ratio.
| g | The Graphics2D context used for rendering the QR code. |
| config | QR code configuration containing size, logo file, and image ratio. |
| IOException | If reading the logo file fails or the file is not a valid image. |
|
private |
Draws a single QR code module at the specified coordinates with configured size and shape.
Supports square or rounded modules depending on configuration.
| g | the graphics context used for rendering |
| x | the module's x-coordinate in the matrix |
| y | the module's y-coordinate in the matrix |
| moduleSizeX | width of the module in pixels |
| moduleSizeY | height of the module in pixels |
| config | the QR code configuration |
|
private |
Renders all QR code modules onto the provided graphics context.
Modules that are part of finder patterns or the central logo area are skipped. Supports rounded or square modules according to configuration.
| g | the graphics context used for drawing |
| matrix | the QR code bit matrix representing module positions |
| config | the QR code configuration including size, colors, module shape, margin, and logo ratio |
Here is the call graph for this function:
|
private |
Draws a QR code finder pattern with rounded corners at the specified pixel coordinates.
| g | Graphics2D context to draw on. |
| x | X-coordinate of the top-left corner. |
| y | Y-coordinate of the top-left corner. |
| diameter | Diameter of the finder pattern. |
| qrColor | Color of the QR modules. |
| bgColor | Background color inside the pattern. |
| void fr.softsf.canscan.ui.EncodedImage.drawSquareFinderPatternAtPixel | ( | Graphics2D | g, |
| double | x, | ||
| double | y, | ||
| double | diameter, | ||
| Color | qrColor, | ||
| Color | bgColor ) |
Draws a standard square QR code finder pattern at the specified pixel coordinates.
| g | Graphics2D context to draw on. |
| x | X-coordinate of the top-left corner. |
| y | Y-coordinate of the top-left corner. |
| diameter | Diameter of the finder pattern. |
| qrColor | Color of the QR modules. |
| bgColor | Background color inside the pattern. |
|
private |
Estimates the memory required to create a BufferedImage.
| size | The width and height of the square image. |
|
private |
Fills the entire QR code area with the specified background color.
| g | The graphics context used for drawing. |
| size | The width and height of the QR code area in pixels. |
| bgColor | The background color to fill. |
| void fr.softsf.canscan.ui.EncodedImage.freeQrOriginal | ( | ) |
Releases the current QR code image and its resources.
| BufferedImage fr.softsf.canscan.ui.EncodedImage.generateImage | ( | String | data, |
| CommonFields | config ) throws WriterException, IOException |
Generates a QR code image with optional logo and styling.
Uses ZXing with high error correction to ensure scanability even when a logo is embedded. Visual properties such as size, colors, margin, and module style are applied from the given configuration.
| data | the string to encode in the QR code |
| config | configuration including size, colors, margin, module style, and optional logo |
| WriterException | if encoding the data fails |
| IOException | if reading the logo file fails |
| OutOfMemoryError | if the requested size exceeds available memory |
Here is the call graph for this function:
|
private |
Gets the available memory in the JVM with safety margin for image generation.
| BufferedImage fr.softsf.canscan.ui.EncodedImage.getQrOriginal | ( | ) |
Retrieves a defensive copy of the QR code image.
Synchronized. Returns a copy to prevent external mutation of the internal state.
null.
Here is the call graph for this function:
|
private |
Checks if coordinates are within the bottom-left position pattern.
| x | X-coordinate |
| y | Y-coordinate |
| matrixHeight | Height of the QR matrix |
| margin | QR code margin |
true if inside bottom-left pattern; false otherwise
|
private |
Determines whether the given coordinates fall within any of the three QR code position patterns.
| x | X-coordinate in the QR matrix. |
| y | Y-coordinate in the QR matrix. |
| matrixWidth | Width of the QR matrix. |
| matrixHeight | Height of the QR matrix. |
| margin | QR code margin in modules. |
true if the coordinate is inside a position pattern; false otherwise.
Here is the call graph for this function:
|
private |
Checks if coordinates are within the top-left position pattern.
| x | X-coordinate |
| y | Y-coordinate |
| margin | QR code margin |
true if inside top-left pattern; false otherwise
|
private |
Checks if coordinates are within the top-right position pattern.
| x | X-coordinate |
| y | Y-coordinate |
| matrixWidth | Width of the QR matrix |
| margin | QR code margin |
true if inside top-right pattern; false otherwise
|
private |
Determines whether a QR code module should be skipped during rendering.
A module is skipped if it is unset, part of a finder pattern, or overlaps the central logo area.
| x | the module's x-coordinate in the QR matrix |
| y | the module's y-coordinate in the QR matrix |
| matrix | the QR code bit matrix |
| ctx | the module context containing configuration, matrix dimensions, and logo box |
Here is the call graph for this function:| void fr.softsf.canscan.ui.EncodedImage.updateQrOriginal | ( | BufferedImage | newImage | ) |
Updates the QR code image using a defensive copy.
Stores a copy of the input (input defense).
| newImage | The new image; null clears the current image. |
Here is the call graph for this function:
|
private |
Validates that sufficient memory is available to generate a square image of the given size.
Applies a hard limit of 200M px and ensures a minimum memory margin before allocation.
| size | the width and height of the square image in pixels |
| OutOfMemoryError | if the image exceeds pixel limits or available memory is insufficient |
Here is the call graph for this function:
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |
|
staticprivate |
|
private |
|
staticprivate |