From d4bcffed62d29a69a514d915a0654c65cb40dd74 Mon Sep 17 00:00:00 2001 From: Lutz Mueller Date: Sun, 25 Mar 2001 16:30:16 +0000 Subject: [PATCH] =?UTF-8?q?Applied=20patch=20from=20St=EF=BF=BDphane=20Cas?= =?UTF-8?q?tejon=20.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@1791 67ed7778-7388-44ab-90cf-0a291f65f57c --- camlibs/sierra/sierra.c | 49 ++++++++++++++++++++++++++++++++++++----- libgphoto2/exif.c | 26 ++++++++++++++++++++++ libgphoto2/exif.h | 6 +++++ 3 files changed, 76 insertions(+), 5 deletions(-) diff --git a/camlibs/sierra/sierra.c b/camlibs/sierra/sierra.c index f7e7dd746..9046703e1 100644 --- a/camlibs/sierra/sierra.c +++ b/camlibs/sierra/sierra.c @@ -20,6 +20,7 @@ #include "library.h" #include "sierra.h" +#include "../../libgphoto2/exif.h" #define TIMEOUT 2000 @@ -49,6 +50,7 @@ SierraCamera sierra_cameras[] = { {"Epson PhotoPC 600", 0, 0, 0, 0 }, {"Epson PhotoPC 700", 0, 0, 0, 0 }, {"Epson PhotoPC 800", 0, 0, 0, 0 }, + {"Epson PhotoPC 3000z", 0x4b8, 0x403, 0x83, 0x04}, {"Nikon CoolPix 100", 0, 0, 0, 0 }, {"Nikon CoolPix 300", 0, 0, 0, 0 }, {"Nikon CoolPix 700", 0, 0, 0, 0 }, @@ -466,7 +468,7 @@ int camera_folder_list_folders (Camera *camera, const char *folder, CameraList *list) { SierraData *fd = (SierraData*)camera->camlib_data; - int count, i, bsize, ret; + int count, i, j, bsize, ret; char buf[1024]; gp_debug_printf (GP_DEBUG_LOW, "sierra", @@ -506,8 +508,8 @@ int camera_folder_list_folders (Camera *camera, const char *folder, break; /* remove trailing spaces */ - for (i = strlen (buf)-1; i >= 0 && buf[i] == ' '; i--) - buf[i]='\0'; + for (j = strlen (buf)-1; j >= 0 && buf[j] == ' '; j--) + buf[j]='\0'; /* append the folder name on to the folder list */ gp_list_append (list, buf, GP_LIST_FOLDER); @@ -551,6 +553,7 @@ int camera_file_get_generic (Camera *camera, CameraFile *file, { int regl, regd, file_number; SierraData *fd = (SierraData*)camera->camlib_data; + CameraFile *tmp_file; gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** sierra_file_get_generic"); gp_debug_printf (GP_DEBUG_LOW, "sierra", "*** folder: %s", folder); @@ -583,9 +586,45 @@ int camera_file_get_generic (Camera *camera, CameraFile *file, } strcpy (file->name, filename); + /* Creation of a temporary file */ + if ((tmp_file = gp_file_new()) == NULL) + return (GP_ERROR); + strcpy(tmp_file->name, filename); + /* Get the picture data */ - CHECK (sierra_get_string_register (camera, regd, file_number + 1, file, - NULL, NULL)); + CHECK (sierra_get_string_register (camera, regd, file_number + 1, + tmp_file, NULL, NULL)); + + /* Some camera (e.g. Epson 3000z) send only the Exif data + as thumbnail. A valid Jpeg file needs to be built */ + if (tmp_file->data[0] == (char)0xFF && + tmp_file->data[1] == (char)0xD8) { + + /* OK : this is a complete JPEG file */ + gp_file_append (file, tmp_file->data, tmp_file->size); + + } else if (tmp_file->data[0] == (char)0xFF && + tmp_file->data[1] == (char)0xE1) { + + /* The JPEG file needs to be built */ + exifparser exifdat; + + exifdat.header = (char*) malloc ((size_t)tmp_file->size+2); + exifdat.header[0] = 0xFF; + exifdat.header[1] = 0xD8; + memcpy (exifdat.header + 2, tmp_file->data, + (size_t)tmp_file->size); + exifdat.data = exifdat.header + 12; + + exif_parse_data (&exifdat); + file->data = exif_get_thumbnail_and_size (&exifdat, + &file->size); + + free (exifdat.header); + } else { + //FIXME: What happens here? + } + return (camera_stop (camera)); } diff --git a/libgphoto2/exif.c b/libgphoto2/exif.c index 4ed64d767..9431fabe9 100644 --- a/libgphoto2/exif.c +++ b/libgphoto2/exif.c @@ -411,6 +411,20 @@ int exif_set_comment(exifparser *exifdat, char *comment) { * The returned thumbnail might be in JPEG or TIFF format. */ unsigned char *exif_get_thumbnail(exifparser *exifdat) { + + long size; + + return exif_get_thumbnail_and_size(exifdat, &size); +} + + +/** + * Gets the thumbnail of an EXIF image. + * The thumbnail size is provided + * + * The returned thumbnail might be in JPEG or TIFF format. + */ +unsigned char *exif_get_thumbnail_and_size(exifparser *exifdat, long *size) { unsigned char *imagedata,*exifimg,*newimg,*curptr; unsigned int entry; long dataptr,dsize,tag,datvec,tmp; @@ -419,6 +433,7 @@ unsigned char *exif_get_thumbnail(exifparser *exifdat) { exif_debug=1; if (exif_parse_data(exifdat)<0) return(NULL); + *size = 0; newimg=malloc(exifdat->exiflen); if (newimg==NULL){ fprintf(stderr,"exif_get_thumbnail: could not malloc\n"); @@ -428,6 +443,7 @@ unsigned char *exif_get_thumbnail(exifparser *exifdat) { /* Copy header*/ memcpy(newimg,exifdat->data,8); curptr=newimg+8; + *size += 8; if (exif_debug) { ExifData owner; @@ -446,6 +462,7 @@ unsigned char *exif_get_thumbnail(exifparser *exifdat) { if (exif_debug) { fprintf(stderr,"Too few ifds, doesn't look right. Giving up\n"); }; + *size = 0; return(NULL); /* Things don't look right...*/ }; @@ -455,6 +472,7 @@ unsigned char *exif_get_thumbnail(exifparser *exifdat) { /* Copy number of entries */ memcpy(curptr,exifimg,2); curptr+=2; + *size += 2; entry=exif_get_lilend(exifimg,2); @@ -467,10 +485,12 @@ unsigned char *exif_get_thumbnail(exifparser *exifdat) { dsize=gpe_getintval(exifimg,EXIF_JPEGInterchangeFormatLength); if (dsize==-1){ fprintf(stderr,"No Jpeg size tag for thumbnail, skipping\n"); + *size = 0; return(NULL); }; imagedata=exifdat->data+tmp; memcpy(newimg,imagedata,dsize); + *size += dsize; return(newimg); }; @@ -478,6 +498,7 @@ unsigned char *exif_get_thumbnail(exifparser *exifdat) { tmp=gpe_getintval(exifimg,EXIF_StripOffsets); /*imagedata start*/ if (tmp==-1) { fprintf(stderr,"gpe_get_thumbnail: Tiff or jpeg data not found, skipping\n"); + *size = 0; return(NULL); }; imagedata=exifdat->data+tmp; @@ -485,6 +506,7 @@ unsigned char *exif_get_thumbnail(exifparser *exifdat) { dataptr=gpe_getintval(exifimg,EXIF_StripByteCounts); /* imagedata size */ if (dataptr==-1) { printf("Split two\n"); + *size = 0; return(NULL); }; @@ -502,12 +524,14 @@ unsigned char *exif_get_thumbnail(exifparser *exifdat) { gpe_setval(exifimg,i,12*entry+14); /* set to end of directory */ memcpy(curptr,exifimg+12*i+2,12); curptr+=12; + *size += 12; } else { if (dsize<5){ /* Just copy the field if small */ memcpy(curptr,exifimg+12*i+2,12); curptr+=12; + *size += 12; } else { datvec=gpe_getvalue(exifimg,i); @@ -515,6 +539,7 @@ unsigned char *exif_get_thumbnail(exifparser *exifdat) { for (j=0;jdata[datvec+j]; memcpy(curptr,exifimg+12*i+2,12); curptr+=12; + *size += 12; }; }; }; @@ -522,6 +547,7 @@ unsigned char *exif_get_thumbnail(exifparser *exifdat) { curptr+=4; memcpy(curptr,imagedata,dataptr);/* ? */ curptr+=dataptr; + *size += 4+dataptr; return newimg; return 0; diff --git a/libgphoto2/exif.h b/libgphoto2/exif.h index 1c023c046..1d4839233 100644 --- a/libgphoto2/exif.h +++ b/libgphoto2/exif.h @@ -181,6 +181,12 @@ char *exif_get_tagname(int tag_number); */ unsigned char *exif_get_thumbnail(exifparser *exifdat); +/** + * The same as exif_get_thumbnail but returns + * also the thumbnail size + */ +unsigned char *exif_get_thumbnail_and_size(exifparser *exifdat, long *size); + /** * Gets the comment field if it exists. */