Пример #1
0
static GnomeVFSResult do_get_file_info_from_handle (
    GnomeVFSMethod          *method,
    GnomeVFSMethodHandle    *handle,
    GnomeVFSFileInfo        *info,
    GnomeVFSFileInfoOptions  options,
    GnomeVFSContext         *context)
{
    CameraFileInfo camera_info;
    GnomeVFSResult result;
    FileHandle *fh = (FileHandle *) handle;
    const char *name;

    G_LOCK (cameras);

    gp_file_get_name (fh->file, &name);
    result = GNOME_VFS_RESULT (gp_camera_file_get_info (fh->camera,
                               fh->dirname,
                               name,
                               &camera_info,
                               NULL));
    if (result != GNOME_VFS_OK) {
        G_UNLOCK (cameras);
        return (result);
    }

    get_info_from_camera_info (&camera_info, fh->preview, info);

    G_UNLOCK (cameras);

    return (GNOME_VFS_OK);
}
Пример #2
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);
}
Пример #3
0
static int
put_file_func (CameraFilesystem *fs, const char *folder, CameraFile *file,
		void *data, GPContext *context)
{
#ifdef HAVE_GD
	Camera *camera = data;
	char *filedata = NULL;
	const char *name;
	int ret, in_width, in_height, in_x, in_y;
	double aspect_in, aspect_out;
	unsigned long filesize = 0;
	gdImagePtr im_out, im_in = NULL;

	if (strcmp (folder, "/"))
		return GP_ERROR_DIRECTORY_NOT_FOUND;

	CHECK (gp_file_get_name (file, &name))

	CHECK (gp_file_get_data_and_size (file, (const char **)&filedata,
					  &filesize))

	/* Try loading the file using gd, starting with the most often
	   used types first */

	/* gdImageCreateFromJpegPtr is chatty on error, don't call it on
	   non JPEG files */
	if (filesize > 2 &&
	    (uint8_t)filedata[0] == 0xff && (uint8_t)filedata[1] == 0xd8)
		im_in = gdImageCreateFromJpegPtr(filesize, filedata);
	if (im_in == NULL)
		im_in = gdImageCreateFromPngPtr(filesize, filedata);
	if (im_in == NULL)
		im_in = gdImageCreateFromGifPtr(filesize, filedata);
	if (im_in == NULL)
		im_in = gdImageCreateFromWBMPPtr(filesize, filedata);
	if (im_in == NULL) {
		gp_log (GP_LOG_ERROR, "tp6801",
			"Unrecognized file format for file: %s%s",
			folder, name);
		return GP_ERROR_BAD_PARAMETERS;
	}

	im_out = gdImageCreateTrueColor(camera->pl->width, camera->pl->height);
	if (im_out == NULL) {
		gdImageDestroy (im_in);
		return GP_ERROR_NO_MEMORY;
	}

	/* Keep aspect */
	aspect_in  = (double)im_in->sx / im_in->sy;
	aspect_out = (double)im_out->sx / im_out->sy;
	if (aspect_in > aspect_out) {
		/* Reduce in width (crop left and right) */
		in_width = (im_in->sx / aspect_in) * aspect_out;
		in_x = (im_in->sx - in_width) / 2;
		in_height = im_in->sy;
		in_y = 0;
	} else {
		/* Reduce in height (crop top and bottom) */
		in_width = im_in->sx;
		in_x = 0;
		in_height = (im_in->sy * aspect_in) / aspect_out;
		in_y = (im_in->sy - in_height) / 2;
	}

	gdImageCopyResampled (im_out, im_in, 0, 0, in_x, in_y,
			      im_out->sx, im_out->sy,
			      in_width, in_height);

	if (im_in->sx != im_out->sx ||
	    im_in->sy != im_out->sy)
		gdImageSharpen(im_out, 100);

	ret = tp6801_write_file (camera, im_out->tpixels);
	if (ret >= 0) {
		/* Commit the changes to the device */
		ret = tp6801_commit(camera);
	}

	gdImageDestroy (im_in);
	gdImageDestroy (im_out);
	return ret;
#else
	gp_log(GP_LOG_ERROR,"tp6801", "GD compression not supported - no libGD present during build");
	return GP_ERROR_NOT_SUPPORTED;
#endif
}