From eef6eb5580feafef72e482eee96fa76ac4c2e484 Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Thu, 21 Nov 2019 20:36:27 -0800 Subject: [PATCH] Use standard pixel format for CGs Don't use explicit masks. --- qnt.c | 17 ++++------------- sdl_draw.c | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/qnt.c b/qnt.c index 8c5c170..e0ee032 100644 --- a/qnt.c +++ b/qnt.c @@ -248,18 +248,13 @@ bool qnt_checkfmt(uint8_t *data) */ SDL_Surface *qnt_extract(uint8_t *data) { - // FIXME: endianness? - uint32_t amask = 0x0; - uint32_t rmask = 0xFF; - uint32_t bmask = 0xFF00; - uint32_t gmask = 0xFF0000; struct qnt_header *qnt = extract_header(data); uint8_t *pixels = malloc(sizeof(uint8_t) * ((qnt->width+10) * (qnt->height+10) * 3)); extract_pixel(qnt, pixels, data + qnt->hdr_size); if (!qnt->alpha_size) - return SDL_CreateRGBSurfaceFrom(pixels, qnt->width, qnt->height, 24, qnt->width * 3, - rmask, gmask, bmask, amask); + return SDL_CreateRGBSurfaceWithFormatFrom(pixels, qnt->width, qnt->height, 24, + qnt->width * 3, SDL_PIXELFORMAT_RGB24); // combine color/alpha data uint8_t *alpha = malloc(sizeof(uint8_t) * ((qnt->width+10) * (qnt->height+10))); @@ -274,11 +269,7 @@ SDL_Surface *qnt_extract(uint8_t *data) free(alpha); free(pixels); pixels = tmp; - amask = 0xFF; - rmask = 0xFF00; - gmask = 0xFF0000; - bmask = 0xFF000000; - return SDL_CreateRGBSurfaceFrom(pixels, qnt->width, qnt->height, 32, qnt->width * 4, - rmask, gmask, bmask, amask); + return SDL_CreateRGBSurfaceWithFormatFrom(pixels, qnt->width, qnt->height, 32, + qnt->width * 4, SDL_PIXELFORMAT_ARGB32); } diff --git a/sdl_draw.c b/sdl_draw.c index 9640590..58989bb 100644 --- a/sdl_draw.c +++ b/sdl_draw.c @@ -39,7 +39,7 @@ void sdl_update_screen(void) SDL_Surface *sdl_make_rectangle(int w, int h, SDL_Color *color) { Rectangle rect = { .x = 0, .y = 0, .w = w, .h = w }; - SDL_Surface *s = SDL_CreateRGBSurface(0, w, h, 32, 0xFF00, 0xFF0000, 0xFF000000, 0xFF); + SDL_Surface *s = SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, SDL_PIXELFORMAT_ARGB32); uint32_t c = SDL_MapRGBA(s->format, color->r, color->g, color->b, color->a); SDL_FillRect(s, &rect, c); return s;