예제 #1
0
int main(int argc, char **argv) {
	Camera		*camera = NULL;
	int		ret;
	GPContext	*context;
	CameraWidget	*rootwidget;
	char		buf[200];
	CameraText	summary;

        gp_log_add_func(GP_LOG_DEBUG, errordumper, NULL);

	context = sample_create_context (); /* see context.c */

	strcpy(buf,"usb:");
	if (argc > 1)
		strcat (buf, argv[1]);

	fprintf(stderr,"setting path %s.\n", buf);

	ret = sample_open_camera (&camera, "USB PTP Class Camera", buf, context);
        if (ret < GP_OK) {
		fprintf(stderr,"camera %s not found.\n", buf);
		goto out;
	}

	ret = gp_camera_init (camera, context);
	if (ret < GP_OK) {
		fprintf(stderr,"No camera auto detected.\n");
		goto out;
	}

	/* AFL PART STARTS HERE */

	ret = recursive_directory(camera, "/", context, NULL);
	if (ret < GP_OK) {
		printf ("Could not recursive list files.\n");
		goto out;
	}

	ret = gp_camera_get_summary (camera, &summary, context);
	if (ret < GP_OK) {
		printf ("Could not get summary.\n");
		goto out;
	}

#if 1
	ret = gp_camera_get_config (camera, &rootwidget, context);
	if (ret < GP_OK) {
		fprintf (stderr,"Could not get config.\n");
		goto out;
	}
#endif
	printf ("OK, %s\n", summary.text);
	while (1) {
		CameraEventType evttype;
		void *data = NULL;

		ret = gp_camera_wait_for_event(camera, 1, &evttype, &data, context);
		if (ret < GP_OK) break;
		if (data) free (data);
		if (evttype == GP_EVENT_TIMEOUT) break;
	}

	/* AFL PART ENDS HERE */
out:
	gp_camera_exit (camera, context);
	gp_camera_free (camera);
	return 0;
}
예제 #2
0
static gboolean
get_thumbnail_idle (gpointer data)
{
	GtkamList *list = GTKAM_LIST (data);
	GetThumbnailData *d;
	CameraFile *file;
	GtkWidget *s;
	GdkPixbuf *pixbuf;
	GdkPixbufLoader *loader;
	int result;
	const char *fd;
	unsigned long fs;
	gfloat factor;

	d = list->priv->head;
	if (d == NULL)
		return (FALSE);
	s = gtkam_status_new (_("Downloading thumbnail of '%s' from "
		"folder '%s'..."), d->name, d->folder);

	g_signal_emit (G_OBJECT (list), signals[NEW_STATUS], 0, s);
	gp_file_new (&file);
	result = gp_camera_file_get (d->camera->camera, d->folder, d->name,
			GP_FILE_TYPE_PREVIEW, file,
			GTKAM_STATUS (s)->context->context);
	if (d->camera->multi)
		gp_camera_exit (d->camera->camera, NULL);
	if (result >= 0) {
		gp_file_get_data_and_size (file, &fd, &fs);

		loader = gdk_pixbuf_loader_new ();
		gdk_pixbuf_loader_write (loader, fd, fs, NULL);
		gdk_pixbuf_loader_close (loader, NULL);
		pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
		gtk_list_store_set (list->priv->store, d->iter,
				    PREVIEW_ORIG_COLUMN, pixbuf, -1);
		factor = gtkam_list_get_zoom_factor (list);
		pixbuf = gdk_pixbuf_scale_simple (pixbuf,
			gdk_pixbuf_get_width (pixbuf) * factor,
			gdk_pixbuf_get_height (pixbuf) * factor,
			GDK_INTERP_BILINEAR);
		g_object_unref (G_OBJECT (loader));
		
		gtk_list_store_set (list->priv->store, d->iter,
				PREVIEW_COLUMN, pixbuf, -1);
		g_object_unref (G_OBJECT (pixbuf));
	} 
	
	gp_file_unref (file);
	gtk_object_destroy (GTK_OBJECT (s));

	if (result == GP_ERROR_CAMERA_BUSY)
		return (TRUE);

	g_object_unref (G_OBJECT (d->camera));
	g_free (d->name);
	g_free (d->folder);
	gtk_tree_iter_free (d->iter);
	list->priv->head = d->next;
	g_free (d);
	if (!list->priv->head)
		list->priv->tail = NULL;

	gtk_widget_destroy (s);
	
	if (list->priv->head == NULL)
		return (FALSE);
	else
		return (TRUE);
}
예제 #3
0
파일: main.cpp 프로젝트: Elfhir/tweedy
int main (int argc, char** argv)
{
      std::cout<<"GP_OK = "<<GP_OK<<std::endl;

      GPContext *currentContext = NULL;
      gp_context_new();

      Camera *camera=NULL;
      gp_camera_new (&camera);
      gp_camera_init (camera, currentContext);

      CameraAbilitiesList * abilitiesList;
      CameraAbilities  abilities;
      CameraAbilities * ptr_abilities;
      ptr_abilities = &abilities;
      int haveListAbilities = gp_abilities_list_get_abilities (abilitiesList, 0, ptr_abilities);
      std::cout<<"haveListAbilities : "<< haveListAbilities<<std::endl;

     /* int haveAbilities = gp_camera_set_abilities(camera, abilities);
      std::cout<<"haveAbilities : "<< haveAbilities<<std::endl;*/

/*      //in case camera driver can't figure out the current camera's speed
      //gp_camera_set_port_path or name => pas TROUVE
      int speed; //AURA BESOIN D4UNE VALEUR (???)
      int hasSpeed = gp_camera_set_port_speed (camera, speed);
*/



      //to know port's camera
      GPPortInfo info;
      GPPortInfo * ptr_info;
      ptr_info = &info;
     /* int infoSetted = gp_camera_set_port_info (camera, info);
      std::cout<<"infoSetted : "<< infoSetted<<std::endl;*/


      ///
      int infoGetted = gp_camera_get_port_info(camera, ptr_info);
      std::cout<<"infoGetted : "<< infoGetted<<std::endl;


      //To have a window with camera's config
      CameraWidget ** widget;
      CameraWidgetType type;
      const char *label;
      int widgetCreated = gp_widget_new (type, label, widget);
      std::cout<<"widgetCreated : "<< widgetCreated<<std::endl;

      //get config
      int configGetted = gp_camera_get_config (camera, widget, currentContext);
      std::cout<<"configGetted : "<< configGetted<<std::endl;

      //set the configuration's camera
//      int cameraSetted = gp_camera_set_config (camera, *widget, currentContext);
//      std::cout<<"cameraSetted : "<< cameraSetted<<std::endl;


      //HAVE TO FIND FUNCTION WHICH GET/SET THE PÄTH
      CameraFilePath * path;
      //IDEM
      CameraCaptureType typeCapture;
      CameraFileType typeFile; //mm type à priori
      //capture
      int captured = gp_camera_capture (camera, typeCapture, path, currentContext);
      std::cout<<"captured : "<< captured<<std::endl;

      //To get capture from camera to computer
      //folder on computer
      //TO COMPLETE
      const char *folder = "../pictures";
      //TO COMPLETE
      //(devra être renseigné en fonction du numéro de la photoprécédente par ex)
      const char *file = "picture001";

      //??
      CameraFile * camera_file;
      int captureGetted = gp_camera_file_get(camera, folder, file, typeFile,camera_file, currentContext);
      std::cout<<"captureGetted : "<< captureGetted<<std::endl;


      int indiceCountCamera = gp_camera_unref (camera);



        //Before the end of using camera => better!
        int cameraExited = gp_camera_exit (camera, currentContext);

        return EXIT_SUCCESS;
}
예제 #4
0
int main(int argc, char *argv[]){
        Camera		*camera;
        GPContext	*context = gp_context_new();
        int		retval;
	CameraEventType evttype;
	void    	*evtdata;
	CameraFile	*file;

        gp_camera_new(&camera);
	retval = gp_camera_init(camera, context);
        if(retval != GP_OK)
        {
                printf("Error: %s\n", gp_result_as_string(retval));
                return 1;
        }

	do {
		retval = gp_camera_wait_for_event (camera, 10, &evttype, &evtdata, context);
	} while ((retval == GP_OK) && (evttype != GP_EVENT_TIMEOUT));

	retval = gp_file_new(&file);
	if (retval != GP_OK) {
		printf("gp_file_new: %d\n", retval);
		return 1;
	}
	/*retval = gp_camera_capture_preview(camera, file, context); */
	if (retval != GP_OK) {
		printf("gp_camera_capture_preview: %d\n", retval);
		return 1;
	}
	gp_file_free (file);

        if(argc == 1)
        {
                retval = camera_auto_focus(camera, context, 1);
		if(retval != GP_OK) {
			printf("Error: %s\n", gp_result_as_string(retval));
			return 1;
		}
        }
        else if(argc == 2)
        {
                int value = atoi(argv[1]);
                retval = camera_manual_focus(camera, value, context);
		if(retval != GP_OK) {
			printf("Error: %s\n", gp_result_as_string(retval));
			return 1;
		}
        }
	do {
		retval = gp_camera_wait_for_event (camera, 10, &evttype, &evtdata, context);
	} while ((retval == GP_OK) && (evttype != GP_EVENT_TIMEOUT));

	retval = camera_auto_focus(camera, context, 0);
	if(retval != GP_OK) {
		printf("Error: %s\n", gp_result_as_string(retval));
		return 1;
	}

        gp_camera_exit(camera, context);
        return 0;
}
예제 #5
0
	~CameraController() {
		gp_camera_exit(camera, context);
	}
예제 #6
0
static GtkamCamera *
gtkam_chooser_get_camera (GtkamChooser *chooser)
{
	GtkWidget *dialog, *status;
	GPPortInfo info;
	Camera *camera;
	CameraAbilities abilities;
	const gchar *model, *port, *speed;
	gchar *port_path, *right, *tmp;
	int m, p, r;
	gboolean multi;
	GtkamCamera *c;

	model = gtk_entry_get_text (chooser->priv->entry_model);
	port  = gtk_entry_get_text (chooser->priv->entry_port);
	speed = gtk_entry_get_text (chooser->priv->entry_speed);
	multi = GTK_TOGGLE_BUTTON (chooser->priv->check_multi)->active;

	if (!port || !*port)
		port_path = g_strdup (_("None"));
	else {
		port_path = g_strdup (port);
		right = strrchr (port_path, ')');
		*right = '\0';
		tmp = g_strdup (strrchr (port_path, '(') + 1);
		g_free (port_path);
		port_path = tmp;
	}

	gp_camera_new (&camera);
#ifdef HAVE_GP_CAMERA_SET_TIMEOUT_FUNCS
	gp_camera_set_timeout_funcs (camera, start_timeout_func,
				     stop_timeout_func, NULL);
#endif

	/* Model? */
	m = gp_abilities_list_lookup_model (chooser->priv->al, model);
	gp_abilities_list_get_abilities (chooser->priv->al, m, &abilities);
	gp_camera_set_abilities (camera, abilities);

	/* Port? */
	if (strcmp (port_path, _("None"))) {
		p = gp_port_info_list_lookup_path (chooser->priv->il,
						   port_path);
		gp_port_info_list_get_info (chooser->priv->il, p, &info);
		gp_camera_set_port_info (camera, info);
	}

	/* Speed? */
	if (strcmp (speed, _("Best")))
		gp_camera_set_port_speed (camera, atoi (speed));

	/*
	 * Initialize the camera to check if it is really there. Exit
	 * afterwards because other applications could need the camera, too.
	 */
	status = gtkam_status_new (_("Initializing camera..."));
	gtkam_dialog_add_status (GTKAM_DIALOG (chooser), status);
	r = gp_camera_init (camera, GTKAM_STATUS (status)->context->context);
	if (multi)
		gp_camera_exit (camera, NULL);
	switch (r) {
	case GP_OK:
		break;
	case GP_ERROR_CANCEL:
		g_free (port_path);
		break;
	default:
		g_free (port_path);
		dialog = gtkam_error_new (r, GTKAM_STATUS (status)->context,
			NULL, _("Could not initialize camera."));
		gtk_window_set_transient_for (GTK_WINDOW (dialog),
					      GTK_WINDOW (chooser));
		gtk_widget_show (dialog);
		gp_camera_unref (camera);
		camera = NULL;
	}
	gtk_object_destroy (GTK_OBJECT (status));

	c = gtkam_camera_new (camera, multi);
	gp_camera_unref (camera);

	return (c);
}
예제 #7
0
int cameraFunction(int command) {
    int i, retval, ss, commandint;

    gp_camera_new(&canon);
    canoncontext = gp_context_new();
    gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);
    printf("Camera init.  Takes about 3 seconds.\n");
    retval = gp_camera_init(canon, canoncontext);
    if (retval != GP_OK) {
        printf("  Retval: %d\n", retval);
        exit(1);
    } else {
        printf("okay");
    }

    canon_enable_capture(canon, TRUE, canoncontext);


    printf("ready to rock\n");

    //i = getchar();
    //getchar();
    //commandint = atoi(command);
    switch (command) {
    case 'c': {
        capture(canon, canoncontext);
        break;
    }
    case 's': {
        ss = getchar();
        getchar();
        printf("ss is %c\n", ss);
        shutterchange(canon, canoncontext, ss);
        break;
    }
    case 'a': {
        int ap;
        ap = getchar();
        getchar();
        aperturechange(canon, canoncontext, ap);
        printf("aperture: %d", ap);
        break;
    }
    case 'i': {
        int iso;
        iso = getchar();
        getchar();
        isochange(canon, canoncontext, iso);
        printf("iso: %d", iso);
        break;
    }
    case 'l': {
        while (1) {
            liveview(canon, canoncontext);
        }
        break;
    }
    case 'q': {
        gp_camera_exit(canon, canoncontext);
        break;
    }
    default:
        capture(canon, canoncontext);
        return 0;

    }

    return 0;
} //end of code
예제 #8
0
파일: preview.c 프로젝트: axxel/libgphoto2
int
main(int argc, char **argv) {
	Camera	*canon;
	int	i, retval;
	GPContext *canoncontext = sample_create_context();

	gp_log_add_func(GP_LOG_ERROR, errordumper, 0);
	gp_camera_new(&canon);

	/* When I set GP_LOG_DEBUG instead of GP_LOG_ERROR above, I noticed that the
	 * init function seems to traverse the entire filesystem on the camera.  This
	 * is partly why it takes so long.
	 * (Marcus: the ptp2 driver does this by default currently.)
	 */
	printf("Camera init.  Takes about 10 seconds.\n");
	retval = gp_camera_init(canon, canoncontext);
	if (retval != GP_OK) {
		printf("  Retval: %d\n", retval);
		exit (1);
	}
	canon_enable_capture(canon, TRUE, canoncontext);
	retval = camera_eosviewfinder(canon,canoncontext,1);
	if (retval != GP_OK) {
		fprintf(stderr,"camera_eosviewfinder(1): %d\n", retval);
		exit(1);
	}
	/*set_capturetarget(canon, canoncontext);*/
	printf("Taking 100 previews and saving them to snapshot-XXX.jpg ...\n");
	for (i=0;i<100;i++) {
		CameraFile *file;
		char output_file[32];

		fprintf(stderr,"preview %d\n", i);
		retval = gp_file_new(&file);
		if (retval != GP_OK) {
			fprintf(stderr,"gp_file_new: %d\n", retval);
			exit(1);
		}

		/* autofocus every 10 shots */
		if (i%10 == 9) {
			camera_auto_focus (canon, canoncontext, 1);
			/* FIXME: wait a bit and/or poll events ? */
			camera_auto_focus (canon, canoncontext, 0);
		} else {
			camera_manual_focus (canon, (i/10-5)/2, canoncontext);
		}
#if 0 /* testcase for EOS zooming */
		{
			char buf[20];
			if (i<10) set_config_value_string (canon, "eoszoom", "5", canoncontext);
			sprintf(buf,"%d,%d",(i&0x1f)*64,(i>>5)*64);
			fprintf(stderr, "%d - %s\n", i, buf);
			set_config_value_string (canon, "eoszoomposition", buf, canoncontext);
		}
#endif
		retval = gp_camera_capture_preview(canon, file, canoncontext);
		if (retval != GP_OK) {
			fprintf(stderr,"gp_camera_capture_preview(%d): %d\n", i, retval);
			exit(1);
		}
		sprintf(output_file, "snapshot-%03d.jpg", i);
		retval = gp_file_save(file, output_file);
		if (retval != GP_OK) {
			fprintf(stderr,"gp_camera_capture_preview(%d): %d\n", i, retval);
			exit(1);
		}
		gp_file_unref(file);
	/*
		sprintf(output_file, "image-%03d.jpg", i);
	        capture_to_file(canon, canoncontext, output_file);
	*/
	}
	retval = camera_eosviewfinder(canon,canoncontext,0);
	if (retval != GP_OK) {
		fprintf(stderr,"camera_eosviewfinder(0): %d\n", retval);
		exit(1);
	}

	sleep(10);
	gp_camera_exit(canon, canoncontext);
	return 0;
}