kwo pushed a commit to branch master. http://git.enlightenment.org/legacy/imlib2_loaders.git/commit/?id=709a75e4abd1d69d16738ade570f9c8bc958b220
commit 709a75e4abd1d69d16738ade570f9c8bc958b220 Author: Kim Woelders <[email protected]> Date: Thu Dec 14 20:48:47 2017 +0100 Copy updated headers from imlib2 --- src/modules/loaders/common.h | 24 +- src/modules/loaders/image.h | 332 ++++++++++++++-------------- src/modules/loaders/loader_ani.c | 3 +- src/modules/loaders/loader_xcf_pixelfuncs.c | 2 - 4 files changed, 191 insertions(+), 170 deletions(-) diff --git a/src/modules/loaders/common.h b/src/modules/loaders/common.h index 7a0a7b0..08916a1 100644 --- a/src/modules/loaders/common.h +++ b/src/modules/loaders/common.h @@ -1,15 +1,16 @@ #ifndef __COMMON #define __COMMON 1 +#include "config.h" + #include <stdio.h> #include <stdlib.h> -#ifdef __EMX__ -#include <sys/types.h> -#endif #include <unistd.h> -#include <config.h> +#include <string.h> +#include <math.h> +#include <time.h> #ifdef WITH_DMALLOC -# include <dmalloc.h> +#include <dmalloc.h> #endif #define DATABIG unsigned long long @@ -19,9 +20,20 @@ #define DATA8 unsigned char #ifdef DO_MMX_ASM -int __imlib_get_cpuid(void); +int __imlib_get_cpuid(void); + #define CPUID_MMX (1 << 23) #define CPUID_XMM (1 << 25) #endif +#define CLIP(x, y, w, h, xx, yy, ww, hh) \ +if (x < (xx)) {w += (x - (xx)); x = (xx);} \ +if (y < (yy)) {h += (y - (yy)); y = (yy);} \ +if ((x + w) > ((xx) + (ww))) {w = (ww) - (x - xx);} \ +if ((y + h) > ((yy) + (hh))) {h = (hh) - (y - yy);} +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) + +#define round(x) ((x)>=0?(int)((x)+0.5):(int)((x)-0.5)) + #endif diff --git a/src/modules/loaders/image.h b/src/modules/loaders/image.h index ab34427..3078d38 100644 --- a/src/modules/loaders/image.h +++ b/src/modules/loaders/image.h @@ -1,180 +1,192 @@ #ifndef __IMAGE -# define __IMAGE 1 - -typedef struct _imlibimage ImlibImage; -typedef struct _imlibimagepixmap ImlibImagePixmap; -typedef struct _imlibborder ImlibBorder; -typedef struct _imlibloader ImlibLoader; -typedef struct _imlibimagetag ImlibImageTag; - -typedef int (*ImlibProgressFunction)(ImlibImage *im, char percent, - int update_x, int update_y, - int update_w, int update_h); -typedef void (*ImlibDataDestructorFunction)(ImlibImage *im, void *data); - -enum _load_error -{ - LOAD_ERROR_NONE, - LOAD_ERROR_FILE_DOES_NOT_EXIST, - LOAD_ERROR_FILE_IS_DIRECTORY, - LOAD_ERROR_PERMISSION_DENIED_TO_READ, - LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT, - LOAD_ERROR_PATH_TOO_LONG, - LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT, - LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY, - LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE, - LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS, - LOAD_ERROR_OUT_OF_MEMORY, - LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS, - LOAD_ERROR_PERMISSION_DENIED_TO_WRITE, - LOAD_ERROR_OUT_OF_DISK_SPACE, - LOAD_ERROR_UNKNOWN -}; +#define __IMAGE 1 + +#include "common.h" +#ifdef BUILD_X11 +#include <X11/Xlib.h> +#else +#ifndef X_DISPLAY_MISSING +#define X_DISPLAY_MISSING +#endif +#endif + +typedef struct _imlibimage ImlibImage; -enum _iflags -{ - F_NONE = 0, - F_HAS_ALPHA = (1 << 0), - F_UNLOADED = (1 << 1), - F_UNCACHEABLE = (1 << 2), +#ifdef BUILD_X11 +typedef struct _imlibimagepixmap ImlibImagePixmap; +#endif +typedef struct _imlibborder ImlibBorder; +typedef struct _imlibloader ImlibLoader; +typedef struct _imlibimagetag ImlibImageTag; +typedef enum _imlib_load_error ImlibLoadError; + +typedef int (*ImlibProgressFunction) (ImlibImage * im, char percent, + int update_x, int update_y, + int update_w, int update_h); +typedef void (*ImlibDataDestructorFunction) (ImlibImage * im, + void *data); + +enum _iflags { + F_NONE = 0, + F_HAS_ALPHA = (1 << 0), + F_UNLOADED = (1 << 1), + F_UNCACHEABLE = (1 << 2), F_ALWAYS_CHECK_DISK = (1 << 3), - F_INVALID = (1 << 4), - F_DONT_FREE_DATA = (1 << 5), + F_INVALID = (1 << 4), + F_DONT_FREE_DATA = (1 << 5), F_FORMAT_IRRELEVANT = (1 << 6), F_BORDER_IRRELEVANT = (1 << 7), - F_ALPHA_IRRELEVANT = (1 << 8) + F_ALPHA_IRRELEVANT = (1 << 8) }; -typedef enum _iflags ImlibImageFlags; -typedef enum _load_error ImlibLoadError; +typedef enum _iflags ImlibImageFlags; -struct _imlibborder -{ - int left, right, top, bottom; +struct _imlibborder { + int left, right, top, bottom; }; -struct _imlibimagetag -{ - char *key; - int val; - void *data; - void (*destructor)(ImlibImage *im, void *data); - ImlibImageTag *next; +struct _imlibimagetag { + char *key; + int val; + void *data; + void (*destructor) (ImlibImage * im, void *data); + ImlibImageTag *next; }; -struct _imlibimage -{ - char *file; - int w, h; - DATA32 *data; - ImlibImageFlags flags; - time_t moddate; - ImlibBorder border; - int references; - ImlibLoader *loader; - char *format; - ImlibImage *next; - ImlibImageTag *tags; - char *real_file; - char *key; +struct _imlibimage { + char *file; + int w, h; + DATA32 *data; + ImlibImageFlags flags; + time_t moddate; + ImlibBorder border; + int references; + ImlibLoader *loader; + char *format; + ImlibImage *next; + ImlibImageTag *tags; + char *real_file; + char *key; }; -struct _imlibimagepixmap -{ - int w, h; - Pixmap pixmap, mask; - Display *display; - Visual *visual; - int depth; - int source_x, source_y, source_w, source_h; - Colormap colormap; - char antialias, hi_quality, dither_mask; - ImlibBorder border; - ImlibImage *image; - char dirty; - int references; - DATABIG modification_count; - ImlibImagePixmap *next; +#ifdef BUILD_X11 +struct _imlibimagepixmap { + int w, h; + Pixmap pixmap, mask; + Display *display; + Visual *visual; + int depth; + int source_x, source_y, source_w, source_h; + Colormap colormap; + char antialias, hi_quality, dither_mask; + ImlibBorder border; + ImlibImage *image; + char *file; + char dirty; + int references; + DATABIG modification_count; + ImlibImagePixmap *next; }; +#endif -struct _imlibloader -{ - char *file; - int num_formats; - char **formats; - void *handle; - char (*load)(ImlibImage *im, - ImlibProgressFunction progress, - char progress_granularity, char immediate_load); - char (*save)(ImlibImage *im, - ImlibProgressFunction progress, - char progress_granularity); - ImlibLoader *next; +struct _imlibloader { + char *file; + int num_formats; + char **formats; + void *handle; + char (*load) (ImlibImage * im, + ImlibProgressFunction progress, + char progress_granularity, char immediate_load); + char (*save) (ImlibImage * im, + ImlibProgressFunction progress, + char progress_granularity); + ImlibLoader *next; }; -void __imlib_AttachTag(ImlibImage *im, const char *key, int val, void *data, - ImlibDataDestructorFunction destructor); -ImlibImageTag *__imlib_GetTag(ImlibImage *im, const char *key); -ImlibImageTag *__imlib_RemoveTag(ImlibImage *im, const char *key); -void __imlib_FreeTag(ImlibImage *im, ImlibImageTag *t); -void __imlib_FreeAllTags(ImlibImage *im); - -void __imlib_SetCacheSize(int size); -int __imlib_GetCacheSize(void); -ImlibImage *__imlib_ProduceImage(void); -void __imlib_ConsumeImage(ImlibImage *im); -ImlibImage *__imlib_FindCachedImage(const char *file); -void __imlib_AddImageToCache(ImlibImage *im); -void __imlib_RemoveImageFromCache(ImlibImage *im); -int __imlib_CurrentCacheSize(void); -void __imlib_CleanupImageCache(void); -ImlibImagePixmap *__imlib_ProduceImagePixmap(void); -void __imlib_ConsumeImagePixmap(ImlibImagePixmap *ip); -ImlibImagePixmap *__imlib_FindCachedImagePixmap(ImlibImage *im, int w, int h, - Display *d, Visual *v, - int depth, int sx, int sy, - int sw, int sh, Colormap cm, - char aa, char hiq, char dmask, - DATABIG modification_count); -ImlibImagePixmap *__imlib_FindCachedImagePixmapByID(Display *d, Pixmap p); -void __imlib_AddImagePixmapToCache(ImlibImagePixmap *ip); -void __imlib_RemoveImagePixmapFromCache(ImlibImagePixmap *ip); -void __imlib_CleanupImagePixmapCache(void); -ImlibLoader *__imlib_ProduceLoader(char *file); -char **__imlib_ListLoaders(int *num_ret); -char **__imlib_TrimLoaderList(char **list, int *num); -int __imlib_LoaderInList(char **list, int size, char *item); -void __imlib_ConsumeLoader(ImlibLoader *l); -void __imlib_RescanLoaders(void); -void __imlib_RemoveAllLoaders(void); -void __imlib_LoadAllLoaders(void); -ImlibLoader *__imlib_FindBestLoaderForFile(const char *file); -ImlibLoader *__imlib_FindBestLoaderForFileFormat(const char *file, char *format); -void __imlib_SetImageAlphaFlag(ImlibImage *im, char alpha); -ImlibImage *__imlib_CreateImage(int w, int h, DATA32 *data); -ImlibImage *__imlib_LoadImage(const char *file, - ImlibProgressFunction progress, - char progress_granularity, char immediate_load, - char dont_cache, ImlibLoadError *er); -ImlibImagePixmap *__imlib_FindImlibImagePixmapByID(Display *d, Pixmap p); -void __imlib_FreeImage(ImlibImage *im); -void __imlib_FreePixmap(Display *d, Pixmap p); -void __imlib_FlushCache(void); -void __imlib_DirtyPixmapsForImage(ImlibImage *im); -void __imlib_DirtyImage(ImlibImage *im); -void __imlib_SaveImage(ImlibImage *im, const char *file, - ImlibProgressFunction progress, - char progress_granularity, - ImlibLoadError *er); - -# define IMAGE_HAS_ALPHA(im) ((im)->flags & F_HAS_ALPHA) -# define IMAGE_IS_UNLOADED(im) ((im)->flags & F_UNLOADED) -# define IMAGE_IS_UNCACHEABLE(im) ((im)->flags & F_UNCACHEABLE) -# define IMAGE_ALWAYS_CHECK_DISK(im) ((im)->flags & F_ALWAYS_CHECK_DISK) -# define IMAGE_IS_VALID(im) (!((im)->flags & F_INVALID)) -# define IMAGE_FREE_DATA(im) (!((im)->flags & F_DONT_FREE_DATA)) - -# define SET_FLAG(flags, f) ((flags) |= (f)) -# define UNSET_FLAG(flags, f) ((flags) &= (~f)) +void __imlib_AttachTag(ImlibImage * im, const char *key, + int val, void *data, + ImlibDataDestructorFunction destructor); +ImlibImageTag *__imlib_GetTag(ImlibImage * im, const char *key); +ImlibImageTag *__imlib_RemoveTag(ImlibImage * im, const char *key); +void __imlib_FreeTag(ImlibImage * im, ImlibImageTag * t); +void __imlib_FreeAllTags(ImlibImage * im); + +void __imlib_SetCacheSize(int size); +int __imlib_GetCacheSize(void); +ImlibImage *__imlib_ProduceImage(void); +void __imlib_ConsumeImage(ImlibImage * im); +ImlibImage *__imlib_FindCachedImage(const char *file); +void __imlib_AddImageToCache(ImlibImage * im); +void __imlib_RemoveImageFromCache(ImlibImage * im); +int __imlib_CurrentCacheSize(void); +void __imlib_CleanupImageCache(void); + +#ifdef BUILD_X11 +ImlibImagePixmap *__imlib_ProduceImagePixmap(void); +void __imlib_ConsumeImagePixmap(ImlibImagePixmap * ip); +ImlibImagePixmap *__imlib_FindCachedImagePixmap(ImlibImage * im, int w, int h, + Display * d, Visual * v, + int depth, int sx, int sy, + int sw, int sh, Colormap cm, + char aa, char hiq, char dmask, + DATABIG modification_count); +ImlibImagePixmap *__imlib_FindCachedImagePixmapByID(Display * d, Pixmap p); +void __imlib_AddImagePixmapToCache(ImlibImagePixmap * ip); +void __imlib_RemoveImagePixmapFromCache(ImlibImagePixmap * ip); +void __imlib_CleanupImagePixmapCache(void); +#endif +void __imlib_RemoveAllLoaders(void); +ImlibLoader *__imlib_FindBestLoaderForFile(const char *file, + int for_save); +ImlibLoader *__imlib_FindBestLoaderForFileFormat(const char *file, + char *format, + int for_save); +void __imlib_SetImageAlphaFlag(ImlibImage * im, char alpha); +ImlibImage *__imlib_CreateImage(int w, int h, DATA32 * data); +ImlibImage *__imlib_LoadImage(const char *file, + ImlibProgressFunction progress, + char progress_granularity, + char immediate_load, char dont_cache, + ImlibLoadError * er); +int __imlib_LoadImageData(ImlibImage * im); + +#ifdef BUILD_X11 +ImlibImagePixmap *__imlib_FindImlibImagePixmapByID(Display * d, Pixmap p); +#endif +void __imlib_FreeImage(ImlibImage * im); + +#ifdef BUILD_X11 +void __imlib_FreePixmap(Display * d, Pixmap p); +#endif +void __imlib_FlushCache(void); + +#ifdef BUILD_X11 +void __imlib_DirtyPixmapsForImage(ImlibImage * im); +#else +#define __imlib_DirtyPixmapsForImage(x) /* x */ +#endif +void __imlib_DirtyImage(ImlibImage * im); +void __imlib_SaveImage(ImlibImage * im, const char *file, + ImlibProgressFunction progress, + char progress_granularity, + ImlibLoadError * er); + +#define IMAGE_HAS_ALPHA(im) ((im)->flags & F_HAS_ALPHA) +#define IMAGE_IS_UNLOADED(im) ((im)->flags & F_UNLOADED) +#define IMAGE_IS_UNCACHEABLE(im) ((im)->flags & F_UNCACHEABLE) +#define IMAGE_ALWAYS_CHECK_DISK(im) ((im)->flags & F_ALWAYS_CHECK_DISK) +#define IMAGE_IS_VALID(im) (!((im)->flags & F_INVALID)) +#define IMAGE_FREE_DATA(im) (!((im)->flags & F_DONT_FREE_DATA)) + +#define SET_FLAG(flags, f) ((flags) |= (f)) +#define UNSET_FLAG(flags, f) ((flags) &= (~f)) + +/* The maximum pixmap dimension is 65535. */ +/* However, for now, use 46340 (46340^2 < 2^31) to avoid buffer overflow issues. */ +/* Reduced further to 32767, so that (w * h * sizeof(DATA32)) won't exceed ULONG_MAX */ +#define X_MAX_DIM 32767 + +#define IMAGE_DIMENSIONS_OK(w, h) \ + ( ((w) > 0) && ((h) > 0) && ((w) < X_MAX_DIM) && ((h) < X_MAX_DIM) ) #endif diff --git a/src/modules/loaders/loader_ani.c b/src/modules/loaders/loader_ani.c index bd31013..ea4e69f 100644 --- a/src/modules/loaders/loader_ani.c +++ b/src/modules/loaders/loader_ani.c @@ -302,7 +302,6 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity, { if (chunk->chunk_id == 0x6E6F6369) { - ImlibLoadError err; ImlibImage *temp_im; char *filename; @@ -310,7 +309,7 @@ load(ImlibImage *im, ImlibProgressFunction progress, char progress_granularity, return 0; temp_im = __imlib_LoadImage(filename, progress, progress_granularity, - immediate_load, 0, &err); + immediate_load, 0, NULL); im->w = temp_im->w; im->h = temp_im->h; diff --git a/src/modules/loaders/loader_xcf_pixelfuncs.c b/src/modules/loaders/loader_xcf_pixelfuncs.c index 0d7e3c3..93a9a61 100644 --- a/src/modules/loaders/loader_xcf_pixelfuncs.c +++ b/src/modules/loaders/loader_xcf_pixelfuncs.c @@ -51,8 +51,6 @@ #define EPS 0.00001 #define PI 3.141592654 -#define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define MIN(a, b) ((a) < (b) ? (a) : (b)) #define INT_MULT(a,b,t) ((t) = (a) * (b) + 0x80, ((((t) >> 8) + (t)) >> 8)) #define LINEAR(x,y,w) ((w*y + x)*4) --
