Skip to content
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

feat: import of animated gif images #1141

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

ZauberNerd
Copy link
Contributor

@ZauberNerd ZauberNerd commented Jan 4, 2025

Summary by Sourcery

New Features:

  • Import animated GIFs and convert them to LED matrix display format.

Summary by Sourcery

New Features:

  • Import animated GIFs and convert them into LED matrix animations.

Copy link
Contributor

sourcery-ai bot commented Jan 4, 2025

Reviewer's Guide by Sourcery

This pull request introduces the ability to import animated GIF images and convert them to the LED matrix display format. This is achieved by adding support for GIF files in the file picker, decoding the GIF into frames, converting each frame to the LED matrix format, and saving the result as a JSON file.

Sequence diagram for GIF import process

sequenceDiagram
    actor User
    participant FP as FilePicker
    participant FH as FileHelper
    participant IU as ImageUtils
    participant Storage

    User->>FP: Select GIF file
    FP-->>FH: Return file path
    FH->>FH: Check file extension
    alt is GIF file
        FH->>IU: Convert GIF to LED hex frames
        IU->>IU: Decode GIF
        loop For each frame
            IU->>IU: Resize to 48x11
            IU->>IU: Convert to grayscale
            IU->>IU: Convert to bitmap
            IU->>IU: Convert to LED hex
        end
        IU-->>FH: Return hex frames
        FH->>FH: Create JSON structure
        FH->>Storage: Save as JSON file
    end
Loading

Class diagram for updated image processing classes

classDiagram
    class FileHelper {
        +importFile()
        -_writeToFile()
    }

    class ImageUtils {
        +convertGifFramesToLEDHex(Uint8List)
        -originalHeight: double
        -originalWidth: double
    }

    class Data {
        +fromJson()
        +toJson()
    }

    FileHelper ..> ImageUtils : uses
    FileHelper ..> Data : uses

    note for ImageUtils "New method added for
GIF processing"
Loading

File-Level Changes

Change Details Files
Added support for importing GIF images.
  • Added gif to the list of allowed extensions in the file picker.
  • Implemented the convertGifFramesToLEDHex function to convert GIF frames to LED matrix hex format.
  • Added the image dependency to the pubspec.yaml file.
  • Updated the pubspec.lock file to include the image dependency.
  • Updated the file picker logic to handle GIF files and convert them to JSON format for the LED matrix display.
  • Added a check for GIF file extension and logic to process GIF files accordingly.
  • Added logic to convert GIF frames to hex representation and store them in a JSON structure.
  • Added a new function to convert GIF frames to LED hex format.
  • Added the necessary logic to handle GIF import and conversion in the FileHelper class.
  • Updated the _writeToFile function to handle the generated JSON data from GIF conversion.
lib/bademagic_module/utils/file_helper.dart
lib/bademagic_module/utils/image_utils.dart
pubspec.yaml
pubspec.lock

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 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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ZauberNerd - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider making the image processing parameters (resize dimensions: 48x11, luminance threshold: 128) configurable rather than hardcoded for more flexibility.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

lib/bademagic_module/utils/image_utils.dart Outdated Show resolved Hide resolved
@ZauberNerd ZauberNerd marked this pull request as draft January 4, 2025 19:27
@ZauberNerd ZauberNerd marked this pull request as ready for review January 4, 2025 19:41
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ZauberNerd - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider implementing frame limits or lazy loading for GIF processing to prevent memory issues with large animated GIFs
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

lib/bademagic_module/utils/file_helper.dart Outdated Show resolved Hide resolved
Copy link
Collaborator

@adityastic adityastic left a comment

Choose a reason for hiding this comment

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

Perfect, Thanks much!

@adityastic adityastic merged commit 8cfc9d1 into fossasia:flutter_app Jan 6, 2025
5 checks passed
@ZauberNerd ZauberNerd deleted the gif-import branch January 6, 2025 11:17
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.

2 participants