diff --git a/src/ags.c b/src/ags.c index 412927f..b4e3bb0 100644 --- a/src/ags.c +++ b/src/ags.c @@ -54,7 +54,7 @@ static void palette_changed(void) { } static void initPal(void) { - static const Color initial_palette[256] = { + static const SDL_Color initial_palette[256] = { [ 0] = { 0, 0, 0}, [ 1] = {128, 0, 0}, [ 2] = { 0, 128, 0}, @@ -78,6 +78,9 @@ static void initPal(void) { [255] = {255, 255, 255}, }; memcpy(nact->ags.pal, initial_palette, sizeof(initial_palette)); + for (int i = 0; i < 256; i++) { + nact->ags.pal[i].a = 255; + } sdl_setPalette(nact->ags.pal, 0, 256); palette_changed(); } @@ -242,7 +245,7 @@ void ags_updateFull() { sdl_updateArea(&r, &p); } -void ags_setPalettes(Color *src, int dst, int cnt) { +void ags_setPalettes(SDL_Color *src, int dst, int cnt) { for (int i = 0; i < cnt; i++) { nact->ags.pal[dst + i] = src[i]; } @@ -635,8 +638,10 @@ void ags_fadeOut(int rate, bool flag) { fade_outed = true; if (nact->ags.world_depth == 8) { - Color pal[256]; - memset(&pal, 0, sizeof(pal)); + SDL_Color pal[256]; + for (int i = 0; i < 256; i++) { + pal[i] = (SDL_Color){0, 0, 0, 255}; + } sdl_setPalette(pal, 0, 256); } } @@ -663,7 +668,7 @@ void ags_whiteOut(int rate, bool flag) { fade_outed = true; if (nact->ags.world_depth == 8) { - Color pal[256]; + SDL_Color pal[256]; memset(&pal, 255, sizeof(pal)); sdl_setPalette(pal, 0, 256); } diff --git a/src/ags.h b/src/ags.h index 3d58eef..0155e2b 100644 --- a/src/ags.h +++ b/src/ags.h @@ -112,7 +112,7 @@ typedef enum { } TextDecorationType; struct _ags { - Color pal[256]; /* system palette */ + SDL_Color pal[256]; /* system palette */ bool pal_changed; /* system palette has changed */ MyDimension world_size; /* size of off-screen */ @@ -160,7 +160,7 @@ extern void ags_updateFull(void); extern void ags_updateArea(int x, int y, int width, int height); /* パレット関係 */ -extern void ags_setPalettes(Color *src, int dst, int cnt); +extern void ags_setPalettes(SDL_Color *src, int dst, int cnt); extern void ags_setPalette(int no, int red, int green, int blue); extern void ags_setPaletteToSystem(int src, int cnt); diff --git a/src/bmp.c b/src/bmp.c index 817b63b..5d89421 100644 --- a/src/bmp.c +++ b/src/bmp.c @@ -66,12 +66,13 @@ static bmp_header *extract_header(uint8_t *b) { * Get palette from raw data * b : raw data (pointer to palette) */ -static Color *getpal(uint8_t *b) { - Color *pal = malloc(sizeof(Color) * 256); +static SDL_Color *getpal(uint8_t *b) { + SDL_Color *pal = malloc(sizeof(SDL_Color) * 256); for (int i = 0; i < 256; i++) { pal[i].b = *b++; pal[i].r = *b++; pal[i].g = *b++; + pal[i].a = 255; } return pal; } diff --git a/src/cg.h b/src/cg.h index 1492641..216d525 100644 --- a/src/cg.h +++ b/src/cg.h @@ -57,7 +57,7 @@ typedef struct { uint8_t *pic; // extracted pixel data uint8_t *alpha; // extracted alpha data if exists - Color *pal; // 256-color palette if exists + SDL_Color *pal; // 256-color palette if exists int vsp_bank; // palette bank for vsp int pms_bank; // palette bank for pms diff --git a/src/graphics.h b/src/graphics.h index 2024443..28723cc 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -26,12 +26,7 @@ #include "portab.h" #include - -typedef struct { - uint8_t r; - uint8_t g; - uint8_t b; -} Color; +#include typedef struct { uint8_t r,g,b; diff --git a/src/pms.c b/src/pms.c index 5172a4a..ba529c0 100644 --- a/src/pms.c +++ b/src/pms.c @@ -76,12 +76,13 @@ static pms_header *extract_header(uint8_t *b) { * Get palette from raw data * b : raw data (pointer to palette) */ -static Color *getpal(uint8_t *b) { - Color *pal = malloc(sizeof(Color) * 256); +static SDL_Color *getpal(uint8_t *b) { + SDL_Color *pal = malloc(sizeof(SDL_Color) * 256); for (int i = 0; i < 256; i++) { pal[i].r = *b++; pal[i].g = *b++; pal[i].b = *b++; + pal[i].a = 255; } return pal; } diff --git a/src/sdl_core.h b/src/sdl_core.h index c9a4dbb..13a3fb8 100644 --- a/src/sdl_core.h +++ b/src/sdl_core.h @@ -56,7 +56,7 @@ extern void sdl_updateAll(MyRectangle *view_rect); extern void sdl_updateScreen(void); /* パレット関係 */ -extern void sdl_setPalette(Color *pal, int first, int count); +extern void sdl_setPalette(SDL_Color *pal, int first, int count); /* 描画関係 */ extern void sdl_drawRectangle(int x, int y, int w, int h, uint8_t c); diff --git a/src/sdl_draw.c b/src/sdl_draw.c index 4e33bdd..09eba59 100644 --- a/src/sdl_draw.c +++ b/src/sdl_draw.c @@ -127,15 +127,8 @@ void sdl_updateAll(MyRectangle *view_rect) { } /* Color の複数個指定 */ -void sdl_setPalette(Color *pal, int first, int count) { - SDL_Color colors[256]; - for (int i = 0; i < count; i++) { - colors[i].r = pal[first + i].r; - colors[i].g = pal[first + i].g; - colors[i].b = pal[first + i].b; - colors[i].a = 255; - } - SDL_SetPaletteColors(sdl_palette, colors, first, count); +void sdl_setPalette(SDL_Color *pal, int first, int count) { + SDL_SetPaletteColors(sdl_palette, pal, first, count); } /* 矩形の描画 */ @@ -247,13 +240,7 @@ void sdl_drawImage8(cgdata *cg, int dx, int dy, int sprite_color) { sdl_pal_check(); if (main_surface->format->BitsPerPixel > 8 && cg->pal) { - SDL_Color *c = s->format->palette->colors; - for (int i = 0; i < 256; i++) { - c->r = cg->pal[i].r; - c->g = cg->pal[i].g; - c->b = cg->pal[i].b; - c++; - } + SDL_SetPaletteColors(s->format->palette, cg->pal, 0, 256); } else { SDL_SetSurfacePalette(s, sdl_palette); } diff --git a/src/vsp.c b/src/vsp.c index 5df8c3c..b392f38 100644 --- a/src/vsp.c +++ b/src/vsp.c @@ -67,12 +67,13 @@ static vsp_header *extract_header(uint8_t *b) { * Get palette from raw data * b : raw data (pointer to palette) */ -static Color *getpal(uint8_t *b) { - Color *pal = malloc(sizeof(Color) * 256); +static SDL_Color *getpal(uint8_t *b) { + SDL_Color *pal = malloc(sizeof(SDL_Color) * 256); for (int i = 0; i < 16; i++) { pal[i].b = b[i * 3 + 0] * 17; pal[i].r = b[i * 3 + 1] * 17; pal[i].g = b[i * 3 + 2] * 17; + pal[i].a = 255; } return pal; }