示例#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);
}
示例#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);
}
示例#3
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);
}
示例#4
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;
}
示例#5
0
/* This function reads all thumbnails at once and initializes the whole
 * camera filesystem. This can be done, because finding out how much 
 * pictures are on the camera is done by reading the whole preview picture
 * stream anyway.
 * And since the file infos are static mostly, why not just set them too at
 * the same time.
 */
int
jd11_index_reader(GPPort *port, CameraFilesystem *fs, GPContext *context) {
    int		i, id, count, xsize, curread=0, ret=0;
    unsigned char	*indexbuf;

    ret = jd11_select_index(port);
    if (ret != GP_OK)
	return ret;
    xsize = jd11_imgsize(port);
    if (!xsize) { /* shortcut, no reading needed */
	return GP_OK;
    }
    count = xsize/(64*48);
    xsize = count * (64*48);
    indexbuf = malloc(xsize);
    if (!indexbuf) return GP_ERROR_NO_MEMORY;
    id = gp_context_progress_start (context, xsize,
				    _("Downloading thumbnail..."));
    _send_cmd(port,0xfff1);
    while (curread < xsize) {
	    int readsize = xsize-curread;
	    if (readsize>200) readsize = 200;
	    ret=getpacket(port,indexbuf+curread,readsize);
	    if (ret==0)
		    break;
	    curread+=ret;
	    if (ret<200)
		    break;
	    gp_context_progress_update (context, id, curread);
	    if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) {
		/* What to do...Just free the stuff we allocated for now.*/
		free(indexbuf);
		return GP_ERROR_CANCEL;
	    }
	    _send_cmd(port,0xfff1);
    }
    gp_context_progress_stop (context, id);
    for (i=0;i<count;i++) {
	CameraFile	*file;
	char		fn[20];
	unsigned char *src;
	unsigned char thumb[64*48];
	int y;
	CameraFileInfo	info;
	
	ret = gp_file_new(&file);
	if (ret!=GP_OK) {
	    free(indexbuf);
	    return ret;
	}
	sprintf(fn,"image%02i.pgm",i);
	gp_file_set_mime_type(file, GP_MIME_PGM);
	gp_file_append(file, THUMBHEADER, strlen(THUMBHEADER));
	src = indexbuf+(i*64*48);
	for (y=0;y<48;y++) {
	    int x,off = 64*y;
	    for (x=0;x<64;x++)
		thumb[47*64-off+(63-x)] = src[off+x];
	}
	ret = gp_file_append(file,(char*)thumb,sizeof(thumb));
	if (ret != GP_OK) {
		gp_file_free (file);
		return ret;
	}
	ret = gp_filesystem_append(fs, "/", fn, context);
	if (ret != GP_OK) {
		/* should perhaps remove the entry again */
		gp_file_free (file);
		return ret;
	}
	ret = gp_filesystem_set_file_noop(fs, "/", fn, GP_FILE_TYPE_PREVIEW, file, context);
	if (ret != GP_OK) return ret;

	/* we also get the fs info for free, so just set it */
	info.file.fields = GP_FILE_INFO_TYPE |
			GP_FILE_INFO_WIDTH | GP_FILE_INFO_HEIGHT | 
			GP_FILE_INFO_SIZE;
	strcpy(info.file.type,GP_MIME_PNM);
	info.file.width		= 640;
	info.file.height	= 480;
	info.file.size		= 640*480*3+strlen(IMGHEADER);
	info.preview.fields = GP_FILE_INFO_TYPE |
			GP_FILE_INFO_WIDTH | GP_FILE_INFO_HEIGHT | 
			GP_FILE_INFO_SIZE;
	strcpy(info.preview.type,GP_MIME_PGM);
	info.preview.width	= 64;
	info.preview.height	= 48;
	info.preview.size	= 64*48+strlen(THUMBHEADER);
	ret = gp_filesystem_set_info_noop(fs, "/", fn, info, context);
    }
    free(indexbuf);
    return GP_OK;
}