-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrecombine.cpp
114 lines (101 loc) · 1.76 KB
/
recombine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include "imageutils/tiffsaver.h"
#include "support/progresstext.h"
#include "lcmswrapper.h"
#include "imagesource_cms.h"
#include "imagesource_extractchannel.h"
#include "imagesource_combine.h"
#include "imagesource_util.h"
#ifdef WIN32
#include "getopt.h"
#else
#include <getopt.h>
#endif
void GetColourFromFilename(ISDeviceNValue &c,const char *fn)
{
int sl=strlen(fn)-1;
c[0]=0;
c[1]=0;
c[2]=0;
c[3]=0;
while(sl>=0)
{
if(fn[sl]=='.' && sl>0)
{
switch(fn[sl-1]&~32)
{
case 'C':
c[0]=IS_SAMPLEMAX;
break;
case 'M':
c[1]=IS_SAMPLEMAX;
break;
case 'Y':
c[2]=IS_SAMPLEMAX;
break;
case 'K':
c[3]=IS_SAMPLEMAX;
break;
}
return;
}
--sl;
}
}
char *GetRootFilename(const char *fn)
{
int sl=strlen(fn)-1;
while(sl>=0)
{
if(fn[sl]=='.' && sl>1 && fn[sl-2]=='-')
{
char *result=strdup(fn);
while(result[sl])
{
result[sl-2]=result[sl];
++sl;
}
result[sl-2]=0;
return(result);
}
--sl;
}
return(NULL);
}
int main(int argc, char **argv)
{
try
{
ImageSource *src=NULL;
for(int i=1;i<argc;++i)
{
cerr << "Index " << i << endl;
ISDeviceNValue col(4);
cerr << "Getting colour from " << argv[i] << endl;
GetColourFromFilename(col,argv[i]);
ImageSource *img=ISLoadImage(argv[i]);
src=new ImageSource_Combine(img,col,src);
}
cerr << "Checking combined image and saving..." << endl;
if(src)
{
char *fn=GetRootFilename(argv[optind]);
cerr << "Filename " << fn << endl;
TIFFSaver ts(fn,ImageSource_rp(src));
ProgressText p;
ts.SetProgress(&p);
ts.Save();
free(fn);
}
}
catch(const char *err)
{
cerr << "Error: " << err << endl;
}
catch(int i)
{
}
return(0);
}