feat(graphics): add image rendering capabilities to the emulator#89
Merged
feat(graphics): add image rendering capabilities to the emulator#89
Conversation
- Implement image resizing and grayscale conversion utilities - Introduce image rendering options for better control over image output - Enhance the emulator engine to support image embedding in receipts - Add example demonstrating image embedding in the ESC/POS emulator Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
Contributor
|
👋 Thanks for opening this PR, @adcondev! Here's what will happen next:
Please make sure:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces comprehensive image rendering capabilities to the ESC/POS emulator, enabling accurate WYSIWYG receipt previews with embedded images. The implementation adds a new image processing pipeline with utilities for resizing, grayscale conversion, and thermal print simulation, while refactoring existing graphics code for better maintainability.
Key Changes:
- Adds
ImageRendererto the emulator with methods for embedding images with flexible alignment, scaling, and thermal preview simulation - Introduces reusable image processing utilities (
ResizeImage,ToGrayscale,CompositeOverWhite) to support both emulator and graphics pipeline needs - Refactors graphics pipeline to use the new utility functions, improving code consistency and reducing duplication
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 16 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/graphics/processing.go | New file adding reusable image processing utilities for resizing, grayscale conversion, and transparency handling |
| pkg/graphics/graph_engine.go | Refactored to use new processing utilities, removing duplicate resize/grayscale code |
| pkg/graphics/bitmap.go | Added ToImage() method to convert monochrome bitmaps back to RGBA for emulator preview |
| pkg/emulator/render_image.go | New file implementing ImageRenderer with support for normal and thermal preview modes |
| pkg/emulator/emulator_engine.go | Added image rendering methods and improved cursor management for scaled text |
| examples/emulator/image/image_example.go | New example demonstrating image embedding in receipts with optional physical printing |
| .gitignore | Added WORKFLOWS.md to allowed documentation files |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…onality - Introduce caching mechanism for scaled font faces to improve rendering performance - Add method to clear the scaled face cache, useful for resetting the engine or changing fonts - Update text rendering to utilize cached metrics for better efficiency Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
…detailed technical architecture, new features like the visual emulator, and enhanced ESC/POS command support.
…nce labeling Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
- Improve performance by processing bytes directly instead of calling GetPixel for each pixel - Reduce the number of function calls and enhance rendering speed for the emulator Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
…PI settings - Introduced AutoAdjustCursorOnScale to control cursor adjustment behavior when scaling text. - Updated default DPI in configuration for better consistency across different paper sizes. - Renamed Config58mm to ConfigTest58mm for clarity in testing context. Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
…nd image printing methods - Implement tests for cursor adjustment behavior when scaling up and down - Verify cursor position after printing images with various options - Ensure correct handling of nil images and default options Signed-off-by: Adrián Constante <ad_con.reload@proton.me>
2f6a591 to
3fd0f80
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces comprehensive support for embedding and previewing images in the ESC/POS emulator, enabling accurate WYSIWYG (what you see is what you get) previews of receipts with images. The changes add a new image rendering pipeline to the emulator, including options for simulating thermal printer output, and refactor graphics utilities to support this workflow.
New image embedding and rendering in the emulator:
ImageRendererto the emulator engine, with methods such asPrintImage,PrintImageWithOptions,PrintImageAligned, andPrintImageThermalPreview, allowing flexible image placement and accurate simulation of thermal printing output. (pkg/emulator/emulator_engine.go[1] [2] [3] [4] [5];pkg/emulator/render_image.go[6]ImageOptionsstruct to configure image rendering (width, alignment, scaling, dithering, and thermal simulation) for both normal and thermal preview modes. (pkg/emulator/render_image.gopkg/emulator/render_image.goR1-R168)Graphics and image processing improvements:
pkg/graphics/graph_engine.gopkg/graphics/graph_engine.goL124-R136)ToImagemethod toMonochromeBitmap, enabling conversion back to RGBA images for exact preview in the emulator. (pkg/graphics/bitmap.gopkg/graphics/bitmap.goR67-R87)Examples and demonstration:
examples/emulator/image/image_example.go) that demonstrates embedding images in receipts, saving them as PNGs, and optionally printing them, showcasing the new emulator image features.Constants and imports cleanup:
pkg/emulator/emulator_engine.go[1];pkg/graphics/graph_engine.go[2]These changes significantly enhance the emulator's capabilities, making it possible to preview receipts with images exactly as they will appear when printed, and lay the groundwork for further improvements in image processing and output fidelity.
Type of Change
Component(s) Affected
composer- ESC/POS protocol composerconnection- Printer connectionscommands- ESC/POS command implementationsdocument- Document processinggraphics- Image processingprinter- Barcode generationprofile- Printer profilesservice- High-level printer servicegithub- GitHub related files and workflowsHow Has This Been Tested?
Test Configuration
Checklist
Screenshots/Examples
Breaking Changes
Additional Notes