diff options
author | Theodore Kilgore <kilgota@auburn.edu> | 2010-04-24 20:24:48 +0000 |
---|---|---|
committer | Theodore Kilgore <kilgota@auburn.edu> | 2010-04-24 20:24:48 +0000 |
commit | 7aad296d2ed209911867dc1458f19ba80b4e7b71 (patch) | |
tree | 108accd90e91d8df6b89c444e34a9db24513e397 /camlibs/jl2005c | |
parent | 5da21f0cdc068b5d3509dcfc89b957efe4ca00f1 (diff) | |
download | libgphoto2-7aad296d2ed209911867dc1458f19ba80b4e7b71.tar.gz |
jl2005c: camera info replaced by photo table, for legibility
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@13024 67ed7778-7388-44ab-90cf-0a291f65f57c
Diffstat (limited to 'camlibs/jl2005c')
-rw-r--r-- | camlibs/jl2005c/ChangeLog | 6 | ||||
-rw-r--r-- | camlibs/jl2005c/jl2005c.c | 128 | ||||
-rw-r--r-- | camlibs/jl2005c/jl2005c.h | 10 | ||||
-rw-r--r-- | camlibs/jl2005c/library.c | 42 |
4 files changed, 74 insertions, 112 deletions
diff --git a/camlibs/jl2005c/ChangeLog b/camlibs/jl2005c/ChangeLog index 77e74b98b..acca44e35 100644 --- a/camlibs/jl2005c/ChangeLog +++ b/camlibs/jl2005c/ChangeLog @@ -1,4 +1,10 @@ 2010-04-24 Theodore Kilgore <kilgota@auburn.edu> + * jl2005.[c,h]: "info" replaced by photo table, for clarity + * library.c: references to "info" replaced by "table". + thumbnails fetched even when "thumbnail" is empty as + happens sometimes when a clip is downloaded. + +2010-04-24 Theodore Kilgore <kilgota@auburn.edu> * jl2005bcd_decompress.c: GP_DEBUG() replaces printf() 2010-04-19 Theodore Kilgore <kilgota@auburn.edu> diff --git a/camlibs/jl2005c/jl2005c.c b/camlibs/jl2005c/jl2005c.c index cb908ea26..4a0765fb4 100644 --- a/camlibs/jl2005c/jl2005c.c +++ b/camlibs/jl2005c/jl2005c.c @@ -40,7 +40,7 @@ jl2005c_init (Camera *camera, GPPort *port, CameraPrivateLibrary *priv) char response; int model_string = 0; /* Needs to be big enough to hold (0xfff + 3) * 0x10 */ - unsigned char info[0x10020]; + unsigned char info[0x4020]; const char camera_id[] = {0x4a, 0x4c, 0x32, 0x30, 0x30, 0x35}; int alloc_table_size; int attempts = 0; @@ -54,108 +54,64 @@ restart: gp_port_open(port); } - set_usb_in_endpoint (camera, 0x84); gp_port_write (port, "\x08\x00", 2); usleep (10000); gp_port_write (port, "\x95\x60", 2); - usleep (10000); - gp_port_read (port, &response, 1); + jl2005c_read_data (port, &response, 1); model_string = response; - usleep (10000); gp_port_write (port, "\x95\x61", 2); - usleep (10000); - gp_port_read (port, &response, 1); + jl2005c_read_data (port, &response, 1); model_string += (response & 0xff) << 8; - usleep (10000); gp_port_write (port, "\x95\x62", 2); - usleep (10000); - gp_port_read (port, &response, 1); + jl2005c_read_data (port, &response, 1); model_string += (response & 0xff) << 16; - usleep (10000); gp_port_write (port,"\x95\x63" , 2); - usleep (10000); - gp_port_read (port, &response, 1); + jl2005c_read_data (port, &response, 1); model_string += (response & 0xff) << 24; GP_DEBUG("Model string is %08x\n", model_string); - usleep (10000); gp_port_write (port, "\x95\x64", 2); - usleep (10000); - gp_port_read (port, &response, 1); - - usleep (10000); + jl2005c_read_data (port, &response, 1); gp_port_write (port, "\x95\x65", 2); - usleep (10000); - gp_port_read (port, &response, 1); + jl2005c_read_data (port, &response, 1); /* Number of pix returned here, but not reliably reported */ priv->nb_entries = response & 0xff; GP_DEBUG("%d frames in the camera (unreliable!)\n", priv->nb_entries); - usleep (10000); - gp_port_write (port, "\x95\x66", 2); - usleep (10000); - gp_port_read (port, &response, 1); - usleep (10000); - + jl2005c_read_data (port, &response, 1); gp_port_write (port, "\x95\x67", 2); - usleep (10000); - gp_port_read (port, &response, 1); - usleep (10000); - + jl2005c_read_data (port, &response, 1); gp_port_write (port, "\x95\x68", 2); - usleep (10000); - gp_port_read (port, &response, 1); - usleep (10000); - + jl2005c_read_data (port, &response, 1); gp_port_write (port, "\x95\x69", 2); - usleep (10000); - gp_port_read (port, &response, 1); - usleep (10000); - + jl2005c_read_data (port, &response, 1); gp_port_write (port, "\x95\x6a", 2); - usleep (10000); - gp_port_read (port, &response, 1); - usleep (10000); - + jl2005c_read_data (port, &response, 1); gp_port_write (port, "\x95\x6b", 2); - usleep (10000); - gp_port_read (port, &response, 1); - usleep (10000); - + jl2005c_read_data (port, &response, 1); gp_port_write (port, "\x95\x6c", 2); - usleep (10000); - gp_port_read (port, &response, 1); - + jl2005c_read_data (port, &response, 1); priv->data_to_read = (response & 0xff) * 0x100; - gp_port_write (port, "\x95\x6d", 2); - usleep (10000); - gp_port_read (port, &response, 1); - usleep (10000); - + jl2005c_read_data (port, &response, 1); priv->data_to_read += (response&0xff); priv->total_data_in_camera = priv->data_to_read; GP_DEBUG ("blocks_to_read = 0x%lx = %lu\n", priv->data_to_read, priv->data_to_read); - gp_port_write (port, "\x95\x6e", 2); - usleep (10000); - gp_port_read (port, &response, 1); + jl2005c_read_data (port, &response, 1); alloc_table_size = (response & 0xff) * 0x200; GP_DEBUG("alloc_table_size = 0x%02x * 0x200 = 0x%x\n", response & 0xff, (response & 0xff) * 0x200); - usleep (10000); gp_port_write (port, "\x95\x6f", 2); - usleep (10000); - gp_port_read (port, &response, 1); - usleep (10000); + jl2005c_read_data (port, &response, 1); gp_port_write (port, "\x0a\x00", 2); usleep (10000); /* Switch the inep over to 0x82. It stays there ever after. */ set_usb_in_endpoint (camera, 0x82); - usleep (10000); + /* Read the first block of the allocation table. */ - gp_port_read(port, (char *)info, 0x200); + jl2005c_read_data (port, (char *)info, 0x200); if (strncmp(camera_id, (char*)info, 6)) { GP_DEBUG("Error downloading alloc table\n"); GP_DEBUG("Init attempted %d times\n", attempts + 1); @@ -170,12 +126,11 @@ restart: /* Now check the number of photos. That is found in byte 13 of line 0 * of the allocation table. */ - usleep (10000); priv->nb_entries = (info[12] & 0xff) * 0x100 | (info[13] & 0xff); GP_DEBUG("Number of entries is recalculated as %d\n", priv->nb_entries); - /* Just in case there was a problem, we now recalculate the total + /* Just in case there was a problem, we now recalculate the total * alloc_table_size. */ alloc_table_size = priv->nb_entries * 0x10 + 0x30; if (alloc_table_size%0x200) @@ -187,7 +142,7 @@ restart: if (alloc_table_size > 0x200) gp_port_read(port, (char *)info + 0x200, alloc_table_size - 0x200); - memmove(priv->info, info, alloc_table_size); + memmove(priv->table, info + 0x30, alloc_table_size - 0x30); priv->model=info[6]; switch (priv->model) { case 0x43: @@ -220,31 +175,29 @@ restart: usleep (10000); priv->bytes_read_from_camera = 0; priv->bytes_put_away = 0; - priv->init_done = 1; GP_DEBUG("Leaving jl2005c_init\n"); return GP_OK; } int -jl2005c_get_pic_data_size (CameraPrivateLibrary *priv, Info *info, int n) +jl2005c_get_pic_data_size (CameraPrivateLibrary *priv, Info *table, int n) { int size; - GP_DEBUG("info[48+16*n+7] = %02X\n", info[48 + 16 * n + 7]); - size = info[0x30 + 0x10 * n + 6] * 0x100 +info[0x30 + 0x10 * n + 7]; + GP_DEBUG("table[16 * n + 7] = %02X\n", table[16 * n + 7]); + size = table[0x10 * n + 6] * 0x100 | table[0x10 * n + 7]; size *= priv->blocksize; GP_DEBUG("size = 0x%x = %d\n", size, size); return (size); } unsigned long -jl2005c_get_start_of_photo(CameraPrivateLibrary *priv, Info *info, +jl2005c_get_start_of_photo(CameraPrivateLibrary *priv, Info *table, unsigned int n) { unsigned long start; - start = info[0x30 + 0x10 * n + 0x0c] * 0x100 | - info[0x30 + 0x10 * n + 0x0d]; - start -= info[0x30 + 0x0c] * 0x100 | info[0x30 + 0x0d]; + start = table[0x10 * n + 0x0c] * 0x100 | table[0x10 * n + 0x0d]; + start -= table[0x0c] * 0x100 | table[0x0d]; start *= priv->blocksize; return start; } @@ -262,15 +215,10 @@ set_usb_in_endpoint (Camera *camera, int inep) } int -jl2005c_get_picture_data (GPPort *port, char *data, int size) +jl2005c_read_data (GPPort *port, char *data, int size) { - /* inep has been reset to 0x82 already and does not get set back */ - /* We have to send 0b 00, presumably to access the data register, - * when starting to download the first photo only. But this is already - * done. So here we just download the data, between sleeps. - */ + /* These cameras tend to be slow. */ usleep (10000); - /*Data transfer begins*/ gp_port_read (port, data, size); usleep (10000); return GP_OK; @@ -279,25 +227,23 @@ jl2005c_get_picture_data (GPPort *port, char *data, int size) int jl2005c_reset (Camera *camera, GPPort *port) { - int downloadsize = 0xfa00; + int downloadsize = MAX_DLSIZE; /* These cameras want all data to be dumped. If that is not yet done, * then do it now, before exiting! */ while (camera->pl->bytes_read_from_camera < camera->pl->total_data_in_camera ) { - if (! camera->pl->data_cache ) - camera->pl->data_cache = malloc (0xfa00); - downloadsize=0xfa00; - if (camera->pl->bytes_read_from_camera +0xfa00 >= + if (!camera->pl->data_cache ) + camera->pl->data_cache = malloc (MAX_DLSIZE); + downloadsize = MAX_DLSIZE; + if (camera->pl->bytes_read_from_camera + MAX_DLSIZE >= camera->pl->total_data_in_camera ) downloadsize = camera->pl->total_data_in_camera - camera->pl->bytes_read_from_camera; - if(downloadsize) - jl2005c_get_picture_data ( - camera->port, + if (downloadsize) + jl2005c_read_data (camera->port, (char *) camera->pl->data_cache, downloadsize); - camera->pl->bytes_read_from_camera - += downloadsize; + camera->pl->bytes_read_from_camera += downloadsize; } gp_port_write(port, "\x07\x00", 2); return GP_OK; diff --git a/camlibs/jl2005c/jl2005c.h b/camlibs/jl2005c/jl2005c.h index fe945433d..535fec52d 100644 --- a/camlibs/jl2005c/jl2005c.h +++ b/camlibs/jl2005c/jl2005c.h @@ -24,6 +24,8 @@ #include <unistd.h> #include <gphoto2/gphoto2-port.h> +#define MAX_DLSIZE 0xfa00 + typedef unsigned char Info; struct _CameraPrivateLibrary { @@ -37,7 +39,7 @@ struct _CameraPrivateLibrary { unsigned char *data_cache; unsigned long bytes_read_from_camera; unsigned long bytes_put_away; - Info info[0xe000]; + Info table[0x4000]; }; @@ -45,11 +47,11 @@ int jl2005c_init (Camera *camera, GPPort *port, CameraPrivateLibrary *priv); int jl2005c_reset (Camera *camera, GPPort *port); int jl2005c_get_num_pics (Info *info); -int jl2005c_get_pic_data_size (CameraPrivateLibrary *priv, Info *info, int n); +int jl2005c_get_pic_data_size (CameraPrivateLibrary *priv, Info *table, int n); unsigned long jl2005c_get_start_of_photo (CameraPrivateLibrary *priv, - Info *info, unsigned int n); + Info *table, unsigned int n); int set_usb_in_endpoint (Camera *camera, int inep); -int jl2005c_get_picture_data (GPPort *port, char *data, int size); +int jl2005c_read_data (GPPort *port, char *data, int size); #endif diff --git a/camlibs/jl2005c/library.c b/camlibs/jl2005c/library.c index 783828326..885d2ccee 100644 --- a/camlibs/jl2005c/library.c +++ b/camlibs/jl2005c/library.c @@ -1,4 +1,5 @@ /* library.c + * * Copyright (C) 2006-2010 Theodore Kilgore <kilgota@auburn.edu> * @@ -195,22 +196,22 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, /* Get the number of the photo on the camera */ k = gp_filesystem_number (camera->fs, "/", filename, context); - h = camera->pl->info[48 + 16 * k + 4] << 3; - w = camera->pl->info[48 + 16 * k + 5] << 3; + h = camera->pl->table[16 * k + 4] << 3; + w = camera->pl->table[16 * k + 5] << 3; GP_DEBUG ("height is %i\n", h); - b = jl2005c_get_pic_data_size(camera->pl, camera->pl->info, k); + b = jl2005c_get_pic_data_size(camera->pl, camera->pl->table, k); GP_DEBUG("b = %i = 0x%x bytes\n", b, b); start_of_photo = jl2005c_get_start_of_photo(camera->pl, - camera->pl->info, k); + camera->pl->table, k); GP_DEBUG("start_of_photo number %i = 0x%lx \n", k,start_of_photo); pic_buffer = malloc(b + HEADERSIZE); if (!pic_buffer) return GP_ERROR_NO_MEMORY; memset(pic_buffer, 0, b + HEADERSIZE); GP_DEBUG("buffersize b + 16 = %i = 0x%x bytes\n", b + 16, b + 16); /* Copy info line for photo from allocation table, as header */ - memcpy(pic_buffer, camera->pl->info + 48 + 16 * k, 16); + memcpy(pic_buffer, camera->pl->table + 16 * k, 16); pic_data = pic_buffer + HEADERSIZE; /* @@ -222,7 +223,7 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, */ if (!(camera->pl->data_cache)) { - camera->pl->data_cache = malloc (0xfa00); + camera->pl->data_cache = malloc (MAX_DLSIZE); } if (!(camera->pl->data_cache)) { GP_DEBUG ("no cache memory allocated!\n"); @@ -237,12 +238,12 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, if (start_of_photo < camera->pl->bytes_put_away) { GP_DEBUG("photo number %i starts in a funny place!\n",k); /* We need to start all over again to get this photo. */ - jl2005c_reset(camera, camera->port); + jl2005c_reset (camera, camera->port); jl2005c_init (camera, camera->port, camera->pl); } if (start_of_photo + b > camera->pl->total_data_in_camera) { - GP_DEBUG("Photo runs past end of data. Exiting. \n"); - GP_DEBUG("Block size may be wrong for this camera\n"); + GP_DEBUG ("Photo runs past end of data. Exiting. \n"); + GP_DEBUG ("Block size may be wrong for this camera\n"); return (GP_ERROR); } /* @@ -262,12 +263,12 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, while (camera->pl->bytes_read_from_camera <= start_of_photo) { camera->pl->data_to_read = camera->pl->total_data_in_camera - camera->pl->bytes_read_from_camera; - downloadsize = 0xfa00; + downloadsize = MAX_DLSIZE; if (camera->pl->data_to_read < downloadsize) downloadsize = camera->pl->data_to_read; GP_DEBUG("downloadsize = 0x%x\n", downloadsize); if (downloadsize) - jl2005c_get_picture_data ( + jl2005c_read_data ( camera->port, (char *) camera->pl->data_cache, downloadsize); @@ -279,7 +280,7 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, if (camera->pl->bytes_read_from_camera > start_of_photo) { if(start_of_photo + b <= camera->pl->bytes_read_from_camera) { memcpy(pic_data, camera->pl->data_cache - + (start_of_photo % 0xfa00) + + (start_of_photo % MAX_DLSIZE) , b); camera->pl->bytes_put_away += b; /* @@ -294,7 +295,7 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, - start_of_photo; memcpy(pic_data, camera->pl->data_cache - + (start_of_photo % 0xfa00), + + (start_of_photo % MAX_DLSIZE), filled); camera->pl->bytes_put_away += filled; @@ -304,12 +305,12 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, camera->pl->data_to_read = camera->pl->total_data_in_camera - camera->pl->bytes_read_from_camera; - downloadsize = 0xfa00; + downloadsize = MAX_DLSIZE; if (camera->pl->data_to_read < downloadsize) downloadsize = camera->pl->data_to_read; GP_DEBUG("downloadsize = 0x%x\n", downloadsize); if (downloadsize) - jl2005c_get_picture_data ( + jl2005c_read_data ( camera->port, (char *) camera->pl->data_cache, downloadsize); @@ -341,13 +342,20 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, if (!camera->pl->can_do_capture) return GP_ERROR_NOT_SUPPORTED; outputsize = (pic_buffer[9] & 0xf0) * 192 + 256; - if (outputsize == 256) - return GP_ERROR_NOT_SUPPORTED; + GP_DEBUG("pic_buffer[9] is 0x%02x\n", pic_buffer[9]); + GP_DEBUG("Thumbnail outputsize = 0x%x = %d\n", outputsize, + outputsize); + if (outputsize == 256) { + GP_DEBUG("Frame %d has no thumbnail.\n", k); + return GP_OK; + } pic_output = calloc(outputsize, 1); if (!pic_output) return GP_ERROR_NO_MEMORY; outputsize = jl2005bcd_decompress(pic_output, pic_buffer, b + 16, 1); + GP_DEBUG("Thumbnail outputsize recalculated is 0x%x = %d\n", + outputsize, outputsize); gp_file_set_mime_type(file, GP_MIME_PPM); gp_file_set_data_and_size(file, (char *)pic_output, outputsize); |