diff --git a/camlibs/smal/ChangeLog b/camlibs/smal/ChangeLog new file mode 100644 index 000000000..7775c2798 --- /dev/null +++ b/camlibs/smal/ChangeLog @@ -0,0 +1,11 @@ +2003-01-06 Lee Benfield + +Version 0.01 + +2003-01-13 LB + +Version 0.02 + +- Added support for different header types in returned image as observed +by Vasileios Zografos, on @xia (different faceplate from mine). + diff --git a/camlibs/smal/Makefile.am b/camlibs/smal/Makefile.am new file mode 100644 index 000000000..00b95adec --- /dev/null +++ b/camlibs/smal/Makefile.am @@ -0,0 +1,10 @@ +camlibdir = $(libdir)/gphoto2/$(VERSION) +camlib_LTLIBRARIES = libgphoto2_smal.la + +INCLUDES = \ + -I$(top_srcdir)/libgphoto2_port/libgphoto2_port \ + -I$(top_srcdir)/libgphoto2 + +libgphoto2_smal_la_SOURCES = smal.c ultrapocket.c smal.h ultrapocket.h +libgphoto2_smal_la_LDFLAGS = -module -avoid-version +libgphoto2_smal_la_LIBADD = $(top_builddir)/libgphoto2/libgphoto2.la diff --git a/camlibs/smal/README b/camlibs/smal/README new file mode 100644 index 000000000..4fed91c8e --- /dev/null +++ b/camlibs/smal/README @@ -0,0 +1,31 @@ +Smal Ultrapocket +(fuji @xia slimshot) +___________________________________________________________________ + +This driver is based on packet sniffs of protocol observed under +Windows 2000, and is known to be incomplete. Minimal functionality +is implemented as of the Experimental version. + +RAW images as retrieved from the camera require a not insignificant +amount of post processing. Enabling #DO_GAMMA in ultrapocket.h +helps, but more work is required. +___________________________________________________________________ + +The author takes no responsibility for damage to your camera from +using this driver. Use at your own risk. +___________________________________________________________________ + +TODO: + +- Battery status +- Firmware information +- Current resolution information +- Determine what (if anything) the camera passes as image +modification parameters (Gamma, etc). +___________________________________________________________________ + +Author: Lee Benfield (lee@benf.org) +Thanks: Vasileios Zografos, Dave Scott + +This code borrows heavily from the sipix web2 driver available with +gphoto. Thanks, guys ;) diff --git a/camlibs/smal/smal.c b/camlibs/smal/smal.c new file mode 100644 index 000000000..7907644ee --- /dev/null +++ b/camlibs/smal/smal.c @@ -0,0 +1,184 @@ +/* smal.c + * + * Copyright (C) 2003 Lee Benfield + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "ultrapocket.h" +#include "smal.h" + +#ifdef ENABLE_NLS +# include +# undef _ +# define _(String) dgettext (PACKAGE, String) +# ifdef gettext_noop +# define N_(String) gettext_noop (String) +# else +# define N_(String) (String) +# endif +#else +# define _(String) (String) +# define N_(String) (String) +#endif + +int +camera_id (CameraText *id) +{ + strcpy(id->text, "Smal:Ultrapocket"); + return (GP_OK); +} + +int +camera_abilities (CameraAbilitiesList *list) +{ + CameraAbilities a; + + memset(&a, 0, sizeof(a)); + strcpy(a.model, "Smal:Ultrapocket"); + a.status = GP_DRIVER_STATUS_EXPERIMENTAL; /* highly! */ + a.port = GP_PORT_USB; + a.speed[0] = 0; + a.usb_vendor = USB_VENDOR_ID_SMAL; + a.usb_product = USB_DEVICE_ID_ULTRAPOCKET; + a.operations = GP_OPERATION_NONE; + a.file_operations = GP_FILE_OPERATION_DELETE; + a.folder_operations = GP_FOLDER_OPERATION_DELETE_ALL; + gp_abilities_list_append(list, a); + /* fuji @xia slimshot is just a rebranded SmAL Ultrapocket */ + /* LB: 01/03 - not quite - it's got a different header */ + strcpy(a.model, "Fuji:Slimshot"); + gp_abilities_list_append(list, a); + + return (GP_OK); +} + +static int +camera_exit (Camera *camera, GPContext *context) +{ + return ultrapocket_exit(camera->port, context); +} + +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 size,image_no,result; + unsigned char *data; + + image_no = gp_filesystem_number(fs, folder, filename, context); + if (image_no < GP_OK) + return image_no; + + gp_file_set_name (file, filename); + + switch (type) { + case GP_FILE_TYPE_NORMAL: + result = ultrapocket_getpicture(camera->port,context,&data,&size,filename); + gp_file_set_mime_type (file, GP_MIME_PPM); + break; + case GP_FILE_TYPE_RAW: +#if 0 + return GP_ERROR; + result = ultrapocket_getpicture(camera->port,context,file); + gp_file_set_mime_type (file, GP_MIME_RAW); + break; +#endif + case GP_FILE_TYPE_PREVIEW: + default: + return (GP_ERROR_NOT_SUPPORTED); + } + if (result < 0) + return result; + + CHECK_RESULT(gp_file_set_data_and_size (file, data, size)); + + return (GP_OK); +} + +static int +delete_file_func (CameraFilesystem *fs, const char *folder, + const char *filename, void *data, GPContext *context) +{ + Camera *camera = data; + int image_no; + + image_no = gp_filesystem_number(fs, folder, filename, context); + if (image_no < GP_OK) + return image_no; + + CHECK_RESULT(ultrapocket_deletefile(camera->port, filename)); + + return (GP_OK); +} + +static int +delete_all_func (CameraFilesystem *fs, const char* folder, void *data, + GPContext *context) +{ + Camera *camera = data; + if (strcmp (folder, "/")) + return (GP_ERROR_DIRECTORY_NOT_FOUND); + return ultrapocket_deleteall(&camera->port); +} + +static int +camera_about (Camera *camera, CameraText *about, GPContext *context) +{ + strcpy (about->text, _("Smal Ultrapocket\n" + "Lee Benfield \n" + "Driver for accessing the Smal Ultrapocket camera, and OEM versions (slimshot)")); + + return (GP_OK); +} + +static int +file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, + void *data, GPContext *context) +{ + Camera *camera = data; + int count, result; + + result = ultrapocket_getpicsoverview(&camera->port, context, &count, list); + if (result != GP_OK) + return result; + + return (GP_OK); +} + +int +camera_init (Camera *camera, GPContext *context) +{ + camera->functions->exit = camera_exit; + camera->functions->about = camera_about; + gp_filesystem_set_list_funcs (camera->fs, file_list_func,NULL, camera); + gp_filesystem_set_file_funcs (camera->fs, get_file_func,delete_file_func, camera); + gp_filesystem_set_folder_funcs (camera->fs,NULL,delete_all_func, NULL,NULL,camera); + + /* don't need to do any exciting init stuff until we get pic numbers */ + return GP_OK; +} diff --git a/camlibs/smal/smal.h b/camlibs/smal/smal.h new file mode 100644 index 000000000..910d5f0a2 --- /dev/null +++ b/camlibs/smal/smal.h @@ -0,0 +1,27 @@ +/* smal.h + * + * Copyright (C) 2003 Lee Benfield + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef __SMAL_H__ + +#define __SMAL_H__ 1 + +#define USB_VENDOR_ID_SMAL 0x0dca +#define USB_DEVICE_ID_ULTRAPOCKET 0x0002 + +#endif diff --git a/camlibs/smal/ultrapocket.c b/camlibs/smal/ultrapocket.c new file mode 100644 index 000000000..b29ff3619 --- /dev/null +++ b/camlibs/smal/ultrapocket.c @@ -0,0 +1,352 @@ +/* ultrapocket.c + * + * Copyright (C) 2003 Lee Benfield + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "ultrapocket.h" +#include "smal.h" + +#define GP_MODULE "Smal Ultrapocket" + +#ifdef ENABLE_NLS +# include +# undef _ +# define _(String) dgettext (PACKAGE, String) +# ifdef gettext_noop +# define N_(String) gettext_noop (String) +# else +# define N_(String) (String) +# endif +#else +# define _(String) (String) +# define N_(String) (String) +#endif + +static int +ultrapocket_command(GPPort *port, int iswrite, unsigned char *data, int datasize) { + int ret; + if (iswrite) + ret = gp_port_write(port,data,datasize); + else + ret = gp_port_read(port,data,datasize); + + if (ret>=GP_OK) + ret=GP_OK; + return ret; +} + +int +ultrapocket_exit(GPPort *port, GPContext *context) { + return GP_OK; +} + +int +ultrapocket_getpicture(GPPort *port, GPContext *context, unsigned char **pdata, int *size, const char *filename) +{ + unsigned char command[0x10] = { 0x11, 0x01, 0x00, 0x49, 0x4d, 0x47, 0,0,0,0, 0x2e, 0x52, 0x41, 0x57, 0x00, 0x00 }; + char ppmheader[100]; + unsigned char retdata[0x1000]; + unsigned char header[42]; + unsigned char *rawdata,*outdata; + int width, height, outsize, result, imgstart; + smal_img_type styp; + int ptc,pc,pmmhdr_len, id; +#if DO_GAMMA + unsigned char gtable[256]; +#endif + + memcpy(command+6, filename+3, 4); /* the id of the image to transfer */ + + CHECK_RESULT(ultrapocket_command(port, 1, command, 0x10)); + + /* the first packet has the header in it, plus the start of the data */ + CHECK_RESULT(ultrapocket_command(port, 0, retdata, 0x1000)); + memcpy(header, retdata, 41); + styp = header[3]; + + switch (styp) { + case TYPE_QVGA: + /* 24 packets, including one already got */ + ptc = 24; + width = 320; + height = 240; + imgstart = 0x29; + break; + case TYPE_VGA: + /* 80 including one already got. */ + ptc = 80; + width = 640; + height = 480; + imgstart = 0x29; + break; + case TYPE_QVGA_BH: + ptc = 24; + width = 320; + height = 240; + imgstart = 0x100; + break; + case TYPE_VGA_BH: + ptc = 80; + width = 640; + height = 480; + imgstart = 0x100; + break; + default: + return GP_ERROR; + } + rawdata = malloc(0x1000 * ptc * sizeof(char)); + if (!rawdata) return (GP_ERROR_NO_MEMORY); + + /* show how far we've got on the current image */ + id = gp_context_progress_start(context, ptc-1, _("Downloading image...")); + + memcpy(rawdata, retdata, 0x1000 * sizeof(char)); + for (pc=1;pc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef __ULTRAPOCKET_H__ + +#define __ULTRAPOCKET_H__ 1 + +#include +#include + +#ifndef CHECK_RESULT +#define CHECK_RESULT(result) {int r = (result); if (r < 0) return (r);} +#endif + +#define UP_FLAG_NEEDS_RESET 0x80 + +/* The windows driver downloads a bunch of info from the camera the use of + * which I can't see. Unless you want it, don't get it. + */ +#define COPY_WINDOWS_DRIVER 0 +/* The windows software does a _lot_ of touching up of the images. + * For now, until I figure out what that involves, just do a bit of gamma + * correction + */ +#define DO_GAMMA 0 + +typedef enum ultrapocket_IMG_TYPE { + TYPE_QVGA = 0, + TYPE_VGA = 1, + TYPE_QVGA_BH = 2, + TYPE_VGA_BH = 3 +} smal_img_type; + +int ultrapocket_getpicsoverview(GPPort **pport, GPContext *context,int *numpics, CameraList *list); +int ultrapocket_exit(GPPort *port, GPContext *context); +int ultrapocket_getpicture(GPPort *port, GPContext *context, unsigned char **pdata, int *size, const char *filename); +int ultrapocket_deletefile(GPPort *port, const char *filename); +int ultrapocket_deleteall(GPPort **pport); + +#endif