diff --git a/backend/gphoto2.c b/backend/gphoto2.c index 87a03fc37..a72c4cdcc 100644 --- a/backend/gphoto2.c +++ b/backend/gphoto2.c @@ -385,6 +385,17 @@ init_gphoto2 (void) return SANE_STATUS_INVAL; } + if (camera) + { + /* + * We get here if re-initializing the camera: either because + * the user clicked the "re-establish" button, or we need to + * recalculate the number of photos after taking a picture. + * We must release the old camera before starting over. + */ + CHECK_RET (gp_camera_unref (camera)); + } + CHECK_RET (gp_camera_new (&camera)); CHECK_RET (gp_abilities_list_new (&al)); @@ -450,7 +461,7 @@ init_gphoto2 (void) sod[GPHOTO2_OPT_SNAP].cap |= SANE_CAP_INACTIVE; } - if (!(abilities.operations & GP_OPERATION_CAPTURE_PREVIEW)) + if (!(abilities.file_operations & GP_FILE_OPERATION_PREVIEW)) { DBG (20, "Camera does not support image preview\n"); sod[GPHOTO2_OPT_THUMBS].cap |= SANE_CAP_INACTIVE; @@ -1576,6 +1587,16 @@ snap_pic (void) return SANE_STATUS_INVAL; } + /* + * This is needed when the camera has no files and the first picture + * is taken. I guess it's because a folder needs to be created and + * the filesystem doesn't know about it. + */ + if (Cam_data.pic_taken == 0) + { + gp_filesystem_reset (camera->fs); + } + CHECK_RET (gp_camera_capture (camera, GP_CAPTURE_IMAGE, &path, NULL)); /* Can't just increment picture count, because if the camera has