static int file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, void *data, GPContext *context) { Camera *camera = data; int i = 0, filecount = 0; char temp_file[14]; if (cam_has_flash(camera->pl) || cam_has_card(camera->pl) ) { CHECK (spca50x_flash_get_TOC(camera->pl, &filecount)); for (i=0; i<filecount; i++) { CHECK(spca50x_flash_get_file_name (camera->pl, i, temp_file)); gp_list_append (list, temp_file, NULL); } } if (cam_has_sdram(camera->pl)) { if (camera->pl->dirty_sdram) CHECK (spca50x_sdram_get_info (camera->pl)); for (i = 0; i < camera->pl->num_files_on_sdram; i++) { strncpy (temp_file, camera->pl->files[i].name, 12); temp_file[12] = 0; gp_list_append (list, temp_file, NULL); } } return GP_OK; }
int spca50x_flash_get_filecount (CameraPrivateLibrary *pl, int *filecount) { uint16_t response = 0; if (pl->bridge == BRIDGE_SPCA500) { /* dsc350 cams */ return spca50x_flash_get_TOC (pl, filecount); } else { if (pl->fw_rev == 1) { CHECK (gp_port_usb_msg_read (pl->gpdev, 0x0b, 0x0000, 0x0000, (char*)&response, 0x02)); /* Each file gets two toc entries, one for the image, one for the thumbnail */ LE16TOH (response); *filecount = response/2; } else { CHECK (gp_port_usb_msg_read (pl->gpdev, 0x54, 0x0000, 0x0000, (char*)&response, 0x02)); LE16TOH (response); *filecount = response; } } return GP_OK; }
static int get_info_func (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileInfo *info, void *data, GPContext *context) { Camera *camera = data; int n, flash_file_count = 0; struct SPCA50xFile *file; char name[14]; int w,h; /* Get the file number from the CameraFileSystem */ CHECK (n = gp_filesystem_number (camera->fs, folder, filename, context)); if (cam_has_flash(camera->pl) || cam_has_card(camera->pl) ) { CHECK (spca50x_flash_get_TOC(camera->pl, &flash_file_count)); } if (n < flash_file_count) { CHECK (spca50x_flash_get_file_name(camera->pl, n, name)); CHECK (spca50x_flash_get_file_dimensions( camera->pl, n, &w, &h)); strcpy (info->file.type, GP_MIME_JPEG); info->file.width = w; info->file.height = h; info->preview.width = w/8; info->preview.height = h/8; } if (cam_has_sdram (camera->pl) && n >= flash_file_count ){ CHECK (spca50x_sdram_get_file_info (camera->pl, n-flash_file_count, &file)); if (file->mime_type == SPCA50X_FILE_TYPE_IMAGE) { strcpy (info->file.type, GP_MIME_JPEG); info->preview.width = 160; info->preview.height = 120; } else if (file->mime_type == SPCA50X_FILE_TYPE_AVI) { strcpy (info->file.type, GP_MIME_AVI); info->preview.width = 320; info->preview.height = 240; } info->file.width = file->width; info->file.height = file->height; } info->file.fields = GP_FILE_INFO_TYPE | GP_FILE_INFO_WIDTH | GP_FILE_INFO_HEIGHT; info->file.mtime = 0; info->file.fields |= GP_FILE_INFO_MTIME; info->preview.fields = GP_FILE_INFO_TYPE | GP_FILE_INFO_WIDTH | GP_FILE_INFO_HEIGHT; strcpy (info->preview.type, GP_MIME_BMP); return (GP_OK); }
static int camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath * path, GPContext *context) { struct SPCA50xFile *file; CameraAbilities a; /* Not all our cameras support capture */ gp_camera_get_abilities (camera, &a); if (!a.operations & GP_OPERATION_CAPTURE_IMAGE) return GP_ERROR_NOT_SUPPORTED; if (cam_has_flash(camera->pl)) { int fc; char tmp [14]; CHECK(spca500_flash_capture (camera->pl)); CHECK(spca50x_flash_get_TOC (camera->pl, &fc)); /* assume new pic is the last one in the cam...*/ CHECK(spca50x_flash_get_file_name (camera->pl, (fc - 1), tmp)); /* Add new image name to file list */ /* NOTE: these lines moved from below */ strncpy (path->name, tmp, sizeof (path->name) - 1); path->name[sizeof (path->name) - 1] = '\0'; } else { CHECK (spca50x_capture (camera->pl)); CHECK (spca50x_sdram_get_info (camera->pl)); CHECK (spca50x_sdram_get_file_info (camera->pl, camera->pl->num_files_on_sdram - 1, &file)); /* Add new image name to file list */ /* NOTE: these lines moved from below */ strncpy (path->name, file->name, sizeof (path->name) - 1); path->name[sizeof (path->name) - 1] = '\0'; } /* Now tell the frontend where to look for the image */ strncpy (path->folder, "/", sizeof (path->folder) - 1); path->folder[sizeof (path->folder) - 1] = '\0'; CHECK (gp_filesystem_append (camera->fs, path->folder, path->name, context)); return GP_OK; }
static int spca500_flash_84D_get_file_info (CameraPrivateLibrary * pl, int index, int *w, int *h, int *t, int *sz) { char hdr[260]; char waste[260]; int i; unsigned long size; /* First, check if the info. is already buffered in the cam private lib * We DO NOT want to be fetching the entire thumbnail just to get the file size...*/ if ((pl->dirty_flash == 0) && (pl->files[index].type != 0)){ /* This file must have been checked before */ *w = pl->files[index].width ; *h = pl->files[index].height ; *t = pl->files[index].type ; *sz = pl->files[index].size ; return GP_OK; } else if (pl->dirty_flash != 0){ /* should never happen, but just in case... */ CHECK(spca50x_flash_get_TOC (pl, &i)); if ( index >= i){ /* asking for a picture that doesn't exist */ return GP_ERROR; } } /* ...else we must query the cam the hard way... */ /* command mode */ CHECK (gp_port_usb_msg_write (pl->gpdev, 0x00, 0x0080, 0x0100, NULL, 0x00)); /* trigger Thumbnail upload */ CHECK (gp_port_usb_msg_write (pl->gpdev, 0x07, (index + 1), 0x0000, NULL, 0x00)); /* NOTE: must use (index + 1) here as the cam indexes images from 1, * whereas libgphoto2 indexes from 0.... */ /* wait for ready */ CHECK (spca50x_flash_wait_for_ready(pl)); /* read the header from the cam */ CHECK (gp_port_read (pl->gpdev, hdr, 256)); /* always 256 for the DSC-350+ */ /* Read the rest of the header... and discard it */ CHECK (gp_port_read (pl->gpdev, waste, 256)); /* Now we have to read in the thumbnail data anyway - so we might as well store it for later */ { int j; uint8_t * buf; if (pl->files[index].thumb){ free (pl->files[index].thumb); /* discard any previous thumbnail data */ pl->files[index].thumb = NULL; } buf = malloc (38 * 256); /* create a new buffer to hold the thumbnail data */ if (buf){ j = 0; for (i = 0; i < 38; i++) { /* Now read in the image data */ /* read a buffer from the cam */ CHECK (gp_port_read (pl->gpdev, (char *)&buf[j], 256)); j += 256; } pl->files[index].thumb = buf; } else { /* couldn't get a buffer - read in the data anyway and discard it */ for (i = 0; i < 38; i++) {/* Thumbnails ALWAYS download 38 blocks...*/ CHECK (gp_port_read (pl->gpdev, waste, 256)); } pl->files[index].thumb = NULL; } } /* end of thumbnail storing loop */ /* reset to idle */ CHECK (gp_port_usb_msg_write(pl->gpdev, 0x00, 0x0000, 0x0100, NULL, 0x0)); /* OK, now we have a hdr we can work with... */ /* try and get the size */ size = ((unsigned long)hdr[15] & 0xff) + (((unsigned long)hdr[16] & 0xff) << 8) + (((unsigned long)hdr[17] & 0xff) << 16); *sz = size; /* Try and determine the file type */ /* Should enumerate the possible types properly, somewhere... */ i = (int)hdr[2]; /* should be the file type */ *t = i; switch (i){ case 0: /* this will be 320 x 240 single-frame */ *w = 320; *h = 240; break; case 1: /* this will be 640 x 480 single-frame */ *w = 640; *h = 480; break; case 2: /* this will be 1024 x 768 single-frame */ /* These are actually 640x480 pics - the win driver just expands them * in the host before it stores them... What should we do here? Continue with that * pretence, or tell the user the truth? */ /* *w = 1024; */ /* *h = 768; */ *w = 640; *h = 480; break; case 3: /* this will be 320 x 240 multi-frame */ *w = 320; *h = 240; break; case 4: /* this will be 640 x 480 multi-frame */ *w = 640; *h = 480; break; case 5: /* this will be 1024 x 768 multi-frame */ /* See notes above! */ /* *w = 1024; */ /* *h = 768; */ *w = 640; *h = 480; break; case 6: /* ??? TAKE A GUESS!!! 160 x 120 avi ??? MUST verify this sometime.... */ *w = 160; *h = 120; break; case 7: /* this is 320 x 240 avi */ *w = 320; *h = 240; break; default: *t = 99; /* or something equally invalid... */ *w = 0; *h = 0; *sz = 0; /* if we don't know what it is, it can't have a size! */ break; } /* now add this new set of data to the info_cache */ if (pl->dirty_flash == 0){ /* Only update the files cache if it exists, i.e. if dirty is zero */ /* We should never get here if dirty is set, however ! */ pl->files[index].type = *t; pl->files[index].width = *w; pl->files[index].height = *h; pl->files[index].size = *sz; } return GP_OK; } /* end of spca500_flash_84D_get_file_info */