Added Genius Smart 300 to camlibs/sonix. Cameras now IDed firmware, not Product number. Memory footprint during AVI creation reduced.

git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@10896 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
Theodore Kilgore
2007-12-19 19:26:36 +00:00
parent 49e21423b5
commit d6bd6d73d4
5 changed files with 376 additions and 344 deletions

View File

@@ -1,3 +1,24 @@
2007-12-18 Theodore Kilgore <kilgota@auburn.edu>
* library.c: Processing of AVI output changed, so that output is
written to file one frame at a time, to reduce
memory footprint.
2007-12-09 Theodore Kilgore <kilgota@auburn.edu>
* library.c: Added Genius Smart 300. Thanks to
Norayr Chilingaryan <gnorayr@gmail.com>
for reporting the camera and for testing. New camera
uses optional compression and uses an offset in the
still photos, but not in frames for AVI output.
Also changed from using the USB Product number to
distinguish between camera models and will use the
firmware version code reported during sonix_init()
instead. So the ID-ing of cameras is moved from
camera_init() to sonix_init()
Also cleaned up the camera_capture function.
* sonix.c: Incorporated above changes in sonix_init().
* sonix.h: Changed fwversion variable from 1 byte to the 4
actually reported.
2007-10-16 Theodore Kilgore <kilgota@auburn.edu>
* library.c: Several Sakar cameras added

View File

@@ -33,6 +33,7 @@ Please inform if you get a different ID number!
Here we give a brief description both of currently-supported cameras and of the
supported gphoto2 functions for each.
Vivicam 3350b:
Uses an OV7630 sensor. Produces a maximum resolution of 640x480 and an option
@@ -54,7 +55,7 @@ Features of the camera include the ability to delete all photos. The "delete
last" function and the "capture-image" function, which will work for some
other Sonix sn9c2028 cameras and are thus supported in this library, do not
seem to work with the my Vivicam 3350B and are therefore disabled for this
camera. The camera will also shoot "movie clips" which are saved as AVI files.
camera. These cameras can all shoot "movie clips" which are saved as AVI files.
Webcam functionality uses isochronous transfer; thus it lies outside the scope
of libgphoto2 and is therefore not supported here.
@@ -65,9 +66,7 @@ Yet another camera which the macam driver also supports has been listed here
as a supported camera. It apparently uses 352x288 and 176x144 resolution
settings. I know of it only second hand, have not personally tested it, and
would appreciate any reports about it (I suspect it is similar to the Sakar
Digital Keychain camera). These cameras also can act as pccam or webcam.
They use isochronous transfer to do that. Support for this feature in Linux
requires a kernel module and lies outside of gphoto2.
Digital Keychain camera).
Sakar Digital Keychain #11199:
@@ -92,6 +91,14 @@ This camera has 640x480 and 320x240 resolution settings. Its features are
otherwise quite similar to those of the Sakar Digital Keychain #11199, except
that it exclusively uses the compressed mode.
Genius Smart 300:
This camera has 640x480 and 320x240 resolution settings. Its features are
otherwise quite similar to those of the Sakar Digital Keychain #11199 and the
Mini-Shotz ms350, except that it uses compressed mode for multiframe shooting,
but offers both compressed and uncompressed modes as options for still photos.
It does not support gphoto2 --capture-image. It does support deletion of
the last entry on the camera.
GUI frontends:
@@ -115,4 +122,4 @@ put the AVI file into an "album." Well, perhaps not. But not to worry.
It will save the AVI file anyway, even while protesting.
(This file revised 05/05/2007)
(Most recent revision of this file is on 12/18/2007)

View File

@@ -51,20 +51,22 @@
#define GP_MODULE "sonix"
static const struct {
char *name;
char *name;
CameraDriverStatus status;
unsigned short idVendor;
unsigned short idProduct;
unsigned short idVendor;
unsigned short idProduct;
} models[] = {
{"DC31VC", GP_DRIVER_STATUS_EXPERIMENTAL, 0x0c45, 0x8000},
{"Sakar Digital Keychain 11199", GP_DRIVER_STATUS_EXPERIMENTAL,
{"DC31VC", GP_DRIVER_STATUS_EXPERIMENTAL, 0x0c45, 0x8000},
{"Sakar Digital Keychain 11199", GP_DRIVER_STATUS_EXPERIMENTAL,
0x0c45, 0x8003},
{"Sakar Digital no, 6637x", GP_DRIVER_STATUS_EXPERIMENTAL,
{"Sakar Digital no, 6637x", GP_DRIVER_STATUS_EXPERIMENTAL,
0x0c45, 0x8003},
{"Sakar Digital no, 67480", GP_DRIVER_STATUS_EXPERIMENTAL,
{"Sakar Digital no, 67480", GP_DRIVER_STATUS_EXPERIMENTAL,
0x0c45, 0x8003},
{"Mini Shotz ms-350", GP_DRIVER_STATUS_EXPERIMENTAL, 0x0c45, 0x8008},
{"Vivitar Vivicam3350B", GP_DRIVER_STATUS_EXPERIMENTAL, 0x0c45, 0x800a},
{"Mini Shotz ms-350", GP_DRIVER_STATUS_EXPERIMENTAL, 0x0c45, 0x8008},
{"Vivitar Vivicam3350B", GP_DRIVER_STATUS_EXPERIMENTAL, 0x0c45, 0x800a},
{"Genius Smart 300, version 2", GP_DRIVER_STATUS_EXPERIMENTAL,
0x0458, 0x7005},
{NULL,0,0,0}
};
@@ -72,33 +74,33 @@ int
camera_id (CameraText *id)
{
strcpy (id->text, "Vivitar ViviCam3350B");
return GP_OK;
return GP_OK;
}
int
camera_abilities (CameraAbilitiesList *list)
{
int i;
CameraAbilities a;
int i;
CameraAbilities a;
for (i = 0; models[i].name; i++) {
memset (&a, 0, sizeof(a));
strcpy (a.model, models[i].name);
a.status = models[i].status;
a.port = GP_PORT_USB;
a.speed[0] = 0;
a.usb_vendor = models[i].idVendor;
a.usb_product= models[i].idProduct;
if (a.status == GP_DRIVER_STATUS_EXPERIMENTAL)
for (i = 0; models[i].name; i++) {
memset (&a, 0, sizeof(a));
strcpy (a.model, models[i].name);
a.status = models[i].status;
a.port = GP_PORT_USB;
a.speed[0] = 0;
a.usb_vendor = models[i].idVendor;
a.usb_product= models[i].idProduct;
if (a.status == GP_DRIVER_STATUS_EXPERIMENTAL)
a.operations = GP_OPERATION_NONE;
else
a.operations = GP_OPERATION_CAPTURE_IMAGE;
a.folder_operations = GP_FOLDER_OPERATION_DELETE_ALL;
a.file_operations = GP_FILE_OPERATION_DELETE|
a.folder_operations = GP_FOLDER_OPERATION_DELETE_ALL;
a.file_operations = GP_FILE_OPERATION_DELETE|
GP_FILE_OPERATION_PREVIEW;
gp_abilities_list_append (list, a);
}
return GP_OK;
gp_abilities_list_append (list, a);
}
return GP_OK;
}
static int
@@ -110,15 +112,15 @@ camera_summary (Camera *camera, CameraText *summary, GPContext *context)
if ( ret != GP_OK) {
free(camera->pl);
return ret;
}
}
if (!camera->pl->num_pics)
sonix_exit(camera->port);
sprintf (summary->text,ngettext(
sprintf (summary->text,ngettext(
"Sonix camera.\nThere is %i photo in it.\n",
"Sonix camera.\nThere are %i photos in it.\n",
camera->pl->num_pics
), camera->pl->num_pics);
return GP_OK;
return GP_OK;
}
static int camera_manual (Camera *camera, CameraText *manual, GPContext *context)
@@ -130,7 +132,7 @@ static int camera_manual (Camera *camera, CameraText *manual, GPContext *context
" - thumbnails for a GUI frontend\n"
" - full images in PPM format\n"
" - delete all images\n"
" - delete last image (may not work on all Sonix cameras)\n"
" - delete last image (not all of the Sonix cameras can do this)\n"
" - image capture to camera ( ditto )\n"
"If present on the camera, video clip frames are downloaded \n"
"as consecutive still photos or as AVI files, depending on the model.\n"
@@ -143,9 +145,9 @@ static int camera_manual (Camera *camera, CameraText *manual, GPContext *context
static int
camera_about (Camera *camera, CameraText *about, GPContext *context)
{
strcpy (about->text, _("Sonix camera library\n"
strcpy (about->text, _("Sonix camera library\n"
"Theodore Kilgore <kilgota@auburn.edu>\n"));
return GP_OK;
return GP_OK;
}
/*************** File and Downloading Functions *******************/
@@ -164,7 +166,7 @@ file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
if ( ret != GP_OK) {
free(camera->pl);
return ret;
}
}
if(!camera->pl->num_pics) {
sonix_exit(camera->port);
return GP_OK;
@@ -172,123 +174,128 @@ file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
for (i=0; i<camera->pl->num_pics; i++) {
avitype = (camera->pl->size_code[i])&8;
if (avitype) {
sprintf (name, "sonix%03i.avi", i+1);
snprintf (name, 16, "sonix%03i.avi", i+1);
avitype = 0;
} else
sprintf (name, "sonix%03i.ppm", i+1);
gp_list_append (list, name, NULL);
}
snprintf (name, 16, "sonix%03i.ppm", i+1);
gp_list_append (list, name, NULL);
}
return GP_OK;}
static int
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
CameraFileType type, CameraFile *file, void *user_data,
GPContext *context)
CameraFileType type, CameraFile *file, void *user_data,
GPContext *context)
{
Camera *camera = user_data;
int w, h = 0, buffersize = 0, i, k, rawsize = 0;
unsigned char *data = NULL;
unsigned char *ppm, *ptr, *avi=NULL, *frame_data = NULL;
Camera *camera = user_data;
int w, h = 0, buffersize = 0, i, k, rawsize = 0;
unsigned char *data = NULL;
unsigned char *ppm, *ptr, *avi=NULL, *frame_data = NULL;
unsigned char *p_data = NULL, *p_buf = NULL;
unsigned char gtable[256];
unsigned int numframes = 0;
unsigned int endpoint, bytes_used = 0;
unsigned int framedatasize[1024];
unsigned int framestart[1024];
unsigned int framestart[1024];
unsigned int size = 0, frame_size = 0;
unsigned int avitype = 0;
unsigned int offset=0;
unsigned int cam_offset;
unsigned int CAM_OFFSET;
unsigned char POST_CODE;
unsigned char compressed=0;
char name[16];
int ret = 0;
GP_DEBUG ("Downloading pictures!\n");
GP_DEBUG ("Downloading pictures!\n");
if(!camera->pl->sonix_init_done)
ret = sonix_init(camera->port, camera->pl);
if ( ret != GP_OK) {
free(camera->pl);
return ret;
}
}
if(!camera->pl->num_pics) {
sonix_exit(camera->port);
return GP_OK;
}
cam_offset = camera->pl->offset;
/* Get the number of the photo on the camera */
}
CAM_OFFSET = camera->pl->offset;
POST_CODE = camera->pl->post;
/* Get the number of the photo on the camera */
k = gp_filesystem_number (camera->fs, "/", filename, context);
if (k < GP_OK) return k;
if(type == GP_FILE_TYPE_EXIF) return GP_ERROR_FILE_EXISTS;
/* Cheap camera. No EXIF data. Quick! Kill this before it multiplies! */
if(type == GP_FILE_TYPE_EXIF)
return GP_ERROR_FILE_EXISTS;
i = camera->pl->size_code[k];
switch (i) {
case 0: w=352; h = 288; break; /* always uncompressed? */
case 9: avitype = 1; /* multiframe, always uncompressed? */
case 1: w=176; h = 144; break; /* always uncompressed? */
case 0x0a: avitype = 1; /* multiframe, always compressed? */
case 2: w=640; h = 480; break; /* always compressed? */
case 0x0b: avitype = 1; /* multiframe, always compressed? */
case 3: w=320; h = 240; break; /* always compressed? */
switch (i) {
case 0: w=352; h = 288; break;
case 9: avitype = 1; /* multiframe */
case 1: w=176; h = 144; break;
case 0x0a: avitype = 1; /* multiframe */
case 2: w=640; h = 480; break;
case 0x0b: avitype = 1; /* multiframe */
case 3: w=320; h = 240; break;
default: GP_DEBUG ("Size code unknown\n");
return (GP_ERROR_NOT_SUPPORTED);
}
return (GP_ERROR_NOT_SUPPORTED);
}
GP_DEBUG( "avitype is %d\n", avitype);
GP_DEBUG ("height of picture %i is %i\n", k+1,h);
GP_DEBUG ("height of picture %i is %i\n", k+1,h);
rawsize = sonix_read_data_size (camera->port, k);
GP_DEBUG("rawsize = 0x%x = %i\n", rawsize, rawsize);
if(rawsize%0x40)
buffersize = rawsize - (rawsize%0x40) + 0x40;
else
buffersize = rawsize;
buffersize = rawsize;
data = calloc (buffersize+64, 1);
if (!data) return GP_ERROR_NO_MEMORY;
gp_port_read(camera->port, (char *)data, buffersize);
switch(type) {
case GP_FILE_TYPE_NORMAL:
/* count end of frame markers to know the number of
*frames and the size and starting offset of each */
endpoint = 0;
numframes = 0;
framestart[0] = 0;
p_buf = data;
while (p_buf < data + buffersize+64) {
endpoint = 12;
while ( !((p_buf[endpoint-12]==0xff) &&
(p_buf[endpoint-11]==0xff) &&
(p_buf[endpoint-10]==0x00) &&
(p_buf[endpoint-9]==0xc4) &&
(p_buf[endpoint-8]==0xc4) ) &&
(endpoint < buffersize +64
- bytes_used))
endpoint ++ ;
if ( !((p_buf[endpoint-12]==0xff) &&
(p_buf[endpoint-11]==0xff) &&
(p_buf[endpoint-10]==0x00) &&
(p_buf[endpoint-9]==0xc4) &&
(p_buf[endpoint-8]==0xc4) ) ) {
GP_DEBUG("Finished counting frames!\n");
break;
}
if(!numframes) {
GP_DEBUG("compression byte is %#02x\n",
p_buf[endpoint-5]);
compressed=p_buf[endpoint-5]&1;
}
framestart[numframes+1] =
framestart[numframes] + endpoint;
p_buf += endpoint;
bytes_used += endpoint;
numframes ++;
}
GP_DEBUG("number of frames is %i\n",numframes);
GP_DEBUG("compressed %i\n",compressed);
POST_CODE|=compressed;
GP_DEBUG("POST_CODE is %i\n", POST_CODE);
/* AVI files need separate treatment */
if (avitype) {
CAM_OFFSET = camera->pl->avi_offset;
GP_DEBUG("CAM_OFFSET=%i\n",CAM_OFFSET);
frame_size = w*h;
p_data = data;
/* count end of frame markers to know the number of
*frames and the size and starting offset of each */
endpoint = 0;
numframes = 0;
framestart[0] = 0;
p_buf = data;
while (p_buf < data + buffersize+64) {
endpoint = 12;
while ( !((p_buf[endpoint-12]==0xff) &&
(p_buf[endpoint-11]==0xff) &&
(p_buf[endpoint-10]==0x00) &&
(p_buf[endpoint-9]==0xc4) &&
(p_buf[endpoint-8]==0xc4) ) &&
(endpoint < buffersize +64
- bytes_used))
endpoint ++ ;
if ( !((p_buf[endpoint-12]==0xff) &&
(p_buf[endpoint-11]==0xff) &&
(p_buf[endpoint-10]==0x00) &&
(p_buf[endpoint-9]==0xc4) &&
(p_buf[endpoint-8]==0xc4) ) ) {
GP_DEBUG("Finished counting frames!\n");
break;
}
framedatasize[numframes] = endpoint;
framestart[numframes+1] =
framestart[numframes] + endpoint;
p_buf += endpoint;
bytes_used += endpoint;
numframes ++;
}
GP_DEBUG("number of frames is %i\n",numframes);
gp_file_set_mime_type (file, GP_MIME_AVI);
gp_file_set_name (file, name);
frame_data = malloc(frame_size);
if (!frame_data) {
free (frame_data);
@@ -296,34 +303,47 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
}
size = (numframes)*(3*frame_size+ 8) + 224;
GP_DEBUG("size = %i\n", size);
avi = malloc(size);
if (!avi) {free(avi); return -1;}
memset(avi, 0, size);
memcpy (avi,SakarAviHeader,224);
avi = malloc(224);
if (!avi) {
free(avi);
return -1;
}
GP_DEBUG("avi malloc'ed\n");
memset(avi, 0, SAKAR_AVI_HEADER_LENGTH);
memcpy (avi,SakarAviHeader,SAKAR_AVI_HEADER_LENGTH);
GP_DEBUG("avi standard hdr copied\n");
avi[0x04] = (size -4)&0xff;
avi[0x05] = ((size -4)&0xff00) >> 8;
avi[0x06] = ((size -4)&0xff0000) >> 16;
avi[0x07] = ((size -4)&0xff000000) >> 24;
avi[0x40] = w&0xff;
avi[0x41] = (w>>8)&0xff;
avi[0x41] = (w>>8)&0xff;
avi[0x44] = h&0xff;
avi[0x45] = (h>>8)&0xff;
avi[0x45] = (h>>8)&0xff;
avi[0xb0] = w&0xff;
avi[0xb1] = (w>>8)&0xff;
avi[0xb4] = h&0xff;
avi[0xb5] = (h>>8)&0xff;
avi[0xb5] = (h>>8)&0xff;
avi[0x30] = numframes&0xff;
avi[0x8c] = numframes&0xff;
ptr=avi;
ptr += 224;
ptr=malloc(3*frame_size+8);
if(!ptr) {
free(ptr);
return GP_ERROR_NO_MEMORY;
}
GP_DEBUG("avi hdr written\n");
gp_file_append(file, (char *)avi,
SAKAR_AVI_HEADER_LENGTH);
free(avi);
GP_DEBUG("avi hdr put away\n");
for (i=0; i < numframes; i++) {
memcpy(ptr,SakarAviFrameHeader,8);
memset(ptr, 0, 3*frame_size+
SAKAR_AVI_FRAME_HEADER_LENGTH);
memcpy(ptr,SakarAviFrameHeader,
SAKAR_AVI_FRAME_HEADER_LENGTH);
ptr[4] = (3*frame_size)&0xff;
ptr[5] = ((3*frame_size)&0xff00) >> 8;
ptr[6] = ((3*frame_size)&0xff0000) >> 16;
ptr +=8;
GP_DEBUG("Doing frame number %i\n",i+1);
memset (frame_data, 0, frame_size);
offset = 0x40*(framestart[i]/0x40)+0x40;
@@ -332,45 +352,45 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
GP_DEBUG("framestart[%i] = 0x%x\n", i,
framestart[i]);
GP_DEBUG("offset = 0x%x\n", offset);
switch (camera->pl->post) {
switch (POST_CODE) {
case DECOMP|REVERSE:
sonix_decode (frame_data,
data+offset+cam_offset, w, h);
data+offset+CAM_OFFSET, w, h);
sonix_cols_reverse(frame_data, w, h);
gp_bayer_decode(frame_data, w, h, ptr,
BAYER_TILE_RGGB);
gp_bayer_decode(frame_data, w, h, ptr+
SAKAR_AVI_FRAME_HEADER_LENGTH,
BAYER_TILE_GBRG);
break;
case DECOMP:
sonix_decode (frame_data,
data+offset+cam_offset, w, h);
data+offset+CAM_OFFSET, w, h);
sonix_rows_reverse(frame_data, w, h);
gp_bayer_decode(frame_data, w, h, ptr,
gp_bayer_decode(frame_data, w, h, ptr+
SAKAR_AVI_FRAME_HEADER_LENGTH,
BAYER_TILE_GRBG);
break;
default:
memcpy(frame_data, data +offset+cam_offset,
frame_size);
default:
memcpy(frame_data, data + offset
+CAM_OFFSET, frame_size);
sonix_rows_reverse(frame_data, w, h);
gp_bayer_decode(frame_data, w, h, ptr,
gp_bayer_decode(frame_data, w, h, ptr+
SAKAR_AVI_FRAME_HEADER_LENGTH,
BAYER_TILE_GRBG);
}
}
gp_gamma_fill_table(gtable, .65);
gp_gamma_correct_single(gtable, ptr, w * h);
p_data += framedatasize[i] + 0x40;
ptr += 3*frame_size;
gp_gamma_correct_single(gtable, ptr+
SAKAR_AVI_FRAME_HEADER_LENGTH, w * h);
gp_file_append(file, (char *)ptr,
3*frame_size+
SAKAR_AVI_FRAME_HEADER_LENGTH);
GP_DEBUG("Done with frame number %i\n",i+1);
}
gp_file_set_mime_type (file, GP_MIME_AVI);
gp_file_set_name (file, name);
gp_file_set_data_and_size (file, (char *)avi, size);
avitype = 0;
free(data);
return GP_OK;
}
free(ptr);
free(frame_data);
free(data);
return GP_OK;
}
case GP_FILE_TYPE_PREVIEW:
if (k == camera->pl->num_pics - 1) {
camera->pl->sonix_init_done = 1;
@@ -380,57 +400,48 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
* first frame. Otherwise, still photos are processed
* here, and also the thumbnails for them.
*/
p_data = malloc (w * h);
if (!p_data) {free (data); return GP_ERROR_NO_MEMORY;}
memset (p_data, 0, w * h);
ppm = malloc (w * h * 3 + 256); /* room for data + header */
if (!ppm) {
free (data);
free (p_data);
return GP_ERROR_NO_MEMORY;
}
sprintf ((char *)ppm,
snprintf ((char *)ppm, 50,
"P6\n"
"# CREATOR: gphoto2, SONIX library\n"
"%d %d\n"
"255\n", w, h);
ptr = ppm + strlen ((char *)ppm);
size = strlen ((char *)ppm) + (w * h * 3);
switch (camera->pl->post)
switch (POST_CODE)
case DECOMP|REVERSE:
/* Images for Vivicam 3350b are upside down. */
if (camera->pl->post&REVERSE) {
sonix_decode (p_data, data+offset+cam_offset, w, h);
sonix_decode (p_data, data+CAM_OFFSET, w, h);
sonix_byte_reverse(p_data, w*h);
gp_bayer_decode (p_data, w , h , ptr,
gp_bayer_decode (p_data, w, h, ptr,
BAYER_TILE_BGGR);
break;
break;
case DECOMP:
sonix_decode (p_data, data+offset, w, h);
gp_bayer_decode (p_data, w , h , ptr,
sonix_decode (p_data, data+CAM_OFFSET, w, h);
gp_bayer_decode (p_data, w, h, ptr,
BAYER_TILE_RGGB);
break;
default:
memcpy (p_data, data+offset, w*h);
gp_bayer_decode (p_data, w , h , ptr, BAYER_TILE_RGGB);
memcpy (p_data, data+CAM_OFFSET, w*h);
gp_bayer_decode (p_data, w, h, ptr, BAYER_TILE_RGGB);
}
free (p_data);
gp_gamma_fill_table(gtable, .65);
gp_gamma_correct_single(gtable, ptr, w * h);
gp_file_set_mime_type (file, GP_MIME_PPM);
gp_file_set_name (file, filename);
gp_file_set_name (file, filename);
gp_file_set_data_and_size (file, (char *)ppm, size);
free (p_data);
free (data);
return GP_OK;
return GP_OK;
case GP_FILE_TYPE_RAW:
gp_file_set_mime_type(file, GP_MIME_RAW);
gp_file_set_name(file, filename);
@@ -438,7 +449,6 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
free(data);
GP_DEBUG("rawsize= 0x%x = %i\n", rawsize, rawsize);
return GP_OK;
default:
free(data);
return GP_ERROR_NOT_SUPPORTED;
@@ -457,8 +467,7 @@ delete_all_func (CameraFilesystem *fs, const char *folder, void *data,
if ( ret != GP_OK) {
free(camera->pl);
return ret;
}
}
sonix_delete_all_pics (camera->port);
return GP_OK;
}
@@ -475,13 +484,14 @@ delete_file_func (CameraFilesystem *fs, const char *folder,
if ( ret != GP_OK) {
free(camera->pl);
return ret;
}
if ((camera->pl->fwversion == 0x0a))
}
if ((camera->pl->fwversion[1] == 0x0a))
return GP_ERROR_NOT_SUPPORTED;
k = gp_filesystem_number (camera->fs, "/", filename, context);
if (k+1 != camera->pl->num_pics)
k = gp_filesystem_number (camera->fs, "/", filename, context);
if (k+1 != camera->pl->num_pics) {
GP_DEBUG("Only the last photo can be deleted!\n");
return GP_ERROR_NOT_SUPPORTED;
else
} else
sonix_delete_last (camera->port);
camera->pl->num_pics -= 1;
return GP_OK;
@@ -492,19 +502,26 @@ static int
camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath *path,
GPContext *context)
{
int ret = 0;
int ret = 0, n;
char name[16];
if(!camera->pl->sonix_init_done)
ret = sonix_init(camera->port, camera->pl);
if ( ret != GP_OK) {
free(camera->pl);
return ret;
}
if ((camera->pl->fwversion == 0x0a))
}
if (!(camera->pl->can_do_capture)) {
GP_DEBUG("This camera does not do capture-image\n");
return GP_ERROR_NOT_SUPPORTED;
}
if (camera->pl->full)
return GP_ERROR_NO_MEMORY;
sonix_capture_image(camera->port);
n=camera->pl->num_pics;
sonix_capture_image(camera->port);
snprintf(name, 16, "sonix%03i.ppm",n+1);
snprintf(path->folder,1,"/");
snprintf(path->name,16,"sonix%03i.ppm",n+1);
gp_filesystem_append(camera->fs, "/", name, context);
return GP_OK;
}
@@ -544,13 +561,12 @@ camera_init(Camera *camera, GPContext *context)
if (ret < 0) return ret;
GP_DEBUG("product number is 0x%x\n", abilities.usb_product);
/* First, set up all the function pointers */
camera->functions->capture = camera_capture;
camera->functions->capture = camera_capture;
camera->functions->manual = camera_manual;
camera->functions->summary = camera_summary;
camera->functions->about = camera_about;
camera->functions->exit = camera_exit;
camera->functions->summary = camera_summary;
camera->functions->about = camera_about;
camera->functions->exit = camera_exit;
GP_DEBUG ("Initializing the camera\n");
ret = gp_port_get_settings(camera->port,&settings);
@@ -560,11 +576,11 @@ camera_init(Camera *camera, GPContext *context)
case GP_PORT_SERIAL:
return ( GP_ERROR );
case GP_PORT_USB:
settings.usb.config = 1;
settings.usb.config = 1;
settings.usb.altsetting = 0;
settings.usb.interface = 0;
settings.usb.inep = 0x82;
settings.usb.outep =0x05;
settings.usb.interface = 0;
settings.usb.inep = 0x82;
settings.usb.outep = 0x05;
break;
default:
return ( GP_ERROR );
@@ -574,7 +590,7 @@ camera_init(Camera *camera, GPContext *context)
if (ret < 0) return ret;
GP_DEBUG("interface = %i\n", settings.usb.interface);
GP_DEBUG("inep = %x\n", settings.usb.inep);
GP_DEBUG("inep = %x\n", settings.usb.inep);
GP_DEBUG("outep = %x\n", settings.usb.outep);
/* Now, tell the filesystem where to get lists, files and info */
@@ -588,29 +604,11 @@ camera_init(Camera *camera, GPContext *context)
camera->pl->avitype = 0;
camera->pl->sonix_init_done = 0;
camera->pl->post = 0;
switch (abilities.usb_product) {
case 0x8003:
camera->pl->post = 0;
camera->pl->offset = 8;
break;
case 0x8008:
camera->pl->post = DECOMP;
camera->pl->offset = 0;
break;
case 0x8000: /* Please report if inaccurate ! */
case 0x800a:
camera->pl->post = DECOMP|REVERSE;
camera->pl->offset = 8;
break;
default:
return(GP_ERROR);
}
GP_DEBUG("post code is 0x%x\n", camera->pl->post);
/* Connect to the camera only if something is actually being done,
* because otherwise the Sakar Digital Keychain camera is put into
* some kind of active mode when gtkam is run, and will not leave
* some kind of excited mode when gtkam is run, and will not leave
* this mode even after gtkam is exited.
*/
return GP_OK;
}

View File

@@ -104,90 +104,103 @@ int sonix_init (GPPort *port, CameraPrivateLibrary *priv)
* string ought to start with the command byte c[0], plus 0x80
*/
memset(reading, 0, 4);
SONIX_READ4 (port, (char *)reading);
SONIX_READ4 (port, (char *)reading);
SONIX_READ(port, &status);
memset (c, 0, 6);
while (!reading[1]&&!reading[2]&&!reading[3]) {
c[0]=0x16;
SONIX_COMMAND ( port, c );
/*
* For the Vivicam 3350b this always gives
* 96 0a 76 07. This could be a firmware version. The
* webcam-osx driver says the 0x0a gives the sensor type, which
* is OV7630. For the Sakar Digital Keychain 11199 the string is
* 96 03 31 08, instead. For the Mini-Shotz ms350 it is
* 96 08 26 09. Since the cameras have different
* abilities, we ought to distinguish.
*/
SONIX_READ4 (port, (char *)reading);
c[0]=0x16;
SONIX_COMMAND ( port, c );
/*
* For the Vivicam 3350b this always gives
* 96 0a 76 07. This is apparently the firmware version.
* The webcam-osx comments that the 0x0a gives the sensor
* type, which is OV7630. For the Sakar Digital Keychain
* 11199 the string is 96 03 31 08, instead. For the
* Mini-Shotz ms350 it is 96 08 26 09. For the Genius
* Smart 300 it is 96 00 67 09. Since the cameras have
* different abilities, we ought to distinguish.
*/
SONIX_READ4 (port, (char *)reading);
}
GP_DEBUG("Above is the 4-byte ID string of your camera.");
GP_DEBUG("Please report if it is anything other than");
GP_DEBUG("96 0a 76 07 or 96 03 31 08 or 96 08 26 09\n");
GP_DEBUG("Thanks!\n" );
priv->fwversion = reading[1];
GP_DEBUG("or 96 00 67 09\n");
GP_DEBUG("Thanks!\n" );
for(i=0;i<4;i++)
priv->fwversion[i] = reading[i];
GP_DEBUG("fwversion[1] is %#02x\n", reading[1]);
SONIX_READ(port, &status);
/* case 0x03: uses the default settings, above. */
switch(priv->fwversion[1]) {
case 0x08:
priv->offset=0;
priv->avi_offset=0;
priv->can_do_capture=1;
priv->post = DECOMP;
break;
case 0x0a:
priv->offset=8;
priv->avi_offset=8;
priv->can_do_capture=0;
priv->post = DECOMP|REVERSE;
break;
case 0x00:
priv->offset=0;
priv->avi_offset=0;
priv->can_do_capture=0;
priv->post=0;
break;
case 0x03:
default:
priv->offset=8;
priv->avi_offset=8;
priv->can_do_capture=1;
priv->post=0;
}
/*
* This sequence gives the photos in the camera and sets a flag
* in reading[3] if the camera is full. Alas, it does not count
* clip frames separately on the Sakar Digital Keychain camera.
* in reading[3] if the camera is full. Alas, clip frames are
* not counted; the AVI constructor will need to count them
*/
memset (c,0,6);
c[0]=0x18;
SONIX_READ(port, &status);
SONIX_COMMAND ( port, c );
SONIX_READ(port, &status);
SONIX_READ4 (port, (char *)reading);
if (reading[0] != 0x98)
return GP_ERROR_CAMERA_ERROR;
GP_DEBUG ("number of photos is %d\n", reading[1]+ 256*reading[2]);
/*
* If reading[3] = 0x01, it means the camera is full.
* Not much use here if capture doesn't work, but for some models
* capture does work. So we store this information.
* If reading[3] = 0x01, it means the camera is full of data.
* The capture_image() function must then be disabled.
*/
if (!(reading[3])) priv->full = 0;
SONIX_READ(port, &status);
priv->num_pics = (reading[1] + 256*reading[2]);
memset(c,0,sizeof(c));
for (i = 0; i < priv->num_pics; i++) {
GP_DEBUG("getting size_code for picture %i\n", i+1);
/* Gets the resolution setting, also flags a multi-frame entry. */
c[0] = 0x19;
c[1] = (i+1)%256;
c[2] = (i+1)/256;
SONIX_COMMAND ( port, c );
SONIX_READ(port, &status);
SONIX_READ4 (port, (char *)reading);
SONIX_READ4 (port, (char *)reading);
if (reading[0] != 0x99)
return GP_ERROR_CAMERA_ERROR;
return GP_ERROR_CAMERA_ERROR;
SONIX_READ(port, &status);
/* For the code meanings, see get_file_func() in library.c */
priv->size_code[i] = (reading[1]&0x0f);
}
priv->sonix_init_done = 1;
GP_DEBUG("Leaving sonix_init\n");
return GP_OK;
return GP_OK;
}
int
@@ -196,7 +209,6 @@ sonix_read_data_size (GPPort *port, int n)
char status;
unsigned char c[6];
unsigned char reading[4];
GP_DEBUG("running sonix_read_data_size for picture %i\n", n+1);
memset (c, 0, 6);
c[0] = 0x1a;
@@ -204,9 +216,9 @@ sonix_read_data_size (GPPort *port, int n)
c[2] = (n+1)/256;
SONIX_COMMAND ( port, (char *)c );
SONIX_READ(port, &status);
SONIX_READ4 (port, (char *)reading);
SONIX_READ4 (port, (char *)reading);
if (reading[0] != 0x9a)
return GP_ERROR_CAMERA_ERROR;
return GP_ERROR_CAMERA_ERROR;
return (reading[1] + reading[2]*0x100 + reading[3] *0x10000);
}
@@ -216,17 +228,14 @@ sonix_delete_all_pics (GPPort *port)
char status;
char c[6];
unsigned char reading[4];
memset (c,0,6);
c[0]=0x05;
c[0]=0x05;
SONIX_READ(port, &status);
SONIX_COMMAND ( port, c );
SONIX_READ(port, &status);
SONIX_READ4 (port, (char *)reading);
SONIX_READ4 (port, (char *)reading);
if (reading[0] != 0x85)
return GP_ERROR_CAMERA_ERROR;
return GP_ERROR_CAMERA_ERROR;
return GP_OK;
}
@@ -236,34 +245,32 @@ sonix_delete_last (GPPort *port)
char status;
char c[6];
unsigned char reading[4];
memset (c,0,6);
c[0]= 0x05; c[1] = 0x01;
SONIX_READ(port, &status);
SONIX_COMMAND ( port, c );
SONIX_READ(port, &status);
SONIX_READ4 (port, (char *)reading);
SONIX_READ4 (port, (char *)reading);
if (reading[0] != 0x85)
return GP_ERROR_CAMERA_ERROR;
return GP_ERROR_CAMERA_ERROR;
return GP_OK;
}
}
int
sonix_capture_image (GPPort *port)
sonix_capture_image (GPPort *port)
{
char status;
char c[6];
unsigned char reading[4];
GP_DEBUG("Running sonix_capture_image\n");
memset (c,0,6);
c[0]=0x0e;
SONIX_READ(port, &status);
SONIX_COMMAND ( port, c );
SONIX_READ(port, &status);
SONIX_READ4 (port, (char *)reading);
SONIX_READ4 (port, (char *)reading);
if (reading[0] != 0x8e)
return GP_ERROR_CAMERA_ERROR;
return GP_ERROR_CAMERA_ERROR;
return GP_OK;
}
@@ -289,10 +296,10 @@ sonix_exit (GPPort *port)
/* Four defines for bitstream operations, for the decode function */
#define PEEK_BITS(num,to) {\
if (bitBufCount<num){\
do {\
bitBuf=(bitBuf<<8)|(*(src++));\
bitBufCount+=8; \
if (bitBufCount<num){\
do {\
bitBuf=(bitBuf<<8)|(*(src++));\
bitBufCount+=8; \
}\
while(bitBufCount<24);\
}\
@@ -314,52 +321,52 @@ sonix_exit (GPPort *port)
*/
#define PARSE_PIXEL(val) {\
PEEK_BITS(10,bits);\
if ((bits&0x200)==0) { \
EAT_BITS(1); \
} \
else if ((bits&0x380)==0x280) { \
EAT_BITS(3); \
val+=3; \
if (val>255) val=255; \
}\
else if ((bits&0x380)==0x300) { \
EAT_BITS(3); \
val-=3; \
if (val<0) val=0; \
}\
else if ((bits&0x3c0)==0x200) { \
EAT_BITS(4); \
val+=8; \
if (val>255) val=255;\
}\
else if ((bits&0x3c0)==0x240) { \
EAT_BITS(4); \
val-=8; \
if (val<0) val=0;\
}\
else if ((bits&0x3c0)==0x3c0) { \
EAT_BITS(4); \
val-=20; \
if (val<0) val=0;\
}\
else if ((bits&0x3e0)==0x380) { \
EAT_BITS(5); \
val+=20; \
if (val>255) val=255;\
}\
else { \
EAT_BITS(10); \
val=8*(bits&0x1f)+0; \
}\
PEEK_BITS(10,bits);\
if ((bits&0x200)==0) { \
EAT_BITS(1); \
} \
else if ((bits&0x380)==0x280) { \
EAT_BITS(3); \
val+=3; \
if (val>255) val=255; \
}\
else if ((bits&0x380)==0x300) { \
EAT_BITS(3); \
val-=3; \
if (val<0) val=0; \
}\
else if ((bits&0x3c0)==0x200) { \
EAT_BITS(4); \
val+=8; \
if (val>255) val=255;\
}\
else if ((bits&0x3c0)==0x240) { \
EAT_BITS(4); \
val-=8; \
if (val<0) val=0;\
}\
else if ((bits&0x3c0)==0x3c0) { \
EAT_BITS(4); \
val-=20; \
if (val<0) val=0;\
}\
else if ((bits&0x3e0)==0x380) { \
EAT_BITS(5); \
val+=20; \
if (val>255) val=255;\
}\
else { \
EAT_BITS(10); \
val=8*(bits&0x1f)+0; \
}\
}
#define PUT_PIXEL_PAIR {\
long pp;\
pp=(c1val<<8)+c2val;\
*((unsigned short *) (dst+dst_index))=pp;\
dst_index+=2; }
long pp;\
pp=(c1val<<8)+c2val;\
*((unsigned short *) (dst+dst_index))=pp;\
dst_index+=2; }
/* Now the decode function itself */
@@ -374,7 +381,6 @@ sonix_decode(unsigned char * dst, unsigned char * src, int width, int height)
int x, y;
unsigned long bitBuf = 0;
unsigned long bitBufCount = 0;
/* Columns were reversed during compression ! */
for (y = starting_row; y < height; y++) {
PEEK_BITS(8, bits);
@@ -384,13 +390,10 @@ sonix_decode(unsigned char * dst, unsigned char * src, int width, int height)
EAT_BITS(8);
c1val = bits & 0xff;
PUT_PIXEL_PAIR;
for (x = 2; x < width ; x += 2) {
PARSE_PIXEL(c2val);
PARSE_PIXEL(c1val);
PUT_PIXEL_PAIR;
PARSE_PIXEL(c1val);
PUT_PIXEL_PAIR;
}
}
return GP_OK;
@@ -400,12 +403,12 @@ int sonix_byte_reverse (unsigned char *imagedata, int datasize)
{
int i;
unsigned char temp;
for (i=0; i< datasize/2 ; ++i) {
temp = imagedata[i];
imagedata[i] = imagedata[datasize - 1 - i];
imagedata[datasize - 1 - i] = temp;
}
return GP_OK;
for (i=0; i< datasize/2 ; ++i) {
temp = imagedata[i];
imagedata[i] = imagedata[datasize - 1 - i];
imagedata[datasize - 1 - i] = temp;
}
return GP_OK;
}
int sonix_rows_reverse (unsigned char *imagedata, int width, int height)
@@ -414,12 +417,12 @@ int sonix_rows_reverse (unsigned char *imagedata, int width, int height)
unsigned char temp;
for (col = 0; col < width; col++)
for (row=0; row< height /2 ; row++) {
temp = imagedata[row*width+col];
imagedata[row*width+col] =
imagedata[(height-row-1)*width +col];
imagedata[(height-row-1)*width + col] = temp;
}
return GP_OK;
temp = imagedata[row*width+col];
imagedata[row*width+col] =
imagedata[(height-row-1)*width +col];
imagedata[(height-row-1)*width + col] = temp;
}
return GP_OK;
}
int sonix_cols_reverse (unsigned char *imagedata, int width, int height)
@@ -427,11 +430,12 @@ int sonix_cols_reverse (unsigned char *imagedata, int width, int height)
int col, row;
unsigned char temp;
for (row=0; row < height ; row++) {
for (col =0; col< width/2 ; col++) {
temp = imagedata[row*width + col];
imagedata[row*width + col] = imagedata[row*width - 1 - col];
imagedata[row*width - 1 - col] = temp;
}
}
return GP_OK;
for (col =0; col< width/2 ; col++) {
temp = imagedata[row*width + col];
imagedata[row*width + col] =
imagedata[row*width + width - 1 - col];
imagedata[row*width + width - 1 - col] = temp;
}
}
return GP_OK;
}

View File

@@ -30,11 +30,13 @@ struct _CameraPrivateLibrary {
/* Model model; */ /* "model" and "fwversion" functionally equal */
int num_pics;
unsigned char size_code[512];
unsigned char fwversion;
unsigned char fwversion[4];
unsigned char full;
unsigned char avitype;
unsigned char post;
unsigned char offset;
unsigned char avi_offset;
unsigned char can_do_capture;
int sonix_init_done;
};
@@ -44,7 +46,7 @@ int sonix_get_picture_size (GPPort *port, int n);
int sonix_read_data_size (GPPort *port, int n);
int sonix_delete_all_pics (GPPort *port);
int sonix_delete_last (GPPort *port);
int sonix_capture_image (GPPort *port);
int sonix_capture_image (GPPort *port);
int sonix_exit (GPPort *port);
int sonix_decode (unsigned char * dst, unsigned char * src,
int width, int height);