aboutsummaryrefslogtreecommitdiff
path: root/src/image.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-01-20 23:03:37 +0000
committerHarry Jeffery <harry@exec64.co.uk>2019-01-29 22:25:05 +0000
commit2d5bb23bede92adf10f496f62e38c6611591e923 (patch)
tree7215a948866202de6b17b86a31feb8bf4bdb582a /src/image.c
parentc987d66cef2205fc1cf4284104bd8bcc6eb092d0 (diff)
downloadimv-2d5bb23bede92adf10f496f62e38c6611591e923.tar.gz
bitmap: Support multiple pixel formats
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/image.c b/src/image.c
index 8934cbc..5d0546e 100644
--- a/src/image.c
+++ b/src/image.c
@@ -44,6 +44,18 @@ void imv_image_free(struct imv_image *image)
free(image);
}
+static int convert_pixelformat(enum imv_pixelformat fmt)
+{
+ if (fmt == IMV_ARGB) {
+ return SDL_PIXELFORMAT_ARGB8888;
+ } else if (fmt == IMV_ABGR) {
+ return SDL_PIXELFORMAT_ABGR8888;
+ } else {
+ fprintf(stderr, "Unknown pixel format. Defaulting to ARGB\n");
+ return SDL_PIXELFORMAT_ARGB8888;
+ }
+}
+
int imv_image_set_bitmap(struct imv_image *image, struct imv_bitmap *bmp)
{
image->width = bmp->width;
@@ -73,6 +85,7 @@ int imv_image_set_bitmap(struct imv_image *image, struct imv_bitmap *bmp)
image->num_chunks = image->num_chunks_wide * image->num_chunks_tall;
image->chunks = malloc(sizeof(SDL_Texture*) * image->num_chunks);
+ const int format = convert_pixelformat(bmp->format);
int failed_at = -1;
for(int y = 0; y < image->num_chunks_tall; ++y) {
for(int x = 0; x < image->num_chunks_wide; ++x) {
@@ -80,7 +93,7 @@ int imv_image_set_bitmap(struct imv_image *image, struct imv_bitmap *bmp)
const int is_last_v_chunk = (y == image->num_chunks_tall - 1);
image->chunks[x + y * image->num_chunks_wide] =
SDL_CreateTexture(image->renderer,
- SDL_PIXELFORMAT_ARGB8888,
+ format,
SDL_TEXTUREACCESS_STATIC,
is_last_h_chunk ? image->last_chunk_width : image->chunk_width,
is_last_v_chunk ? image->last_chunk_height : image->chunk_height);