diff options
author | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2020-12-14 19:48:31 +0100 |
---|---|---|
committer | sternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org> | 2020-12-14 19:48:31 +0100 |
commit | 662424e096776f21e2df766068a4b42533a5a554 (patch) | |
tree | 02a98ace8ab34253aca1707813a2e6927ea8a171 | |
parent | dcea971e7d66fa41b14e3a53fb1127dedd698fee (diff) |
feat(bs_bitmap_extend): don't fail if one dimension is smaller
If the requested size is smaller than the actual size in a dimension or both, the actual size in the respective dimension(s) is kept.
-rw-r--r-- | bitmap.c | 11 | ||||
-rw-r--r-- | bs-renderflipdot.c | 7 | ||||
-rw-r--r-- | buchstabensuppe.c | 7 |
3 files changed, 4 insertions, 21 deletions
diff --git a/bitmap.c b/bitmap.c index 5920d65..95d0d77 100644 --- a/bitmap.c +++ b/bitmap.c @@ -9,8 +9,8 @@ #include "util.h" bool bs_bitmap_extend(bs_bitmap_t *b, int new_w, int new_h, unsigned char init) { - int diff_x = new_w - b->bs_bitmap_width; - int diff_y = new_h - b->bs_bitmap_height; + int diff_x = MAX(new_w - b->bs_bitmap_width, 0); + int diff_y = MAX(new_h - b->bs_bitmap_height, 0); if(diff_y == 0 && diff_x == 0) { return true; @@ -22,13 +22,6 @@ bool bs_bitmap_extend(bs_bitmap_t *b, int new_w, int new_h, unsigned char init) b->bs_bitmap_height = new_h; } - if(diff_y < 0 || diff_x < 0) { - // don't perform downsizing because we don't keep track of - // capacity and we can use views for such tasks - errno = EINVAL; - return false; - } - // perform y only resize if possible because it doesn't require copying // since the bitmap consists of rows we can just use realloc diff --git a/bs-renderflipdot.c b/bs-renderflipdot.c index 77e1e17..4ab4ff9 100644 --- a/bs-renderflipdot.c +++ b/bs-renderflipdot.c @@ -10,8 +10,6 @@ #include <buchstabensuppe.h> -#include "util.h" - #define DEFAULT_FONT_SIZE 16 #define FLIPDOT_WIDTH 80 @@ -174,10 +172,7 @@ int main(int argc, char **argv) { if(!dry_run && (bitmap.bs_bitmap_width < FLIPDOT_WIDTH || bitmap.bs_bitmap_height < FLIPDOT_HEIGHT)) { - bs_bitmap_extend(&bitmap, - MAX(bitmap.bs_bitmap_width, FLIPDOT_WIDTH), - MAX(bitmap.bs_bitmap_height, FLIPDOT_HEIGHT), - invert); + bs_bitmap_extend(&bitmap, FLIPDOT_WIDTH, FLIPDOT_HEIGHT, invert); } bs_bitmap_print(bitmap, true); diff --git a/buchstabensuppe.c b/buchstabensuppe.c index cb1748e..9963379 100644 --- a/buchstabensuppe.c +++ b/buchstabensuppe.c @@ -12,8 +12,6 @@ #include <buchstabensuppe.h> -#include "util.h" - #define FONT_SCALE_MULTIPLIER 1 #define LOG(...) \ @@ -152,10 +150,7 @@ bool bs_cursor_insert(bs_bitmap_t *dst, bs_cursor_t *cursor, int offset_x, int o if(required_width > dst->bs_bitmap_width || required_height > dst->bs_bitmap_height) { - bool success = bs_bitmap_extend(dst, - MAX(required_width, dst->bs_bitmap_width), - MAX(required_height, dst->bs_bitmap_height), - 0); + bool success = bs_bitmap_extend(dst, required_width, required_height, 0); if(!success) { return false; |