这是indexloc提供的服务,不要输入任何密码
Skip to content

Add options to reduce image quality to fix thumbnails on TJC displays #998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 15 commits into from

Conversation

Luro02
Copy link

@Luro02 Luro02 commented Jul 23, 2023

Description

This PR changes the thumbnail generation script for CURA. It adds an option to set the maximum size of the generated thumbnail in bytes. It then lowers the quality of the generated thumbnail until the size is less than the maximum size.

For TJC displays the dimensions must be exactly 200x200px and the generated thumbnail should
not be larger than 20kbytes. Sometimes the script made thumbnails that were larger than the 20kb, which resulted in an error about "missing thumbnail" on my Ender 3 S1.

I hid the option behind a checkbox, so the quality is only lowered when the option is set:
image
image
image

(by default the maximum size is set to about 15kb, if the box is checked)

Requirements

Benefits

  • Adds option to reduce thumbnail size (-> generated gcode will be smaller as well)
  • Makes thumbnail generator work with TJC displays

Configurations

Related Issues

This might be related to #990.

mriscoc and others added 13 commits May 22, 2023 11:42
- Runout icon indicator over the Extruder flow dashboard icon.
- Dashboard Speed shows the current axes speed in mm/s intermittently with the speed percentage
- Enhanced preview with arbitrary thumbnail size
- Preview QR code removed for improve support with some display units
- Improved 3D/BL/CRTouch auto leveling
- Enable BLTouch HS mode for bed tramming wizard
- Set Multiple probing to 0 as default
- Better limits for mesh insets editing
- New C35 custom g-code for launch the bed tramming wizard.
- Added toolbar option for park head.
- Force axes homing to allow parking at pause
- Raise Z when printing is aborted
- Fix a possible bug with filename drawing in printing page
- Fix Crash after removing SD card mriscoc#894
- Several minor bug fixes and Misc. optimizations
- and many more fixes from latest Marlin's bugfix 2.1.x

In source:
- TJC support to enable preview and grid mesh viewer
- Added Creality CV laser module support with automatic file type detection
- Added Creality Cloud Support
- Menu items value faster/smooth change rate
- More #define flags to disable features to help to reduce code size
- Many improvements from the latest Marlin's bugfix sources
Changed download tool
Updated download tool
- Filament Runout: better source code compatibility
- Do not present the bed after canceling the print if the position of the axes is unknown
- Require a PROBING_MARGIN of 10 if PROUI_EX is enabled
- Updated thumbnail demo G-code files
- Small bug fixes
Update user gallery
@mriscoc
Copy link
Owner

mriscoc commented Jul 25, 2023

I like the additional option, but since there is only one additional option at the moment, perhaps it could be displayed without the need to use the checkbox. Maybe a line separator between the normal options and the "extra" option.

@mriscoc mriscoc added the enhancement New feature or request label Jul 25, 2023
@Luro02
Copy link
Author

Luro02 commented Jul 25, 2023

I hid it behind a checkbox, so one can opt to not reduce the quality of the produced image. I could not find a way to leave the box empty by default, except with using a string box (but that has its own problems, like allowing invalid input). Ideally I would like to have it set to <20kb by default, so for all TJC users (who most likely do not read the wiki that thoroughly) the thumbnails will just work.

Would you mind telling me how to add a line separator? The documentation and examples are quite limited for cura plugins. (Maybe I haven't found the right page yet)

@mriscoc
Copy link
Owner

mriscoc commented Jul 26, 2023

Maybe the attached file can help, sorry I couldn't find a newer version.

Cura_Data_Model.pdf

@Luro02
Copy link
Author

Luro02 commented Jul 28, 2023

I removed the checkbox
image
and instead allow -1 as a value
image
in which case the image size will remain unchanged

@Luro02
Copy link
Author

Luro02 commented Jul 30, 2023

I added a bit more code to speed up the search for an optimal thumbnail size. Before it started at a quality of 95 and then reduced it, until the produced image had a size less than the maximum thumbnail size.

The algorithm is simple, but slow, especially in the worst-case scenario: When the image is set to a very low value like 100 bytes (which no image could possibly satisfy), it tries all qualities from 95 to 1, so the snapshot is encoded 95 times. The new one will only need to encode the image ~6 times in the worst-case scenario (log_2(n) runtime for binary search):

image

The algorithm works like this:

The image qualities are proportional to the image sizes and this can be used to find
the best size faster through binary search.

For example when the size should be 15kb, one starts with the middle of the list of possible image qualities (48 for range(1, 95 + 1)). This might produce an image with a size of 17kb. Now one knows that the quality must be less than 48, because all qualities larger than that will produce images that are too large.

Then the quality is halved again (quality=24), which might produce an image of size 3kb. Based on this one knows that the ideal quality must be between 24 and 48. The process is repeated, until the optimal image size has been found.

@mriscoc mriscoc force-pushed the Ender3V2S1-Released branch from 5496c1d to 6ce3545 Compare August 5, 2023 12:13
@mriscoc
Copy link
Owner

mriscoc commented Aug 10, 2023

Merged aeae59a

@mriscoc mriscoc closed this Aug 10, 2023
@Luro02
Copy link
Author

Luro02 commented Aug 10, 2023

Thank you 🎉

@mriscoc mriscoc added the user contribution Contributions from users label Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request user contribution Contributions from users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants