Exemplo n.º 1
0
static void liveview(Camera *canon, GPContext *canoncontext) {
    int retval;
    CameraFile *file;
    char output_file[64];

    retval = gp_file_new(&file);
    if (retval != GP_OK) {
        printf("  Retval: %d\n", retval);
        exit(1);
    }

    retval = gp_camera_capture_preview(canon, file, canoncontext);
    if (retval != GP_OK) {
        printf("  Retval: %d\n", retval);
        exit(1);
    }

    sprintf(output_file, "/dev/shm/liveviewpre.jpg");
    retval = gp_file_save(file, output_file);
    if (retval != GP_OK) {
        printf("  Retval: %d\n", retval);
        exit(1);
    }

    gp_file_unref(file);
}
Exemplo n.º 2
0
/**
 * @brief QTLCamera::_captureImage
 * @param workingDirectory
 * @param retrieveImages
 * @param deleteImages
 * @return
 */
string QTLCamera::_captureImage(string workingDirectory, bool retrieveImages, bool deleteImages) {
    qDebug() << "Capturing Image...";
    CameraFile *cameraFile;
    CameraFilePath path;
    QTLError result;

    result.rc = gp_camera_capture(params->camera, GP_CAPTURE_IMAGE, &path,
                                  params->context);

    if (result.rc != GP_OK) {
        qDebug() << "Could not capture image:\t" << result.rc;
        qDebug() << "check the camera and re-initialise.";
        qDebug() << "Could not capture an image. "
             << "Please check the camera and re-initialise.";
        gp_camera_exit(params->camera, params->context);
        return string("");
    } else {
        qDebug() << "New file is in location " << path.folder << "/" << path.name
             << " on the camera.";
    }

    if (retrieveImages) {
        string localPath = string(workingDirectory);
        localPath += "/";
        localPath += path.name;
        gp_file_new(&cameraFile);

        result.rc = gp_camera_file_get(params->camera, path.folder,
                                       path.name, GP_FILE_TYPE_NORMAL,
                                       cameraFile, params->context);

        if (result.rc != GP_OK) {
            qDebug() << "Could not retieve image:\t" << result.rc;
        } else {
            result.rc = gp_file_save(cameraFile, localPath.c_str());

            if (result.rc != GP_OK) {
                qDebug() << "Couldn't write file " << localPath.c_str()
                     << " - check path/permissions/disk space.";

            } else {
                qDebug() << "Written file " << localPath.c_str();
            }

            // Delete image from camera if checkbox is ticked
            if (deleteImages) {
                _deleteImage(&path, cameraFile);
            }
            qDebug();
        }
        qDebug() << "Created local file " << localPath.c_str();
        return localPath;
    }
    return string();
}
Exemplo n.º 3
0
//SAVE THREAD
//Saves Files from memory -> disk
void * SaveFiles(void*aaa){
    while(1){
        //Wait for Get Thread to tell us we have at least one file waiting
        //Put here to avoid busy waiting
        sem_wait(&NewFileSem);
        CF* my_CF = RemoveFile(); //Dequeue
        if(my_CF != NULL){
            printf("\nFile %s saved!\n", my_CF->filename);
            gp_file_save(my_CF -> my_File, my_CF -> filename);
            gp_file_free(my_CF -> my_File);
            free(my_CF -> filename);
            free(my_CF);
        }
    }
    return NULL;
}
Exemplo n.º 4
0
static int
put_file_func (CameraFilesystem *fs, const char *folder,
	       CameraFile *file, void *data, GPContext *context)
{
	char path[2048];
	const char *name;
	int result;
#ifdef DEBUG
	unsigned int i, id;
#endif
	Camera *camera = (Camera*)data;

	gp_file_get_name (file, &name);

	result = _get_path (camera->port, folder, name, path, sizeof(path));
	if (result < GP_OK)
		return result;

	result = gp_file_save (file, path);
	if (result < 0)
		return (result);

#ifdef DEBUG
	id = gp_context_progress_start (context, 500., "Uploading file...");
	for (i = 0; i < 500; i++) {
		gp_context_progress_update (context, id, i + 1);
		gp_context_idle (context);
		if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL)
			return (result);
		usleep (10);
	}
	gp_context_progress_stop (context, id);
#endif

	return (GP_OK);
}
Exemplo n.º 5
0
static int
save_file (GtkamSave *save, const char *filename, CameraFile *file, CameraFileType type, guint n)
{
	gchar *full_path, *full_filename, *dirname, *msg, *number_filename;
	const char *mime_type;
	const gchar *fsel_filename, *fsel_path, *prefix, *suffix;
	GtkWidget *dialog;
	int result;

	gp_file_get_mime_type (file, &mime_type);

	fsel_path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER_DIALOG (save));

	if ((save->priv->toggle_filename_camera->active) ||
		(g_slist_length (save->priv->data) == 1)) {

		/* Use filename provided by the CameraFile */
		full_filename = create_full_filename (filename, type);

		if (g_slist_length (save->priv->data) == 1)
			full_path = g_strdup(fsel_path);
		else
			full_path = concat_dir_and_file (fsel_path, full_filename);

		g_free (full_filename);

	} else {
		/* Use filename in prefix */
		prefix = g_locale_from_utf8 (gtk_entry_get_text
					(GTK_ENTRY (save->priv->prefix_entry)), -1,
					NULL, NULL, NULL);

		suffix = strrchr (mime_type, '/');
		suffix++;
		number_filename = g_strdup_printf ("%s%04i.%s", prefix,
								n, suffix);
		full_filename = create_full_filename (number_filename,
								type);
		g_free (number_filename);
		
		full_path = concat_dir_and_file (fsel_path,
							full_filename);
		g_free (full_filename);
	}

	/* FIXME Check which is user, and prompt the user */
	if (!save->priv->quiet && file_exists (full_path)) {
		msg = g_strdup_printf (_("The file '%s' already exists."),
				       full_path);
		if (!save->priv->err_shown) {
			dialog = gtkam_error_new (GP_ERROR_FILE_EXISTS, NULL, GTK_WIDGET (save), msg);
			gtk_window_set_transient_for (GTK_WINDOW (dialog),
						      save->priv->main_window);
			gtk_widget_show (dialog);
			g_free (msg);
			g_free (full_path);
			save->priv->err_shown = TRUE;
		}
		return -1;
	}

	/* FIXME Check for sufficient disk space for this file, or
	   calculate total disk space required for all files before
	   save process starts */

	result = gp_file_save (file, full_path);
	if (result < 0) {
		if (!save->priv->err_shown) {
			dialog = gtkam_error_new (result, NULL, GTK_WIDGET (save),
					_("Could not save file to '%s'."), full_path);
			gtk_widget_show (dialog);
			save->priv->err_shown = TRUE;
		}
	} else {
		/* Add the file to the list of files to be opened with
		   the specified external program */
		if (!save->priv->filelist)
				save->priv->filelist = g_string_new ("");
		g_string_append_printf (save->priv->filelist, " %s", full_path);
	}

	g_free (full_path);
	
	return result;
}
Exemplo n.º 6
0
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;
}