diff options
author | Hans de Goede <hdegoede@redhat.com> | 2010-04-11 07:42:38 +0000 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2010-04-11 07:42:38 +0000 |
commit | 35ba8e116e3eaa7f61449595a619a6cd99743e3c (patch) | |
tree | 43f8a7ac27574bbf1d12cd70b56c7827c59c3b9d | |
parent | 04720db0f7d8c17f40d0d0115ffd00e71584a751 (diff) | |
download | libgphoto2-35ba8e116e3eaa7f61449595a619a6cd99743e3c.tar.gz |
ax203: add get-raw-data support
git-svn-id: https://svn.code.sf.net/p/gphoto/code/branches/libgphoto2-2_4/libgphoto2@12960 67ed7778-7388-44ab-90cf-0a291f65f57c
-rw-r--r-- | camlibs/ax203/ax203.c | 55 | ||||
-rw-r--r-- | camlibs/ax203/ax203.h | 6 | ||||
-rw-r--r-- | camlibs/ax203/library.c | 25 |
3 files changed, 69 insertions, 17 deletions
diff --git a/camlibs/ax203/ax203.c b/camlibs/ax203/ax203.c index 02d506a7d..d8281a778 100644 --- a/camlibs/ax203/ax203.c +++ b/camlibs/ax203/ax203.c @@ -956,12 +956,13 @@ ax203_encode_image(Camera *camera, int **src, char *dest, int dest_size) } int -ax203_read_file(Camera *camera, int idx, int **rgb24) +ax203_read_raw_file(Camera *camera, int idx, char **raw) { - char *src; struct ax203_fileinfo fileinfo; int ret; + *raw = NULL; + CHECK (ax203_read_fileinfo (camera, idx, &fileinfo)) if (!fileinfo.present) { @@ -972,16 +973,32 @@ ax203_read_file(Camera *camera, int idx, int **rgb24) /* Allocate 1 extra byte as tinyjpeg's huffman decoding sometimes reads a few bits more then it needs */ - src = malloc(fileinfo.size + 1); - if (!src) { + *raw = malloc (fileinfo.size + 1); + if (!*raw) { gp_log (GP_LOG_ERROR, "ax203", "allocating memory"); return GP_ERROR_NO_MEMORY; } - ret = ax203_read_mem (camera, fileinfo.address, src, fileinfo.size); - if (ret < 0) { free(src); return ret; } + ret = ax203_read_mem (camera, fileinfo.address, *raw, fileinfo.size); + if (ret < 0) { + free (*raw); + *raw = NULL; + return ret; + } + + return fileinfo.size; +} + +int +ax203_read_file(Camera *camera, int idx, int **rgb24) +{ + int ret; + char *src; + + ret = ax203_read_raw_file (camera, idx, &src); + if (ret < 0) return ret; - ret = ax203_decode_image (camera, src, fileinfo.size + 1, rgb24); + ret = ax203_decode_image (camera, src, ret + 1, rgb24); free(src); return ret; @@ -1062,20 +1079,15 @@ ax203_find_free_abfs_slot(Camera *camera) } int -ax203_write_file(Camera *camera, int **rgb24) +ax203_write_raw_file(Camera *camera, char *buf, int size) { struct ax203_fileinfo fileinfo; struct ax203_fileinfo used_mem[AX203_ABFS_SIZE / 2]; - int i, abfs_slot, size, hole_size, used_mem_count, prev_end; - const int buf_size = camera->pl->width * camera->pl->height; - char buf[buf_size]; + int i, abfs_slot, hole_size, used_mem_count, prev_end; abfs_slot = ax203_find_free_abfs_slot (camera); if (abfs_slot < 0) return abfs_slot; - size = ax203_encode_image (camera, rgb24, buf, buf_size); - if (size < 0) return size; - used_mem_count = ax203_build_used_mem_table (camera, used_mem); if (used_mem_count < 0) return used_mem_count; @@ -1105,6 +1117,21 @@ ax203_write_file(Camera *camera, int **rgb24) } int +ax203_write_file(Camera *camera, int **rgb24) +{ + const int buf_size = camera->pl->width * camera->pl->height; + char buf[buf_size]; + int size; + + size = ax203_encode_image (camera, rgb24, buf, buf_size); + if (size < 0) return size; + + CHECK (ax203_write_raw_file (camera, buf, size)) + + return GP_OK; +} + +int ax203_delete_file(Camera *camera, int idx) { struct ax203_fileinfo fileinfo; diff --git a/camlibs/ax203/ax203.h b/camlibs/ax203/ax203.h index f0d7d292b..7a4e9a2fb 100644 --- a/camlibs/ax203/ax203.h +++ b/camlibs/ax203/ax203.h @@ -143,6 +143,12 @@ int ax203_delete_all(Camera *camera); int +ax203_read_raw_file(Camera *camera, int idx, char **raw); + +int +ax203_write_raw_file(Camera *camera, char *buf, int size); + +int ax203_commit(Camera *camera); int diff --git a/camlibs/ax203/library.c b/camlibs/ax203/library.c index cb827c1b0..5bc75bcc7 100644 --- a/camlibs/ax203/library.c +++ b/camlibs/ax203/library.c @@ -79,7 +79,8 @@ camera_abilities (CameraAbilitiesList *list) a.folder_operations = GP_FOLDER_OPERATION_PUT_FILE | GP_FOLDER_OPERATION_DELETE_ALL; /* FIXME add support for downloading RAW images */ - a.file_operations = GP_FILE_OPERATION_DELETE; + a.file_operations = GP_FILE_OPERATION_DELETE | + GP_FILE_OPERATION_RAW; gp_abilities_list_append (list, a); } @@ -159,16 +160,34 @@ get_file_func (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileType type, CameraFile *file, void *data, GPContext *context) { -#ifdef HAVE_GD Camera *camera = data; - gdImagePtr im; int ret, idx, size; +#ifdef HAVE_GD + gdImagePtr im; void *gdpng; +#endif idx = get_file_idx(camera, folder, filename); if (idx < 0) return idx; + if (type == GP_FILE_TYPE_RAW) { + char *raw; + + size = ax203_read_raw_file (camera, idx, &raw); + if (size < 0) return size; + + gp_file_set_mime_type (file, GP_MIME_RAW); + gp_file_set_name (file, filename); + gp_file_set_data_and_size (file, raw, size); + + return GP_OK; + } + +#ifdef HAVE_GD + if (type != GP_FILE_TYPE_NORMAL) + return GP_ERROR_NOT_SUPPORTED; + im = gdImageCreateTrueColor(camera->pl->width, camera->pl->height); if (im == NULL) return GP_ERROR_NO_MEMORY; |