Merge pull request #89 from notYuriy/stretch

bmp: Add support for stretched images
This commit is contained in:
mint 2021-07-07 02:53:23 +02:00 committed by GitHub
commit 4d1a02b0b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;
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);

View File

@ -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);
}
}

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;
}
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;

View File

@ -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