From 1c023df1ff2d9b2284c631208fdc28610bc9a402 Mon Sep 17 00:00:00 2001 From: Zy Date: Sat, 12 Oct 2024 22:22:58 +0200 Subject: [PATCH] dev: clean xpm files from the original minilibx * - rename the source files of the original minilibx to xpm_*.* - make the changes between the original files as minimal as possible --- source/{mlx_int.h => xpm_mlx_int.h} | 62 +++++++++++++++-- ...wordtab.c => xpm_mlx_int_str_to_wordtab.c} | 9 ++- source/{mlx_rgb.c => xpm_mlx_rgb.c} | 4 +- source/{mlx_xpm.c => xpm_mlx_xpm.c} | 69 ++++++++++++++----- 4 files changed, 113 insertions(+), 31 deletions(-) rename source/{mlx_int.h => xpm_mlx_int.h} (58%) rename source/{mlx_int_str_to_wordtab.c => xpm_mlx_int_str_to_wordtab.c} (94%) rename source/{mlx_rgb.c => xpm_mlx_rgb.c} (99%) rename source/{mlx_xpm.c => xpm_mlx_xpm.c} (81%) diff --git a/source/mlx_int.h b/source/xpm_mlx_int.h similarity index 58% rename from source/mlx_int.h rename to source/xpm_mlx_int.h index 7c2fd4d..32af71f 100644 --- a/source/mlx_int.h +++ b/source/xpm_mlx_int.h @@ -17,7 +17,7 @@ * (at https://github.com/frzysk/mlx3ds). */ -// TODO: from mlx xpm: clean + #ifndef MLX_INT_H @@ -42,7 +42,7 @@ # define ERR_NO_TRUECOLOR "MinilibX Error : No TrueColor Visual available.\n" # define WARN_SHM_ATTACH "MinilibX Warning : X server can't attach shared memory.\n" -// [USED] [FULL] + typedef struct s_xpm_col { int name; @@ -63,6 +63,59 @@ typedef struct s_event_list void *param; } t_event_list; + +// typedef struct s_win_list +// { +// Window window; +// GC gc; +// struct s_win_list *next; +// int (*mouse_hook)(); +// int (*key_hook)(); +// int (*expose_hook)(); +// void *mouse_param; +// void *key_param; +// void *expose_param; +// t_event_list hooks[MLX_MAX_EVENT]; +// } t_win_list; + + +// typedef struct s_img +// { +// XImage *image; +// Pixmap pix; +// GC gc; +// int size_line; +// int bpp; +// int width; +// int height; +// int type; +// int format; +// char *data; +// XShmSegmentInfo shm; +// } t_img; + +// typedef struct s_xvar +// { +// Display *display; +// Window root; +// int screen; +// int depth; +// Visual *visual; +// Colormap cmap; +// int private_cmap; +// t_win_list *win_list; +// int (*loop_hook)(); +// void *loop_param; +// int use_xshm; +// int pshm_format; +// int do_flush; +// int decrgb[6]; +// Atom wm_delete_window; +// Atom wm_protocols; +// int end_loop; +// } t_xvar; + + int mlx_int_do_nothing(); int mlx_get_color_value(); int mlx_int_get_good_color(); @@ -72,13 +125,12 @@ int mlx_int_wait_first_expose(); int mlx_int_rgb_conversion(); int mlx_int_deal_shm(); void *mlx_int_new_xshm_image(); -// [USED] [FULL]... char **mlx_int_str_to_wordtab(); void *mlx_new_image(); int shm_att_pb(); -// [USED] [FULL]... +// int mlx_int_get_visual(t_xvar *xvar); +// int mlx_int_set_win_event_mask(t_xvar *xvar); int mlx_int_str_str_cote(char *str,char *find,int len); -// [USED] [FULL]... int mlx_int_str_str(char *str,char *find,int len); diff --git a/source/mlx_int_str_to_wordtab.c b/source/xpm_mlx_int_str_to_wordtab.c similarity index 94% rename from source/mlx_int_str_to_wordtab.c rename to source/xpm_mlx_int_str_to_wordtab.c index 9451f44..65dccf5 100644 --- a/source/mlx_int_str_to_wordtab.c +++ b/source/xpm_mlx_int_str_to_wordtab.c @@ -13,11 +13,9 @@ * (at https://github.com/frzysk/mlx3ds). */ -// TODO: from mlx xpm: clean +#include "xpm_mlx_int.h" -#include "mlx_int.h" -// [USED] [FULL] int mlx_int_str_str(char *str,char *find,int len) { int len_f; @@ -42,7 +40,8 @@ int mlx_int_str_str(char *str,char *find,int len) return (-1); } -// [USED] [FULL] + + int mlx_int_str_str_cote(char *str,char *find,int len) { int len_f; @@ -74,7 +73,7 @@ int mlx_int_str_str_cote(char *str,char *find,int len) return (-1); } -// [USED] [FULL] + char **mlx_int_str_to_wordtab(char *str) { char **tab; diff --git a/source/mlx_rgb.c b/source/xpm_mlx_rgb.c similarity index 99% rename from source/mlx_rgb.c rename to source/xpm_mlx_rgb.c index e18086c..aeec3e8 100644 --- a/source/mlx_rgb.c +++ b/source/xpm_mlx_rgb.c @@ -8,9 +8,7 @@ * (at https://github.com/frzysk/mlx3ds). */ -// TODO: from mlx xpm: clean - -#include "mlx_int.h" +#include "xpm_mlx_int.h" struct s_col_name mlx_col_name[] = { diff --git a/source/mlx_xpm.c b/source/xpm_mlx_xpm.c similarity index 81% rename from source/mlx_xpm.c rename to source/xpm_mlx_xpm.c index 4560a6d..b7003c8 100644 --- a/source/mlx_xpm.c +++ b/source/xpm_mlx_xpm.c @@ -8,14 +8,13 @@ ** Last update Sat Oct 1 14:56:13 2005 Olivier Crouzet */ + /** * Modified by Zy to work with the MinilibX For 3DS project * (at https://github.com/frzysk/mlx3ds). */ -// TODO: from mlx xpm: clean - -#include "mlx_int.h" +#include "xpm_mlx_int.h" #include "mlx.h" #include "mlx_internal.h" #include "mlx3ds.h" @@ -28,7 +27,9 @@ extern struct s_col_name mlx_col_name[]; if (img) free(img); \ return ((void *)0);} -// [USED] [FULL] + + + char *mlx_int_get_line(char *ptr,int *pos,int size) { int pos2; @@ -46,7 +47,7 @@ char *mlx_int_get_line(char *ptr,int *pos,int size) return (ptr+pos4); } -// [USED] [FULL] + unsigned int strlcpy_is_not_posix(char *dest, char *src, unsigned int size) { unsigned count; @@ -65,7 +66,6 @@ unsigned int strlcpy_is_not_posix(char *dest, char *src, unsigned int size) return (count); } -// [USED] [FULL] char *mlx_int_static_line(char **xpm_data,int *pos,int size) { static char *copy = 0; @@ -88,7 +88,7 @@ char *mlx_int_static_line(char **xpm_data,int *pos,int size) return (copy); } -// [USED] [FULL] + int mlx_int_get_col_name(char *str,int size) { int result; @@ -100,7 +100,6 @@ int mlx_int_get_col_name(char *str,int size) return (result); } -// [USED] [FULL] int mlx_int_get_text_rgb(char *name, char *end) { int i; @@ -123,7 +122,7 @@ int mlx_int_get_text_rgb(char *name, char *end) return (0); } -// [USED] [FULL] + int mlx_int_xpm_set_pixel(t_internal_image *img, u8 *data, int opp, int col, int x) { int dec; @@ -142,7 +141,7 @@ int mlx_int_xpm_set_pixel(t_internal_image *img, u8 *data, int opp, int col, int return (0); } -// [USED] [FULL] + void *mlx_int_parse_xpm(t_mlx mlx_ptr,void *info,int info_size,char *(*f)()) { int pos; @@ -172,9 +171,8 @@ void *mlx_int_parse_xpm(t_mlx mlx_ptr,void *info,int info_size,char *(*f)()) if (!(line = f(info,&pos,info_size)) || !(tab = mlx_int_str_to_wordtab(line)) || !(width = atoi(tab[0])) || !(height = atoi(tab[1])) || !(nc = atoi(tab[2])) || - !(cpp = atoi(tab[3]))) + !(cpp = atoi(tab[3])) ) RETURN; - free(tab); tab = 0; @@ -202,18 +200,29 @@ void *mlx_int_parse_xpm(t_mlx mlx_ptr,void *info,int info_size,char *(*f)()) if (!tab[j]) RETURN; rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]); + /* + if ((rgb_col = mlx_int_get_text_rgb(tab[j], tab[j+1]))==-1) + { + if (!(clip_data = malloc(4*width*height)) || ok, nice size .. + !(clip_img = XCreateImage(xvar->display, xvar->visual, + 1, XYPixmap, 0, clip_data, + width, height, 8, (width+7)/8)) ) + RETURN; + memset(clip_data, 0xFF, 4*width*height); + } + */ if (method) colors_direct[mlx_int_get_col_name(line,cpp)] = rgb_col; + // rgb_col>=0?mlx_get_color_value(xvar, rgb_col):rgb_col; else { colors[i].name = mlx_int_get_col_name(line,cpp); - colors[i].col = rgb_col; + colors[i].col = rgb_col; //rgb_col>=0?mlx_get_color_value(xvar,rgb_col):rgb_col; } free(tab); tab = (void *)0; } - if (!(img = mlx_new_image(mlx_ptr,width,height))) RETURN; @@ -240,6 +249,13 @@ void *mlx_int_parse_xpm(t_mlx mlx_ptr,void *info,int info_size,char *(*f)()) j = 0; } } + /* + if (col==-1) + XPutPixel(clip_img, x, height-1-i, 0); + else + mlx_int_xpm_set_pixel(img, data, opp, col, x); + x ++; + */ if (col==-1) col = 0xFF000000; mlx_int_xpm_set_pixel(img, data, 3, col, x); @@ -247,7 +263,25 @@ void *mlx_int_parse_xpm(t_mlx mlx_ptr,void *info,int info_size,char *(*f)()) } data += img->width * 3; } - + /* + if (clip_data) + { + if (!(clip_pix = XCreatePixmap(xvar->display, xvar->root, + width, height, 1)) ) + RETURN; + img->gc = XCreateGC(xvar->display, clip_pix, 0, &xgcv); + XPutImage(xvar->display, clip_pix, img->gc, clip_img, + 0, 0, 0, 0, width, height); + XFreeGC(xvar->display, img->gc); + xgcv.clip_mask = clip_pix; + xgcv.function = GXcopy; + xgcv.plane_mask = AllPlanes; + img->gc = XCreateGC(xvar->display, xvar->root, GCClipMask|GCFunction| + GCPlaneMask, &xgcv); + XSync(xvar->display, False); + XDestroyImage(clip_img); + } + */ if (colors) free(colors); if (colors_direct) @@ -255,7 +289,7 @@ void *mlx_int_parse_xpm(t_mlx mlx_ptr,void *info,int info_size,char *(*f)()) return (img); } -// [USED] [FULL] + int mlx_int_file_get_rid_comment(char *ptr, int size) { int com_begin; @@ -274,7 +308,7 @@ int mlx_int_file_get_rid_comment(char *ptr, int size) return (0); } -// [USED] + t_image mlx_xpm_file_to_image(t_mlx xvar, const char *file,int *width,int *height) { const t_embeddedasset *asset; @@ -304,7 +338,6 @@ t_image mlx_xpm_file_to_image(t_mlx xvar, const char *file,int *width,int *heigh return (img); } -// [USED] [FULL] t_image mlx_xpm_to_image(t_mlx mlx_ptr, const char **xpm_data,int *width,int *height) { t_internal_image *img;