Skip to content

feat(glyph): add --pixel-order option for LSB/MSB bit ordering - #153

Open
hellsge wants to merge 1 commit into
lvgl:masterfrom
hellsge:feat/pixel-order
Open

hellsge wants to merge 1 commit into
lvgl:masterfrom
hellsge:feat/pixel-order

Conversation

@hellsge

@hellsge hellsge commented Apr 17, 2026

Copy link
Copy Markdown

Summary

Add a --pixel-order CLI option to control pixel bit arrangement within each byte of glyph bitmap data. Defaults to MSB (current behavior), with LSB as a new option.

Motivation

Some embedded LCD controllers (e.g., SSD1306 in page-addressing mode, certain SPI-driven monochrome displays) expect pixel data in LSB-first bit ordering. Currently, users must post-process the font output to reverse bit order per byte, which is error-prone and adds complexity to the build pipeline.

This option enables direct compatibility without post-processing.

Changes

File Description
lib/pixel_order.js New module: byte-level pixel bit reordering for 1/2/4/8 BPP
lib/font/table_glyf.js Integrate LSB reordering into storePixelsRaw()
lib/cli.js Add --pixel-order {MSB,LSB} argument with validation
test/test_pixel_order.js Property-based tests (fast-check) + specific cases for all BPP
test/test_cli.js CLI integration tests for the new option
package.json Add fast-check to devDependencies (property-based testing)

Design decisions

  • Byte-level post-processing: Reordering is applied after pixel packing, keeping the core BitStream logic untouched. This minimizes risk to existing functionality.
  • LSB + compression mutual exclusion: RLE compression operates on MSB-ordered data. Allowing LSB with compression would produce incorrect output, so the CLI validates and rejects this combination.
  • 8 BPP passthrough: At 8 bits per pixel, each byte holds exactly one pixel — no reordering is needed regardless of the setting.
  • Default MSB: Fully backward compatible. Existing users see no change.

Usage

# LSB ordering (requires --no-compress)
lv_font_conv --font my_font.ttf -r 0x20-0x7F --size 16 --bpp 1 \
  --format bin --no-compress --pixel-order LSB -o my_font.bin

# MSB ordering (default, same as before)
lv_font_conv --font my_font.ttf -r 0x20-0x7F --size 16 --bpp 1 \
  --format bin -o my_font.bin

Testing

  • Property-based tests using fast-check covering all BPP × order combinations
  • Specific bit-pattern tests for each BPP (1, 2, 4, 8)
  • CLI integration tests: LSB+compress rejection, LSB+no-compress acceptance, MSB default behavior, invalid value rejection
  • All existing tests continue to pass

Notes

package-lock.json has minor "peer": true field removals due to npm version differences. The only actual dependency additions are fast-check and its dependency pure-rand.


Summary by cubic

Add a --pixel-order CLI option to control per-byte pixel bit order in glyph bitmaps. Default stays MSB; LSB is available for devices that read LSB-first.

  • New Features

    • Add --pixel-order {MSB,LSB} to choose pixel bit ordering when packing glyphs.
    • Byte-level reordering happens after packing and only on full pixel bytes to avoid touching glyph headers; supports 1/2/4/8 BPP (8 BPP is a no-op).
    • CLI prevents --pixel-order LSB with compression; use with --no-compress.
  • Migration

    • For LSB-first displays (e.g., SSD1306), run with --pixel-order LSB --no-compress.

Written for commit c0a47c6. Summary will update on new commits.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 7 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/font/table_glyf.js">

<violation number="1" location="lib/font/table_glyf.js:103">
P1: LSB byte reordering can corrupt glyph header bits when pixel data starts mid-byte, because whole bytes are reordered without verifying byte alignment.</violation>

<violation number="2" location="lib/font/table_glyf.js:123">
P2: `pixel_order='LSB'` is only handled in raw glyph storage; when compression is enabled, the option is silently ignored instead of being rejected.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread lib/font/table_glyf.js Outdated
Comment thread lib/font/table_glyf.js
Add a --pixel-order CLI parameter (MSB/LSB, default MSB) to control
the pixel bit arrangement within each byte of glyph bitmap data.

Some embedded LCD controllers require LSB-first pixel ordering.
This option enables direct compatibility without post-processing.

- Implement byte-level pixel bit reordering in lib/pixel_order.js
- Integrate into glyph table generation (storePixelsRaw)
- Add LSB/compression mutual exclusion validation
- Support all BPP configurations (1, 2, 4, 8)
- Add comprehensive property-based tests using fast-check
- Maintain backward compatibility (MSB as default)

Change-Id: Id677ae17b0fb14d13553456793f7dd73968ba9a6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant