1 /* File: imlib2_common.h 2 Time-stamp: <2011-10-10 00:41:40 gawen> 3 4 Copyright (c) 2011 David Hauweele <david@hauweele.net> 5 All rights reserved. 6 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions 9 are met: 10 1. Redistributions of source code must retain the above copyright 11 notice, this list of conditions and the following disclaimer. 12 2. Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 3. Neither the name of the University nor the names of its contributors 16 may be used to endorse or promote products derived from this software 17 without specific prior written permission. 18 19 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 SUCH DAMAGE. */ 30 31 #ifndef _IMLIB2_COMMON_H_ 32 #define _IMLIB2_COMMON_H_ 33 34 /* most of this file comes directly from imlib2 source code */ 35 36 #include <Imlib2.h> 37 38 #define UNSET_FLAGS(flags, f) ((flags) &= ~(f)) 39 #define SET_FLAGS(flags, f) ((flags) |= (f)) 40 41 typedef struct _imlibimage ImlibImage; 42 # ifdef BUILD_X11 43 typedef struct _imlibimagepixmap ImlibImagePixmap; 44 # endif 45 typedef struct _imlibborder ImlibBorder; 46 typedef struct _imlibloader ImlibLoader; 47 typedef struct _imlibimagetag ImlibImageTag; 48 49 typedef int (*ImlibProgressFunction)(ImlibImage *im, char percent, 50 int update_x, int update_y, 51 int update_w, int update_h); 52 typedef void (*ImlibDataDestructorFunction)(ImlibImage *im, void *data); 53 54 enum _iflags 55 { 56 F_NONE = 0, 57 F_HAS_ALPHA = (1 << 0), 58 F_UNLOADED = (1 << 1), 59 F_UNCACHEABLE = (1 << 2), 60 F_ALWAYS_CHECK_DISK = (1 << 3), 61 F_INVALID = (1 << 4), 62 F_DONT_FREE_DATA = (1 << 5), 63 F_FORMAT_IRRELEVANT = (1 << 6), 64 F_BORDER_IRRELEVANT = (1 << 7), 65 F_ALPHA_IRRELEVANT = (1 << 8) 66 }; 67 68 typedef enum _iflags ImlibImageFlags; 69 70 struct _imlibborder 71 { 72 int left, right, top, bottom; 73 }; 74 75 struct _imlibimagetag 76 { 77 char *key; 78 int val; 79 void *data; 80 void (*destructor)(ImlibImage *im, void *data); 81 ImlibImageTag *next; 82 }; 83 84 struct _imlibimage 85 { 86 char *file; 87 int w, h; 88 DATA32 *data; 89 ImlibImageFlags flags; 90 time_t moddate; 91 ImlibBorder border; 92 int references; 93 ImlibLoader *loader; 94 char *format; 95 ImlibImage *next; 96 ImlibImageTag *tags; 97 char *real_file; 98 char *key; 99 }; 100 101 # ifdef BUILD_X11 102 struct _imlibimagepixmap 103 { 104 int w, h; 105 Pixmap pixmap, mask; 106 Display *display; 107 Visual *visual; 108 int depth; 109 int source_x, source_y, source_w, source_h; 110 Colormap colormap; 111 char antialias, hi_quality, dither_mask; 112 ImlibBorder border; 113 ImlibImage *image; 114 char *file; 115 char dirty; 116 int references; 117 DATABIG modification_count; 118 ImlibImagePixmap *next; 119 }; 120 # endif 121 122 struct _imlibloader 123 { 124 char *file; 125 int num_formats; 126 char **formats; 127 void *handle; 128 char (*load)(ImlibImage *im, 129 ImlibProgressFunction progress, 130 char progress_granularity, char immediate_load); 131 char (*save)(ImlibImage *im, 132 ImlibProgressFunction progress, 133 char progress_granularity); 134 ImlibLoader *next; 135 }; 136 137 # define IMAGE_HAS_ALPHA(im) ((im)->flags & F_HAS_ALPHA) 138 # define IMAGE_IS_UNLOADED(im) ((im)->flags & F_UNLOADED) 139 # define IMAGE_IS_UNCACHEABLE(im) ((im)->flags & F_UNCACHEABLE) 140 # define IMAGE_ALWAYS_CHECK_DISK(im) ((im)->flags & F_ALWAYS_CHECK_DISK) 141 # define IMAGE_IS_VALID(im) (!((im)->flags & F_INVALID)) 142 # define IMAGE_FREE_DATA(im) (!((im)->flags & F_DONT_FREE_DATA)) 143 144 # define SET_FLAG(flags, f) ((flags) |= (f)) 145 # define UNSET_FLAG(flags, f) ((flags) &= (~f)) 146 147 # define IMAGE_DIMENSIONS_OK(w, h) \ 148 ( ((w) > 0) && ((h) > 0) && \ 149 ((unsigned long long)(w) * (unsigned long long)(h) <= (1ULL << 29) - 1) ) 150 151 EAPI ImlibImageTag *__imlib_GetTag(ImlibImage *im, const char *key); 152 153 #endif /* _IMLIB2_COMMON_H_ */ 154