Example #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);
}
Example #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);
}
Example #3
0
/*
 *	file list function 
 */
static int 
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		void *data, GPContext *context)
{
	Camera *camera = data;
	CameraFileInfo info;
	int32_t tpages=0;
	int pcnt,ecnt;		/* pagecounter, entrycounter*/
	struct traveler_toc_page toc;
	int id;
 
	/* get number of TOC pages */
	CR (sx330z_get_toc_num_pages (camera, context, &tpages));
	/* Read the TOC pages */
	id = gp_context_progress_start (context, tpages, _("Getting "
			"information on %i files..."), tpages);
	for (pcnt = 0; pcnt < tpages; pcnt++) {
		CR (sx330z_get_toc_page (camera, context, &toc, pcnt));
		for (ecnt = 0; ecnt < toc.numEntries; ecnt++) {
			char fn[20];

			info.audio.fields = GP_FILE_INFO_NONE;
			info.preview.fields = GP_FILE_INFO_TYPE;
			strcpy (info.preview.type, GP_MIME_EXIF);
			info.file.fields = GP_FILE_INFO_SIZE |
					   GP_FILE_INFO_TYPE |
					   GP_FILE_INFO_PERMISSIONS;
			info.file.size = toc.entries[ecnt].size;
			info.file.permissions = GP_FILE_PERM_READ |
						GP_FILE_PERM_DELETE;
			strcpy (info.file.type,GP_MIME_JPEG); 
			sprintf (fn, "%.12s", toc.entries[ecnt].name);

			/*
			 * 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_context_progress_update (context, id, pcnt);
		if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL)
			return (GP_ERROR_CANCEL);
	}
	
	gp_context_progress_stop (context, id);

	return (GP_OK);
}
Example #4
0
static void
decode_and_get_info(Camera *camera, const char *folder, struct tf_packet *p, const char *fn,
		CameraFileInfo *info, GPContext *context)
{
	unsigned short count = (get_u16(&p->length) - PACKET_HEAD_SIZE) / sizeof(struct typefile);
	struct typefile *entries = (struct typefile *) p->data;
	int i;
	char *name;

	for(i = 0; i < count; i++) {
		switch (entries[i].filetype) {
		case 1: break;/*dir*/
		case 2:	/* file */
			name = _convert_and_logname (camera, (char*)entries[i].name);
			if (!strcmp (name, fn)) { /* the wanted current one */
				memset (info, 0, sizeof (*info));
				info->file.fields = GP_FILE_INFO_SIZE|GP_FILE_INFO_MTIME;
				if (strstr (name, ".rec")) {
					info->file.fields |= GP_FILE_INFO_TYPE;
					strcpy (info->file.type, GP_MIME_MPEG);
				}
				info->file.size = get_u64(&entries[i].size);
				info->file.mtime = tfdt_to_time(&entries[i].stamp);
			} else { /* cache the others to avoid further turnarounds */
				CameraFileInfo	xinfo;

				memset (&xinfo, 0, sizeof (xinfo));
				xinfo.file.fields = GP_FILE_INFO_TYPE|GP_FILE_INFO_SIZE|GP_FILE_INFO_MTIME;
				strcpy (xinfo.file.type, GP_MIME_MPEG);
				xinfo.file.size = get_u64(&entries[i].size);
				xinfo.file.mtime = tfdt_to_time(&entries[i].stamp);
				gp_filesystem_append (camera->fs, folder, name, context); /* FIXME: might fail if exist? */
				gp_filesystem_set_info_noop (camera->fs, folder, name, xinfo, context);
			}
			break;
		default:
			break;
	}
#if 0
        /* This makes the assumption that the timezone of the Toppy and the system
         * that puppy runs on are the same. Given the limitations on the length of
         * USB cables, this condition is likely to be satisfied. */
        timestamp = tfdt_to_time(&entries[i].stamp);
        printf("%c %20llu %24.24s %s\n", type, get_u64(&entries[i].size),
               ctime(&timestamp), entries[i].name);
#endif
    }
}
Example #5
0
static int file_list_func (CameraFilesystem *fs, const char *folder,
			   CameraList *list, void *data, GPContext *context){
  
  Camera *camera = data;
  CameraFileInfo info;
  int ret,n,i,nr_of_blocks;
  int offset = 64;
  char *temp;
  char buffer[512];
  FileEntry *file_entry;

  file_entry = malloc(sizeof(FileEntry));
  if ( (nr_of_blocks = pccam600_get_file_list(camera->port, context)) < 0 ){
    gp_log(GP_LOG_DEBUG,"pccam600","pccam600->get_file_list return <0");
    free (file_entry);
    return GP_ERROR;
  }
  for (n = 0; n != nr_of_blocks; n++)
    {
      ret = pccam600_read_data(camera->port, buffer);
      for (i = offset; i <= 512-32; i=i+32)
	{
	  memcpy(file_entry,&(buffer)[i],32);
	  /*Fileentry valid? */
	  if( !((file_entry->state & 0x02) != 2)  && 
	      !((file_entry->state & 0x08) == 8) )
	    {
	      info.file.fields = 0;
	      temp = &(file_entry->name)[5];
	      if (strncmp(temp,"JPG",3) == 0)
		{
		  memcpy(&(file_entry->name)[5],".jpg",4);
		  strcpy(info.file.type,GP_MIME_JPEG);
		  info.file.fields = GP_FILE_INFO_TYPE;
		}
	      else if (strncmp(temp,"AVI",3) == 0)
		{
		  memcpy(&(file_entry->name)[5],".avi",4);
		  info.file.fields = GP_FILE_INFO_WIDTH | GP_FILE_INFO_HEIGHT | GP_FILE_INFO_TYPE;
		  info.file.height = 352;
		  info.file.width = 288;
		  strcpy(info.file.type, GP_MIME_AVI);
		}
	      else if (strncmp(temp,"WAV",3) == 0)
		{
		  memcpy(&(file_entry->name)[5],".wav",4);
		  strcpy(info.file.type, GP_MIME_WAV);
		  info.file.fields = GP_FILE_INFO_TYPE;
		  info.file.height = 0;
		}
	      else if (strncmp(temp,"RAW",3) == 0)
		{
		  memcpy(&(file_entry->name)[5],".raw",4);
		  info.file.width = 1280;
		  info.file.height = 960;
		  info.file.fields = GP_FILE_INFO_WIDTH | GP_FILE_INFO_HEIGHT | GP_FILE_INFO_TYPE;
		  strcpy(info.file.type, GP_MIME_RAW);
		}
	      strcpy(info.file.name,file_entry->name);
	      gp_filesystem_append(fs,folder,info.file.name,context);
	      info.preview.fields = 0;
	      info.file.size = (file_entry->size[1]*256+
				file_entry->size[0]) * 256;
	      info.file.permissions = GP_FILE_PERM_READ | GP_FILE_PERM_DELETE;
	      info.file.fields |= GP_FILE_INFO_SIZE | GP_FILE_INFO_PERMISSIONS 
		|GP_FILE_INFO_TYPE | GP_FILE_INFO_NAME ;
	      ret = gp_filesystem_set_info_noop(fs, folder, info, context);
	    }
	}
	offset = 0;
    }
  return GP_OK;
}
Example #6
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;
}
Example #7
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;
}