1 #ifndef __IMAGE
2 #define __IMAGE 1
3 
4 #include "common.h"
5 #ifdef BUILD_X11
6 #include <X11/Xlib.h>
7 #else
8 #ifndef X_DISPLAY_MISSING
9 #define X_DISPLAY_MISSING
10 #endif
11 #endif
12 
13 typedef struct _imlibimage ImlibImage;
14 typedef struct _imlibldctx ImlibLdCtx;
15 
16 #ifdef BUILD_X11
17 typedef struct _imlibimagepixmap ImlibImagePixmap;
18 #endif
19 typedef struct _imlibborder ImlibBorder;
20 typedef struct _imlibloader ImlibLoader;
21 typedef struct _imlibimagetag ImlibImageTag;
22 typedef enum _imlib_load_error ImlibLoadError;
23 
24 typedef int         (*ImlibProgressFunction)(ImlibImage * im, char percent,
25                                              int update_x, int update_y,
26                                              int update_w, int update_h);
27 typedef void        (*ImlibDataDestructorFunction)(ImlibImage * im, void *data);
28 typedef void       *(*ImlibImageDataMemoryFunction)(void *, size_t size);
29 
30 enum _iflags {
31    F_NONE = 0,
32    F_HAS_ALPHA = (1 << 0),
33    F_UNLOADED = (1 << 1),
34    F_UNCACHEABLE = (1 << 2),
35    F_ALWAYS_CHECK_DISK = (1 << 3),
36    F_INVALID = (1 << 4),
37    F_DONT_FREE_DATA = (1 << 5),
38    F_FORMAT_IRRELEVANT = (1 << 6),
39    F_BORDER_IRRELEVANT = (1 << 7),
40    F_ALPHA_IRRELEVANT = (1 << 8)
41 };
42 
43 typedef enum _iflags ImlibImageFlags;
44 
45 struct _imlibborder {
46    int                 left, right, top, bottom;
47 };
48 
49 struct _imlibimagetag {
50    char               *key;
51    int                 val;
52    void               *data;
53    void                (*destructor)(ImlibImage * im, void *data);
54    ImlibImageTag      *next;
55 };
56 
57 struct _imlibimage {
58    char               *file;
59    int                 w, h;
60    DATA32             *data;
61    ImlibImageFlags     flags;
62    time_t              moddate;
63    ImlibBorder         border;
64    int                 references;
65    ImlibLoader        *loader;
66    char               *format;
67    ImlibImage         *next;
68    ImlibImageTag      *tags;
69    char               *real_file;
70    char               *key;
71    ImlibImageDataMemoryFunction data_memory_func;
72    ImlibLdCtx         *lc;
73    FILE               *fp;
74 };
75 
76 #ifdef BUILD_X11
77 struct _imlibimagepixmap {
78    int                 w, h;
79    Pixmap              pixmap, mask;
80    Display            *display;
81    Visual             *visual;
82    int                 depth;
83    int                 source_x, source_y, source_w, source_h;
84    Colormap            colormap;
85    char                antialias, hi_quality, dither_mask;
86    ImlibBorder         border;
87    ImlibImage         *image;
88    char               *file;
89    char                dirty;
90    int                 references;
91    DATABIG             modification_count;
92    ImlibImagePixmap   *next;
93 };
94 #endif
95 
96 void                __imlib_LoadAllLoaders(void);
97 void                __imlib_RemoveAllLoaders(void);
98 ImlibLoader       **__imlib_GetLoaderList(void);
99 ImlibLoader        *__imlib_FindBestLoaderForFile(const char *file,
100                                                   int for_save);
101 ImlibLoader        *__imlib_FindBestLoaderForFormat(const char *format,
102                                                     int for_save);
103 ImlibLoader        *__imlib_FindBestLoaderForFileFormat(const char *file,
104                                                         const char *format,
105                                                         int for_save);
106 void                __imlib_LoaderSetFormats(ImlibLoader * l,
107                                              const char *const *fmt,
108                                              unsigned int num);
109 
110 ImlibImage         *__imlib_CreateImage(int w, int h, DATA32 * data);
111 ImlibImage         *__imlib_LoadImage(const char *file, FILE * fp,
112                                       ImlibProgressFunction progress,
113                                       char progress_granularity,
114                                       char immediate_load, char dont_cache,
115                                       ImlibLoadError * er);
116 int                 __imlib_LoadEmbedded(ImlibLoader * l, ImlibImage * im,
117                                          const char *file, int load_data);
118 int                 __imlib_LoadImageData(ImlibImage * im);
119 void                __imlib_DirtyImage(ImlibImage * im);
120 void                __imlib_FreeImage(ImlibImage * im);
121 void                __imlib_SaveImage(ImlibImage * im, const char *file,
122                                       ImlibProgressFunction progress,
123                                       char progress_granularity,
124                                       ImlibLoadError * er);
125 
126 DATA32             *__imlib_AllocateData(ImlibImage * im);
127 void                __imlib_FreeData(ImlibImage * im);
128 void                __imlib_ReplaceData(ImlibImage * im, DATA32 * new_data);
129 
130 void                __imlib_LoadProgressSetPass(ImlibImage * im,
131                                                 int pass, int n_pass);
132 int                 __imlib_LoadProgress(ImlibImage * im,
133                                          int x, int y, int w, int h);
134 int                 __imlib_LoadProgressRows(ImlibImage * im,
135                                              int row, int nrows);
136 
137 #ifdef BUILD_X11
138 ImlibImagePixmap   *__imlib_ProduceImagePixmap(void);
139 void                __imlib_ConsumeImagePixmap(ImlibImagePixmap * ip);
140 ImlibImagePixmap   *__imlib_FindCachedImagePixmap(ImlibImage * im, int w, int h,
141                                                   Display * d, Visual * v,
142                                                   int depth, int sx, int sy,
143                                                   int sw, int sh, Colormap cm,
144                                                   char aa, char hiq, char dmask,
145                                                   DATABIG modification_count);
146 ImlibImagePixmap   *__imlib_FindCachedImagePixmapByID(Display * d, Pixmap p);
147 void                __imlib_AddImagePixmapToCache(ImlibImagePixmap * ip);
148 void                __imlib_RemoveImagePixmapFromCache(ImlibImagePixmap * ip);
149 void                __imlib_CleanupImagePixmapCache(void);
150 
151 ImlibImagePixmap   *__imlib_FindImlibImagePixmapByID(Display * d, Pixmap p);
152 void                __imlib_FreePixmap(Display * d, Pixmap p);
153 void                __imlib_DirtyPixmapsForImage(ImlibImage * im);
154 #endif
155 
156 void                __imlib_AttachTag(ImlibImage * im, const char *key,
157                                       int val, void *data,
158                                       ImlibDataDestructorFunction destructor);
159 ImlibImageTag      *__imlib_GetTag(const ImlibImage * im, const char *key);
160 ImlibImageTag      *__imlib_RemoveTag(ImlibImage * im, const char *key);
161 void                __imlib_FreeTag(ImlibImage * im, ImlibImageTag * t);
162 void                __imlib_FreeAllTags(ImlibImage * im);
163 
164 void                __imlib_SetCacheSize(int size);
165 int                 __imlib_GetCacheSize(void);
166 int                 __imlib_CurrentCacheSize(void);
167 
168 #define IMAGE_HAS_ALPHA(im) ((im)->flags & F_HAS_ALPHA)
169 #define IMAGE_IS_UNLOADED(im) ((im)->flags & F_UNLOADED)
170 #define IMAGE_IS_UNCACHEABLE(im) ((im)->flags & F_UNCACHEABLE)
171 #define IMAGE_ALWAYS_CHECK_DISK(im) ((im)->flags & F_ALWAYS_CHECK_DISK)
172 #define IMAGE_IS_VALID(im) (!((im)->flags & F_INVALID))
173 #define IMAGE_FREE_DATA(im) (!((im)->flags & F_DONT_FREE_DATA))
174 
175 #define SET_FLAG(flags, f) ((flags) |= (f))
176 #define UNSET_FLAG(flags, f) ((flags) &= (~f))
177 
178 #define LOAD_FAIL       0
179 #define LOAD_SUCCESS    1
180 #define LOAD_BREAK      2
181 
182 /* 32767 is the maximum pixmap dimension and ensures that
183  * (w * h * sizeof(DATA32)) won't exceed ULONG_MAX */
184 #define X_MAX_DIM 32767
185 /* NB! The image dimensions are sometimes used in (dim << 16) like expressions
186  * so great care must be taken if ever it is attempted to change this
187  * condition */
188 
189 #define IMAGE_DIMENSIONS_OK(w, h) \
190    ( ((w) > 0) && ((h) > 0) && ((w) <= X_MAX_DIM) && ((h) <= X_MAX_DIM) )
191 
192 #endif
193