iceWing
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Grender.h
Go to the documentation of this file.
1 /* -*- mode: C; tab-width: 4; c-basic-offset: 4; -*- */
2 
3 /*
4  * Author: Frank Loemker
5  *
6  * Copyright (C) 1999-2009
7  * Frank Loemker, Applied Computer Science, Faculty of Technology,
8  * Bielefeld University, Germany
9  *
10  * This file is part of iceWing, a graphical plugin shell.
11  *
12  * iceWing is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * iceWing is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25  */
26 
27 #ifndef iw_Grender_H
28 #define iw_Grender_H
29 
30 #include "Gpreview.h"
31 #include "main/region.h"
32 
33 #define FONT_SMALL 0x01 /* Font to use for displaying text */
34 #define FONT_MED 0x02 /* " */
35 #define FONT_BIG 0x03 /* " */
36 #define FONT_MASK 0x03 /* All bits of the fonts */
37 #define FONT_SHIFT 0x02 /* Number of bits used by the fonts */
38 
39 #define REGION_NONE (1<<FONT_SHIFT) /* Display no text */
40 #define REGION_COM (2<<FONT_SHIFT) /* Display center of mass */
41 #define REGION_PCOUNT (3<<FONT_SHIFT) /* Display pixel count */
42 #define REGION_LENGTH (4<<FONT_SHIFT) /* Display length of polygon */
43 #define REGION_ECCENTRICITY (5<<FONT_SHIFT) /* Display eccentricity */
44 #define REGION_COMPACTNESS (6<<FONT_SHIFT) /* Display compactness */
45 #define REGION_AVGCONF (7<<FONT_SHIFT) /* Display avg. confidenceValue */
46 #define REGION_RATING (8<<FONT_SHIFT) /* Display rating of the region */
47 #define REGION_RAT_KALMAN (9<<FONT_SHIFT) /* Display kalman rating of the region */
48 #define REGION_RAT_MOTION (10<<FONT_SHIFT) /* Display motion rating of the region */
49 #define REGION_ID (11<<FONT_SHIFT) /* Display the ID */
50 #define REGION_MASK 0x3C /* All bits above */
51 
52 #define RENDER_XOR (0x20000000)
53 #define RENDER_THICK (0x40000000) /* Use thickness for line oriented drawings */
54 #define RENDER_CLEAR (0x80000000) /* Clear the buffer and free all old render
55  data (IMPORTANT to prevent mem leaks) */
56 
57 typedef struct {
59  void *data;
60 } prevData;
61 
62 /* ctab : Color table, supported are IW_YUV, IW_RGB, IW_BGR, IW_BW (only r is used),
63  IW_INDEX and any other colortable (r is used as an index into the table)\n
64  r, g, b: Color components,
65  if -1 the corresponding channel is not changed for color images */
66 typedef struct {
68  int r,g,b;
69  int x, y; /* Position of anchor (default left upper edge) of displayed text */
70  char *text; /* The to be displayed text */
71 } prevDataText;
72 
73 typedef struct {
74  iwColtab ctab; /* See prevDataText */
75  int r,g,b;
76  int x1, y1, x2, y2; /* Start / end points */
77 } prevDataLine;
78 
79 typedef struct {
80  iwColtab ctab; /* See prevDataText */
81  int r,g,b;
82  int x1, y1, x2, y2; /* Upper Left / lower right points */
83 } prevDataRect;
84 
85 typedef struct {
86  int x,y;
88 
89 typedef struct {
90  iwColtab ctab; /* See prevDataText */
91  int r,g,b;
92  int npts; /* Number of points in next array */
93  prevDataPoint *pts; /* The points of the polygon */
94 } prevDataPoly;
95 
96 typedef struct {
97  iwColtab ctab; /* See prevDataText */
98  int r,g,b;
99  int x, y; /* Center point */
100  int radius; /* Radius of the circle */
102 
103 typedef struct {
104  iwColtab ctab; /* See prevDataText */
105  int r,g,b;
106  int x, y; /* Center of ellipse */
107  int width, height; /* Major / minor radius of ellipse */
108  int angle; /* Rotation angle in grad */
109  int start, end; /* Start / end angle in grad */
110  gboolean filled;
112 
113 typedef struct {
115  int x, y; /* Position where i should be displayed */
116 } prevDataImage;
117 
118 typedef struct {
119  iwColtab ctab; /* See prevDataText */
120  int r,g,b;
121  float x1, y1, x2, y2; /* Start / end points */
122 } prevDataLineF;
123 
124 typedef struct {
125  iwColtab ctab; /* See prevDataText */
126  int r,g,b;
127  float x1, y1, x2, y2; /* Upper Left / lower right points */
128 } prevDataRectF;
129 
130 typedef struct {
131  float x,y;
133 
134 typedef struct {
135  iwColtab ctab; /* See prevDataText */
136  int r,g,b;
137  int npts; /* Number of points in next array */
138  prevDataPointF *pts; /* The points of the polygon */
139 } prevDataPolyF;
140 
141 typedef struct {
142  iwColtab ctab; /* See prevDataText */
143  int r,g,b;
144  float x, y; /* Center point */
145  float radius; /* Radius of the circle */
147 
148 typedef struct {
149  iwColtab ctab; /* See prevDataText */
150  int r,g,b;
151  float x, y; /* Center of ellipse */
152  float width, height; /* Major / minor radius of ellipse */
153  int angle; /* Rotation angle in grad */
154  int start, end; /* Start / end angle in grad */
155  gboolean filled;
157 
158 #ifdef __cplusplus
159 extern "C" {
160 #endif
161 
162 /*********************************************************************
163  Set color and dest buffer for the primitive drawing functions
164  prev_drawPoint() to prev_drawString(). If a color component is set
165  to -1, the corresponding channel is not changed.
166  prev_drawInitFull(): Return zoom factor.
167 *********************************************************************/
168 void prev_drawInit (prevBuffer *buf, gint r, gint g, gint b);
169 float prev_drawInitFull (prevBuffer *buf, gint r, gint g, gint b, gint disp_mode);
170 
171 /*********************************************************************
172  PRIVATE: Convert from ctab to the rgb color space.
173 *********************************************************************/
174 void prev_colConvert (iwColtab ctab, gint r, gint g, gint b,
175  gint *rd, gint *gd, gint *bd);
176 
177 /*********************************************************************
178  Calls prev_colConvert() and returns a pointer to a static string
179  '#rrggbb'.
180 *********************************************************************/
181 char *prev_colString (iwColtab ctab, gint r, gint g, gint b);
182 
183 /*********************************************************************
184  Set color and buffer for following drawing primitives.
185  Calls prev_drawInitFull() and returns zoom factor.
186 *********************************************************************/
187 float prev_colInit (prevBuffer *buf, int disp_mode, iwColtab model,
188  gint r, gint g, gint b, gint colindex);
189 
190 /*********************************************************************
191  Draw a point/filled rectangle/line/polygon/filled polygon/
192  convex filled polygon/circle/filled cirecle/ellipse in the
193  buffer set with drawInit().
194  .._nc() : No clipping (-> no check of the coordinates).
195  .._gray|color_..(): Assume buffer is gray|color.
196  ATTENTION: Low-Level functions without buffer locking or check for
197  open windows.
198 *********************************************************************/
199 void prev_drawPoint (int x, int y);
200 void prev_drawPoint_gray_nc (int x, int y);
201 void prev_drawPoint_gray_nc_xor (int x, int y);
202 void prev_drawPoint_color_nc (int x, int y);
203 void prev_drawPoint_color_nc_xor (int x, int y);
204 void prev_drawPoint_color_nc_nm (int x, int y);
205 
206 void prev_drawFRect (int x, int y, int width, int height);
207 void prev_drawFRect_gray_nc (int x, int y, int width, int height);
208 void prev_drawFRect_color_nc (int x, int y, int width, int height);
209 
210 void prev_drawLine (int x, int y, int X, int Y);
211 void prev_drawPoly (int npts, const prevDataPoint *pts);
212 void prev_drawFPoly (int npts, const prevDataPoint *pts);
213 void prev_drawConvexPoly (int npts, const prevDataPoint *pts);
214 void prev_drawCircle (int x, int y, int radius);
215 void prev_drawFCircle (int x, int y, int radius);
216 void prev_drawEllipse (int x, int y, int width, int height,
217  int angle, int arc_start, int arc_end, gboolean filled);
218 
219 /*********************************************************************
220  Draw a text at pos (x,y) with font given with prev_drawInitFull() or
221  via the menu appended with prev_opts_append().
222  Differnt in-string formating options and '\n','\t' are supported:
223  Format: <tag1=value tag2="value" tag3> with
224  tag value result
225  < '<' - string
226  anchor tl|tr|br|bl|c (x,y) at topleft,..., center pos of text
227  fg [rgb:|yuv:|bgr:|bw:|index:]r g b forground color
228  bg [rgb:|yuv:|bgr:|bw:|index:]r g b background color
229  font small|med|big font to use
230  adjust left|center|right text adjustment
231  rotate 0|90|180|270 rotate text beginning with the current line
232  shadow 1|0 shadow on/off
233  zoom 1|0 zoom text on/off
234  / return to values before last <>
235  ATTENTION: Low-Level function without buffer locking or check for
236  open windows.
237 *********************************************************************/
238 void prev_drawString (int x, int y, const char *str);
239 
240 /*********************************************************************
241  PRIVATE: Fill gc struct with default values.
242 *********************************************************************/
243 void prev_gc_init (prevGC *gc);
244 
245 /*********************************************************************
246  Fill b with the bg color.
247  ATTENTION: Low-Level function without buffer locking or check for
248  open windows.
249 *********************************************************************/
251 
252 /*********************************************************************
253  Set color which is used for clearing the buffer (RENDER_CLEAR).
254 *********************************************************************/
255 void prev_set_bg_color (prevBuffer *buf, uchar r, uchar g, uchar b);
256 /*********************************************************************
257  Set thickness for line oriented drawings.
258 *********************************************************************/
259 void prev_set_thickness (prevBuffer *buf, int thickness);
260 
261 /*********************************************************************
262  Some random things which must be done before drawing
263  (is already done for all prev_render_...()):
264  - lock the buffer
265  - if RENDER_CLEAR is set:
266  - clear the buffer
267  - free all old render data
268  - store the render size (width,height) in b->gc (if >= 0)
269  Returns TRUE if anything should be done (-> if the window is open).
270 *********************************************************************/
271 gboolean prev_prepare_draw (prevBuffer *b, int disp_mode, int width, int height);
272 
273 /*********************************************************************
274  Draw the data (
275  - one element of type type
276  - a list, length: cnt, size of one element: size, type:type
277  - a set of different elements with cnt elements)
278  in buffer b, such that an area of size width x height fits into the
279  buffer. If width/height < 0 or RENDER_CLEAR is not set, the last
280  values for this buffer b are used. Mode of display disp_mode
281  defined by flags in header file. If no flags are set and option
282  widgets are appended to the window, these widgets are used.
283 *********************************************************************/
284 void prev_render_data (prevBuffer *b, prevType type, const void *data,
285  int disp_mode, int width, int height);
286 void prev_render_list (prevBuffer *b, prevType type, const void *data,
287  int size, int cnt,
288  int disp_mode, int width, int height);
289 void prev_render_set (prevBuffer *b, const prevData *data, int cnt,
290  int disp_mode, int width, int height);
291 
292 /*********************************************************************
293  Wrapper around prev_render_list().
294  _texts(): Formating options of prev_drawString() are supported.
295 *********************************************************************/
296 void prev_render_texts (prevBuffer *b, const prevDataText *texts, int cnt,
297  int disp_mode, int width, int height);
298 void prev_render_lines (prevBuffer *b, const prevDataLine *lines, int cnt,
299  int disp_mode, int width, int height);
300 void prev_render_rects (prevBuffer *b, const prevDataRect *rects, int cnt,
301  int disp_mode, int width, int height);
302 void prev_render_frects (prevBuffer *b, const prevDataRect *frects, int cnt,
303  int disp_mode, int width, int height);
304 void prev_render_polys (prevBuffer *b, const prevDataPoly *polys, int cnt,
305  int disp_mode, int width, int height);
306 void prev_render_fpolys (prevBuffer *b, const prevDataPoly *polys, int cnt,
307  int disp_mode, int width, int height);
308 void prev_render_circles (prevBuffer *b, const prevDataCircle *circ, int cnt,
309  int disp_mode, int width, int height);
310 void prev_render_fcircles (prevBuffer *b, const prevDataCircle *circ, int cnt,
311  int disp_mode, int width, int height);
312 void prev_render_ellipses (prevBuffer *b, const prevDataEllipse *ellipse, int cnt,
313  int disp_mode, int width, int height);
314 void prev_render_regions (prevBuffer *b, const iwRegion *regions, int cnt,
315  int disp_mode, int width, int height);
316 void prev_render_COMinfos (prevBuffer *b, const iwRegCOMinfo *regions, int cnt,
317  int disp_mode, int width, int height);
318 void prev_render_imgs (prevBuffer *b, const prevDataImage *imgs, int cnt,
319  int disp_mode, int width, int height);
320 
321 /*********************************************************************
322  Render planes of size width x height and color mode/table ctab
323  (IW_YUV, IW_RGB, ..., or an own table) in preview window b.
324 *********************************************************************/
325 void prev_render (prevBuffer *b, guchar **planes, int width, int height, iwColtab ctab);
326 
327 /*********************************************************************
328  Render the img src (size: w x h) in buffer b by using the function
329  dest = src * col_step % 256.
330  If col_step > 255 it is interpreted as a color table for rendering
331  the dest image (and a col_Step of 1 is used).
332 *********************************************************************/
333 void prev_render_int (prevBuffer *b, const gint32 *src, int w, int h, long col_step);
334 
335 /*********************************************************************
336  Render str in b at position (x,y). Printf style arguments and the
337  formating options of prev_drawString() are supported.
338 *********************************************************************/
339 void prev_render_text (prevBuffer *b, int disp_mode, int width, int height,
340  int x, int y, const char *format, ...) G_GNUC_PRINTF(7, 8);
341 
342 /*********************************************************************
343  PRIVATE: Called from prev_init() to initialise the render functions.
344 *********************************************************************/
345 void prev_render_init (void);
346 
347 #ifdef __cplusplus
348 }
349 #endif
350 
351 #endif /* iw_Grender_H */