1 /* Header for the .desc file parser in vips_global_balance()
2  *
3  * 1/11/01 JC
4  *	- cut from global_balance.c
5  */
6 
7 /*
8 
9     This file is part of VIPS.
10 
11     VIPS is free software; you can redistribute it and/or modify
12     it under the terms of the GNU Lesser General Public License as published by
13     the Free Software Foundation; either version 2 of the License, or
14     (at your option) any later version.
15 
16     This program is distributed in the hope that it will be useful,
17     but WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19     GNU Lesser General Public License for more details.
20 
21     You should have received a copy of the GNU Lesser General Public License
22     along with this program; if not, write to the Free Software
23     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24     02110-1301  USA
25 
26  */
27 
28 /*
29 
30     These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
31 
32  */
33 
34 /* Number of entries in spine of file name hash table.
35  */
36 #define SYM_TAB_SIZE (113)
37 
38 typedef enum _JoinType JoinType;
39 typedef struct _OverlapInfo OverlapInfo;
40 typedef struct _JoinNode JoinNode;
41 typedef struct _SymbolTable SymbolTable;
42 
43 /* Type of a transform function.
44  */
45 typedef VipsImage *(*transform_fn)( JoinNode *, void * );
46 
47 /* Join type.
48  */
49 enum _JoinType {
50 	JOIN_LR,		/* vips__lrmerge join */
51 	JOIN_TB,		/* vips__tbmerge join */
52 	JOIN_LRROTSCALE,	/* 1st oder lrmerge */
53 	JOIN_TBROTSCALE,	/* 1st oder tbmerge */
54 	JOIN_CP,		/* vips_copy operation */
55 	JOIN_LEAF		/* Base file */
56 };
57 
58 /* An overlap struct. Attach a list of these to each leaf, one for each of
59  * the other leaves we touch.
60  */
61 struct _OverlapInfo {
62 	JoinNode *node;		/* The base node - we are on this list */
63 	JoinNode *other;	/* Node we overlap with */
64 	VipsRect overlap;		/* The overlap area */
65 	VipsImage *nstats;	/* Node's stats for overlap area */
66 	VipsImage *ostats;	/* Other's stats for overlap area */
67 };
68 
69 /* Struct for a join node.
70  */
71 struct _JoinNode {
72 	char *name;		/* This file name */
73 	JoinType type;		/* What kind of join */
74 	SymbolTable *st;	/* Symbol table we are on */
75 	int dirty;		/* Used for circularity detection */
76 
77 	/* Params from join line in .desc file.
78 	 */
79 	double a, b;
80 	double dx, dy;
81 	int mwidth;
82 
83 	/* Cumulative transform for this node. What our parents do to us.
84 	 * cumtrn.area is position and size of us, thistrn.area is pos and
85 	 * size of arg2.
86 	 */
87 	VipsTransformation cumtrn;
88 
89 	/* X-tras for LR/TB. thistrn is what we do to arg2.
90 	 */
91 	JoinNode *arg1;		/* Left or up thing to join */
92 	JoinNode *arg2;		/* Right or down thing to join */
93 	VipsTransformation thistrn;	/* Transformation for arg2 */
94 
95 	/* Special for leaves: all the join_nodes we overlap with, the
96 	 * VipsImage for that file, and the index.
97 	 */
98 	GSList *overlaps;
99 	VipsImage *im;
100 	VipsImage *trnim;		/* Transformed image .. used in 2nd pass */
101 	int index;
102 };
103 
104 /* We need to keep a table of JoinNode, indexed by file name. Hash into one
105  * of these from the name to get a pointer to the base of a list of JoinNode
106  * which hash to that offset.
107  */
108 struct _SymbolTable {
109 	GSList **table;		/* Ptr to base of hash table */
110 	int sz;			/* Size of hash table */
111 	VipsImage *im;		/* Malloc relative to this */
112 
113 	int novl;		/* Number of unique overlaps */
114 	int nim;		/* Number of leaf images */
115 	int njoin;		/* Number of join nodes */
116 
117 	JoinNode *root;		/* Root of join tree */
118 	JoinNode *leaf;		/* Leaf nominated to be 1.000 */
119 	double *fac;		/* Correction factors */
120 };
121 
122 VipsImage *vips__global_open_image( SymbolTable *st, char *name );
123 SymbolTable *vips__build_symtab( VipsImage *out, int sz );
124 int vips__parse_desc( SymbolTable *st, VipsImage *in );
125 void *vips__map_table( SymbolTable *st, VipsSListMap2Fn fn, void *a, void *b );
126 int vips__build_mosaic( SymbolTable *st,
127 	VipsImage *out, transform_fn tfn, void *a );
128