-
[my-code/ivac.git] / webcam.c
1 /*
2  * webcam.c - fetch data from webcam and display
3  *
4  * author: hackbard
5  *
6  */
7
8 /* includes */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include <X11/Xlib.h>
14 #include <X11/Xutil.h>
15 #include <X11/xpm.h>
16 #include <X11/extensions/shape.h>
17 #include "minirgb.h"
18 // #include "images/ivac-logo.xpm"
19 // #include "images/ivac-logo.h"
20 #include "images/example_orig.xbm"
21
22 /* defines */
23 #define XBM_WIDTH 256
24 #define XBM_REAL_WIDTH 512
25 #define XBM_HEIGHT 256
26 // #define ivac_logo pixel_data
27 #define ivac_logo example_bits
28
29 /* global variables */
30 Display *display;
31 Window ivac_win,icon_win;
32 GC my_gc;
33 MiniRGB rgb1,rgb2;
34
35
36 void open_window(char *name,char *ivac_mask) {
37
38  /* local variables */
39  int screen,width,height;
40  Window root_win;
41  XSizeHints my_size_hints;
42  XClassHint my_class_hints;
43  Pixel black,white;
44  XGCValues my_gc_val;
45  Pixmap pixmap_mask;
46  XWMHints my_wm_hints;
47  
48
49  screen=DefaultScreen(display);
50  root_win=DefaultRootWindow(display);
51  
52  width=XBM_WIDTH; /* DisplayWidth(display,screen)/5; */
53  height=XBM_HEIGHT; /* DisplayHeight(diplay,screen)/5; */
54  my_size_hints.flags=USSize;
55  my_size_hints.width=width;
56  my_size_hints.height=height;
57
58  my_class_hints.res_name=name;
59  my_class_hints.res_class=name;
60
61  black=BlackPixel(display,screen);
62  white=WhitePixel(display,screen);
63
64  /* create window */
65  ivac_win=XCreateSimpleWindow(display,root_win,0,0,
66                                 my_size_hints.width,
67                                 my_size_hints.height,
68                                 1,black,white);
69  icon_win=XCreateSimpleWindow(display,ivac_win,0,0,
70                                 my_size_hints.width,
71                                 my_size_hints.height,
72                                 1,black,white);
73
74  /* set wm and class hints */
75  XSetWMNormalHints(display,ivac_win,&my_size_hints);
76  XSetClassHint(display,ivac_win,&my_class_hints);
77
78  /* select event input - what are we listening to? */
79  XSelectInput(display,ivac_win,
80                 ExposureMask | ButtonPressMask | ButtonReleaseMask |
81                 StructureNotifyMask);
82  XSelectInput(display,icon_win,
83                 ExposureMask | ButtonPressMask | ButtonReleaseMask |
84                 StructureNotifyMask);
85
86  /* set names for windows */
87  XStoreName(display,ivac_win,name);
88  XSetIconName(display,ivac_win,name);
89
90  /* graphics context values */
91  my_gc_val.foreground=black;
92  my_gc_val.background=white;
93  my_gc_val.graphics_exposures=False;
94  
95  /* set graphics context */
96  my_gc=XCreateGC(display,ivac_win,
97                 GCForeground | GCBackground | GCGraphicsExposures,
98                 &my_gc_val);
99
100  /* create pixmap mask and shape windows */
101  pixmap_mask=XCreateBitmapFromData(display,ivac_win,ivac_mask,
102                                         XBM_WIDTH,XBM_HEIGHT);
103  XShapeCombineMask(display,ivac_win,ShapeBounding,0,0,pixmap_mask,ShapeSet);
104  XShapeCombineMask(display,icon_win,ShapeBounding,0,0,pixmap_mask,ShapeSet);
105
106  /* define and set wmhints */
107  my_wm_hints.initial_state=WithdrawnState;
108  my_wm_hints.flags=StateHint;
109  my_wm_hints.icon_window=icon_win;
110  my_wm_hints.icon_x=my_size_hints.x;
111  my_wm_hints.icon_y=my_size_hints.y;
112  my_wm_hints.window_group=ivac_win;
113  my_wm_hints.flags =
114         StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
115  // XSetWMHints(display,ivac_win,&my_wm_hints);
116
117  /* finaly ... map that stuff ;) */
118  XMapWindow(display,ivac_win);
119
120 }
121
122
123 /* main routine */
124 int main(int argc,char **argv) {
125
126  /* local variables */
127  XEvent xevent;
128
129
130  /* opening display */
131  display=XOpenDisplay(NULL); /* connect on local display :0 */
132  if(display==NULL) {
133   printf("cannot connect to xserver!\n");
134   exit(EXIT_FAILURE);
135  }
136  
137  /* minirgb initialization */
138  if (minirgb_init(display)) {
139   printf("minirgb initialization failed!\n");
140   exit(1);
141  }
142
143  open_window(argv[0],(char *)ivac_logo);
144  minirgb_new(&rgb1,XBM_WIDTH,XBM_HEIGHT);
145  minirgb_new(&rgb2,XBM_WIDTH,XBM_HEIGHT);
146  minirgb_copy(&rgb2,&rgb1,0,0,XBM_WIDTH,XBM_HEIGHT,0,0);
147
148  /* to be continued ... here is a test! */
149  XFlush(display);
150  sleep(10);
151  printf("blaaaa, schmaeee\n");
152  XCloseDisplay(display);
153  return 0;
154
155 }