Пример #1
0
int pdrm11_get_filenames(GPPort *port, CameraList *list)
{
	int i, j;
	uint32_t numPics;
	char name[20];
	char buf[30];


	gp_port_set_timeout(port, 10000);
	CHECK(gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_NUMPICS, 0, buf, 10));
	/* trying to remain endian friendly */
	numPics = le16atoh(&buf[2]) + (le16atoh(&buf[0]) * 1024);
	GP_DEBUG("found %d pictures", numPics);

	

	for(i=1;  i<numPics+1;  i++) {
		CHECK( pdrm11_select_file(port, i) );

		CHECK(gp_port_usb_msg_read(port, 0x01, 0xe600, i, buf, 14));

		/* the filename is 12 chars starting at the third byte */
		CHECK(gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_FILENAME, i, buf, 26));
		for(j=0; j<12; j+=2) {
			name[j] = buf[j+2+1];
			name[j+1] = buf[j+2];
		}
		name[12] = '\0';

		GP_DEBUG("%s",name);
		gp_list_append(list, name, NULL);
	}


	return(GP_OK);
}
Пример #2
0
/* Return the number of images in the EEPROM */
int
mesa_get_image_count( GPPort *port )
{
	uint8_t		b;
	uint8_t		r[2];

	b = IMAGE_CNT;

	CHECK (mesa_send_command( port, &b, 1, 10 ));

	if ( mesa_read( port, r, sizeof( r ), 10, 0 ) != sizeof( r ) )
	{
		return GP_ERROR_TIMEOUT;
	}

	return le16atoh(r);
}
Пример #3
0
int pdrm11_get_file(CameraFilesystem *fs, const char *filename, CameraFileType type, 
			CameraFile *file, GPPort *port, uint16_t picNum)
{
	uint32_t size = 0;
	uint16_t thumbsize = 0;
	uint8_t buf[30];
	uint8_t *image;
	uint8_t temp;
	int i;
	int ret;
	int file_type;

		
	gp_port_set_timeout(port,10000);
	CHECK( pdrm11_select_file(port, picNum) );

	if(type == GP_FILE_TYPE_PREVIEW) {
		CHECK(gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_INFO, picNum, (char *)buf, 8));
		file_type = buf[4];

		CHECK( gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_THUMBSIZE, picNum, (char *)buf, 14) );
		thumbsize = le16atoh( &buf[8] );
		
		/* add 1 to file size only for jpeg thumbnails */
		if(file_type == 1) { 
			GP_DEBUG("thumbnail file_type: %s.", "jpeg");
			size = (uint32_t)thumbsize + 1;
		} else if(file_type == 2) {
			/* NOTE: tiff thumbnails are 160x120 pixel 8bpc rgb images, NOT jpegs... */
			GP_DEBUG("thumbnail file_type: %s.", "tiff");
			size = (uint32_t)thumbsize;
		} else {
			GP_DEBUG("Unknown thumbnail file format!");
			return(GP_ERROR_NOT_SUPPORTED);
		}

	} else if(type == GP_FILE_TYPE_NORMAL) {
		CHECK( gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_FILESIZE, picNum, (char *)buf, 26) );
		size = le32atoh( &buf[18] );
	} else {
		GP_DEBUG("Unsupported file type!");
		return(GP_ERROR_NOT_SUPPORTED);
	}

	GP_DEBUG("size: %d 0x%x", size, size);

	image = malloc(sizeof(char)*size);
	if(!image)
		return(GP_ERROR_NO_MEMORY);



	if(type == GP_FILE_TYPE_PREVIEW) {
		CHECK_AND_FREE( gp_port_usb_msg_write(port, 0x01, PDRM11_CMD_GET_THUMB, picNum, NULL, 0), image );
	} else {
		CHECK_AND_FREE( gp_port_usb_msg_write(port, 0x01, PDRM11_CMD_GET_PIC, picNum, NULL, 0), image );
	}

	ret = gp_port_read(port, (char *)image, size);
	if(ret != size) {
		GP_DEBUG("failed to read from port.  Giving it one more try...");
		ret = gp_port_read(port, (char *)image, size);
		if(ret != size) {
			GP_DEBUG("gp_port_read returned %d 0x%x.  size: %d 0x%x", ret, ret, size, size);
			free (image);
			return(GP_ERROR_IO_READ);
		}
	}

	/* swap the bytes for the thumbnail, but not the file */
	if(type == GP_FILE_TYPE_PREVIEW) {
		for(i=0; i<size;  i+=2) {
			temp = image[i];
			image[i] = image[i+1];
			image[i+1] = temp;
		}
	}
	

	gp_file_set_mime_type(file, GP_MIME_JPEG);
	gp_file_set_data_and_size(file, (char *)image, size);

	return(GP_OK);
}