Exemplo n.º 1
0
static int
spca50x_flash_process_image (CameraPrivateLibrary *pl,	/*  context */
		uint8_t ** data, unsigned int *len,				/*  return these items */
		uint8_t * buf, uint32_t buf_size, int index)	/*  input these items */
{
	uint8_t *lp_jpg;
	uint8_t qIndex = 0, format;
	int file_size;

	int w = pl->files[index].width;
	int h = pl->files[index].height;

	/* qindex == 2 seems to be right for all the dsc350 images - so far!!! */
	qIndex = 2 ; /*  FIXME - what to do about Qtable stuff? */

	/* decode the image size */
	if (w > 320){
		format = 0x21; /*  for 640 size images */
	} else {
		format = 0x22; /*  for 320 x 240 size images */
	}

	file_size = buf_size + SPCA50X_JPG_DEFAULT_HEADER_LENGTH + 1024 * 10;

	/* now build a jpeg */
	lp_jpg = malloc (file_size);
	if (!lp_jpg)
		return GP_ERROR_NO_MEMORY;

	create_jpeg_from_data (lp_jpg, buf, qIndex, w,
			       h, format, buf_size, &file_size,
			       0, 0);
	free (buf);
	lp_jpg = realloc (lp_jpg, file_size);
	*data = lp_jpg;
	*len = file_size;

	return (GP_OK);
}
Exemplo n.º 2
0
static int
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
	       CameraFileType type, CameraFile *file, void *user_data,
	       GPContext *context)
{
    	Camera *camera = user_data;
	int w=0, h=0, b=0;
	int k, res;
	unsigned char *data;
	unsigned char *jpeg_out = NULL;
	int file_size;
	unsigned char jpeg_format;

	/* Get the entry number of the photo on the camera */
    	k = gp_filesystem_number (camera->fs, "/", filename, context);
    	
	if (GP_FILE_TYPE_EXIF==type) return GP_ERROR_FILE_EXISTS;

	if (GP_FILE_TYPE_RAW!=type && GP_FILE_TYPE_NORMAL !=type && GP_FILE_TYPE_PREVIEW!=type)
		return GP_ERROR_NOT_SUPPORTED;

	res = clicksmart_get_res_setting (camera->pl, k);

    	switch (res) {
	case 0: w = 352;
		h = 288;
		jpeg_format = JPEG_CIF_FORMAT;
		break;
	case 1:
	case 3:
		w = 176;
		h = 144;
		jpeg_format = JPEG_QCIF_FORMAT;
		break;
	default:  GP_DEBUG ( "Unknown resolution setting %i\n", res);
		return GP_ERROR;		
	}

	data = malloc (w*h);
	if(!data)
		return GP_ERROR_NO_MEMORY;

	GP_DEBUG("Fetch entry %i\n", k);
	b = clicksmart_read_pic_data (camera->pl, camera->port, data, k);

	if (GP_FILE_TYPE_RAW == type) {	/* type is GP_FILE_TYPE_RAW */
		gp_file_set_mime_type (file, GP_MIME_RAW);
	        gp_file_set_data_and_size (file, (char *)data, b);
		/* Reset camera when done, for more graceful exit. */
		if (k +1 == camera->pl->num_pics) {
	    		clicksmart_reset (camera->port);	
		}
		return GP_OK;
	}
		
	GP_DEBUG ("size = %i\n", b);	

	/* It looks as though o_size = b */
	/* It seems that qIndex is byte7, which is always 3, so I use that. */
	
	file_size = b + 589 + 1024 * 10;

	jpeg_out = malloc(file_size);
	if (!jpeg_out) {
		free(data);
		return GP_ERROR_NO_MEMORY;
	}

	GP_DEBUG("width:  %d, height:  %d, data size:  %d\n", w, h, b);
	create_jpeg_from_data (jpeg_out, data, 3, w, h, jpeg_format,
		    b, &file_size, 0, 0);

	gp_file_set_mime_type (file, GP_MIME_JPEG);
	gp_file_set_data_and_size (file, (char *)jpeg_out, file_size);
	/* Reset camera when done, for more graceful exit. */
	if (k +1 == camera->pl->num_pics) {
    		clicksmart_reset (camera->port);
	}
	free(data);
	return GP_OK;
}