Raycaster_G90/src/sdl_image.h

147 lines
3.0 KiB
C

//Fcalva 14/02/2024
#ifdef SDL2
#ifndef sdl__h
#define sdl__h
//==== État des choses ===
// Implémentation de :
// - Intialisation (sdl_image_init() ) - X
// - Fermeture (sdl_image_quit() ) - X
// - Importation (sdl_tex_load() ) - 20%
// - gint/display.h :
// - dprint() - X
// - dimage() - X
// - dclear() - X
// - dupdate() - X
// - gint_dvline() - X
// - gint/image.h :
// - image_t - X
// - image_linear_map - 90%
// - image_create_vram() - 0%
// - image_alloc() - X
// - image_free() - X
// - image_fill() - 0%
// - image_sub() - X
// - image_scale() - 90%
// - image_linear() - 90%
// - libprof :
// - prof_t - 90%
// - prof_make - X
// - prof_enter - 90%
// - prof_leave - 90%
// - prof_time - 90%
//
//SDL-ported gint functions and defs
#define C_WHITE (SDL_Color){255, 255, 255, 255}
#define C_BLACK (SDL_Color){0, 0, 0, 255}
#define C_PINK (SDL_Color){31, 23, 26, 255}
#define C_BSKY (SDL_Color){156, 182, 239, 255}
#define C_DGRAY (SDL_Color){123, 121, 123, 255}
//From gint/image.h
/* image_t: gint's native bitmap image format
Images of this format can be created through this header's API but also by
using the fxSDK's built-in image converters with fxconv. */
typedef struct {
SDL_Texture *tex;
SDL_Rect *subrect;
uint8_t is_vram;
} image_t;
enum img_type{
IMAGE_RGB565 = 0, /* Converted to RGBA8888*/
IMAGE_RGB565A = 1
};
struct image_linear_map{
float h_scale;
float v_scale;
};
image_t *image_create_vram(void);
image_t *image_alloc(int w, int h, enum img_type image_type);
void image_fill(image_t *img, SDL_Color color);
image_t *image_sub(image_t *src, int x, int y, int w, int h, image_t *dest);
#define image_sub1(src, x, y, w, h, dst, ...) image_sub(src, x, y, w, h, dst)
#define image_sub(...) image_sub1(__VA_ARGS__, NULL)
#define image_at(img, x, y) image_sub(img, x, y, -1, -1)
void image_free(image_t *img);
void image_scale(image_t const *src, int gamma_x, int gamma_y, struct image_linear_map *map);
void image_linear(image_t const *src, image_t *dst, struct image_linear_map *map);
//From gint/display.h
void dprint(int x, int y, SDL_Color fg, char const *format, ...);
void dclear(SDL_Color color);
void dupdate(void);
void dimage(int x, int y, image_t *image);
//From gint/render.h
void gint_dvline(int y1, int y2, int x, SDL_Color color);
//Libprof
typedef struct{
uint32_t start;
uint32_t current;
uint8_t rec;
} prof_t;
int prof_init(void);
void prof_quit(void);
#define prof_make() ((prof_t){0,0,0})
#define prof_enter(prof) { if(1>prof.rec){ prof.start=SDL_GetTicks(); prof.rec=1; }}
#define prof_leave(prof) { if(prof.rec>1){ prof.current=SDL_GetTicks(); prof.rec=0; }}
#define prof_time(prof) (prof.current-prof.start)
//SDL specific defs
typedef struct{
SDL_Window *window;
SDL_Renderer *renderer;
TTF_Font *font;
} SDL_Info;
image_t sdl_tex_load(char *filename);
void sdl_image_init();
void sdl_image_quit();
#endif
#endif