⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tools.c

📁 Coriander is a GUI for controlling a Digital Camera (in the sense of the IIDC specs issued by the 1
💻 C
📖 第 1 页 / 共 3 页
字号:
  }    if (was_on>0) {    if (dc1394_get_iso_status(camera->camera_info.handle, camera->camera_info.id,&camera->misc_info.is_iso_on)!=DC1394_SUCCESS)      MainError("Could not get ISO status");    else {      if (!camera->misc_info.is_iso_on) {	MainError("ISO could not be restarted. Trying again for 5 seconds");	timeout=0;	while ((!camera->misc_info.is_iso_on)&&(timeout<5000)) {	  usleep(DELAY);	  timeout+=DELAY/1000;	  if (dc1394_start_iso_transmission(camera->camera_info.handle, camera->camera_info.id)!=DC1394_SUCCESS)	    // ... (if not done, restarting is no more possible)	    MainError("Could not start ISO transmission");	  else {	    if (dc1394_get_iso_status(camera->camera_info.handle, camera->camera_info.id,&camera->misc_info.is_iso_on)!=DC1394_SUCCESS)	      MainError("Could not get ISO status");	  }	}	if (!camera->misc_info.is_iso_on)	  MainError("Can't start ISO, giving up...");      }    }    UpdateIsoFrame();  }}void GetContextStatus(){  ctxt.model_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"camera_model_status"),"");  ctxt.vendor_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"camera_vendor_status"),"");  ctxt.handle_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"camera_handle_status"),"");  ctxt.node_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"camera_node_status"),"");  ctxt.guid_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"camera_guid_status"),"");  ctxt.max_iso_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"camera_maxiso_status"),"");  ctxt.delay_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"camera_delay_status"),"");  ctxt.dc_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"camera_dc_status"),"");  ctxt.pwclass_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"camera_pwclass_status"),"");  ctxt.iso_channel_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"iso_channel_status"),"");  // init message ids.  ctxt.model_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"camera_model_status"), ctxt.model_ctxt, "");  ctxt.vendor_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"camera_vendor_status"), ctxt.vendor_ctxt, "");  ctxt.handle_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"camera_handle_status"), ctxt.handle_ctxt, "");  ctxt.node_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"camera_node_status"), ctxt.node_ctxt, "");  ctxt.guid_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"camera_guid_status"), ctxt.guid_ctxt, "");  ctxt.max_iso_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"camera_maxiso_status"), ctxt.max_iso_ctxt, "");  ctxt.delay_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"camera_delay_status"), ctxt.delay_ctxt, "");  ctxt.dc_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"camera_dc_status"), ctxt.dc_ctxt, "");  ctxt.pwclass_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"camera_pwclass_status"), ctxt.pwclass_ctxt, "");  ctxt.iso_channel_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"iso_channel_status"), ctxt.iso_channel_ctxt, "");  // note: these empty messages will be replaced after the execution of update_frame for status window  ctxt.cursor_pos_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"cursor_pos"),"");  ctxt.cursor_rgb_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"cursor_rgb"),"");  ctxt.cursor_yuv_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"cursor_yuv"),"");  ctxt.cursor_pos_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"cursor_pos"), ctxt.cursor_pos_ctxt, "");  ctxt.cursor_rgb_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"cursor_rgb"), ctxt.cursor_rgb_ctxt, "");  ctxt.cursor_yuv_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"cursor_yuv"), ctxt.cursor_yuv_ctxt, "");  // FPS:  ctxt.fps_receive_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"fps_receive"),"");  ctxt.fps_display_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"fps_display"),"");  ctxt.fps_save_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"fps_save"),"");  ctxt.fps_ftp_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"fps_ftp"),"");  ctxt.fps_v4l_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"fps_v4l"),"");  ctxt.fps_receive_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"fps_receive"), ctxt.fps_receive_ctxt, "");  ctxt.fps_display_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"fps_display"), ctxt.fps_display_ctxt, "");  ctxt.fps_save_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"fps_save"), ctxt.fps_save_ctxt, "");  ctxt.fps_ftp_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"fps_ftp"), ctxt.fps_ftp_ctxt, "");  ctxt.fps_v4l_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"fps_v4l"), ctxt.fps_v4l_ctxt, "");  // format7:  ctxt.format7_imagebytes_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"format7_imagebytes"),"");  ctxt.format7_totalbytes_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"format7_totalbytes"),"");  ctxt.format7_padding_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"format7_padding"),"");  ctxt.format7_imagepixels_ctxt=gtk_statusbar_get_context_id( (GtkStatusbar*) lookup_widget(main_window,"format7_imagepixels"),"");  ctxt.format7_imagebytes_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"format7_imagebytes"), ctxt.format7_imagebytes_ctxt, "");  ctxt.format7_imagepixels_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"format7_imagepixels"), ctxt.format7_imagepixels_ctxt, "");  ctxt.format7_totalbytes_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"format7_totalbytes"), ctxt.format7_totalbytes_ctxt, "");  ctxt.format7_padding_id=gtk_statusbar_push( (GtkStatusbar*) lookup_widget(main_window,"format7_padding"), ctxt.format7_padding_ctxt, "");}void GrabSelfIds(raw1394handle_t* handles, int portmax){   RAW1394topologyMap *topomap;  SelfIdPacket_t packet;  unsigned int* pselfid_int;  int i, port;  camera_t* camera_ptr;  for (port=0;port<portmax;port++) {    if (handles[port]!=0) {      // get and decode SelfIds.      topomap=raw1394GetTopologyMap(handles[port]);            for (i=0;i<topomap->selfIdCount;i++) {	pselfid_int = (unsigned int *) &topomap->selfIdPacket[i];	decode_selfid(&packet,pselfid_int);	// find the camera related to this packet:		camera_ptr=cameras;	while (camera_ptr!=NULL) {	  if (camera_ptr->camera_info.id==packet.packetZero.phyID) {	    camera_ptr->selfid=packet;	  }	  camera_ptr=camera_ptr->next;	}      }    }  } }voidSetChannels(void){  unsigned int channel, speed;  camera_t* camera_ptr;  camera_ptr=cameras;  while(camera_ptr!=NULL) {    if (dc1394_get_iso_channel_and_speed(camera_ptr->camera_info.handle, camera_ptr->camera_info.id, &channel, &speed)!=DC1394_SUCCESS)      MainError("Can't get iso channel and speed");    if (dc1394_set_iso_channel_and_speed(camera_ptr->camera_info.handle, camera_ptr->camera_info.id, camera_ptr->camera_info.id, speed)!=DC1394_SUCCESS)      MainError("Can't set iso channel and speed");    camera_ptr=camera_ptr->next;  }}void MainError(const char *string){  char *temp;  temp=(char*)malloc(STRING_SIZE*sizeof(char));  sprintf(temp,"ERROR: %s\n",string);  if (main_window !=NULL) {    gtk_text_insert((GtkText*)lookup_widget(main_window,"main_status"), NULL,NULL,NULL,temp,-1);  }  free(temp);}void MainStatus(const char *string){  char *temp;  temp=(char*)malloc(STRING_SIZE*sizeof(char));  sprintf(temp,"%s\n",string);  if (main_window !=NULL) {    gtk_text_insert((GtkText*)lookup_widget(main_window,"main_status"), NULL,NULL,NULL,temp,-1);  }  free(temp);}static void MessageBox_clicked (GtkWidget *widget, gpointer data){    gtk_widget_destroy( GTK_WIDGET(data));}static void MessageBox_destroy (GtkWidget *widget, gpointer data){    gtk_grab_remove (GTK_WIDGET(widget));}void MessageBox( gchar *message){  static GtkWidget *label;  GtkWidget *button;  GtkWidget *dialog_window;    dialog_window = gtk_dialog_new();  gtk_signal_connect( GTK_OBJECT(dialog_window), "destroy", GTK_SIGNAL_FUNC(MessageBox_destroy), dialog_window);  gtk_window_set_title (GTK_WINDOW(dialog_window), "Coriander Message");  gtk_container_border_width (GTK_CONTAINER(dialog_window), 5);  label = gtk_label_new (message);  gtk_misc_set_padding (GTK_MISC(label), 10, 10);  gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog_window)->vbox), label, TRUE, TRUE, 0);  gtk_widget_show (label);  button = gtk_button_new_with_label ("OK");  gtk_signal_connect (GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(MessageBox_clicked), dialog_window);  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);  gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog_window)->action_area), button, TRUE, TRUE, 0);  gtk_widget_grab_default (button);  gtk_widget_show (button);  gtk_widget_show (dialog_window);  gtk_grab_add (dialog_window);}voidSetScaleSensitivity(GtkWidget* widget, int feature, dc1394bool_t sense){   char *stemp;  stemp=(char*)malloc(STRING_SIZE*sizeof(char));  switch (feature) {  case FEATURE_WHITE_BALANCE:    sprintf(stemp,"feature_%d_bu_scale",feature);    gtk_widget_set_sensitive(GTK_WIDGET (lookup_widget(GTK_WIDGET (widget), stemp)),sense);    sprintf(stemp,"feature_%d_rv_scale",feature);    gtk_widget_set_sensitive(GTK_WIDGET (lookup_widget(GTK_WIDGET (widget), stemp)),sense);    break;  case FEATURE_TEMPERATURE:    sprintf(stemp,"feature_%d_target_scale",feature);    gtk_widget_set_sensitive(GTK_WIDGET (lookup_widget(GTK_WIDGET (widget), stemp)),sense);    break;  default:    sprintf(stemp,"feature_%d_scale",feature);    gtk_widget_set_sensitive(GTK_WIDGET (lookup_widget(GTK_WIDGET (widget), stemp)),sense);    break;  }  free(stemp);}voidSetAbsoluteControl(int feature, int power){  if (dc1394_absolute_setting_on_off(camera->camera_info.handle, camera->camera_info.id, feature, power)!=DC1394_SUCCESS)    MainError("Could not toggle absolute setting control\n");  else {    camera->feature_set.feature[feature-FEATURE_MIN].abs_control=power;    if (power>0) {      GetAbsValue(feature);    }    else {      UpdateRange(feature);    }  }}voidSetAbsValue(int feature){  char *stemp, *string;  char *stringp;  float value;  stemp=(char*)malloc(STRING_SIZE*sizeof(char));  string=(char*)malloc(STRING_SIZE*sizeof(char));   sprintf(stemp,"feature_%d_abs_entry",feature);  stringp=gtk_entry_get_text(GTK_ENTRY(lookup_widget(main_window,stemp)));  value=atof(stringp);  if (dc1394_set_absolute_feature_value(camera->camera_info.handle, camera->camera_info.id, feature, value)!=DC1394_SUCCESS) {    MainError("Can't set absolute value!");  }  else {    if (dc1394_query_absolute_feature_value(camera->camera_info.handle, camera->camera_info.id, feature, &value)!=DC1394_SUCCESS) {      MainError("Can't get absolute value!");    }    else {      sprintf(string,"%.8f",value);      gtk_entry_set_text(GTK_ENTRY(lookup_widget(main_window,stemp)),string);    }  }  free(stemp);  free(string);}voidGetAbsValue(int feature){  char *stemp, *string;  float value;  stemp=(char*)malloc(STRING_SIZE*sizeof(char));  string=(char*)malloc(STRING_SIZE*sizeof(char));     if (dc1394_query_absolute_feature_value(camera->camera_info.handle, camera->camera_info.id, feature, &value)!=DC1394_SUCCESS) {    MainError("Can't get absolute value!");  }  else {    sprintf(string,"%.8f",value);    sprintf(stemp,"feature_%d_abs_entry",feature);    gtk_entry_set_text(GTK_ENTRY(lookup_widget(main_window,stemp)),string);  }  free(stemp);  free(string);}/*  The timeout/bus_reset handling technique is 'strongly inspired' by the code found in  GScanbus by Andreas Micklei.*/intbus_reset_handler(raw1394handle_t handle, unsigned int generation) {  BusInfo_t bi; // WHY NOT USE THE BUS_INFO GLOBAL VARIABLE HERE???  int i, ic, icfound, channel, speed;  int port;  camera_t *camera_ptr, *cp2;  camera_t* new_camera;  int index;  dc1394bool_t iso_status;  dc1394_camerainfo camera_info;  unsigned long long int new_guids[128];  bi.handles=NULL;  bi.port_camera_num=NULL;  bi.camera_nodes=NULL;  MainStatus("Bus reset detected");  gtk_widget_set_sensitive(main_window,FALSE);  usleep(DELAY); // sleep some time (50ms) to allow the cam to warm-up/boot  raw1394_update_generation(handle, generation);  // Now we have to deal with this bus reset...  // get camera nodes:  GetCameraNodes(&bi);  /*  cp2=cameras;  while(cp2!=NULL) {    fprintf(stderr,"Channel %d used\n",cp2->misc_info.iso_channel);    cp2=cp2->next;  }  */  // ADD NEW CAMERAS AND UPDATE PREVIOUS ONES ---------------------------------  // try to match the GUID with previous cameras  for (port=0;port<bi.port_num;port++) {    if (bi.handles[port]!=0) {      for (i=0;i<bi.port_camera_num[port];i++) {	if (dc1394_get_camera_info(bi.handles[port], bi.camera_nodes[port][i], &camera_info)!=DC1394_SUCCESS)	  MainError("Can't get camera basic information in bus-reset handler");	//fprintf(stderr, " current GUID: 0x%llx\n", camera_info.euid_64);	// was the current GUID already there?	camera_ptr=cameras;	while(camera_ptr!=NULL) {	  if (camera_ptr->camera_info.euid_64==camera_info.euid_64) { // yes, the camera was there	    //fprintf(stderr,"  camera was already there, updating...\n");	    if (dc1394_get_camera_info(bi.handles[port], bi.camera_nodes[port][i], &camera_ptr->camera_info)!=DC1394_SUCCESS)	      MainError("Could not update camera basic information in bus reset handler");	    // If ISO service is on, stop it and restart it.	    /*if (GetService(camera_ptr,SERVICE_ISO)!=NULL) {	      fprintf(stderr,"  Restarting ISO service\n");	      IsoStopThread(camera_ptr);	      fprintf(stderr,"   stop\n");	      usleep(DELAY);	      IsoStartThread(camera_ptr);	      fprintf(stderr,"   start\n");	      }*/	    break;	  }	  camera_ptr=camera_ptr->next;	}	if (camera_ptr==NULL) { // the camera is new	  //fprintf(stderr,"  A new camera was added\n");	  new_camera=NewCamera();	  GetCameraData(port, bi.camera_nodes[port][i], new_camera);	  // set ISO channel for this camera	  ic=0;	  icfound=0;	  while(icfound!=1) {	    //fprintf(stderr,"    Trying channel %d...\n",ic);	    cp2=cameras;	    while(cp2!=NULL) {	      if (cp2->misc_info.iso_channel==ic) {		//fprintf(stderr,"    Found a cam with channel %d\n",channel);		break;	      }	      cp2=cp2->next;	    }	    if (cp2==NULL)	      icfound=1;	    else	      ic++;	  }	  if (dc1394_get_iso_channel_and_speed(new_camera->camera_info.handle, new_camera->camera_info.id,					       &channel, &speed)!=DC1394_SUCCESS)	    MainError("Can't get iso channel and speed");	  //fprintf(stderr,"   Channel was %d\n",channel);	  if (dc1394_set_iso_channel_and_speed(new_camera->camera_info.handle, new_camera->camera_info.id,					       ic, speed)!=DC1394_SUCCESS)	    MainError("Can't set iso channel and speed");	  //fprintf(stderr,"   Channel set to %d\n",ic);	  if (cameras==NULL) {	    AppendCamera(new_camera);	    SetCurrentCamera(new_camera->camera_info.euid_64);	  }	  else {	    AppendCamera(new_camera);	  }	}      }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -