~ubuntu-branches/ubuntu/trusty/argyll/trusty-proposed

« back to all changes in this revision

Viewing changes to xicc/ccss.c

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-02-12 00:35:39 UTC
  • mfrom: (13.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20140212003539-24tautzlitsiz61w
Tags: 1.5.1-5ubuntu1
* Merge from Debian unstable. (LP: #1275572) Remaining changes:
  - debian/control:
    + Build-depend on libtiff-dev rather than libtiff4-dev.
  - debian/control, debian/patches/06_fix_udev_rule.patch:
    + Fix udev rules to actually work; ENV{ACL_MANAGE} has
      stopped working ages ago, and with logind it's now the
      "uaccess" tag. Dropping also consolekit from Recommends.
  - debian/patches/drop-usb-db.patch:
    + Use hwdb builtin, instead of the obsolete usb-db
      in the udev rules.
* debian/patches/05_ftbfs-underlinkage.diff:
  - Dropped change, no needed anymore.
* Refresh the patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "xspect.h"
38
38
#include "ccss.h"
39
39
 
 
40
#ifdef NT       /* You'd think there might be some standards.... */
 
41
# ifndef __BORLANDC__
 
42
#  define stricmp _stricmp
 
43
# endif
 
44
#else
 
45
# define stricmp strcasecmp
 
46
#endif
 
47
 
40
48
/* Forward declarations */
41
49
static void free_ccss(ccss *p);
42
50
 
44
52
 
45
53
/* Method implimentations */
46
54
 
47
 
/* Write out the ccss to a CGATS format .ccss file */
 
55
/* Write out the ccss to a CGATS format object */
48
56
/* Return nz on error */
49
 
static int write_ccss(
 
57
static int create_ccss_cgats(
50
58
ccss *p,                        /* This */
51
 
char *outname   /* Filename to write to */
 
59
cgats **pocg            /* return CGATS structure */
52
60
) {
53
61
        int i, j;
54
62
        time_t clk = time(0);
59
67
        cgats_set_elem *setel;  /* Array of set value elements */
60
68
        char buf[100];
61
69
 
62
 
        if (p->no_samp < 3) {
63
 
                strcpy(p->err, "Need at least three spectral samples");
64
 
                return 1;
65
 
        }
66
 
 
67
70
        atm[strlen(atm)-1] = '\000';    /* Remove \n from end */
68
71
 
69
72
        /* Setup output cgats file */
88
91
        if (p->tech)
89
92
                ocg->add_kword(ocg, 0, "TECHNOLOGY", p->tech,NULL);
90
93
        if (p->disp == NULL && p->tech == NULL) {
91
 
                sprintf(p->err, "write_ccss: ccss for file '%s' doesn't contain display or techology strings",outname);
 
94
                sprintf(p->err, "write_ccss: ccss doesn't contain display or techology strings");
92
95
                ocg->del(ocg);
93
96
                return 1;
94
97
        }
 
98
        if (p->refrmode >= 0)
 
99
                ocg->add_kword(ocg, 0, "DISPLAY_TYPE_REFRESH", p->refrmode ? "YES" : "NO", NULL);
 
100
        if (p->sel != NULL)
 
101
                ocg->add_kword(ocg, 0, "UI_SELECTORS", p->sel, NULL);
95
102
        if (p->ref != NULL)
96
103
                ocg->add_kword(ocg, 0, "REFERENCE",p->ref, NULL);
97
104
 
101
108
        ocg->add_kword(ocg, 0, "SPECTRAL_START_NM",buf, NULL);
102
109
        sprintf(buf,"%f", p->samples[0].spec_wl_long);
103
110
        ocg->add_kword(ocg, 0, "SPECTRAL_END_NM",buf, NULL);
 
111
        sprintf(buf,"%f", p->samples[0].norm);
 
112
        ocg->add_kword(ocg, 0, "SPECTRAL_NORM",buf, NULL);
104
113
 
105
114
        /* Fields we want */
106
115
        ocg->add_field(ocg, 0, "SAMPLE_ID", nqcs_t);
139
148
        }
140
149
        free(setel);
141
150
 
142
 
        /* Write it */
 
151
        if (pocg != NULL)
 
152
                *pocg = ocg;
 
153
 
 
154
        return 0;
 
155
}
 
156
 
 
157
/* Write out the ccss to a CGATS format .ccss file */
 
158
/* Return nz on error */
 
159
static int write_ccss(
 
160
ccss *p,                /* This */
 
161
char *outname   /* Filename to write to */
 
162
) {
 
163
        int rv;
 
164
        cgats *ocg;                             /* CGATS structure */
 
165
 
 
166
        if (p->no_samp < 3) {
 
167
                strcpy(p->err, "Need at least three spectral samples");
 
168
                return 1;
 
169
        }
 
170
 
 
171
        /* Create CGATS elements */
 
172
        if ((rv = create_ccss_cgats(p, &ocg)) != 0) {
 
173
                return rv;
 
174
        }
 
175
 
 
176
        /* Write it to file */
143
177
        if (ocg->write_name(ocg, outname)) {
144
178
                strcpy(p->err, ocg->err);
145
179
                ocg->del(ocg);          /* Clean up */
146
180
                return 1;
147
181
        }
148
 
 
149
 
        ocg->del(ocg);          /* Clean up */
150
 
 
151
 
        return 0;
152
 
}
153
 
 
154
 
/* Read in the ccss CGATS .ccss file */
 
182
        ocg->del(ocg);          /* Clean up */
 
183
 
 
184
        return 0;
 
185
}
 
186
 
 
187
/* write to a CGATS .ccss file to a memory buffer. */
 
188
/* return nz on error, with message in err[] */
 
189
static int buf_write_ccss(
 
190
ccss *p,
 
191
unsigned char **buf,            /* Return allocated buffer */
 
192
int *len                                        /* Return length */
 
193
) {
 
194
        int rv;
 
195
        cgats *ocg;                             /* CGATS structure */
 
196
        cgatsFile *fp;
 
197
 
 
198
        if (p->no_samp < 3) {
 
199
                strcpy(p->err, "Need at least three spectral samples");
 
200
                return 1;
 
201
        }
 
202
 
 
203
        /* Create CGATS elements */
 
204
        if ((rv = create_ccss_cgats(p, &ocg)) != 0) {
 
205
                return rv;
 
206
        }
 
207
 
 
208
        if ((fp = new_cgatsFileMem(NULL, 0)) == NULL) {
 
209
                strcpy(p->err, "new_cgatsFileMem failed");
 
210
                return 2;
 
211
        }
 
212
 
 
213
        /* Write it to file */
 
214
        if (ocg->write(ocg, fp)) {
 
215
                strcpy(p->err, ocg->err);
 
216
                ocg->del(ocg);          /* Clean up */
 
217
                fp->del(fp);
 
218
                return 1;
 
219
        }
 
220
 
 
221
        /* Get the buffer the ccss has been written to */
 
222
        if (fp->get_buf(fp, buf, (size_t *)len)) {
 
223
                strcpy(p->err, "cgatsFileMem get_buf failed");
 
224
                return 2;
 
225
        }
 
226
 
 
227
        ocg->del(ocg);          /* Clean up */
 
228
        fp->del(fp);
 
229
 
 
230
        return 0;
 
231
}
 
232
 
 
233
/* Read in the ccss CGATS .ccss file from cgats */
155
234
/* Return nz on error */
156
 
static int read_ccss(
157
 
ccss *p,                        /* This */
158
 
char *inname    /* Filename to read from */
 
235
static int read_ccss_cgats(
 
236
ccss *p,                /* This */
 
237
cgats *icg              /* input cgats structure */
159
238
) {
160
239
        int i, j;
161
 
        cgats *icg;                     /* input cgats structure */
162
240
        int ti, ii;                     /* Temporary CGATs index */
163
241
        int  spi[XSPECT_MAX_BANDS];     /* CGATS indexes for each wavelength */
164
242
        xspect sp;
165
243
 
166
 
        /* Open and look at the .ccss file */
167
 
        if ((icg = new_cgats()) == NULL) {              /* Create a CGATS structure */
168
 
                sprintf(p->err, "read_ccss: new_cgats() failed");
169
 
                return 2;
170
 
        }
171
 
        icg->add_other(icg, "CCSS");            /* our special type is Model Printer Profile */
172
 
 
173
 
        if (icg->read_name(icg, inname)) {
174
 
                strcpy(p->err, icg->err);
175
 
                icg->del(icg);
176
 
                return 1;
177
 
        }
178
 
 
179
244
        if (icg->ntables == 0 || icg->t[0].tt != tt_other || icg->t[0].oi != 0) {
180
 
                sprintf(p->err, "read_ccss: Input file '%s' isn't a CCSS format file",inname);
 
245
                sprintf(p->err, "read_ccss: Input file isn't a CCSS format file");
181
246
                icg->del(icg);
182
247
                return 1;
183
248
        }
184
249
        if (icg->ntables != 1) {
185
 
                sprintf(p->err, "Input file '%s' doesn't contain exactly one table",inname);
 
250
                sprintf(p->err, "Input file doesn't contain exactly one table");
186
251
                icg->del(icg);
187
252
                return 1;
188
253
        }
226
291
                }
227
292
        }
228
293
        if (p->disp == NULL && p->tech == NULL) {
229
 
                sprintf(p->err, "read_ccss: Input file '%s' doesn't contain keyword DISPLAY or TECHNOLOGY",inname);
 
294
                sprintf(p->err, "read_ccss: Input file doesn't contain keyword DISPLAY or TECHNOLOGY");
230
295
                icg->del(icg);
231
296
                return 1;
232
297
        }
 
298
        if ((ti = icg->find_kword(icg, 0, "DISPLAY_TYPE_REFRESH")) >= 0) {
 
299
                if (stricmp(icg->t[0].kdata[ti], "YES") == 0)
 
300
                        p->refrmode = 1;
 
301
                else if (stricmp(icg->t[0].kdata[ti], "NO") == 0)
 
302
                        p->refrmode = 0;
 
303
        }
 
304
 
 
305
        if ((ti = icg->find_kword(icg, 0, "UI_SELECTORS")) >= 0) {
 
306
                if ((p->sel = strdup(icg->t[0].kdata[ti])) == NULL) {
 
307
                        sprintf(p->err, "read_ccss: malloc failed");
 
308
                        icg->del(icg);
 
309
                        return 2;
 
310
                }
 
311
        }
233
312
 
234
313
        if ((ti = icg->find_kword(icg, 0, "REFERENCE")) >= 0) {
235
314
                if ((p->ref = strdup(icg->t[0].kdata[ti])) == NULL) {
240
319
        }
241
320
 
242
321
        if ((ii = icg->find_kword(icg, 0, "SPECTRAL_BANDS")) < 0) {
243
 
                sprintf(p->err,"Input file '%s' doesn't contain keyword SPECTRAL_BANDS",inname);
 
322
                sprintf(p->err,"Input file doesn't contain keyword SPECTRAL_BANDS");
244
323
                icg->del(icg);
245
324
                return 1;
246
325
        }
247
326
        sp.spec_n = atoi(icg->t[0].kdata[ii]);
248
327
        if ((ii = icg->find_kword(icg, 0, "SPECTRAL_START_NM")) < 0) {
249
 
                sprintf(p->err,"Input file '%s' doesn't contain keyword SPECTRAL_START_NM",inname);
 
328
                sprintf(p->err,"Input file doesn't contain keyword SPECTRAL_START_NM");
250
329
                icg->del(icg);
251
330
                return 1;
252
331
        }
253
332
        sp.spec_wl_short = atof(icg->t[0].kdata[ii]);
254
333
        if ((ii = icg->find_kword(icg, 0, "SPECTRAL_END_NM")) < 0) {
255
 
                sprintf(p->err,"Input file '%s' doesn't contain keyword SPECTRAL_END_NM",inname);
 
334
                sprintf(p->err,"Input file doesn't contain keyword SPECTRAL_END_NM");
256
335
                icg->del(icg);
257
336
                return 1;
258
337
        }
259
338
        sp.spec_wl_long = atof(icg->t[0].kdata[ii]);
260
 
        sp.norm = 1.0;
 
339
 
 
340
        if ((ii = icg->find_kword(icg, 0, "SPECTRAL_NORM")) < 0) {
 
341
                sp.norm = 1.0;                  /* Older versions don't have SPECTRAL_NORM */
 
342
        } else {
 
343
                sp.norm = atof(icg->t[0].kdata[ii]);
 
344
        }
261
345
 
262
346
        /* Find the fields for spectral values */
263
347
        for (j = 0; j < sp.spec_n; j++) {
271
355
                sprintf(buf,"SPEC_%03d",nm);
272
356
 
273
357
                if ((spi[j] = icg->find_field(icg, 0, buf)) < 0) {
274
 
                        sprintf(p->err,"Input file '%s' doesn't contain field %s",inname,buf);
 
358
                        sprintf(p->err,"Input file doesn't contain field %s",buf);
275
359
                        icg->del(icg);
276
360
                        return 1;
277
361
                }
278
362
        }
279
363
 
280
364
        if ((p->no_samp = icg->t[0].nsets) < 3) {
281
 
                sprintf(p->err, "Input file '%s' doesn't contain at least three spectral samples",inname);
 
365
                sprintf(p->err, "Input file doesn't contain at least three spectral samples");
282
366
                p->no_samp = 0;
283
367
                icg->del(icg);          /* Clean up */
284
368
                return 1;
303
387
                }
304
388
        }
305
389
 
 
390
        return 0;
 
391
}
 
392
 
 
393
/* Read in the ccss CGATS .ccss file */
 
394
/* Return nz on error */
 
395
static int read_ccss(
 
396
ccss *p,                /* This */
 
397
char *inname    /* Filename to read from */
 
398
) {
 
399
        int rv;
 
400
        cgats *icg;                     /* input cgats structure */
 
401
 
 
402
        /* Open and look at the .ccss file */
 
403
        if ((icg = new_cgats()) == NULL) {              /* Create a CGATS structure */
 
404
                sprintf(p->err, "read_ccss: new_cgats() failed");
 
405
                return 2;
 
406
        }
 
407
        icg->add_other(icg, "CCSS");            /* our special type is Model Printer Profile */
 
408
 
 
409
        if (icg->read_name(icg, inname)) {
 
410
                strcpy(p->err, icg->err);
 
411
                icg->del(icg);
 
412
                return 1;
 
413
        }
 
414
 
 
415
        if ((rv = read_ccss_cgats(p, icg)) != 0) {
 
416
                icg->del(icg);          /* Clean up */
 
417
                return rv;
 
418
        }
 
419
 
 
420
        icg->del(icg);          /* Clean up */
 
421
 
 
422
        return 0;
 
423
}
 
424
 
 
425
/* Read in the ccss CGATS .ccss file from a memory buffer */
 
426
/* Return nz on error */
 
427
static int buf_read_ccss(
 
428
ccss *p,                /* This */
 
429
unsigned char *buf,
 
430
int len
 
431
) {
 
432
        int rv;
 
433
        cgatsFile *fp;
 
434
        cgats *icg;                     /* input cgats structure */
 
435
 
 
436
        if ((fp = new_cgatsFileMem(buf, len)) == NULL) {
 
437
                strcpy(p->err, "new_cgatsFileMem failed");
 
438
                return 2;
 
439
        }
 
440
 
 
441
        /* Open and look at the .ccss file */
 
442
        if ((icg = new_cgats()) == NULL) {              /* Create a CGATS structure */
 
443
                sprintf(p->err, "read_ccss: new_cgats() failed");
 
444
                fp->del(fp);
 
445
                return 2;
 
446
        }
 
447
        icg->add_other(icg, "CCSS");            /* our special type is Model Printer Profile */
 
448
        
 
449
        if (icg->read(icg, fp)) {
 
450
                strcpy(p->err, icg->err);
 
451
                icg->del(icg);
 
452
                fp->del(fp);
 
453
                return 1;
 
454
        }
 
455
        fp->del(fp);
 
456
 
 
457
        if ((rv = read_ccss_cgats(p, icg)) != 0) {
 
458
                icg->del(icg);          /* Clean up */
 
459
                return rv;
 
460
        }
 
461
 
306
462
        icg->del(icg);          /* Clean up */
307
463
 
308
464
        return 0;
316
472
char *desc,                     /* General description (optional) */
317
473
char *disp,                     /* Display make and model (optional if tech) */
318
474
char *tech,                     /* Display technology description (optional if disp) */
319
 
char *ref,                      /* Reference spectrometer description (optional) */
 
475
int refrmode,           /* Display refresh mode, -1 = unknown, 0 = n, 1 = yes */
 
476
char *sel,                      /* UI selector characters - NULL for none */
 
477
char *refd,                     /* Reference spectrometer description (optional) */
320
478
xspect *samples,        /* Arry of spectral samples. All assumed to be same dim as first */
321
479
int no_samp                     /* Number of spectral samples */
322
480
) {
353
511
                        return 2;
354
512
                }
355
513
        }
356
 
        if (ref != NULL) {
357
 
                if ((p->ref = strdup(ref)) == NULL) {
 
514
        p->refrmode = refrmode;
 
515
        if (sel != NULL) {
 
516
                if ((p->sel = strdup(sel)) == NULL) {
 
517
                        sprintf(p->err, "set_ccss: malloc sel failed");
 
518
                        return 2;
 
519
                }
 
520
        }
 
521
        if (refd != NULL) {
 
522
                if ((p->ref = strdup(refd)) == NULL) {
358
523
                        sprintf(p->err, "set_ccss: malloc ref failed");
359
524
                        return 2;
360
525
                }
404
569
                if (p->tech != NULL)
405
570
                        free(p->tech);
406
571
                p->tech = NULL;
 
572
                if (p->sel != NULL)
 
573
                        free(p->sel);
 
574
                p->sel = NULL;
407
575
                if (p->ref != NULL)
408
576
                        free(p->ref);
409
577
                p->ref = NULL;
431
599
                return NULL;
432
600
 
433
601
        /* Init method pointers */
434
 
        p->del         = del_ccss;
435
 
        p->set_ccss    = set_ccss;
436
 
        p->write_ccss  = write_ccss;
437
 
        p->read_ccss   = read_ccss;
 
602
        p->del             = del_ccss;
 
603
        p->set_ccss        = set_ccss;
 
604
        p->write_ccss      = write_ccss;
 
605
        p->buf_write_ccss  = buf_write_ccss;
 
606
        p->read_ccss       = read_ccss;
 
607
        p->buf_read_ccss   = buf_read_ccss;
438
608
 
439
609
        return p;
440
610
}