~ubuntu-branches/ubuntu/saucy/argyll/saucy

« back to all changes in this revision

Viewing changes to spectro/spyd2en.c

  • Committer: Package Import Robot
  • Author(s): Christian Marillat
  • Date: 2012-04-25 07:46:07 UTC
  • mfrom: (1.2.2) (13.1.15 sid)
  • Revision ID: package-import@ubuntu.com-20120425074607-yjqadetw8kum9skc
Tags: 1.4.0-4
Should Build-Depends on libusb-dev (Closes: #670329).

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include <string.h>
34
34
#if defined (NT)
35
35
#define WIN32_LEAN_AND_MEAN
 
36
#include <io.h>
36
37
#include <windows.h>
37
38
#endif
38
39
#ifdef UNIX
58
59
struct _archive {
59
60
        int verb;
60
61
        int isvise;                             /* Is this an archive ? */
 
62
        unsigned int vbase;             /* Base address of archive */
61
63
        unsigned char *abuf;    /* Buffer holding archive file */
62
64
        unsigned int asize;             /* Nuber of bytes in file */
63
65
        unsigned int off;               /* Current offset */
128
130
                        if (strncmp((char *)&p->abuf[i], name, sl) == 0) {
129
131
                                int sto;
130
132
                                /* Found it */
 
133
                                if (p->verb)
 
134
                                        printf("Located driver entry '%s' at offset 0x%x\n",name,i);
131
135
                                i += sl;
132
136
                                if (i >= (p->asize - 1))
133
137
                                        return 1;
139
143
                                p->off += (p->abuf[i + 1] << 8);
140
144
                                p->off += (p->abuf[i + 2] << 16);
141
145
                                p->off += (p->abuf[i + 3] << 24);
142
 
                                p->off += 0x10000;
 
146
                                p->off += p->vbase;
143
147
                                if (p->off >= p->asize - 10)
144
148
                                        return 1;
145
149
                                if (p->verb)
180
184
}
181
185
 
182
186
/* --------------------------------------------------------- */
183
 
/* Interface with inflate.c */
 
187
/* Interface with vinflate.c */
 
188
 
 
189
int vinflate(void);
184
190
 
185
191
archive *g_va = NULL;
186
192
 
187
193
/* fetch the next 16 bits, big endian */
188
194
/* if we get 0xffffffff, we are at EOF */
189
 
unsigned int get_16bits() {
 
195
unsigned int vget_16bits() {
190
196
        return get16_arch(g_va);
191
197
}
192
198
 
193
199
/* unget 16 bits */
194
 
void unget_16bits() {
 
200
void vunget_16bits() {
195
201
        unget16_arch(g_va);
196
202
}
197
203
 
198
204
/* Save the decompressed file to the buffer */
199
 
int write_output(unsigned char *buf, unsigned int len) {
 
205
int vwrite_output(unsigned char *buf, unsigned int len) {
200
206
        if ((g_va->dsize + len) >= g_va->maxdsize) {
201
207
                warning("Uncompressed buffer is unexpectedly large (%d > %d)!",
202
208
                (g_va->dsize + len), g_va->maxdsize);
212
218
/* create an archive by reading the file into memory */
213
219
archive *new_arch(char *name, int verb) {
214
220
        FILE *ifp;
215
 
        unsigned int bread;
 
221
        unsigned int bread, i;
216
222
        int rv = 0;
217
223
        archive *p;
218
224
 
257
263
        
258
264
        fclose(ifp);
259
265
 
260
 
        if (p->asize >= 0x10100
261
 
         && p->abuf[0x10003] == 'V'
262
 
         && p->abuf[0x10002] == 'I'
263
 
         && p->abuf[0x10001] == 'S'
264
 
         && p->abuf[0x10000] == 'E')
265
 
                p->isvise = 1;
 
266
        /* See if it looks like a VIZE archive */
 
267
        for (i = 0x10000; i < 0x11000 && i < (p->asize-4); i++) {
 
268
                if (p->abuf[i + 3] == 'V'
 
269
                 && p->abuf[i + 2] == 'I'
 
270
                 && p->abuf[i + 1] == 'S'
 
271
                 && p->abuf[i + 0] == 'E') {
 
272
                        p->isvise = 1;
 
273
                        p->vbase = i;
 
274
                }
 
275
        }
266
276
 
267
277
        if (p->isvise) {                /* Need to locate driver file and decompress it */
268
278
                char *dname = "CVSpyder.dll";
269
279
 
270
280
                if (verb)
271
 
                        printf("Input file '%s' is a VISE archive file\n",name);
 
281
                        printf("Input file '%s' is a VISE archive file base 0x%x\n",name,p->vbase);
272
282
                p->dsize = 0;
273
283
                p->maxdsize = 650000;
274
284
                if ((p->dbuf = (unsigned char *)malloc(p->asize)) == NULL)
278
288
                        error("Failed to locate file '%s'\n",dname);
279
289
 
280
290
                g_va = p;
281
 
                if (inflate()) {
 
291
                if (vinflate()) {
282
292
                        error("Inflating file '%s' failed",dname);
283
293
                }
284
294
                if (verb)
289
299
                        free(p->abuf);
290
300
                p->abuf = NULL;
291
301
                
 
302
        } else {
 
303
                if (verb)
 
304
                        printf("Input file '%s' is NOT a VISE archive file - assume it's a .dll\n",name);
292
305
        }
293
306
 
294
307
        /* Locate the Spyder firmware image */
571
584
void usage(void) {
572
585
        fprintf(stderr,"Transfer Spyder 2 PLD pattern from file, Version %s\n",ARGYLL_VERSION_STR);
573
586
        fprintf(stderr,"Author: Graeme W. Gill, licensed under the GPL Version 2 or later\n");
574
 
        fprintf(stderr,"usage: Transfer [-v] infile\n");
 
587
        fprintf(stderr,"usage: spyd2en [-v] infile\n");
575
588
        fprintf(stderr," -v              Verbose\n");
576
589
        fprintf(stderr," -S d            Specify the install scope u = user (def.), l = local system]\n");
577
590
        fprintf(stderr," infile          Binary driver file to search\n");
594
607
        char patch_name[MAXNAMEL+1] = "\000" ;
595
608
        char *header_name = "spyd2PLD.h";
596
609
        char *bin_name = "color/spyd2PLD.bin";
597
 
        char *bin_path = NULL;
 
610
        char **bin_paths = NULL;
 
611
        int no_paths = 0;
598
612
        xdg_scope scope = xdg_user;
599
613
        int verb = 0;
600
614
        int header = 0;
854
868
                error("Failed to create archive object from '%s'",in_name);
855
869
        }
856
870
 
857
 
        if(amount) umiso();
 
871
        if (amount) umiso();
858
872
        
859
873
        /* Get path. This may drop uid/gid if we are su */
860
 
        if ((bin_path = xdg_bds(NULL, xdg_data, xdg_write, scope, bin_name)) == NULL) {
 
874
        if ((no_paths = xdg_bds(NULL, &bin_paths, xdg_data, xdg_write, scope, bin_name)) < 1) {
861
875
                error("Failed to find/create XDG_DATA path");
862
876
        }
863
877
 
864
878
        get_firmware_arch(va, &fbuf, &fsize);
865
879
        
866
880
        if (verb)
867
 
                printf("Firmware is being save to '%s'\n",bin_path);
 
881
                printf("Firmware is being save to '%s'\n",bin_paths[0]);
868
882
 
869
883
        /* Create a binary file containing the firmware */
870
884
        /* that drivers for the Spyder 2 can use */
871
 
        write_bin(bin_path, fbuf, fsize, verb);
872
 
        free(bin_path);
 
885
        write_bin(bin_paths[0], fbuf, fsize, verb);
 
886
        xdg_free(bin_paths, no_paths);
873
887
 
874
888
        /* Create a header file that can be compiled in */
875
889
        if (header)