Exemplo n.º 1
0
void redraw(void (*drawfunc)(Screencell*,unsigned int,unsigned int),bool copyover,bool forceredraw){
	unsigned int scrwidth,scrheight;
	tie(scrwidth,scrheight)=IO::screensize();
	const bool validprev=prevscreen&&scrwidth==prevwidth&&scrheight==prevheight;
	Screencell *newscreen=new Screencell[scrwidth*scrheight];
	//cerr<<"redraw: validprev="<<validprev<<" copyover="<<copyover<<" prevscreen?="<<!!prevscreen<<endl;
	if(copyover&&validprev)
		memcpy(newscreen,prevscreen,scrwidth*scrheight*sizeof(Screencell));
	drawfunc(newscreen,scrwidth,scrheight);
	if(!validprev||forceredraw){
		copytoscreen(newscreen,scrwidth,0,0,scrwidth,scrheight);
		if(prevscreen)delete[] prevscreen;
		prevwidth=scrwidth;
		prevheight=scrheight;
		prevscreen=new Screencell[scrwidth*scrheight];
		assert(prevscreen);
		memcpy(prevscreen,newscreen,scrwidth*scrheight*sizeof(Screencell));
	} else {
		unsigned int x,y;
		for(y=0;y<scrheight;y++){
			for(x=0;x<scrwidth;x++){
				if(prevscreen[scrwidth*y+x]!=newscreen[scrwidth*y+x])break;
			}
			if(x<scrwidth){
				//cerr<<"refreshing line "<<y<<" (diff at x="<<x<<')'<<endl;
				copylinetoscreen(newscreen,scrwidth,0,y,scrwidth);
			}
		}
		memcpy(prevscreen,newscreen,scrwidth*scrheight*sizeof(Screencell));
	}
	gotoFrontBufferCursor();
	cout.flush();
}
Exemplo n.º 2
0
int main(int argc, char** argv)
{
    if(argc == 2) {
        strcpy(my_video_dev, argv[1]);
    } else {
        strcpy(my_video_dev, "/dev/video0");
    }
   
   //if (-1 == (fd = open(my_video_dev, O_RDWR))) {
   if (-1 == (fd = v4l1_open(my_video_dev, O_RDWR))) {
	printf("Error opening device: %s\n", my_video_dev);
	goto error;
   }





    //if( -1 == ioctl(fd, VIDIOC_QUERYCAP, &v4l2_capability) ) {
    if( ioctl(fd, VIDIOC_QUERYCAP, &v4l2_capability) < 0 ) {
        printf("asd  1\n");
        if( -1 == ioctl(fd, VIDIOCGCAP, &capability) ) {
        printf("asd  2\n");
            printf("Error1: ioctl(fd,VIDIOCGCAP,&capability)\n");
            camDriver = DRIVER_NONE;
            goto error;
        } else {
        printf("asd  3\n");
            camDriver = DRIVER_V4L;
        }
    } else {
        printf("asd  4\n");
        camDriver = DRIVER_V4L2;

        v4l1_close(fd);
        fd = v4l1_open(my_video_dev, O_RDWR);

        if( -1 == my_ioctl(VIDIOCGCAP, &capability)) {
        printf("asd  5\n");
            printf("Error2: ioctl(fd,VIDIOCGCAP,&capability)\n");
            goto error;
        }
    }


//    if( DRIVER_V4L == camDriver ) {

        printf("\n -----[  VIDIOCGCAP returns ]-----\n");
        printf(" name:      %s\n", capability.name);
        printf(" type:      %i\n", capability.type);
        printf(" channels:  %i\n", capability.channels);
        printf(" audios:    %i\n", capability.audios);
        printf(" maxwidth:  %i\n", capability.maxwidth);
        printf(" maxheight: %i\n", capability.maxheight);
        printf(" minwidth:  %i\n", capability.minwidth);
        printf(" minheight: %i\n", capability.minheight);

//    }


   if (-1 == my_ioctl(VIDIOCGPICT,&picture)) {
        printf("Error: ioctl(fd,VIDIOCGCPICT,&picture)\n");
        goto error;
   }

	printf("\n -----[  VIDIOCGPICT returns ]-----\n");
	printf(" brightness: %i\n", picture.brightness);
	printf(" hue:        %i\n", picture.hue);
	printf(" colour:     %i\n", picture.colour);
	printf(" contrast:   %i\n", picture.contrast);
	printf(" whiteness:  %i\n", picture.whiteness);
	printf(" depth:      %i\n", picture.depth);

	char static palet_tipi_str[64];
	palette_name(palet_tipi_str, picture.palette);
	printf(" palette:    %s\n\n", palet_tipi_str);


	

   vch.channel = 0;
   // vch.norm = VIDEO_MODE_PAL;
   
   if(-1 == my_ioctl(VIDIOCSCHAN,&vch)) {
        perror("Setting channel\n");
	goto error;
   }
   
   fcntl(fd,F_SETFD,FD_CLOEXEC);
   if (-1 == my_ioctl(VIDIOCGMBUF,&gb_buffers)) {
	printf("Error: Error getting buffers\n");
	goto error;
   }

   map = my_mmap(0,gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); 
   if (map == NULL) {
	printf("Error: Mmap returned NULL\n");
	goto error;
   }

   // Set up out capture to use the correct resolution
   
   my_buf.width = mywidth;
   my_buf.height = myheight;
   my_buf.format = VIDEO_PALETTE_RGB24;

   // Set up out video output

   SDL_Init(SDL_INIT_VIDEO);
   screen = SDL_SetVideoMode(mywidth, myheight, 24, SDL_SWSURFACE);
   if ( screen == NULL ) {
	fprintf(stderr, "Couldn't set video mode: %s\n",
	SDL_GetError());
	exit(1);
   }
   SDL_WM_SetCaption("Oy oy oy teve pirogrami", NULL);

   // Tell the capture card to fill frame 0
   
   my_buf.frame = 0;
   if (-1 == my_ioctl(VIDIOCMCAPTURE, &my_buf)) { 
	printf(" ilk my_buf.frame=0 da hata olustu\n");
	// printf("Error: Grabber chip can't sync (no station tuned in?)\n"); 
	goto error;
   }

   // This is the infinate loop
   // We basically:
   //	capture frame 1
   //   sync frame 0
   //   process frame 0
   //	capture frame 0 
   //   sync frame 1
   //   process frame 1
   // For more information, read the programming how-to that came with xawtv
   
   do {

	my_buf.frame = 1;
	if (-1 == my_ioctl(VIDIOCMCAPTURE, &my_buf)) {
		printf(" loop icinde frame=1 \n");
		// printf("Error: Grabber chip can't sync (no station tuned in?)\n"); 
		goto error;
	}
 
	my_buf.frame = 0;
	if (-1 == my_ioctl(VIDIOCSYNC, &my_buf.frame)) {
		 printf("Error on sync!\n"); 
		goto error;
	}

	copytoscreen(map);

	my_buf.frame = 0;
	if (-1 == my_ioctl(VIDIOCMCAPTURE, &my_buf)) {
		printf(" loop icinde frame=0 \n");
		// printf("Error: Grabber chip can't sync (no station tuned in?)\n"); 
		goto error;
	}

	my_buf.frame = 1;
	if (-1 == my_ioctl(VIDIOCSYNC, &my_buf.frame)) {
		printf("Error on sync!\n"); 
		goto error;
	}

	copytoscreen(map + gb_buffers.offsets[1]);
	SDL_PollEvent(&event);
   } while (event.type != SDL_KEYDOWN);

   error:

	SDL_Quit();
   	return EXIT_SUCCESS;

}