Skip to content

Commit

Permalink
feat: enable convertBitmapToLEDHex to trim or keep empty columns (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZauberNerd authored Jan 5, 2025
1 parent aa8d49c commit 0f5b982
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
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

0 comments on commit 0f5b982

Please sign in to comment.