meerk40t / meerk40t

Hackable Laser software for K40 / GRBL / Fibre Lasers
MIT License
233 stars 62 forks source link

Deal with 32bit grayscale images #2677

Closed jpirnay closed 1 week ago

jpirnay commented 1 week ago

32 bit grayscale images like this one:

were not recognized properly:

That's fixed now:

Summary by Sourcery

Improve handling of 32-bit grayscale images by converting them to 8-bit grayscale, ensuring proper recognition and processing. Simplify exception handling in image processing functions.

Bug Fixes:

Enhancements:

sourcery-ai[bot] commented 1 week ago

Reviewer's Guide by Sourcery

This PR adds support for 32-bit grayscale images by implementing proper conversion from PIL's "I" mode to "L" mode. The changes also include code cleanup and optimization of image processing operations.

Updated class diagram for image processing

classDiagram
    class ImageProcessor {
        +operations: list
        +invert: bool
        +dither: bool
        +dither_type: str
        +process_image(step_x, step_y, crop)
        +_convert_image_to_grayscale(image)
        +_process_script(image)
        +_apply_keyhole()
    }

    ImageProcessor : +_convert_image_to_grayscale(image)
    ImageProcessor : +_process_script(image)
    ImageProcessor : +_apply_keyhole()

    note for ImageProcessor "Added support for 32-bit grayscale images by converting 'I' mode to 'L' mode."

File-Level Changes

Change Details Files
Added support for 32-bit grayscale images (PIL mode 'I')
  • Implemented normalization of 32-bit images to 8-bit grayscale range (0-255)
  • Added specific handling for 'I' mode images before general grayscale conversion
meerk40t/core/node/elem_image.py
Improved error handling and code optimization
  • Replaced specific exception handling with general Exception catch in process_image
  • Simplified conditional statements in image processing operations
  • Optimized keyhole image dimension checking logic
meerk40t/core/node/elem_image.py
Code cleanup and minor improvements
  • Changed list() constructor to [] literal
  • Improved variable naming and reduced redundant operations
  • Fixed code formatting and removed unnecessary comments
meerk40t/core/node/elem_image.py

Tips and commands #### Interacting with Sourcery - **Trigger a new review:** Comment `@sourcery-ai review` on the pull request. - **Continue discussions:** Reply directly to Sourcery's review comments. - **Generate a GitHub issue from a review comment:** Ask Sourcery to create an issue from a review comment by replying to it. - **Generate a pull request title:** Write `@sourcery-ai` anywhere in the pull request title to generate a title at any time. - **Generate a pull request summary:** Write `@sourcery-ai summary` anywhere in the pull request body to generate a PR summary at any time. You can also use this command to specify where the summary should be inserted. #### Customizing Your Experience Access your [dashboard](https://app.sourcery.ai) to: - Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others. - Change the review language. - Add, remove or edit custom review instructions. - Adjust other review settings. #### Getting Help - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).