Skip to content

feat(graphics): add image rendering capabilities to the emulator#89

Merged
adcondev merged 7 commits intomasterfrom
feat/emugraph
Dec 17, 2025
Merged

feat(graphics): add image rendering capabilities to the emulator#89
adcondev merged 7 commits intomasterfrom
feat/emugraph

Conversation

@adcondev
Copy link
Copy Markdown
Owner

@adcondev adcondev commented Dec 16, 2025

  • 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

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:

  • Adds an ImageRenderer to the emulator engine, with methods such as PrintImage, PrintImageWithOptions, PrintImageAligned, and PrintImageThermalPreview, 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]
  • Introduces the ImageOptions struct to configure image rendering (width, alignment, scaling, dithering, and thermal simulation) for both normal and thermal preview modes. (pkg/emulator/render_image.go pkg/emulator/render_image.goR1-R168)

Graphics and image processing improvements:

  • Refactors image resizing and grayscale conversion in the graphics pipeline to use new utility functions, improving maintainability and consistency. (pkg/graphics/graph_engine.go pkg/graphics/graph_engine.goL124-R136)
  • Adds a ToImage method to MonochromeBitmap, enabling conversion back to RGBA images for exact preview in the emulator. (pkg/graphics/bitmap.go pkg/graphics/bitmap.goR67-R87)

Examples and demonstration:

  • Provides a new example program (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:

  • Updates imports and constants usage in various files to reflect the new graphics utilities and image rendering features. (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

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation only
  • 🔧 Configuration/DevOps
  • ♻️ Code refactoring
  • 📦 Dependency update
  • ⚡ Performance improvement
  • 🧪 Test addition/modification

Component(s) Affected

  • composer - ESC/POS protocol composer
  • connection - Printer connections
  • commands - ESC/POS command implementations
  • document - Document processing
  • graphics - Image processing
  • printer - Barcode generation
  • profile - Printer profiles
  • service - High-level printer service
  • github - GitHub related files and workflows

How Has This Been Tested?

  • Unit tests pass locally
  • Integration tests pass
  • Manual testing with physical printer
  • Examples built and run successfully
  • N/A (documentation/configuration only)

Test Configuration

  • Go Version:
  • OS:
  • Printer Model (if applicable):

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Screenshots/Examples

Breaking Changes

Additional Notes

- 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>
@github-actions
Copy link
Copy Markdown
Contributor

👋 Thanks for opening this PR, @adcondev!

Here's what will happen next:

  • 🤖 Automated checks will run
  • 🏷️ Labels will be added automatically
  • 👀 A maintainer will review your changes

Please make sure:

  • ✅ All tests pass
  • 📝 The PR title follows conventional commits
  • 📋 The PR template is filled out completely

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ImageRenderer to 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.

Comment thread pkg/emulator/render_image.go Outdated
Comment thread examples/emulator/image/image_example.go Outdated
Comment thread pkg/graphics/processing.go
Comment thread pkg/graphics/graph_engine.go
Comment thread examples/emulator/image/image_example.go Outdated
Comment thread pkg/graphics/processing.go Outdated
Comment thread examples/emulator/image/image_example.go Outdated
Comment thread pkg/graphics/bitmap.go Outdated
Comment thread examples/emulator/image/image_example.go Outdated
Comment thread pkg/emulator/render_image.go Outdated
…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.
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Dec 17, 2025
@adcondev adcondev moved this to In progress in POS RED2000 Dec 17, 2025
…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>
@adcondev adcondev merged commit 6a0c896 into master Dec 17, 2025
17 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in POS RED2000 Dec 17, 2025
@adcondev adcondev deleted the feat/emugraph branch December 17, 2025 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants