Skip to content

feat(preview): show embedded G-code thumbnails - #1864

Merged
l0gicgate merged 5 commits into
lgse:mainfrom
signal-9:feat/1863-gcode-thumbnails
Oct 25, 2026
Merged

l0gicgate merged 5 commits into
lgse:mainfrom
signal-9:feat/1863-gcode-thumbnails

Conversation

@signal-9

Copy link
Copy Markdown
Contributor

Description

Show the embedded slicer thumbnail from .gcode, .gco, and binary .bgcode files in the preview pane and as the file icon. Text files carry PNG, JPEG, or QOI images as base64 comments (thumbnail, thumbnail_PNG, thumbnail_JPG, thumbnail_QOI). Binary .bgcode stores the same images in thumbnail blocks. Quick Preview uses the largest image that decodes. A text file with no usable thumbnail keeps the ordinary text preview. A binary file with none reports that it has no usable embedded thumbnail. The toolpath is not drawn, and the STL model-thumbnails setting does not gate these icons.

Visual evidence

N/A. Screenshots are not attached with this submission. In the preview pane, a G-code file with an embedded thumbnail shows that image and no camera controls. A text G-code file with no thumbnail shows the file text. A binary .bgcode file with no thumbnail shows “This G-code file has no usable embedded thumbnail”. In icon view, the same files show the thumbnail whenever Show thumbnails is on.

How to test

  1. Open a folder that contains a sliced .gcode or .gco file whose header has a ; thumbnail begin block (or thumbnail_PNG, thumbnail_JPG, or thumbnail_QOI), and a binary .bgcode file with a thumbnail block.
  2. Select the text file. The preview pane shows the largest embedded image. A text file with no thumbnail shows the G-code text instead.
  3. Select the binary file. The preview pane shows its thumbnail. A binary file with no thumbnail shows the message that it has no usable embedded thumbnail.
  4. Switch the folder to icon view with Show thumbnails on and STL model thumbnails off. The G-code files still show their embedded images.
  5. Open a very large text G-code file. Preview reads the header thumbnail and does not scan the toolpath.

Expected result: The preview pane and file icon show the largest decodable embedded thumbnail. Files without one keep the existing text preview, or the specific missing-thumbnail message when the file is binary. No toolpath is rendered.

Related issue

Closes #1863

Joshua Pickard added 2 commits October 24, 2026 12:36
Read PNG, JPEG, and QOI slicer thumbnails from text G-code comments and
binary bgcode blocks, and show the largest one in the preview pane and
as a file icon.
Apply rustfmt and the Clippy fixes from the local check, and reword the
preview note so the spell checker does not split "PNGs".
@signal-9

Copy link
Copy Markdown
Contributor Author
screenshot-2026-10-24_12-48-17

# Conflicts:
#	data/locales/de.json
#	data/locales/en.json
#	data/locales/es.json
#	data/locales/fr.json
#	data/locales/it.json
#	data/locales/ja.json
#	data/locales/ko.json
#	data/locales/pt-BR.json
#	data/locales/ru.json
#	data/locales/vi.json
#	data/locales/zh-CN.json
#	data/locales/zh-TW.json
G-code joined the model formats, so remote .gcode files hit the
local-only model route: Quick Preview refused them and the provider
reported that remote models are not supported, although main previewed
them as text. Treat remote G-code as an ordinary text file.
Remove the argument and from_argument constant checks and a no-op write
from the G-code reader tests, and tighten the header-limit doc comment.
@l0gicgate

l0gicgate commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review and cleanup

Merged main at 41148b2. Every one of the twelve data/locales/*.json catalogs had a conflict between this PR's This G-code file has no usable embedded thumbnail and main's This PDF is password protected. Both keys are kept.

Review against the description and #1863. Every claim checks out. Text .gcode/.gco reads thumbnail, thumbnail_PNG, thumbnail_JPG and thumbnail_QOI comments only up to the first command, capped at 2 MiB. Binary .bgcode reads thumbnail blocks and stops at the first G-code block. Quick Preview uses the largest image that decodes. A text file with no thumbnail falls back to text, a binary one reports the specific message, and browser icons skip the STL setting. I also ran the reader on PrusaSlicer's own sample files from prusa3d/libbgcode (tests/data). mini_cube_a.gcode (PNG) and mini_cube_b.bgcode both decoded the 220×124 thumbnail. mini_cube_ps2.8.1.gcode (QOI) and mini_cube_ps2.8.1.bgcode both decoded the 313×173 image, scaled to 256×141. There were no open review threads.

Fixes pushed

  • ac2c43e fix(preview): keep the text preview for remote G-code. G-code was added to the model formats, so remote .gcode files (SFTP, SMB and other URI locations) went down the local-only model route. entry_supports_quick_preview refused them, and the provider reported "Remote model previews are not supported", even though main shows them as text (text/x.gcode is a subclass of text/plain). services::model_format/is_model now take the entry and leave out remote G-code, so it keeps the text preview. The issue asks that files without a usable thumbnail keep the normal text preview. gcode_without_a_thumbnail_keeps_text_and_binary_reports_the_gap now checks that a remote text G-code file yields text without reaching the renderer. docs/preview-sandbox.md notes the behaviour.
  • 3efc54f test(preview): drop tautological G-code format assertions. See below. Also tightened the MAX_GCODE_HEADER_BYTES doc comment.

Tests removed

  • The ModelFormat::Gcode.argument() == "gcode" and from_argument("gcode") assertions in names_gcode_and_keeps_the_largest_embedded_image only repeated constants. The gcode:64x64:… render spec in jpeg_and_qoi_comments_decode_and_a_missing_thumbnail_stays_specific still covers the argument round trip. Also removed a no-op out.write(&[]) from the bgcode fixture builder.

Validation

  • ./scripts/test-headless.py -- sandbox_helper::model adapters::local_preview sandbox:: ui::preview ui::thumbnail i18n:: services::preview services::model_preview: 277 passed, 0 failed.
  • After the final clippy fix: ./scripts/test-headless.py -- ui::preview adapters::local_preview sandbox_helper::model: 128 passed, 0 failed.
  • ./scripts/quality.sh fmt, ./scripts/quality.sh clippy: clean.
  • Not run: qa.sh. No QA scenario covers G-code, and the fix only changes routing, which the provider test covers.

Follow-ups outside this PR

  • A text G-code preview without a thumbnail briefly shows the model loading view (camera dots disabled) before the text arrives. FreeCAD loads the same way, so this is cosmetic and was left as is.

CI: all checks green on 3efc54f as of 2026-10-24 22:38 UTC (the workflow skipped QA scenarios).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

G-code thumbnails

2 participants