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: enable convertBitmapToLEDHex to trim or keep empty columns #1140

Merged
merged 1 commit into from
Jan 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/bademagic_module/utils/converters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class Converters {

//function to convert the bitmap to the LED hex format
//it takes the 2D list of pixels and converts it to the LED hex format
static List<String> convertBitmapToLEDHex(
List<List<int>> image, bool isDrawn) {
static List<String> convertBitmapToLEDHex(List<List<int>> image, bool trim) {
// Determine the height and width of the image
int height = image.length;
int width = image.isNotEmpty ? image[0].length : 0;
Expand All @@ -67,7 +66,7 @@ class Converters {
for (int i = 0; i < height; i++) {
sum += image[i][j]; // Sum up pixel values in each column
}
if (sum == 0) {
if (sum == 0 && trim) {
// If column sum is zero, mark all pixels in that column as -1
for (int i = 0; i < height; i++) {
image[i][j] = -1;
Expand All @@ -86,7 +85,7 @@ class Converters {
sum += image[i]
[j]; // Sum up pixel values in each column (from right to left)
}
if (sum == 0) {
if (sum == 0 && trim) {
// If column sum is zero, mark all pixels in that column as -1
for (int i = 0; i < height; i++) {
image[i][j] = -1;
Expand Down Expand Up @@ -176,6 +175,6 @@ class Converters {
hexArray[i].add(1);
}

return convertBitmapToLEDHex(hexArray, false);
return convertBitmapToLEDHex(hexArray, true);
}
}
2 changes: 1 addition & 1 deletion lib/bademagic_module/utils/image_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ class ImageUtils {
}
}
}
return Converters.convertBitmapToLEDHex(pixelArray, false);
return Converters.convertBitmapToLEDHex(pixelArray, true);
}
}
2 changes: 1 addition & 1 deletion lib/view/draw_badge_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class _DrawBadgeState extends State<DrawBadge> {
.map((e) => e.map((e) => e ? 1 : 0).toList())
.toList();
List<String> hexString =
Converters.convertBitmapToLEDHex(badgeGrid, false);
Converters.convertBitmapToLEDHex(badgeGrid, true);
widget.isSavedCard!
? fileHelper.updateBadgeText(
widget.filename!,
Expand Down
2 changes: 1 addition & 1 deletion test/converters_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void main() {
[0, 1]
];

List<String> result = Converters.convertBitmapToLEDHex(image, false);
List<String> result = Converters.convertBitmapToLEDHex(image, true);

expect(result, ["1008"]);
});
Expand Down
Loading