From: hackbard Date: Wed, 6 Nov 2002 23:33:40 +0000 (+0000) Subject: improved webcam.c X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=041c97e2ca46c5cb594123faf5b124b34993d83b;p=my-code%2Fivac.git improved webcam.c --- diff --git a/Makefile b/Makefile index 0924a8b..2c4f89a 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,9 @@ INCLUDEDIR = /usr/include -CFLAGS = -DDEBUG -O3 -Wall +CFLAGS = -DDEBUG -O3 -Wall -I/usr/X11/include -L/usr/X11/lib -lX11 -OBJS = stream receive datagram dgramrcv +OBJS = stream receive datagram dgramrcv webcam all: $(OBJS) diff --git a/webcam.c b/webcam.c index 3c5e7a8..7b4be7e 100644 --- a/webcam.c +++ b/webcam.c @@ -5,30 +5,68 @@ * */ -include -include -include - -include - -include "minirgb.h" +/* includes */ +#include +#include +#include +#include +#include +#include "minirgb.h" +/* variables */ Display *display; +/* main routine */ int main(int argc,char **argv) { - XEvent xevent; - char *image, *device=VIDEO_DEV; + /* local variables */ + int screen_id,screen_width,screen_height; + Window root_window,win; + unsigned long white_pixel,black_pixel; - display=XOpenDisplay(NULL); - if(!display) { - printf("cannot open display\n"); - exit(1); + /* opening display */ + display=XOpenDisplay(NULL); /* connect on local display :0 */ + if(display==NULL) { + printf("cannot connect to xserver!\n"); + exit(EXIT_FAILURE); } - if (minirg_init(display)) { - printf("minirg init process failed\n"); - exit(1); - } + /* getting basic xserver information */ + // our screen id + screen_id=DefaultScreen(display); + // dimensions of screen + screen_width=DisplayWidth(display,screen_id); + screen_height=DisplayHeight(display,screen_id); + // how to draw white/black pixels */ + white_pixel=WhitePixel(display,screen_id); + black_pixel=BlackPixel(display,screen_id); + // the screen's root window id + root_window=RootWindow(display,screen_id); + + /* print basic xserver settings */ + printf("screen ID: %d\n",screen_id); + printf("dimensions: %d x %d\n",screen_width,screen_height); + printf("white color -> %d\n",white_pixel); + printf("black color -> %d\n",black_pixel); + /* open a window */ + win=XCreateSimpleWindow(display, + root_window, + 0,0, // coordinates + screen_width/3,screen_height/3, + 500,black_pixel,white_pixel); + /* map the window */ + XMapWindow(display,win); + + /* flush */ + XFlush(display); + + /* wait a bit */ + sleep(5); + printf("blabla ....\n"); + + /* close display */ + XCloseDisplay(display); + +}