~ubuntu-branches/ubuntu/saucy/libgphoto2/saucy-proposed

« back to all changes in this revision

Viewing changes to camlibs/jl2005c/library.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-07-31 07:00:09 UTC
  • mfrom: (1.4.4)
  • Revision ID: package-import@ubuntu.com-20130731070009-enrbvg3hry64cxl1
Tags: 2.5.2-0ubuntu1
* New upstream release.
* Drop 01-increase_max_entries.patch, 02-libusbx_no_debug.patch,
  03-libusbx-fixes.patch: fixed upstream.
* Add libxml2-dev build dependency for new optional features.
* ABI changes: libgphoto2-2 → libgphoto2-6,
  libgphoto2-port0 → libgphoto2-port10
* debian/libgphoto2-dev-doc.install: Adjust to changed HTML API doc folder
  name.
* debian/libgphoto2-port10.install: Adjust for changed libgphoto-port ABI.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 * License as published by the Free Software Foundation; either
9
9
 * version 2 of the License, or (at your option) any later version.
10
10
 *
11
 
 * This library is distributed in the hope that it will be useful, 
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 * Lesser General Public License for more details. 
 
14
 * Lesser General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU Lesser General Public
17
17
 * License along with this library; if not, write to the
49
49
#define GP_MODULE "jl2005c"
50
50
 
51
51
struct {
52
 
        char *name;
 
52
        char *name;
53
53
        CameraDriverStatus status;
54
 
        unsigned short idVendor;
55
 
        unsigned short idProduct;
 
54
        unsigned short idVendor;
 
55
        unsigned short idProduct;
56
56
} models[] = {
57
57
        {" JL2005B/C/D camera", GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
58
 
        {"Argus DC1512e", GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
 
58
        {"Argus DC1512e",       GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
59
59
        {"Amazing Spiderman",   GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
60
60
        {"Aries ATC-0017",      GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
61
 
        {"Sakar no. 75379",     GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
 
61
        {"Sakar no. 75379",     GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
62
62
        {"Sakar no. 81890",     GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
63
63
        {"Sakar Nickelodeon iCarly no. 88061", GP_DRIVER_STATUS_EXPERIMENTAL,
64
64
                                                        0x0979, 0x0227},
66
66
                                                        0x0979, 0x0227},
67
67
        {"Sakar no. 91379",     GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
68
68
        {"Sakar no. 98379",     GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
69
 
        {"Sakar Kidz-Cam no. 88379",     GP_DRIVER_STATUS_EXPERIMENTAL, 
70
 
                                                                0x0979, 0x0227},
71
 
        {"Sakar clipshot no. 1169x",     GP_DRIVER_STATUS_EXPERIMENTAL, 
72
 
                                                                0x0979, 0x0227},
73
 
        {"Sakar Sticker Wizard no. 59379",     GP_DRIVER_STATUS_EXPERIMENTAL, 
74
 
                                                                0x0979, 0x0227},
 
69
        {"Sakar Kidz-Cam no. 88379", GP_DRIVER_STATUS_EXPERIMENTAL,
 
70
                                                               0x0979, 0x0227},
 
71
        {"Sakar clipshot no. 1169x", GP_DRIVER_STATUS_EXPERIMENTAL,
 
72
                                                               0x0979, 0x0227},
 
73
        {"Sakar Sticker Wizard no. 59379", GP_DRIVER_STATUS_EXPERIMENTAL,
 
74
                                                               0x0979, 0x0227},
75
75
        {"Sakar Star Wars kit no. 92022", GP_DRIVER_STATUS_EXPERIMENTAL,
76
76
                                                               0x0979, 0x0227},
77
77
        {"Jazwares Star Wars no. 15256", GP_DRIVER_STATUS_EXPERIMENTAL,
78
78
                                                               0x0979, 0x0227},
79
 
        {"Argus Bean Sprout",     GP_DRIVER_STATUS_EXPERIMENTAL, 
80
 
                                                                0x0979, 0x0227},
 
79
        {"Argus Bean Sprout",   GP_DRIVER_STATUS_EXPERIMENTAL,
 
80
                                                               0x0979, 0x0227},
81
81
        {"Global Point Clipster", GP_DRIVER_STATUS_EXPERIMENTAL,
82
82
                                                               0x0979, 0x0227},
83
83
        {"Global Point 3 in 1 Digital Fun Graffiti 00044",
87
87
                                GP_DRIVER_STATUS_EXPERIMENTAL, 0x0979, 0x0227},
88
88
        {"Vivitar Freelance", GP_DRIVER_STATUS_EXPERIMENTAL,
89
89
                                                               0x0979, 0x0227},
90
 
        {NULL,0,0,0}
 
90
        {"Sakar Hello Kitty no. 94009", GP_DRIVER_STATUS_EXPERIMENTAL,
 
91
                                                               0x0979, 0x0227},
 
92
        {NULL,0,0,0}
91
93
};
92
94
 
93
95
int
94
96
camera_id (CameraText *id)
95
97
{
96
98
        strcpy (id->text, "JL2005B/C/D camera");
97
 
        return GP_OK;
 
99
        return GP_OK;
98
100
}
99
101
 
100
102
int
101
103
camera_abilities (CameraAbilitiesList *list)
102
104
{
103
 
        int i;    
104
 
        CameraAbilities a;
 
105
        int i;
 
106
        CameraAbilities a;
105
107
 
106
 
        for (i = 0; models[i].name; i++) {
107
 
                memset (&a, 0, sizeof(a));
108
 
                strcpy (a.model, models[i].name);
109
 
                a.status = models[i].status;
110
 
                a.port   = GP_PORT_USB;
111
 
                a.speed[0] = 0;
112
 
                a.usb_vendor = models[i].idVendor;
113
 
                a.usb_product= models[i].idProduct;
114
 
                if (a.status == GP_DRIVER_STATUS_EXPERIMENTAL)
 
108
        for (i = 0; models[i].name; i++) {
 
109
                memset (&a, 0, sizeof(a));
 
110
                strcpy (a.model, models[i].name);
 
111
                a.status = models[i].status;
 
112
                a.port   = GP_PORT_USB;
 
113
                a.speed[0] = 0;
 
114
                a.usb_vendor = models[i].idVendor;
 
115
                a.usb_product= models[i].idProduct;
 
116
                if (a.status == GP_DRIVER_STATUS_EXPERIMENTAL)
115
117
                        a.operations = GP_OPERATION_NONE;
116
118
                else
117
119
                        a.operations = GP_OPERATION_CAPTURE_IMAGE;
118
120
                a.folder_operations = GP_FOLDER_OPERATION_DELETE_ALL;
119
 
                a.file_operations   = GP_FILE_OPERATION_PREVIEW 
120
 
                                        + GP_FILE_OPERATION_RAW; 
121
 
                gp_abilities_list_append (list, a);
122
 
        }
123
 
        return GP_OK;
 
121
                a.file_operations   = GP_FILE_OPERATION_PREVIEW
 
122
                                        + GP_FILE_OPERATION_RAW;
 
123
                gp_abilities_list_append (list, a);
 
124
        }
 
125
        return GP_OK;
124
126
}
125
127
 
126
128
static int
131
133
        GP_DEBUG("camera->pl->nb_entries = %i\n",camera->pl->nb_entries);
132
134
        sprintf(summary->text,
133
135
                        _("This camera contains a Jeilin JL2005%c chipset.\n"
134
 
                        "The number of photos in it is %i. \n"), 
135
 
                        camera->pl->model, num_pics);  
136
 
        return GP_OK;
 
136
                        "The number of photos in it is %i. \n"),
 
137
                        camera->pl->model, num_pics);
 
138
        return GP_OK;
137
139
}
138
140
 
139
141
static int
140
142
camera_manual (Camera *camera, CameraText *manual, GPContext *context)
141
143
{
142
 
        strcpy(manual->text, 
 
144
        strcpy(manual->text,
143
145
        _(
144
146
        "This driver supports cameras with Jeilin JL2005B or C or D  chip \n"
145
147
        "These cameras do not support deletion of photos, nor uploading\n"
147
149
        "If present on the camera, video clip frames are downloaded \n"
148
150
        "as consecutive still photos.\n"
149
151
        "For more details please consult libgphoto2/camlibs/README.jl2005c\n"
150
 
        )); 
 
152
        ));
151
153
 
152
154
        return (GP_OK);
153
155
}
158
160
{
159
161
        strcpy (about->text, _("jl2005bcd camera library\n"
160
162
                            "Theodore Kilgore <kilgota@auburn.edu>\n"));
161
 
        return GP_OK;
 
163
        return GP_OK;
162
164
}
163
165
 
164
166
/*************** File and Downloading Functions *******************/
165
167
 
166
168
static int
167
169
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
168
 
                void *data, GPContext *context)
 
170
                                void *data, GPContext *context)
169
171
{
170
 
        Camera *camera = data; 
 
172
        Camera *camera = data;
171
173
        int n;
172
174
        n = camera->pl->nb_entries;
173
 
        gp_list_populate (list, "jl_%03i.ppm", n);
174
 
        return GP_OK;
 
175
        gp_list_populate (list, "jl_%03i.ppm", n);
 
176
        return GP_OK;
175
177
}
176
178
 
177
179
static int
178
180
get_info_func (CameraFilesystem *fs, const char *folder, const char *filename,
179
 
               CameraFileInfo *info, void *data, GPContext *context)
 
181
                CameraFileInfo *info, void *data, GPContext *context)
180
182
{
181
183
        info->file.fields = GP_FILE_INFO_TYPE;
182
184
        strcpy (info->file.type, GP_MIME_PPM);
186
188
 
187
189
static int
188
190
get_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
189
 
               CameraFileType type, CameraFile *file, void *user_data,
190
 
               GPContext *context)
 
191
                CameraFileType type, CameraFile *file, void *user_data,
 
192
                GPContext *context)
191
193
{
192
 
        Camera *camera = user_data; 
 
194
        Camera *camera = user_data;
193
195
        int w, h = 0, b = 0, k;
194
196
        unsigned char *pic_data, *pic_buffer, *pic_output = NULL;
195
197
        int HEADERSIZE=16;
205
207
        if (GP_FILE_TYPE_EXIF == type) return GP_ERROR_FILE_EXISTS;
206
208
 
207
209
        /* Get the number of the photo on the camera */
208
 
        k = gp_filesystem_number (camera->fs, "/", filename, context); 
 
210
        k = gp_filesystem_number (camera->fs, "/", filename, context);
209
211
        h = camera->pl->table[16 * k + 4] << 3;
210
212
        w = camera->pl->table[16 * k + 5] << 3;
211
213
 
212
214
        GP_DEBUG ("height is %i\n", h);
213
 
    
 
215
 
214
216
        b = jl2005c_get_pic_data_size(camera->pl, camera->pl->table, k);
215
 
        GP_DEBUG("b = %i = 0x%x bytes\n", b,b);
216
 
        start_of_photo = jl2005c_get_start_of_photo(camera->pl, 
 
217
        GP_DEBUG("b = %i = 0x%x bytes\n", b, b);
 
218
        start_of_photo = jl2005c_get_start_of_photo(camera->pl,
217
219
                                                    camera->pl->table, k);
218
220
        GP_DEBUG("start_of_photo number %i = 0x%lx \n", k,start_of_photo);
219
221
        pic_buffer = malloc(b + HEADERSIZE);
220
222
        if (!pic_buffer) return GP_ERROR_NO_MEMORY;
221
223
        memset(pic_buffer, 0, b + HEADERSIZE);
222
 
        GP_DEBUG ("buffersize b+16 = %i = 0x%x bytes\n", b+16,b+16); 
 
224
        GP_DEBUG("buffersize b + 16 = %i = 0x%x bytes\n", b + 16, b + 16);
223
225
        /* Copy info line for photo from allocation table, as header */
224
226
        memcpy(pic_buffer, camera->pl->table + 16 * k, 16);
225
 
        pic_data = pic_buffer+HEADERSIZE;
 
227
        pic_data = pic_buffer + HEADERSIZE;
226
228
 
227
229
        /*
228
230
         * Camera can download in blocks of 0xfa00, with only the last block
239
241
                GP_DEBUG ("no cache memory allocated!\n");
240
242
                return GP_ERROR_NO_MEMORY;
241
243
        }
242
 
        
243
 
        /* Is there data in the cache, or not? If yes, read from it into the 
 
244
 
 
245
        /* Is there data in the cache, or not? If yes, read from it into the
244
246
         * current photo, immediately. Update settings. But first two sanity
245
247
         * checks.
246
248
         */
248
250
        if (start_of_photo < camera->pl->bytes_put_away) {
249
251
                GP_DEBUG("photo number %i starts in a funny place!\n",k);
250
252
                /* We need to start all over again to get this photo. */
251
 
                jl2005c_reset(camera, camera->port);
 
253
                jl2005c_reset (camera, camera->port);
252
254
                jl2005c_init (camera, camera->port, camera->pl);
253
255
        }
254
 
        if (start_of_photo+b > camera->pl->total_data_in_camera) {
 
256
        if (start_of_photo + b > camera->pl->total_data_in_camera) {
255
257
                GP_DEBUG ("Photo runs past end of data. Exiting. \n");
256
258
                GP_DEBUG ("Block size may be wrong for this camera\n");
257
259
                return (GP_ERROR);
258
260
        }
259
261
        /*
260
262
         * This while loop is entered if the photo number k-1 was not requested
261
 
         * and thus has not been downloaded. The camera's rudimentary hardware 
 
263
         * and thus has not been downloaded. The camera's rudimentary hardware
262
264
         * obliges us to download all data consecutively and toss whatever
263
265
         * portion of said data that we do not intend to use. The rudimentary
264
266
         * hardware also does not like to stop downloading at the end of one
279
281
                GP_DEBUG("downloadsize = 0x%x\n", downloadsize);
280
282
                if (downloadsize)
281
283
                        jl2005c_read_data (
282
 
                                            camera->port, 
283
 
                                            (char *) camera->pl->data_cache, 
 
284
                                            camera->port,
 
285
                                            (char *) camera->pl->data_cache,
284
286
                                            downloadsize);
285
287
                camera->pl->bytes_read_from_camera += downloadsize;
286
288
        }
287
289
 
288
 
        camera->pl->bytes_put_away=start_of_photo;
 
290
        camera->pl->bytes_put_away = start_of_photo;
289
291
 
290
292
        if (camera->pl->bytes_read_from_camera > start_of_photo) {
291
293
                if(start_of_photo + b <= camera->pl->bytes_read_from_camera) {
292
294
                        memcpy(pic_data, camera->pl->data_cache
293
295
                                        + (start_of_photo % MAX_DLSIZE)
294
 
                            , b);
 
296
                                                                , b);
295
297
                        camera->pl->bytes_put_away += b;
296
298
                        /*
297
299
                         * Photo data is contained in what is already
298
300
                         * downloaded.
299
 
                         * Jump immediately to process the photo. 
300
 
                         */
 
301
                         * Jump immediately to process the photo.
 
302
                         */
301
303
                } else {
302
304
                        /* Photo starts in one 0xfa00-sized download and ends
303
305
                         * in another */
304
 
                        filled = camera->pl->bytes_read_from_camera 
 
306
                        filled = camera->pl->bytes_read_from_camera
305
307
                                    - start_of_photo;
306
308
 
307
309
                        memcpy(pic_data, camera->pl->data_cache
308
310
                                        + (start_of_photo % MAX_DLSIZE),
309
 
                                    filled);
 
311
                                                        filled);
310
312
 
311
313
                        camera->pl->bytes_put_away += filled;
312
314
                }
321
323
                GP_DEBUG("downloadsize = 0x%x\n", downloadsize);
322
324
                if (downloadsize)
323
325
                        jl2005c_read_data (
324
 
                                            camera->port, 
325
 
                                            (char *) camera->pl->data_cache, 
 
326
                                            camera->port,
 
327
                                            (char *) camera->pl->data_cache,
326
328
                                            downloadsize);
327
329
                camera->pl->bytes_read_from_camera += downloadsize;
328
 
                
 
330
 
329
331
                if (camera->pl->bytes_read_from_camera >=
330
332
                                                start_of_photo + b ) {
331
333
                        GP_DEBUG("THIS ONE?\n");
332
 
                        memcpy(pic_data+filled, camera->pl->data_cache, 
 
334
                        memcpy(pic_data + filled, camera->pl->data_cache,
333
335
                                                b - filled);
334
336
                        camera->pl->bytes_put_away += b - filled;
335
337
                        break;
336
 
                } else {        
 
338
                } else {
337
339
                        GP_DEBUG("THIS ONE??\n");
338
340
                        if (!downloadsize)
339
341
                                break;
346
348
 
347
349
        if (type == GP_FILE_TYPE_RAW) {
348
350
                gp_file_set_mime_type(file, GP_MIME_RAW);
349
 
                gp_file_set_data_and_size(file, (char *)pic_buffer , b+16 );
 
351
                gp_file_set_data_and_size(file, (char *)pic_buffer, b + 16);
350
352
                return GP_OK;
351
353
#ifdef HAVE_LIBJPEG
352
354
        } else if (type == GP_FILE_TYPE_PREVIEW) {
384
386
        } else
385
387
                return GP_ERROR_NOT_SUPPORTED;
386
388
 
387
 
        return GP_OK;
 
389
        return GP_OK;
388
390
}
389
391
 
390
392
static int
391
393
delete_all_func (CameraFilesystem *fs, const char *folder, void *data,
392
394
                 GPContext *context)
393
395
{
394
 
        Camera *camera = data;
395
 
 
396
 
        GP_DEBUG(" * delete_all_func()");
397
 
        jl2005c_delete_all(camera, camera->port);
398
 
 
399
 
        return (GP_OK);
 
396
        Camera *camera = data;
 
397
 
 
398
        GP_DEBUG(" * delete_all_func()");
 
399
        jl2005c_delete_all(camera, camera->port);
 
400
 
 
401
        return (GP_OK);
400
402
}
401
403
 
402
404
 
424
426
};
425
427
 
426
428
int
427
 
camera_init(Camera *camera, GPContext *context)
 
429
camera_init (Camera *camera, GPContext *context)
428
430
{
429
431
        GPPortSettings settings;
430
432
        int ret = 0;
431
433
 
432
434
        /* First, set up all the function pointers */
433
435
        camera->functions->manual       = camera_manual;
434
 
        camera->functions->summary      = camera_summary;
435
 
        camera->functions->about        = camera_about;
436
 
        camera->functions->exit     = camera_exit;
437
 
   
 
436
        camera->functions->summary      = camera_summary;
 
437
        camera->functions->about        = camera_about;
 
438
        camera->functions->exit         = camera_exit;
 
439
 
438
440
        GP_DEBUG ("Initializing the camera\n");
439
441
        ret = gp_port_get_settings(camera->port,&settings);
440
442
        if (ret < 0) return ret; 
455
457
        }
456
458
 
457
459
        ret = gp_port_set_settings(camera->port,settings);
458
 
        if (ret < 0) return ret; 
 
460
        if (ret < 0) return ret;
459
461
 
460
462
        GP_DEBUG("interface = %i\n", settings.usb.interface);
461
 
        GP_DEBUG("inep = %x\n", settings.usb.inep);     
 
463
        GP_DEBUG("inep = %x\n", settings.usb.inep);
462
464
        GP_DEBUG("outep = %x\n", settings.usb.outep);
463
465
 
464
 
        /* Tell the CameraFilesystem where to get lists from */
 
466
        /* Tell the CameraFilesystem where to get lists from */
465
467
        gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);
466
468
 
467
469
        camera->pl = malloc (sizeof (CameraPrivateLibrary));
474
476
        camera->pl->data_reg_opened = 0;
475
477
        camera->pl->data_cache = NULL;
476
478
        camera->pl->init_done = 0;
477
 
        jl2005c_init (camera,camera->port, camera->pl);
 
479
        jl2005c_init (camera, camera->port, camera->pl);
478
480
 
479
481
        return GP_OK;
480
482
}