/** * Retrieves a file from the #Camera. * * @param camera a #Camera * @param folder a folder * @param file the name of a file * @param type the #CameraFileType * @param camera_file a #CameraFile * @param context a #GPContext * @return a gphoto2 error code * **/ int gp_camera_file_get (Camera *camera, const char *folder, const char *file, CameraFileType type, CameraFile *camera_file, GPContext *context) { gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Getting file '%s' in " "folder '%s'...", file, folder); CHECK_NULL (camera && folder && file && camera_file); CHECK_INIT (camera, context); CR (camera, gp_file_clean (camera_file), context); /* Did we get reasonable foldername/filename? */ if (strlen (folder) == 0) { CAMERA_UNUSED (camera, context); return (GP_ERROR_DIRECTORY_NOT_FOUND); } if (strlen (file) == 0) { CAMERA_UNUSED (camera, context); return (GP_ERROR_FILE_NOT_FOUND); } CHECK_RESULT_OPEN_CLOSE (camera, gp_filesystem_get_file (camera->fs, folder, file, type, camera_file, context), context); CAMERA_UNUSED (camera, context); return (GP_OK); }
/** * Captures a preview that won't be stored on the camera but returned in * supplied file. * * @param camera a #Camera * @param file a #CameraFile * @param context a #GPContext * @return a gphoto2 error code * * For example, you could use gp_capture_preview() for taking some sample * pictures before calling gp_capture(). * **/ int gp_camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context) { char *xname; C_PARAMS (camera && file); CHECK_INIT (camera, context); CR (camera, gp_file_clean (file), context); if (!camera->functions->capture_preview) { gp_context_error (context, _("This camera can " "not capture previews.")); CAMERA_UNUSED (camera, context); return (GP_ERROR_NOT_SUPPORTED); } CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->capture_preview ( camera, file, context), context); gp_file_get_name_by_type (file, "capture_preview", GP_FILE_TYPE_NORMAL, &xname); /* FIXME: Marcus ... will go away, just keep compatible now. */ gp_file_set_name (file, xname); free (xname); CAMERA_UNUSED (camera, context); return (GP_OK); }
/** * Captures a preview that won't be stored on the camera but returned in * supplied file. * * @param camera a #Camera * @param file a #CameraFile * @param context a #GPContext * @return a gphoto2 error code * * For example, you could use #gp_capture_preview for taking some sample * pictures before calling #gp_capture. * **/ int gp_camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context) { CHECK_NULL (camera && file); CHECK_INIT (camera, context); CR (camera, gp_file_clean (file), context); if (!camera->functions->capture_preview) { gp_context_error (context, _("This camera can " "not capture previews.")); CAMERA_UNUSED (camera, context); return (GP_ERROR_NOT_SUPPORTED); } CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->capture_preview ( camera, file, context), context); CAMERA_UNUSED (camera, context); return (GP_OK); }
void GPhotoCameraWorker::capturePreview() { openCamera(); if (m_status != QCamera::ActiveStatus) { setStatus(QCamera::StartingStatus); } gp_file_clean(m_file); int ret = gp_camera_capture_preview(m_camera, m_file, m_context); if (GP_OK == ret) { const char* data; unsigned long int size = 0; ret = gp_file_get_data_and_size(m_file, &data, &size); if (GP_OK == ret) { m_capturingFailCount = 0; const QImage &result = QImage::fromData(QByteArray(data, int(size))); setStatus(QCamera::ActiveStatus); emit previewCaptured(result); return; } } qWarning() << "Failed retrieving preview" << ret; ++m_capturingFailCount; if (m_capturingFailCount >= capturingFailLimit) { qWarning() << "Closing camera because of capturing fail"; emit error(QCamera::CameraError, tr("Unable to capture frame")); setStatus(QCamera::UnloadedStatus); closeCamera(); } }