bmp: Add support for stretched images

This commit is contained in:
Iurii Zamiatin 2021-07-07 03:46:40 +03:00
parent a092368895
commit 6b15b0f97b
4 changed files with 31 additions and 3 deletions

View File

@ -51,6 +51,11 @@ static uint32_t get_pixel(struct image *this, int x, int y) {
return this->back_colour; return this->back_colour;
break; 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); size_t pixel_offset = local->pitch * (header->bi_height - y - 1) + x * (header->bi_bpp / 8);

View File

@ -488,6 +488,8 @@ bool gterm_init(int *_rows, int *_cols, int width, int height) {
background_colour = "0"; background_colour = "0";
uint32_t bg_col = strtoui(background_colour, NULL, 16); uint32_t bg_col = strtoui(background_colour, NULL, 16);
image_make_centered(background, fbinfo.framebuffer_width, fbinfo.framebuffer_height, bg_col); 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);
} }
} }

View File

@ -13,6 +13,17 @@ void image_make_centered(struct image *image, int frame_x_size, int frame_y_size
image->back_colour = back_colour; 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) { int open_image(struct image *image, struct file_handle *file) {
image->file = file; image->file = file;

View File

@ -9,8 +9,16 @@ struct image {
int x_size; int x_size;
int y_size; int y_size;
int type; int type;
int x_displacement; union {
int y_displacement; struct {
int x_displacement;
int y_displacement;
};
struct {
int old_x_size;
int old_y_size;
};
};
uint32_t back_colour; uint32_t back_colour;
uint32_t (*get_pixel)(struct image *this, int x, int y); uint32_t (*get_pixel)(struct image *this, int x, int y);
void *local; void *local;
@ -18,10 +26,12 @@ struct image {
enum { enum {
IMAGE_TILED, 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_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); int open_image(struct image *image, struct file_handle *file);
#endif #endif