bmp: Add support for stretched images
diff --git a/stage23/lib/bmp.c b/stage23/lib/bmp.c
index 266dac13..fb90149a 100644
--- a/stage23/lib/bmp.c
+++ b/stage23/lib/bmp.c
@@ -51,6 +51,11 @@ static uint32_t get_pixel(struct image *this, int x, int y) {
return this->back_colour;
break;
}
+ case IMAGE_STRETCHED: {
+ x = (x * this->old_x_size) / this->x_size;
+ y = (y * this->old_y_size) / this->y_size;
+ break;
+ }
}
size_t pixel_offset = local->pitch * (header->bi_height - y - 1) + x * (header->bi_bpp / 8);
diff --git a/stage23/lib/gterm.c b/stage23/lib/gterm.c
index 254d0216..33a5a566 100644
--- a/stage23/lib/gterm.c
+++ b/stage23/lib/gterm.c
@@ -488,6 +488,8 @@ bool gterm_init(int *_rows, int *_cols, int width, int height) {
background_colour = "0";
uint32_t bg_col = strtoui(background_colour, NULL, 16);
image_make_centered(background, fbinfo.framebuffer_width, fbinfo.framebuffer_height, bg_col);
+ } else if (background_layout != NULL && strcmp(background_layout, "stretched") == 0) {
+ image_make_stretched(background, fbinfo.framebuffer_width, fbinfo.framebuffer_height);
}
}
diff --git a/stage23/lib/image.c b/stage23/lib/image.c
index f104fc9f..fe0f08b4 100644
--- a/stage23/lib/image.c
+++ b/stage23/lib/image.c
@@ -13,6 +13,17 @@ void image_make_centered(struct image *image, int frame_x_size, int frame_y_size
image->back_colour = back_colour;
}
+
+void image_make_stretched(struct image *image, int new_x_size, int new_y_size) {
+ image->type = IMAGE_STRETCHED;
+
+ image->old_x_size = image->x_size;
+ image->old_y_size = image->y_size;
+
+ image->x_size = new_x_size;
+ image->y_size = new_y_size;
+}
+
int open_image(struct image *image, struct file_handle *file) {
image->file = file;
diff --git a/stage23/lib/image.h b/stage23/lib/image.h
index 7b74acf9..7e9cbd8f 100644
--- a/stage23/lib/image.h
+++ b/stage23/lib/image.h
@@ -9,8 +9,16 @@ struct image {
int x_size;
int y_size;
int type;
- int x_displacement;
- int y_displacement;
+ union {
+ struct {
+ int x_displacement;
+ int y_displacement;
+ };
+ struct {
+ int old_x_size;
+ int old_y_size;
+ };
+ };
uint32_t back_colour;
uint32_t (*get_pixel)(struct image *this, int x, int y);
void *local;
@@ -18,10 +26,12 @@ struct image {
enum {
IMAGE_TILED,
- IMAGE_CENTERED
+ IMAGE_CENTERED,
+ IMAGE_STRETCHED
};
void image_make_centered(struct image *image, int frame_x_size, int frame_y_size, uint32_t back_colour);
+void image_make_stretched(struct image *image, int new_x_size, int new_y_size);
int open_image(struct image *image, struct file_handle *file);
#endif
