1 /* Decls for imageinfo.c 2 */ 3 4 /* 5 6 Copyright (C) 1991-2003 The National Gallery 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 2 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License along 19 with this program; if not, write to the Free Software Foundation, Inc., 20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 21 22 */ 23 24 /* 25 26 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk 27 28 */ 29 30 /* Meta we attach for the filename we loaded from. 31 */ 32 #define ORIGINAL_FILENAME "original-filename" 33 34 /* Group imageinfo with this. 35 */ 36 37 #define TYPE_IMAGEINFOGROUP (imageinfogroup_get_type()) 38 #define IMAGEINFOGROUP( obj ) \ 39 (G_TYPE_CHECK_INSTANCE_CAST( (obj), \ 40 TYPE_IMAGEINFOGROUP, Imageinfogroup )) 41 #define IMAGEINFOGROUP_CLASS( klass ) \ 42 (G_TYPE_CHECK_CLASS_CAST( (klass), \ 43 TYPE_IMAGEINFOGROUP, ImageinfogroupClass)) 44 #define IS_IMAGEINFOGROUP( obj ) \ 45 (G_TYPE_CHECK_INSTANCE_TYPE( (obj), TYPE_IMAGEINFOGROUP )) 46 #define IS_IMAGEINFOGROUP_CLASS( klass ) \ 47 (G_TYPE_CHECK_CLASS_TYPE( (klass), TYPE_IMAGEINFOGROUP )) 48 #define IMAGEINFOGROUP_GET_CLASS( obj ) \ 49 (G_TYPE_INSTANCE_GET_CLASS( (obj), \ 50 TYPE_IMAGEINFOGROUP, ImageinfogroupClass )) 51 52 typedef struct _Imageinfogroup { 53 iContainer parent_object; 54 55 /* Hash from filename to list of imageinfo. We can't use the 56 * icontainer hash, since our filenames are not unique (we can have 57 * the same file loaded several times, if some other application is 58 * changing our files behind our back). 59 */ 60 GHashTable *filename_hash; 61 } Imageinfogroup; 62 63 typedef struct _ImageinfogroupClass { 64 iContainerClass parent_class; 65 66 } ImageinfogroupClass; 67 68 GType imageinfogroup_get_type( void ); 69 Imageinfogroup *imageinfogroup_new( void ); 70 71 /* An image. 72 */ 73 74 #define TYPE_IMAGEINFO (imageinfo_get_type()) 75 #define IMAGEINFO( obj ) \ 76 (G_TYPE_CHECK_INSTANCE_CAST( (obj), TYPE_IMAGEINFO, Imageinfo )) 77 #define IMAGEINFO_CLASS( klass ) \ 78 (G_TYPE_CHECK_CLASS_CAST( (klass), TYPE_IMAGEINFO, ImageinfoClass)) 79 #define IS_IMAGEINFO( obj ) \ 80 (G_TYPE_CHECK_INSTANCE_TYPE( (obj), TYPE_IMAGEINFO )) 81 #define IS_IMAGEINFO_CLASS( klass ) \ 82 (G_TYPE_CHECK_CLASS_TYPE( (klass), TYPE_IMAGEINFO )) 83 #define IMAGEINFO_GET_CLASS( obj ) \ 84 (G_TYPE_INSTANCE_GET_CLASS( (obj), TYPE_IMAGEINFO, ImageinfoClass )) 85 86 /* A fragment of an undo buffer. 87 */ 88 typedef struct _Undofragment { 89 struct _Undobuffer *undo; /* Main undo area */ 90 IMAGE *im; /* Old area */ 91 Rect pos; /* Where we took it from */ 92 } Undofragment; 93 94 /* Hold a list of the above, a bounding box for this list and a link back to 95 * the main imageinfo. 96 */ 97 typedef struct _Undobuffer { 98 struct _Imageinfo *imageinfo; /* Main paint area */ 99 GSList *frags; /* List of paint fragments */ 100 Rect bbox; /* Bounding box for frags */ 101 } Undobuffer; 102 103 /* Attach one of these to any IMAGE we monitor. It has the same lifetime as 104 * the IMAGE and gets zapped by the imageinfo on dispose. This lets us spot 105 * IMAGE events after the holding Imageinfo has gone. 106 */ 107 typedef struct _Imageinfoproxy { 108 IMAGE *im; 109 Imageinfo *imageinfo; 110 } Imageinfoproxy; 111 112 /* A VIPS image wrapped up nicely. 113 */ 114 struct _Imageinfo { 115 Managed parent_object; 116 117 IMAGE *im; /* Image we manage, LUT if delayed */ 118 IMAGE *mapped_im; /* Cache image mapped-thru-lut here */ 119 IMAGE *identity_lut; /* For base images, keep an id lut if poss */ 120 Imageinfo *underlying; /* If we're a LUT, the image we are a LUT of */ 121 Imageinfoproxy *proxy; /* Proxy for IMAGE callbacks */ 122 123 gboolean dfile; /* delete_file on final close */ 124 char *delete_filename; /* and the file we delete */ 125 126 gboolean from_file; /* Set if ->name is a user file */ 127 time_t mtime; /* What mtime was when we loaded this file */ 128 129 /* Exprs which are thought to have this image as their value. See 130 * expr_value_new(). 131 */ 132 GSList *exprs; 133 134 /* Set if we've checked with the user that it's OK to paint on this 135 * imageinfo. 136 */ 137 gboolean ok_to_paint; 138 139 /* Undo/redo buffers. 140 */ 141 GSList *undo; /* List of undo buffers */ 142 GSList *redo; /* List of redo buffers */ 143 Undobuffer *cundo; /* Current buffer */ 144 145 /* Have we attached progress stuff to this ii? 146 */ 147 gboolean monitored; 148 149 /* If we're from a file, the timestamp on the file we loaded from ... 150 * used to spot changes. 151 */ 152 time_t check_mtime; 153 guint check_tid; 154 }; 155 156 typedef struct _ImageinfoClass { 157 ManagedClass parent_class; 158 159 /* An area of the screen needs repainting. This can happen for regions 160 * being dragged, for example, and doesn't always mean pixels have 161 * changed. 162 */ 163 void (*area_changed)( Imageinfo *, Rect * ); 164 165 /* An area of the image has been paintboxed ... invalidate caches and 166 * trigger area_changed. 167 */ 168 void (*area_painted)( Imageinfo *, Rect * ); 169 170 /* Our IMAGE* has signaled "invalidate". This can happen indirectly: 171 * if we paint on an image, im_invalidate() will trigger on that image 172 * and all derived images. 173 */ 174 void (*invalidate)( Imageinfo * ); 175 176 /* Update undo/redo button sensitivities. 177 */ 178 void (*undo_changed)( Imageinfo * ); 179 180 /* The underlying file has changed ... higher levels should try to 181 * reload. 182 */ 183 void (*file_changed)( Imageinfo * ); 184 } ImageinfoClass; 185 186 void *imageinfo_area_changed( Imageinfo *imageinfo, Rect *dirty ); 187 void *imageinfo_area_painted( Imageinfo *imageinfo, Rect *dirty ); 188 189 void *imageinfo_expr_remove( Expr *expr, Imageinfo *imageinfo ); 190 void imageinfo_expr_add( Imageinfo *imageinfo, Expr *expr ); 191 GSList *imageinfo_expr_which( Imageinfo *imageinfo ); 192 IMAGE *imageinfo_get_underlying( Imageinfo *imageinfo ); 193 194 GType imageinfo_get_type( void ); 195 Imageinfo *imageinfo_new( Imageinfogroup *imageinfogroup, 196 Heap *heap, IMAGE *im, const char *name ); 197 Imageinfo *imageinfo_new_temp( Imageinfogroup *imageinfogroup, 198 Heap *heap, const char *name, const char *mode ); 199 Imageinfo *imageinfo_new_from_pixbuf( Imageinfogroup *imageinfogroup, 200 Heap *heap, GdkPixbuf *pixbuf ); 201 void imageinfo_set_underlying( Imageinfo *top_imageinfo, Imageinfo *imageinfo ); 202 gboolean imageinfo_is_from_file( Imageinfo *imageinfo ); 203 Imageinfo *imageinfo_new_input( Imageinfogroup *imageinfogroup, 204 GtkWidget *parent, Heap *heap, const char *name ); 205 206 IMAGE *imageinfo_get( gboolean use_lut, Imageinfo *imageinfo ); 207 gboolean imageinfo_same_underlying( Imageinfo *imageinfo[], int n ); 208 209 gboolean imageinfo_write( Imageinfo *imageinfo, const char *filename ); 210 gboolean imageinfo_check_paintable( Imageinfo *imageinfo, 211 GtkWidget *parent, iWindowNotifyFn nfn, void *sys ); 212 213 void imageinfo_note( Symbol *sym, Imageinfo *imageinfo ); 214 void imageinfo_forget( Symbol *sym, Imageinfo *imageinfo ); 215 GSList *imageinfo_which( Imageinfo *im ); 216 217 void imageinfo_make_sub( Imageinfo *out, int n, Imageinfo **in ); 218 void imageinfo_mark( Imageinfo *imageinfo ); 219 220 Imageinfo *imageinfo_sym_image( Symbol *sym ); 221 222 void imageinfo_undo_mark( Imageinfo *imageinfo ); 223 gboolean imageinfo_undo( Imageinfo *imageinfo ); 224 gboolean imageinfo_redo( Imageinfo *imageinfo ); 225 void imageinfo_undo_clear( Imageinfo *imageinfo ); 226 227 gboolean imageinfo_paint_line( Imageinfo *imageinfo, 228 Imageinfo *ink, Imageinfo *mask, 229 int x1, int y1, int x2, int y2 ); 230 gboolean imageinfo_paint_flood( Imageinfo *imageinfo, Imageinfo *ink, 231 int x, int y, gboolean blob ); 232 gboolean imageinfo_paint_smudge( Imageinfo *imageinfo, 233 Rect *oper, int x1, int y1, int x2, int y2 ); 234 gboolean imageinfo_paint_dropper( Imageinfo *imageinfo, Imageinfo *ink, 235 int x, int iy ); 236 gboolean imageinfo_paint_rect( Imageinfo *imageinfo, Imageinfo *ink, 237 Rect *area ); 238 gboolean imageinfo_paint_text( Imageinfo *imageinfo, 239 const char *font_name, const char *text, Rect *tarea ); 240 gboolean imageinfo_paint_nib( Imageinfo *imageinfo, int nib_radius ); 241 gboolean imageinfo_paint_mask( Imageinfo *imageinfo, 242 Imageinfo *ink, Imageinfo *mask, int x, int y ); 243 244 void imageinfo_to_text( Imageinfo *imageinfo, VipsBuf *buf ); 245 gboolean imageinfo_from_text( Imageinfo *imageinfo, const char *text ); 246 void imageinfo_to_rgb( Imageinfo *imageinfo, double *rgb ); 247 void imageinfo_from_rgb( Imageinfo *imageinfo, double *rgb ); 248 void imageinfo_colour_edit( GtkWidget *parent, Imageinfo *imageinfo ); 249 250