Exemple #1
0
static int
camera_capture (Camera* camera, CameraCaptureType type, CameraFilePath* path,
                GPContext *context)
{
        int r;
        CameraFile *file = NULL;
        CameraFileInfo info;
	KncCamRes cr;
	KncCntrlRes cntrl_res;
	KncImageInfo i;

        C_NULL (camera && path);

        /* We only support capturing of images */
        if (type != GP_CAPTURE_IMAGE) return (GP_ERROR_NOT_SUPPORTED);

        /* Stop the timeout, take the picture, and restart the timeout. */
        gp_camera_stop_timeout (camera, camera->pl->timeout);
	gp_file_new (&file);
	knc_cntrl_set_func_data (camera->pl->c, data_func, file);
        cntrl_res = knc_take_picture (camera->pl->c, &cr, KNC_SOURCE_CARD, &i);
        camera->pl->timeout = gp_camera_start_timeout (camera, PING_TIMEOUT,
                                                       timeout_func);
	if (cntrl_res) gp_file_unref (file);
        CR (cntrl_res, context);

        sprintf (path->name, "%06i.jpeg", (int) i.id);
        strcpy (path->folder, "/");
        r = gp_filesystem_append (camera->fs, path->folder,
				  path->name, context);
	if (r < 0) {
		gp_file_unref (file);
		return r;
	}

        info.preview.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE;
	gp_file_get_data_and_size (file, NULL, &info.preview.size);
        strcpy (info.preview.type, GP_MIME_JPEG);

        info.file.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_PERMISSIONS |
                            GP_FILE_INFO_TYPE | GP_FILE_INFO_NAME;
        info.file.size = i.size;
        info.file.permissions = GP_FILE_PERM_READ;
        if (!i.prot) info.file.permissions |= GP_FILE_PERM_DELETE;
        strcpy (info.file.type, GP_MIME_JPEG);
        snprintf (info.file.name, sizeof (info.file.name),
                  "%06i.jpeg", (int) i.id);
        gp_filesystem_set_info_noop (camera->fs, path->folder, info, context);

        gp_file_set_name (file, info.file.name);
        gp_file_set_mime_type (file, GP_MIME_JPEG);
        gp_file_set_type (file, GP_FILE_TYPE_EXIF);
        gp_filesystem_set_file_noop (camera->fs, path->folder, file, context);
        gp_file_unref (file);

        return (GP_OK);
}
Exemple #2
0
static int
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
                void *data, GPContext *context)
{
        CameraFile *file;
        CameraFileInfo info;
        KncStatus status;
        unsigned int i, id;
        Camera *camera = data;
        int result;
	KncCamRes cr;

        /*
         * We can't get the filename from the camera.
         * But we decide to call the images %6i.jpeg', with the image id as
         * parameter. Therefore, let's get the image ids.
         */
        CR (knc_get_status (camera->pl->c, &cr, &status), context);
	CCR (cr, context);

        id = gp_context_progress_start (context, status.pictures,
                                        _("Getting file list..."));
        for (i = 0; i < status.pictures; i++) {

                /* Get information */
                gp_file_new (&file);
                result = get_info (camera, i + 1, &info, file, context);
                if (result < 0) {
                        gp_file_unref (file);
                        return (result);
                }

                /*
                 * Append directly to the filesystem instead of to the list,
                 * because we have additional information.
                 */
                gp_filesystem_append (camera->fs, folder, info.file.name,
                                      context);
                gp_filesystem_set_info_noop (camera->fs, folder, info, context);
                gp_filesystem_set_file_noop (camera->fs, folder, file, context);
                gp_file_unref (file);

                gp_context_idle (context);
                gp_context_progress_update (context, id, i + 1);
                if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL)
                        return (GP_ERROR_CANCEL);
        }
        gp_context_progress_stop (context, id);

        return (GP_OK);
}
Exemple #3
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);
}
Exemple #4
0
/**
 * Retrieves information about a file.
 *
 * @param camera a #Camera
 * @param folder a folder
 * @param file the name of the file
 * @param info
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 **/
int
gp_camera_file_get_info (Camera *camera, const char *folder, 
			 const char *file, CameraFileInfo *info,
			 GPContext *context)
{
	int result = GP_OK;
	const char *mime_type;
	const char *data;
	/* long int size; */
	CameraFile *cfile;

	gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Getting file info for '%s' "
		"in '%s'...", file, folder);

	CHECK_NULL (camera && folder && file && info);
	CHECK_INIT (camera, context);

	memset (info, 0, sizeof (CameraFileInfo));

	/* Check first if the camera driver supports the filesystem */
	CHECK_OPEN (camera, context);
	result = gp_filesystem_get_info (camera->fs, folder, file, info,
					 context);
	CHECK_CLOSE (camera, context);
	if (result != GP_ERROR_NOT_SUPPORTED) {
		CAMERA_UNUSED (camera, context);
		return (result);
	}

	/*
	 * The CameraFilesystem doesn't support file info. We simply get
	 * the preview and the file and look for ourselves...
	 */

	/* It takes too long to get the file */
	info->file.fields = GP_FILE_INFO_NONE;

	/* Get the preview */
	info->preview.fields = GP_FILE_INFO_NONE;
	CRS (camera, gp_file_new (&cfile), context);
	if (gp_camera_file_get (camera, folder, file, GP_FILE_TYPE_PREVIEW,
						cfile, context) == GP_OK) {
		unsigned long size;
		info->preview.fields |= GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE;
		gp_file_get_data_and_size (cfile, &data, &size);
		info->preview.size = size;
		gp_file_get_mime_type (cfile, &mime_type);
		strncpy (info->preview.type, mime_type,
			 sizeof (info->preview.type));
	}
	gp_file_unref (cfile);

	/* We don't trust the camera libraries */
	info->file.fields |= GP_FILE_INFO_NAME;
	strncpy (info->file.name, file, sizeof (info->file.name));
	info->preview.fields &= ~GP_FILE_INFO_NAME;

	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
Exemple #5
0
static int
get_file (GtkamSave *save, GtkamCamera *camera,
	  const gchar *folder, const gchar *name, CameraFileType type, guint n,
	  GtkamContext *context)
{
	int result;
	GtkWidget *dialog;
	CameraFile *file;

	gp_file_new (&file);
	result = gp_camera_file_get (camera->camera, folder, name, type, file,
				     context->context);
	if (camera->multi)
		gp_camera_exit (camera->camera, NULL);
	switch (result) {
	case GP_OK:
		result = save_file (save, name, file, type, n);
		break;
	case GP_ERROR_CANCEL:
		break;
	default:
		if (!save->priv->err_shown) {
			dialog = gtkam_error_new (result, context,
				GTK_WIDGET (save), _("Could not get '%s' "
				"from folder '%s'."),
				name, folder);
			gtk_widget_show (dialog);
			save->priv->err_shown = TRUE;
		}
	}
	gp_file_unref (file);

	return result;
}
Exemple #6
0
static void
on_view_as_activate (GtkMenuItem *item, ViewAsData *d)
{
	GtkWidget *w, *c, *s;
	Bonobo_Control control;
	CORBA_Environment ev;
	CameraFile *f;
	int result;
	Bonobo_PersistStream pstream;
	BonoboObject *stream;
	const char *data = NULL;
	unsigned long int size;
	const char *type;

	g_return_if_fail (d->iid != NULL);

	CORBA_exception_init (&ev);
	control = bonobo_get_object (d->iid, "IDL:Bonobo/Control:1.0", &ev);
	if (BONOBO_EX (&ev) || (control == CORBA_OBJECT_NIL)) {
		CORBA_exception_free (&ev);
		g_warning ("Could not get control from '%s'.", d->iid);
		return;
	}

	w = bonobo_window_new (d->file, d->file);
	c = bonobo_widget_new_control_from_objref (control, CORBA_OBJECT_NIL);
	gtk_widget_show (c);
	bonobo_window_set_contents (BONOBO_WINDOW (w), c);

	gtk_widget_show (w);

	s = gtkam_status_new (_("Downloading '%s' from '%s'..."), d->file,
			      d->folder);
	g_signal_emit (G_OBJECT (d->list), signals[NEW_STATUS], 0, s);
	gp_file_new (&f);
	result = gp_camera_file_get (d->camera->camera, d->folder, d->file,
				     GP_FILE_TYPE_NORMAL, f,
				     GTKAM_STATUS (s)->context->context);
	if (d->camera->multi)
		gp_camera_exit (d->camera->camera, NULL);
	if (result >= 0) {
		CORBA_exception_init (&ev);
		pstream = Bonobo_Unknown_queryInterface (control,
					"IDL:Bonobo/PersistStream:1.0", &ev);
		if (!BONOBO_EX (&ev) && (pstream != CORBA_OBJECT_NIL)) {
			gp_file_get_data_and_size (f, &data, &size);
			gp_file_get_mime_type (f, &type);
			stream = bonobo_stream_mem_create (data, size,
							   TRUE, FALSE);
			Bonobo_PersistStream_load (pstream,
				bonobo_object_corba_objref (stream), type, &ev);
			g_object_unref (G_OBJECT (stream));
			bonobo_object_release_unref (pstream, NULL);
		}
		CORBA_exception_free (&ev);
	}
	gp_file_unref (f);
	gtk_object_destroy (GTK_OBJECT (s));
}
Exemple #7
0
bool GPCamera::getThumbnail(const QString& folder, const QString& itemName, QImage& thumbnail)
{
#ifdef HAVE_GPHOTO2
    int                errorCode;
    CameraFile*        cfile = 0;
    const char*        data  = 0;
    unsigned long int  size;

    gp_file_new(&cfile);

    d->status->cancel = false;
    errorCode         = gp_camera_file_get(d->camera, QFile::encodeName(folder).constData(),
                                           QFile::encodeName(itemName).constData(),
                                           GP_FILE_TYPE_PREVIEW,
                                           cfile, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get camera item!" << folder << itemName;
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    errorCode = gp_file_get_data_and_size(cfile, &data, &size);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get thumbnail from camera item!" << folder << itemName;
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    thumbnail.loadFromData((const uchar*) data, (uint) size);

    gp_file_unref(cfile);
    return !thumbnail.isNull();
#else
    Q_UNUSED(folder);
    Q_UNUSED(itemName);
    Q_UNUSED(thumbnail);
    return false;
#endif /* HAVE_GPHOTO2 */
}
Exemple #8
0
bool GPCamera::getPreview(QImage& preview)
{
#ifdef HAVE_GPHOTO2
    int               errorCode;
    CameraFile*       cfile = 0;
    const char*       data  = 0;
    unsigned long int size;

    d->status->cancel = false;
    gp_file_new(&cfile);

    errorCode = gp_camera_capture_preview(d->camera, cfile, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to initialize camera preview mode!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    errorCode = gp_file_get_data_and_size(cfile, &data, &size);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get preview from camera!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    preview.loadFromData((const uchar*) data, (uint) size);

    gp_file_unref(cfile);
    return true;
#else
    Q_UNUSED(preview);
    return false;
#endif /* HAVE_GPHOTO2 */
}
Exemple #9
0
/**
 * @brief CameraHandler::_deleteImage
 */
QTLError QTLCamera::_deleteImage(CameraFilePath *cameraFilePath, CameraFile *cameraFile) {
    QTLError result;
    result.rc = gp_camera_file_delete(params->camera, cameraFilePath->folder,
                                      cameraFilePath->name, params->context);
    if (result.rc != GP_OK) {
        result.errorText = gp_result_as_string(result.rc);
        qDebug() << "Problem deleting file from camera." << result.errorText;
    } else {
        qDebug() << "File" << cameraFilePath->folder << cameraFilePath->name
             << "deleted from camera.";
        gp_file_unref(cameraFile);
    }
    return result;
}
Exemple #10
0
void* capture(void* arg)
{
	int res;
	int i = 0;
	CameraFile* file;

	pthread_cleanup_push(cleanup, NULL);
					while(!global->stop)
					{
						unsigned long int xsize;
						const char* xdata;
						pthread_mutex_lock(&control_mutex);
						res = gp_file_new(&file);
						CAMERA_CHECK_GP(res, "gp_file_new");
						res = gp_camera_capture_preview(camera, file, context);
						CAMERA_CHECK_GP(res, "gp_camera_capture_preview");
						pthread_mutex_lock(&global->in[plugin_id].db);
						res = gp_file_get_data_and_size(file, &xdata, &xsize);
						if(xsize == 0)
						{
							if(i++ > 3)
							{
								IPRINT("Restarted too many times; giving up\n");
								return NULL;
							}
							int value = 0;
							IPRINT("Read 0 bytes from camera; restarting it\n");
							camera_set("capture", &value);
							sleep(3);
							value = 1;
							camera_set("capture", &value);
						}
						else
							i = 0;
						CAMERA_CHECK_GP(res, "gp_file_get_data_and_size");
						memcpy(global->in[plugin_id].buf, xdata, xsize);
						res = gp_file_unref(file);
						pthread_mutex_unlock(&control_mutex);
						CAMERA_CHECK_GP(res, "gp_file_unref");
						global->in[plugin_id].size = xsize;
						DBG("Read %d bytes from camera.\n", global->in[plugin_id].size);
						pthread_cond_broadcast(&global->in[plugin_id].db_update);
						pthread_mutex_unlock(&global->in[plugin_id].db);
						usleep(delay);
					}
					pthread_cleanup_pop(1);

	return NULL;
}
Exemple #11
0
static Bonobo_Stream
impl_GNOME_Camera_capturePreview (PortableServer_Servant servant, 
				  CORBA_Environment *ev)
{
	BonoboStream *stream;
	CameraFile *file;
	GnoCamCamera *c;

	g_message ("impl_GNOME_Camera_capturePreview");

	c = GNOCAM_CAMERA (bonobo_object_from_servant (servant));
	CR (gp_file_new (&file), ev);
	CR (gp_camera_capture_preview (c->camera, file), ev);
	if (BONOBO_EX (ev)) {
		gp_file_unref (file);
		g_message ("Returning...");
		return (CORBA_OBJECT_NIL);
	}

	stream = bonobo_stream_mem_create (file->data, file->size, TRUE, FALSE);
	gp_file_unref (file);

	return (CORBA_Object_duplicate (BONOBO_OBJREF (stream), ev));
}
Exemple #12
0
static int
get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
               CameraFileInfo *info, void *data, GPContext *context)
{
        Camera *camera = data;
        CameraFile *file;
        int n, result;

        /* We need image numbers starting with 1 */
        n = gp_filesystem_number (camera->fs, folder, filename, context);
        if (n < 0) return (n);
        n++;

        gp_file_new (&file);
        result = get_info (camera, n, info, file, context);
        if (result < 0) {
                gp_file_unref (file);
                return (result);
        }
        gp_filesystem_set_file_noop (fs, folder, file, context);
        gp_file_unref (file);

        return (GP_OK);
}
Exemple #13
0
static int try_get_camera_file(GPParams* gp_params, const char* folder, const char* filename)
{
	int ret = 0;
    CameraFile *file = NULL;
	if ( (ret = gp_file_new (&file)) < 0) {
		LOG_E("gp_file_new failed %d\n", ret);
		return -1;
	}
    if ( (ret = gp_camera_file_get (gp_params->camera, folder, filename, GP_FILE_TYPE_NORMAL,
			  file, gp_params->context)) < 0) {
		LOG_I("gp_camera_file_get: %s\n", gp_port_result_as_string(ret));
	}
	gp_file_unref (file);
	return ret;
}
Exemple #14
0
/**
 * Read stored file with image.
 */
bool DigitalCameraCapture::retrieveFrame(int, OutputArray outputFrame)
{
    if (grabbedFrames.size() > 0)
    {
        CameraFile * file = grabbedFrames.front();
        grabbedFrames.pop_front();
        try
        {
            readFrameFromFile(file, outputFrame);
            CR(gp_file_unref(file));
        }
        catch (GPhoto2Exception & e)
        {
            message(WARNING, "cannot read file grabbed from device", e);
            return false;
        }
    }
    else
    {
        return false;
    }
    return true;
}
Exemple #15
0
/**
 * Capture image, and store file in @field grabbedFrames.
 * Do not read a file. File will be deleted from camera automatically.
 */
bool DigitalCameraCapture::grabFrame()
{
    CameraFilePath filePath;
    CameraFile * file = NULL;
    try
    {
        CR(gp_file_new(&file));

        if (preview)
        {
            CR(gp_camera_capture_preview(camera, file, context));
        }
        else
        {
            // Capture an image
            CR(gp_camera_capture(camera, GP_CAPTURE_IMAGE, &filePath, context));
            CR(gp_camera_file_get(camera, filePath.folder, filePath.name, GP_FILE_TYPE_NORMAL,
                    file, context));
            CR(gp_camera_file_delete(camera, filePath.folder, filePath.name, context));
        }
        // State update
        if (firstCapturedFrameTime == 0)
        {
            firstCapturedFrameTime = time(0);
        }
        capturedFrames++;
        grabbedFrames.push_back(file);
    }
    catch (GPhoto2Exception & e)
    {
        if (file)
            gp_file_unref(file);
        message(WARNING, "cannot grab new frame", e);
        return false;
    }
    return true;
}
Exemple #16
0
/**
 * Close connection to the camera. Remove all unread frames/files.
 */
void DigitalCameraCapture::close()
{
    try
    {
        if (!frame.empty())
        {
            frame.release();
        }
        if (camera)
        {
            CR(gp_camera_exit(camera, context));
            CR(gp_camera_unref(camera));
            camera = NULL;
        }
        opened = false;
        if (int frames = grabbedFrames.size() > 0)
        {
            while (frames--)
            {
                CameraFile * file = grabbedFrames.front();
                grabbedFrames.pop_front();
                CR(gp_file_unref(file));
            }
        }
        if (rootWidget)
        {
            widgetInfo.clear();
            CR(gp_widget_unref(rootWidget));
            rootWidget = NULL;
        }
    }
    catch (GPhoto2Exception & e)
    {
        message(ERROR, "cannot close device properly", e);
    }
}
Exemple #17
0
bool GPCamera::downloadItem(const QString& folder, const QString& itemName,
                            const QString& saveFile)
{
#ifdef HAVE_GPHOTO2
    int         errorCode;
    CameraFile* cfile = 0;

    d->status->cancel = false;
    QFile file(saveFile);

    if (!file.open(QIODevice::ReadWrite))
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to open file" << file.fileName() << file.errorString();
        return false;
    }

    // dup fd, passing fd control to gphoto2 later
    int handle = dup(file.handle());

    if (handle == -1)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to dup file descriptor";
        return false;
    }

    errorCode = gp_file_new_from_fd(&cfile, handle);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get camera item!";
        printGphotoErrorDescription(errorCode);
        return false;
    }

    errorCode = gp_camera_file_get(d->camera, QFile::encodeName(folder).constData(),
                                   QFile::encodeName(itemName).constData(),
                                   GP_FILE_TYPE_NORMAL, cfile,
                                   d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get camera item!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    time_t mtime;
    errorCode = gp_file_get_mtime(cfile, &mtime);

    if (errorCode == GP_OK && mtime)
    {
        struct utimbuf ut;
        ut.modtime = mtime;
        ut.actime  = mtime;
        ::utime(QFile::encodeName(saveFile).constData(), &ut);
    }

    file.close();

    gp_file_unref(cfile);
    return true;
#else
    Q_UNUSED(folder);
    Q_UNUSED(itemName);
    Q_UNUSED(saveFile);
    return false;
#endif /* HAVE_GPHOTO2 */
}
Exemple #18
0
bool GPCamera::uploadItem(const QString& folder, const QString& itemName, const QString& localFile, CamItemInfo& itemInfo)
{
#ifdef HAVE_GPHOTO2
    int         errorCode;
    CameraFile* cfile = 0;
    errorCode         = gp_file_new(&cfile);
    d->status->cancel = false;

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to init new camera file instance!";
        printGphotoErrorDescription(errorCode);
        return false;
    }

    errorCode = gp_file_open(cfile, QFile::encodeName(localFile).constData());

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to open file!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    errorCode = gp_file_set_name(cfile, QFile::encodeName(itemName).constData());

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to rename item from camera!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

#ifdef HAVE_GPHOTO25
    errorCode = gp_camera_folder_put_file(d->camera,
                                          QFile::encodeName(folder).constData(),
                                          QFile::encodeName(itemName).constData(),
                                          GP_FILE_TYPE_NORMAL,
                                          cfile,
                                          d->status->context);
#else
    errorCode = gp_camera_folder_put_file(d->camera,
                                          QFile::encodeName(folder).constData(),
                                          cfile,
                                          d->status->context);
#endif

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to upload item to camera!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    // Get new camera item information.

    itemInfo.name   = itemName;
    itemInfo.folder = folder;

    CameraFileInfo info;
    errorCode       = gp_camera_file_get_info(d->camera, QFile::encodeName(folder).constData(),
                                              QFile::encodeName(itemName).constData(), &info, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get camera item information!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    itemInfo.ctime            = QDateTime();
    itemInfo.mime             = QString();
    itemInfo.size             = -1;
    itemInfo.width            = -1;
    itemInfo.height           = -1;
    itemInfo.downloaded       = CamItemInfo::DownloadUnknown;
    itemInfo.readPermissions  = -1;
    itemInfo.writePermissions = -1;

    /* The mime type returned by Gphoto2 is dummy with all RAW files.
    if (info.file.fields & GP_FILE_INFO_TYPE)
        itemInfo.mime = info.file.type;
    */

    itemInfo.mime = mimeType(itemInfo.name.section(QLatin1Char('.'), -1).toLower());

    if (info.file.fields & GP_FILE_INFO_MTIME)
    {
        itemInfo.ctime = QDateTime::fromTime_t(info.file.mtime);
    }

    if (info.file.fields & GP_FILE_INFO_SIZE)
    {
        itemInfo.size = info.file.size;
    }

    if (info.file.fields & GP_FILE_INFO_WIDTH)
    {
        itemInfo.width = info.file.width;
    }

    if (info.file.fields & GP_FILE_INFO_HEIGHT)
    {
        itemInfo.height = info.file.height;
    }

    if (info.file.fields & GP_FILE_INFO_STATUS)
    {
        if (info.file.status == GP_FILE_STATUS_DOWNLOADED)
        {
            itemInfo.downloaded = CamItemInfo::DownloadedYes;
        }
        else
        {
            itemInfo.downloaded = CamItemInfo::DownloadedNo;
        }
    }

    if (info.file.fields & GP_FILE_INFO_PERMISSIONS)
    {
        if (info.file.permissions & GP_FILE_PERM_READ)
        {
            itemInfo.readPermissions = 1;
        }
        else
        {
            itemInfo.readPermissions = 0;
        }

        if (info.file.permissions & GP_FILE_PERM_DELETE)
        {
            itemInfo.writePermissions = 1;
        }
        else
        {
            itemInfo.writePermissions = 0;
        }
    }

    gp_file_unref(cfile);
    return true;
#else
    Q_UNUSED(folder);
    Q_UNUSED(itemName);
    Q_UNUSED(localFile);
    Q_UNUSED(itemInfo);
    return false;
#endif /* HAVE_GPHOTO2 */
}
Exemple #19
0
TW_UINT16
_get_gphoto2_file_as_DIB(
    const char *folder, const char *filename, CameraFileType type,
    HWND hwnd, HBITMAP *hDIB
) {
    const unsigned char *filedata;
    unsigned long	filesize;
    int			ret;
    CameraFile		*file;
    struct jpeg_source_mgr		xjsm;
    struct jpeg_decompress_struct	jd;
    struct jpeg_error_mgr		jerr;
    HDC 		dc;
    BITMAPINFO 		bmpInfo;
    LPBYTE		bits;
    JSAMPROW		samprow, oldsamprow;

    if(!libjpeg_handle) {
	if(!load_libjpeg()) {
	    FIXME("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG);
	    filedata = NULL;
	    return TWRC_FAILURE;
	}
    }

    gp_file_new (&file);
    ret = gp_camera_file_get(activeDS.camera, folder, filename, type, file, activeDS.context);
    if (ret < GP_OK) {
	FIXME("Failed to get file?\n");
	gp_file_unref (file);
	return TWRC_FAILURE;
    }
    ret = gp_file_get_data_and_size (file, (const char**)&filedata, &filesize);
    if (ret < GP_OK) {
	FIXME("Failed to get file data?\n");
	return TWRC_FAILURE;
    }

    /* FIXME: Actually we might get other types than JPEG ... But only handle JPEG for now */
    if (filedata[0] != 0xff) {
	ERR("File %s/%s might not be JPEG, cannot decode!\n", folder, filename);
    }

    /* This is basically so we can use in-memory data for jpeg decompression.
     * We need to have all the functions.
     */
    xjsm.next_input_byte	= filedata;
    xjsm.bytes_in_buffer	= filesize;
    xjsm.init_source	= _jpeg_init_source;
    xjsm.fill_input_buffer	= _jpeg_fill_input_buffer;
    xjsm.skip_input_data	= _jpeg_skip_input_data;
    xjsm.resync_to_restart	= _jpeg_resync_to_restart;
    xjsm.term_source	= _jpeg_term_source;

    jd.err = pjpeg_std_error(&jerr);
    /* jpeg_create_decompress is a macro that expands to jpeg_CreateDecompress - see jpeglib.h
     * jpeg_create_decompress(&jd); */
    pjpeg_CreateDecompress(&jd, JPEG_LIB_VERSION, (size_t) sizeof(struct jpeg_decompress_struct));
    jd.src = &xjsm;
    ret=pjpeg_read_header(&jd,TRUE);
    jd.out_color_space = JCS_RGB;
    pjpeg_start_decompress(&jd);
    if (ret != JPEG_HEADER_OK) {
	ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret);
	gp_file_unref (file);
	return TWRC_FAILURE;
    }

    ZeroMemory (&bmpInfo, sizeof (BITMAPINFO));
    bmpInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
    bmpInfo.bmiHeader.biWidth = jd.output_width;
    bmpInfo.bmiHeader.biHeight = -jd.output_height;
    bmpInfo.bmiHeader.biPlanes = 1;
    bmpInfo.bmiHeader.biBitCount = jd.output_components*8;
    bmpInfo.bmiHeader.biCompression = BI_RGB;
    bmpInfo.bmiHeader.biSizeImage = 0;
    bmpInfo.bmiHeader.biXPelsPerMeter = 0;
    bmpInfo.bmiHeader.biYPelsPerMeter = 0;
    bmpInfo.bmiHeader.biClrUsed = 0;
    bmpInfo.bmiHeader.biClrImportant = 0;
    *hDIB = CreateDIBSection ((dc = GetDC(hwnd)), &bmpInfo, DIB_RGB_COLORS, (LPVOID)&bits, 0, 0);
    if (!*hDIB) {
	FIXME("Failed creating DIB.\n");
	gp_file_unref (file);
	return TWRC_FAILURE;
    }
    samprow = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,jd.output_width*jd.output_components);
    oldsamprow = samprow;
    while ( jd.output_scanline<jd.output_height ) {
	int i, x = pjpeg_read_scanlines(&jd,&samprow,1);
	if (x != 1) {
	    FIXME("failed to read current scanline?\n");
	    break;
	}
	/* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */
	for(i=0;i<jd.output_width;i++,samprow+=jd.output_components) {
	    *(bits++) = *(samprow+2);
	    *(bits++) = *(samprow+1);
	    *(bits++) = *(samprow);
	}
	bits = (LPBYTE)(((UINT_PTR)bits + 3) & ~3);
	samprow = oldsamprow;
    }
    if (hwnd) ReleaseDC (hwnd, dc);
    HeapFree (GetProcessHeap(), 0, samprow);
    gp_file_unref (file);
    return TWRC_SUCCESS;
}
Exemple #20
0
/* DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET */
TW_UINT16 GPHOTO2_ImageNativeXferGet (pTW_IDENTITY pOrigin, 
                                    TW_MEMREF pData)
{
#ifdef HAVE_GPHOTO2
    pTW_UINT32 pHandle = (pTW_UINT32) pData;
    HBITMAP hDIB;
    BITMAPINFO bmpInfo;
    LPBYTE bits;
    JSAMPROW samprow, oldsamprow;
    HDC dc;

    FIXME("DG_IMAGE/DAT_IMAGENATIVEXFER/MSG_GET: implemented, but expect program crash due to DIB.\n");

/*  NOTE NOTE NOTE NOTE NOTE NOTE NOTE
 *
 *  While this is a mandatory transfer mode and this function
 *  is correctly implemented and fully works, the calling program
 *  will likely crash after calling.
 *
 *  Reason is that there is a lot of example code that does:
 *  bmpinfo = GlobalLock(hBITMAP); ... pointer access to bmpinfo
 *
 *  Our current HBITMAP handles do not support getting GlobalLocked -> App Crash
 *
 *  This needs a GDI Handle rewrite, at least for DIB sections.
 *  - Marcus
 */
    if (activeDS.currentState != 6) {
        activeDS.twCC = TWCC_SEQERROR;
        return TWRC_FAILURE;
    }
    if (TWRC_SUCCESS != _get_image_and_startup_jpeg()) {
	FIXME("Failed to get an image\n");
	activeDS.twCC = TWCC_OPERATIONERROR;
	return TWRC_FAILURE;
    }
    TRACE("Acquiring image %dx%dx%d bits from gphoto.\n",
	activeDS.jd.output_width, activeDS.jd.output_height,
	activeDS.jd.output_components*8);
    ZeroMemory (&bmpInfo, sizeof (BITMAPINFO));
    bmpInfo.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
    bmpInfo.bmiHeader.biWidth = activeDS.jd.output_width;
    bmpInfo.bmiHeader.biHeight = -activeDS.jd.output_height;
    bmpInfo.bmiHeader.biPlanes = 1;
    bmpInfo.bmiHeader.biBitCount = activeDS.jd.output_components*8;
    bmpInfo.bmiHeader.biCompression = BI_RGB;
    bmpInfo.bmiHeader.biSizeImage = 0;
    bmpInfo.bmiHeader.biXPelsPerMeter = 0;
    bmpInfo.bmiHeader.biYPelsPerMeter = 0;
    bmpInfo.bmiHeader.biClrUsed = 0;
    bmpInfo.bmiHeader.biClrImportant = 0;
    hDIB = CreateDIBSection ((dc = GetDC(activeDS.hwndOwner)), &bmpInfo,
			     DIB_RGB_COLORS, (LPVOID)&bits, 0, 0);
    if (!hDIB) {
	FIXME("Failed creating DIB.\n");
	gp_file_unref (activeDS.file);
	activeDS.file = NULL;
	activeDS.twCC = TWCC_LOWMEMORY;
	return TWRC_FAILURE;
    }
    samprow = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,activeDS.jd.output_width*activeDS.jd.output_components);
    oldsamprow = samprow;
    while ( activeDS.jd.output_scanline<activeDS.jd.output_height ) {
	int i, x = pjpeg_read_scanlines(&activeDS.jd,&samprow,1);
	if (x != 1) {
		FIXME("failed to read current scanline?\n");
		break;
	}
	/* We have to convert from RGB to BGR, see MSDN/ BITMAPINFOHEADER */
	for(i=0;i<activeDS.jd.output_width;i++,samprow+=activeDS.jd.output_components) {
	    *(bits++) = *(samprow+2);
	    *(bits++) = *(samprow+1);
	    *(bits++) = *(samprow);
	}
	bits = (LPBYTE)(((UINT_PTR)bits + 3) & ~3);
	samprow = oldsamprow;
    }
    HeapFree (GetProcessHeap(), 0, samprow);
    gp_file_unref (activeDS.file);
    activeDS.file = NULL;
    ReleaseDC (activeDS.hwndOwner, dc);
    *pHandle = (UINT_PTR)hDIB;
    activeDS.twCC = TWCC_SUCCESS;
    activeDS.currentState = 7;
    return TWRC_XFERDONE;
#else
    return TWRC_FAILURE;
#endif
}
Exemple #21
0
/* DG_IMAGE/DAT_IMAGEMEMXFER/MSG_GET */
TW_UINT16 GPHOTO2_ImageMemXferGet (pTW_IDENTITY pOrigin, 
                                 TW_MEMREF pData)
{
#ifdef HAVE_GPHOTO2
    TW_UINT16 twRC = TWRC_SUCCESS;
    pTW_IMAGEMEMXFER pImageMemXfer = (pTW_IMAGEMEMXFER) pData;
    LPBYTE buffer;
    int readrows;
    unsigned int curoff;

    TRACE ("DG_IMAGE/DAT_IMAGEMEMXFER/MSG_GET\n");
    if (activeDS.currentState < 6 || activeDS.currentState > 7) {
        activeDS.twCC = TWCC_SEQERROR;
        return TWRC_FAILURE;
    }
    TRACE("pImageMemXfer.Compression is %d\n", pImageMemXfer->Compression);
    if (activeDS.currentState == 6) {
	if (TWRC_SUCCESS != _get_image_and_startup_jpeg()) {
	    FIXME("Failed to get an image\n");
	    activeDS.twCC = TWCC_SEQERROR;
	    return TWRC_FAILURE;
	}

    if (!activeDS.progressWnd)
        activeDS.progressWnd = TransferringDialogBox(NULL,0);
    TransferringDialogBox(activeDS.progressWnd,0);

        activeDS.currentState = 7;
    } else {
	if (!activeDS.file) {
    	    activeDS.twCC = TWRC_SUCCESS;
	    return TWRC_XFERDONE;
	}
    }

    if (pImageMemXfer->Memory.Flags & TWMF_HANDLE) {
	FIXME("Memory Handle, may not be locked correctly\n");
	buffer = LocalLock(pImageMemXfer->Memory.TheMem);
    } else
	buffer = pImageMemXfer->Memory.TheMem;
   
    memset(buffer,0,pImageMemXfer->Memory.Length);
    curoff = 0; readrows = 0;
    pImageMemXfer->YOffset	= activeDS.jd.output_scanline;
    pImageMemXfer->XOffset	= 0;	/* we do whole strips */
    while ((activeDS.jd.output_scanline<activeDS.jd.output_height) &&
	   ((pImageMemXfer->Memory.Length - curoff) > activeDS.jd.output_width*activeDS.jd.output_components)
    ) {
	JSAMPROW row = buffer+curoff;
	int x = pjpeg_read_scanlines(&activeDS.jd,&row,1);
	if (x != 1) {
		FIXME("failed to read current scanline?\n");
		break;
	}
	readrows++;
	curoff += activeDS.jd.output_width*activeDS.jd.output_components;
    }
    pImageMemXfer->Compression	= TWCP_NONE;
    pImageMemXfer->BytesPerRow	= activeDS.jd.output_components * activeDS.jd.output_width;
    pImageMemXfer->Rows		= readrows;
    pImageMemXfer->Columns	= activeDS.jd.output_width; /* we do whole strips */
    pImageMemXfer->BytesWritten = curoff;

    TransferringDialogBox(activeDS.progressWnd,0);

    if (activeDS.jd.output_scanline == activeDS.jd.output_height) {
        pjpeg_finish_decompress(&activeDS.jd);
        pjpeg_destroy_decompress(&activeDS.jd);
	gp_file_unref (activeDS.file);
	activeDS.file = NULL;
	TRACE("xfer is done!\n");

	/*TransferringDialogBox(activeDS.progressWnd, -1);*/
	twRC = TWRC_XFERDONE;
    }
    activeDS.twCC = TWRC_SUCCESS;
    if (pImageMemXfer->Memory.Flags & TWMF_HANDLE)
        LocalUnlock(pImageMemXfer->Memory.TheMem);
    return twRC;
#else
    return TWRC_FAILURE;
#endif
}
Exemple #22
0
static TW_UINT16 _get_image_and_startup_jpeg(void) {
    const char *folder = NULL, *filename = NULL;
    struct gphoto2_file *file;
    const unsigned char *filedata;
    unsigned long filesize;
    int ret;

    if (activeDS.file) /* Already loaded. */
	return TWRC_SUCCESS;

    if(!libjpeg_handle) {
	if(!load_libjpeg()) {
	    FIXME("Failed reading JPEG because unable to find %s\n", SONAME_LIBJPEG);
	    filedata = NULL;
	    return TWRC_FAILURE;
	}
    }

    LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry ) {
	if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg")) {
	    filename = file->filename;
	    folder = file->folder;
	    TRACE("downloading %s/%s\n", folder, filename);
	    if (file->download) {
		file->download = FALSE; /* mark as done */
		break;
	    }
	}
    }
    gp_file_new (&activeDS.file);
    ret = gp_camera_file_get(activeDS.camera, folder, filename, GP_FILE_TYPE_NORMAL,
			     activeDS.file, activeDS.context);
    if (ret < GP_OK) {
	FIXME("Failed to get file?\n");
	activeDS.twCC = TWCC_SEQERROR;
	return TWRC_FAILURE;
    }
    ret = gp_file_get_data_and_size (activeDS.file, (const char**)&filedata, &filesize);
    if (ret < GP_OK) {
	FIXME("Failed to get file data?\n");
	activeDS.twCC = TWCC_SEQERROR;
	return TWRC_FAILURE;
    }

    /* This is basically so we can use in-memory data for jpeg decompression.
     * We need to have all the functions.
     */
    activeDS.xjsm.next_input_byte	= filedata;
    activeDS.xjsm.bytes_in_buffer	= filesize;
    activeDS.xjsm.init_source	= _jpeg_init_source;
    activeDS.xjsm.fill_input_buffer	= _jpeg_fill_input_buffer;
    activeDS.xjsm.skip_input_data	= _jpeg_skip_input_data;
    activeDS.xjsm.resync_to_restart	= _jpeg_resync_to_restart;
    activeDS.xjsm.term_source	= _jpeg_term_source;

    activeDS.jd.err = pjpeg_std_error(&activeDS.jerr);
    /* jpeg_create_decompress is a macro that expands to jpeg_CreateDecompress - see jpeglib.h
     * jpeg_create_decompress(&jd); */
    pjpeg_CreateDecompress(&activeDS.jd, JPEG_LIB_VERSION, (size_t) sizeof(struct jpeg_decompress_struct));
    activeDS.jd.src = &activeDS.xjsm;
    ret=pjpeg_read_header(&activeDS.jd,TRUE);
    activeDS.jd.out_color_space = JCS_RGB;
    pjpeg_start_decompress(&activeDS.jd);
    if (ret != JPEG_HEADER_OK) {
	ERR("Jpeg image in stream has bad format, read header returned %d.\n",ret);
	gp_file_unref (activeDS.file);
	activeDS.file = NULL;
	return TWRC_FAILURE;
    }
    return TWRC_SUCCESS;
}
Exemple #23
0
int
main (int argc, char **argv)
{
    fd_set rs;
    struct timeval tv;
    int n, cmd_len;
    char cmd[PATH_MAX + 32];
    const char *arg;
    GFParams params;

    memset (&params, 0, sizeof (GFParams));
    if (gp_camera_new (&(params.camera)) < 0)
        goto ExitError;
    if (gp_abilities_list_new (&(params.al)) < 0)
        goto ExitError;
    if (gp_abilities_list_load (params.al, NULL) < 0)
        goto ExitError;
    if (gp_port_info_list_new (&params.il) < 0)
        goto ExitError;
    if (gp_port_info_list_load (params.il) < 0)
        goto ExitError;
    params.folder = malloc (strlen ("/") + 1);
    if (!params.folder)
        goto ExitError;
    strcpy (params.folder, "/");
    params.idletime = 1800;

    n = sizeof (struct sockaddr_in);
    if (getsockname (0, (struct sockaddr *) &params.sai_sock, &n)) {
        fprintf (stdout, "421 Can not get name of sock.\r\n");
        fflush (stdout);
        goto ExitError;
    }
    n = sizeof (struct sockaddr_in);
    if (getpeername (0, (struct sockaddr *) &params.sai_peer, &n)) {
        fprintf (stdout, "421 Can not get name of peer.\r\n");
        fflush (stdout);
        goto ExitError;
    }
    n = IPTOS_LOWDELAY;
    setsockopt (0, IPPROTO_IP, IP_TOS, (char *) &n, sizeof (int));

    fprintf (stdout, "220-Hello and welcome to the wonderful world\r\n");
    fprintf (stdout, "220-of gphoto!\r\n");
    fprintf (stdout, "220-\r\n");
    fprintf (stdout, "220-Use this server like a standard FTP-Server.\r\n");
    fprintf (stdout, "220-List files in virtual directory\r\n");
    fflush (stdout);
    fprintf (stdout, "220-'/capture-image' in order to capture\r\n");
    fflush (stdout);
    fprintf (stdout, "220-an image, in '/capture-preview' in order\r\n");
    fflush (stdout);
    fprintf (stdout, "220-to capture a preview.\r\n");
    fflush (stdout);
    fprintf (stdout, "220 FTP server ready.\r\n");
    fflush (stdout);

    while (1) {

        /* Read something. */
        syslog (LOG_INFO, "Reading...");
        FD_ZERO (&rs);
        tv.tv_sec = 1800;
        tv.tv_usec = 0;
        memset (cmd, 0, sizeof (cmd));
        cmd_len = n = 0;
        while (1) {
            if (!n) {
                FD_SET (0, &rs);
                select (1, &rs, NULL, NULL, &tv);
                if (ioctl (0, FIONREAD, &n) < 0)
                    n = 0;
            }
            if (FD_ISSET (0, &rs)) {
                if (read (0, cmd + cmd_len, 1) <= 0)
                    goto ExitError;
                if (n)
                    n--;
                if (cmd[cmd_len] == '\n') {
                    cmd[cmd_len + 1] = '\0';
                    break;
                }
                if (cmd_len < sizeof (cmd) - 2)
                    cmd_len++;
            } else
                goto ExitError;
        }

        syslog (LOG_INFO, "Got '%s'...", cmd);
        for (n = 0; isalpha (cmd[n]) && n < sizeof (cmd); n++)
            cmd[n] = tolower (cmd[n]);
        if (!n) {
            printf ("%3d %s\r\n", 221, "Goodbye.");
            fflush (stdout);
            goto ExitOk;
        }
        while (isspace (cmd[n]) && n < sizeof (cmd))
            cmd[n++] = '\0';
        arg = cmd + n;
        while (cmd[n] && n < sizeof (cmd))
            n++;
        n--;
        while (isspace (cmd[n]))
            cmd[n--] = '\0';
        syslog (LOG_INFO, "Processing '%s' - '%s'...", cmd, arg);
        if (!strcasecmp (cmd, "cwd")) {
            gf_cwd (&params, arg);
        } else if (!strcasecmp (cmd, "list")) {
            if (gf_list (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "noop")) {
            fprintf (stdout, "200 NOOP command successful.\r\n");
            fflush (stdout);
        } else if (!strcasecmp (cmd, "pass")) {
            if (gf_pass (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "pasv")) {
            gf_pasv (&params);
        } else if (!strcasecmp (cmd, "port")) {
            if (gf_port (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "pwd") ||
                   !strcasecmp (cmd, "xpwd")) {
            fprintf (stdout, "257 \"%s\"\r\n", params.folder);
            fflush (stdout);
        } else if (!strcasecmp (cmd, "quit")) {
            printf ("%3d %s\r\n", 221, "Goodbye.");
            fflush (stdout);
            syslog (LOG_INFO, "Quit.");
            return (0);
        } else if (!strcasecmp (cmd, "retr")) {
            if (gf_retr (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "syst")) {
            printf ("215 UNIX Type: L8\r\n");
            fflush (stdout);
        } else if (!strcasecmp (cmd, "type")) {
            if (!arg)
                goto ExitError;
            gf_type (&params, *arg);
        } else if (!strcasecmp (cmd, "user")) {
            if (gf_user (&params, arg) < 0)
                goto ExitError;
        } else {
            syslog (LOG_INFO, "Command '%s'...", cmd);
            printf ("%3d %s\r\n", 550, "Unknown command.");
            fflush (stdout);
        }
    }

ExitError:
    gp_abilities_list_free (params.al);
    gp_port_info_list_free (params.il);
    gp_camera_unref (params.camera);
    gp_file_unref (params.file);
    free (params.camera);
    syslog (LOG_INFO, "Error: 1");
    return (1);

ExitOk:
    gp_abilities_list_free (params.al);
    gp_port_info_list_free (params.il);
    gp_camera_unref (params.camera);
    gp_file_unref (params.file);
    free (params.camera);
    return (0);
}
Exemple #24
0
bool GPCamera::getMetadata(const QString& folder, const QString& itemName, DMetadata& meta)
{
#ifdef HAVE_GPHOTO2
    int               errorCode;
    CameraFile*       cfile = 0;
    const char*       data  = 0;
    unsigned long int size;

    gp_file_new(&cfile);

    d->status->cancel = false;
    errorCode         = gp_camera_file_get(d->camera, QFile::encodeName(folder).constData(),
                                           QFile::encodeName(itemName).constData(),
                                           GP_FILE_TYPE_EXIF,
                                           cfile, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get camera item!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    errorCode = gp_file_get_data_and_size(cfile, &data, &size);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get Exif data from camera item!";
        printGphotoErrorDescription(errorCode);
        gp_file_unref(cfile);
        return false;
    }

    QByteArray exifData(data, size);

    gp_file_unref(cfile);

    // Sometimes, GPhoto2 drivers return complete APP1 JFIF section. Exiv2 cannot
    // decode (yet) exif metadata from APP1. We will find Exif header to get data at this place
    // to please with Exiv2...

    qCDebug(DIGIKAM_IMPORTUI_LOG) << "Size of Exif metadata from camera = " << exifData.size();

    if (!exifData.isEmpty())
    {
        char exifHeader[] = { 0x45, 0x78, 0x69, 0x66, 0x00, 0x00 };
        int i             = exifData.indexOf(*exifHeader);

        if (i != -1)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Exif header found at position " << i;
            i = i + sizeof(exifHeader);
            QByteArray data;
            data.resize(exifData.size() - i);
            memcpy(data.data(), exifData.data() + i, data.size());
            meta.setExif(data);
            return true;
        }
    }

    return false;
#else
    Q_UNUSED(folder);
    Q_UNUSED(itemName);
    Q_UNUSED(meta);
    return false;
#endif /* HAVE_GPHOTO2 */
}
Exemple #25
0
bool photo_camera::photo_camera_capture( photo_image* image )
{
  int fd, error_code;
  CameraFile *photo_file;
  CameraFilePath photo_file_path;
  char temp_file_name[20];

  // NOP: This gets overridden in the library to /capt0000.jpg
  strcpy( photo_file_path.folder, "/" );
  strcpy( photo_file_path.name, "foo.jpg" );

  error_code = gp_camera_capture( camera_, GP_CAPTURE_IMAGE, &photo_file_path, context_ );
  if( error_code < GP_OK )
  {
    photo_reporter::error( "gp_camera_capture()" );
    gp_context_error( context_, "Could not capture image  (error code %d)\n", error_code );
    return false;
  }

  // create temporary file
  strcpy( temp_file_name, "tmpfileXXXXXX" );
  fd = mkstemp( temp_file_name );
  error_code = gp_file_new_from_fd( &photo_file, fd );
  if( error_code < GP_OK )
  {
    close( fd );
    unlink( temp_file_name );

    photo_reporter::error( "gp_file_new_from_fd()" );
    gp_context_error( context_, "Could not create a new image file from %s%s (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
    gp_file_free( photo_file );
    return false;
  }

  // get image from camera and store in temporary file
  error_code = gp_camera_file_get( camera_, photo_file_path.folder, photo_file_path.name, GP_FILE_TYPE_NORMAL, photo_file, context_ );
  if( error_code < GP_OK )
  {
    gp_file_unref( photo_file );
    unlink( temp_file_name );
    photo_reporter::error( "gp_camera_file_get()" );
    gp_context_error( context_, "Could not get file %s%s (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
    return false;
  }

  // delete image from camera's memory
  error_code = gp_camera_file_delete( camera_, photo_file_path.folder, photo_file_path.name, context_ );
  if( error_code < GP_OK )
  {
    unlink( temp_file_name );
    photo_reporter::error( "gp_camera_file_delete()" );
    gp_context_error( context_, "Could delete file %s%s  (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
    gp_file_free( photo_file );
    return false;
  }

  // load image from temporary file
  if( image->photo_image_read( std::string(temp_file_name) ) == true )
  {
    gp_file_free( photo_file );
    unlink( temp_file_name );
    return true;
  }

  photo_reporter::error( "photo_image_read()" );
  gp_file_free( photo_file );
  unlink( temp_file_name );
  return false;
}
Exemple #26
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);
}
Exemple #27
0
static int
file_list_func (CameraFilesystem *fs, const char *folder,
		CameraList *list, void *data, GPContext *context)
{
	Camera *camera = data;
	unsigned int i, filecount, id, size, type;
	CameraFile *file;
	CameraFileInfo info;
	unsigned char *buffer = NULL;
	int ret, n_img=0, n_avi=0, n_wav=0;
	char fn[100];

	CHECK (pccam300_get_filecount (camera->port, &filecount));

	id = gp_context_progress_start (context, filecount,
			_("Getting file list..."));
	
	for (i = 0; i < filecount; i++) {
		/* Get information */
		gp_file_new (&file);
	
		ret = pccam300_get_file (camera->port, context, i,
		                          &buffer, &size, &type);
		if (ret < GP_OK) {
			gp_file_free (file);
			return ret;
		}

		info.audio.fields = GP_FILE_INFO_NONE;
		info.preview.fields = GP_FILE_INFO_NONE;

		info.file.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_TYPE;
		info.file.size = size;

		switch (type) {
			case PCCAM300_MIME_JPEG:
				strcpy (info.file.type, GP_MIME_JPEG);
				sprintf (fn, "Image%03i.jpeg", n_img++);
				break;
			case PCCAM300_MIME_AVI:
				strcpy (info.file.type, GP_MIME_AVI);
				sprintf (fn, "Movie%03i.UNUSABLE", n_avi++);
				break;
			case PCCAM300_MIME_WAV:
				strcpy (info.file.type, GP_MIME_WAV);
				sprintf (fn, "Audio%03i.UNUSABLE", n_wav++);
				break;
			default:
				break;
		}

		if (file)
			gp_file_set_data_and_size (file, buffer, size);
		else
			free (buffer);
		
		/*
		 * Append directly to the filesystem instead of to the list,
		 * because we have additional information. 
		 * */
		gp_filesystem_append (camera->fs, folder, fn, context);
		gp_filesystem_set_info_noop (camera->fs, folder, fn, info, context);
		gp_filesystem_set_file_noop (camera->fs, folder, fn, GP_FILE_TYPE_NORMAL,
					file, context);
		gp_file_unref (file);

		gp_context_idle (context);
		gp_context_progress_update (context, id, i + 1);
		if (gp_context_cancel(context) == GP_CONTEXT_FEEDBACK_CANCEL)
			return (GP_ERROR_CANCEL);
	}
	gp_context_progress_stop (context, id);
	return GP_OK;
}
Exemple #28
0
static void
freeOpenFile(OpenFile *openFile)
{
   gp_file_unref(openFile->file);
   g_free(openFile);
}
Exemple #29
0
bool GPhotoCCD::capturePreview()
{

    if (sim)
        return false;

    int rc = GP_OK;
    char errMsg[MAXRBUF];
    const char* previewData;
    unsigned long int previewSize;

    CameraFile* previewFile = NULL;

    rc = gp_file_new(&previewFile);
    if (rc != GP_OK)
    {
       DEBUGF(INDI::Logger::DBG_ERROR, "Error creating gphoto file: %s", gp_result_as_string(rc));
      return false;
    }

    for (int i=0; i < MAX_RETRIES; i++)
    {
        rc = gphoto_capture_preview(gphotodrv, previewFile, errMsg);
        if (rc == true)
            break;
    }

    if (rc != GP_OK)
    {
        DEBUGF(INDI::Logger::DBG_ERROR, "%s", errMsg);
        return false;
    }

    if (rc >= GP_OK)
    {
       rc = gp_file_get_data_and_size(previewFile, &previewData, &previewSize);
       if (rc != GP_OK)
       {
           DEBUGF(INDI::Logger::DBG_ERROR, "Error getting preview image data and size: %s", gp_result_as_string(rc));
           return false;
       }
    }

    //DEBUGF(INDI::Logger::DBG_DEBUG, "Preview capture size %d bytes.", previewSize);

   char *previewBlob = (char *) previewData;

   imageB->blob = previewBlob;
   imageB->bloblen = previewSize;
   imageB->size = previewSize;
   strncpy(imageB->format, "stream_jpeg", MAXINDIBLOBFMT);

   IDSetBLOB (imageBP, NULL);

    if (previewFile)
    {
       gp_file_unref(previewFile);
       previewFile = NULL;
    }

    return true;
}
Exemple #30
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;
}