void CameraClose(int cameraNum) { if (-1 == fd) return; stream_off(); uninit_device(); close_device(); }
int camera_work() { cam_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (cam_window), 0); gtk_window_set_title (GTK_WINDOW (cam_window), "Camera"); gtk_window_set_position(GTK_WINDOW(cam_window), GTK_WIN_POS_CENTER); gtk_widget_set_size_request(cam_window, preview_width, preview_height + 40 + 30); g_signal_connect (G_OBJECT (cam_window), "delete_event", G_CALLBACK (delete_event), NULL); layout = gtk_fixed_new (); gtk_widget_set_size_request(layout, preview_width, preview_height + 40 + 30); gtk_container_add(GTK_CONTAINER(cam_window), layout); image_face = gtk_drawing_area_new (); gtk_widget_set_size_request(image_face, preview_width, preview_height); gtk_fixed_put(GTK_FIXED(layout), image_face, 0, 0); ok_btn = gtk_button_new_with_label("OK"); gtk_widget_set_size_request(ok_btn, 50, 30); gtk_fixed_put(GTK_FIXED(layout), ok_btn, preview_width - 20 - 20 - 50 * 2, preview_height + 20); g_signal_connect (G_OBJECT (ok_btn), "clicked", G_CALLBACK (ok_btn_cb), cam_window); ng_btn = gtk_button_new_with_label("NG"); gtk_widget_set_size_request(ng_btn, 50, 30); gtk_fixed_put(GTK_FIXED(layout), ng_btn, preview_width - 50 - 20, preview_height + 20); g_signal_connect (G_OBJECT (ng_btn), "clicked", G_CALLBACK (ng_btn_cb), cam_window); gtk_widget_show_all(cam_window); open_device(); init_device(); stream_on(); // defined in color.h, and used to pixel format changing initLut(); timeId = g_timeout_add(1000/FPS, show_camera, NULL); gtk_main (); freeLut(); stream_off(); mem_unmap_and_close_dev(); return 0; }
int main (int argc,char *argv[]) { int videofd1 = open("/dev/video0",O_RDWR); int videofd2 = open("/dev/video0",O_RDWR); IDirectFBSurface *SurfaceHandle; IDirectFBSurface *SurfaceHandle2; void *ptr,*ptr2; int pitch,pitch2; int colour_palette[256]; int colour_palette2_real[256]; /* random... */ int *colour_palette2 = colour_palette2_real; int is_lut8; is_lut8 = (argc > 1 && !strcmp (argv[1], "both")); memset(&colour_palette,0x0,4*256); //memset(&colour_palette[1],0xff,255*4); colour_palette[0] = 0xff000000; // black colour_palette[1] = 0xffff0000; // red colour_palette[2] = 0xff00ff00; // green colour_palette[3] = 0xff0000ff; // blue colour_palette[4] = 0xffffffff; // white colour_palette[5] = 0x80808000; // half-transp yellow colour_palette[6] = 0x00000000; // transp black if (videofd1 < 0) perror("Couldn't open video device 1\n"); if (videofd2 < 0) perror("Couldn't open video device 2\n"); v4l2_list_outputs (videofd1); fb_make_transparent(); init_dfb(&SurfaceHandle,is_lut8); init_dfb(&SurfaceHandle2,1); v4l2_set_output_by_name (videofd1, "RGB1"); v4l2_set_output_by_name (videofd2, "RGB2"); init_v4l(videofd1,0,0,1280,720,is_lut8); init_v4l(videofd2,0,0,1280,720,1); printf("%s:%d\n",__FUNCTION__,__LINE__); // memcpy (colour_palette, colour_palette2, sizeof (colour_palette)); colour_palette2 = colour_palette; { int coords = 60; int size = 100; // clear if (!is_lut8) SurfaceHandle->Clear (SurfaceHandle, 0x00, 0x00, 0x00, 0x00); else { SurfaceHandle->SetColorIndex (SurfaceHandle, 0x6); SurfaceHandle->FillRectangle (SurfaceHandle, 0, 0, 600, 600); } // White if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x4); else SurfaceHandle->SetColor (SurfaceHandle, 0xff, 0xff, 0xff, 0xff); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; // Red if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x1); else SurfaceHandle->SetColor (SurfaceHandle, 0xff, 0x00, 0x00, 0xff); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; // Green if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x2); else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0xff, 0x00, 0xff); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; // Blue if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x3); else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0x00, 0xff, 0xff); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; // half transp yellow if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x5); else SurfaceHandle->SetColor (SurfaceHandle, 0x80, 0x80, 0x00, 0x80); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; // transp if (is_lut8) SurfaceHandle->SetColorIndex (SurfaceHandle, 0x6); else SurfaceHandle->SetColor (SurfaceHandle, 0x00, 0x00, 0x00, 0x00); SurfaceHandle->FillRectangle (SurfaceHandle, coords, coords, size, size); coords += size; } { int xcoords = 60 + (100 * 6), ycoords = 60; int size = 100; // clear SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x6); SurfaceHandle2->FillRectangle (SurfaceHandle2, 220, 220, 440, 440); // transp SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x6); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; // half transp yellow SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x5); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; // Blue SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x3); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; // Green SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x2); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; // Red SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x1); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; // White SurfaceHandle2->SetColorIndex (SurfaceHandle2, 0x4); SurfaceHandle2->FillRectangle (SurfaceHandle2, xcoords, ycoords, size, size); xcoords -= size; ycoords += size; } DFBCHECK (SurfaceHandle->Lock (SurfaceHandle, DSLF_READ, &ptr, &pitch)); DFBCHECK (SurfaceHandle2->Lock (SurfaceHandle2, DSLF_READ, &ptr2, &pitch2)); printf("%s:%d\n",__FUNCTION__,__LINE__); zorder(videofd2,V4L2_CID_STM_Z_ORDER_RGB2,1); zorder(videofd1,V4L2_CID_STM_Z_ORDER_RGB1,2); queue_buffer( videofd1, ptr, (is_lut8 ? colour_palette : 0), 0ULL); stream_on( videofd1 ); getchar(); queue_buffer( videofd2, ptr2, colour_palette2, 0ULL); printf("%s:%d\n",__FUNCTION__,__LINE__); stream_on( videofd2 ); printf("%s:%d\n",__FUNCTION__,__LINE__); getchar(); zorder(videofd2,V4L2_CID_STM_Z_ORDER_RGB2,2); zorder(videofd1,V4L2_CID_STM_Z_ORDER_RGB1,1); fprintf(stderr,"Press Return/Enter to quit\n"); getchar(); // This seems to dequeue all buffers too, but that's what the spec says // so this is ok. stream_off( videofd1 ); stream_off( videofd2 ); deinit_dfb(); close(videofd1); return 0; }
V4L2UpscaledInputAdapter::~V4L2UpscaledInputAdapter( ) { stream_off( ); cleanup_frame_buffers( ); close(fd); }