mirror of
https://github.com/kichikuou/xsystem35-sdl2.git
synced 2026-09-24 23:48:04 +03:00
Replace Color struct with SDL_Color
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+1
-6
@@ -26,12 +26,7 @@
|
||||
|
||||
#include "portab.h"
|
||||
#include <SDL_rect.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
} Color;
|
||||
#include <SDL_pixels.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t r,g,b;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
+3
-16
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user