94 {
95 int minargs = 8;
96 if (argc < minargs) {
97 std::cerr << "Usage: SpecSep2Tiff output_file compress_flag sep_flag infile_fmt_file start_nm end_nm inc_nm [embedded_icc_profile_file]\n";
98 return -1;
99 }
100
103 int i, j, k;
104 long bpl, bps;
105 bool invert = false;
106 int start, end, step, n;
107 float xRes, yRes;
108
109 bool bCompress = atoi(argv[2]) != 0;
110 bool bSep = atoi(argv[3]) != 0;
111
112 start = atoi(argv[5]);
113 end = atoi(argv[6]);
114 step = atoi(argv[7]);
115
116 if (step == 0) {
117 std::cerr << "Error: increment ('inc_nm') cannot be zero.\n";
118 return -1;
119 }
120
121 n = (end - start) / step + 1;
122
123 for (i=0; i<n; i++) {
124 sprintf(filename, argv[4], i*step + start);
125 if (!infile[i].Open(filename)) {
126 printf("Cannot open %s\n", filename);
127 return -1;
128 }
129
130 if (infile[i].GetSamples() != 1) {
131 printf("%s does not have 1 sampleperpixel\n", filename);
132 return -1;
133 }
134
135 if (infile[i].GetPhoto() == PHOTOMETRIC_PALETTE) {
136 printf("%s is a palette based file\n", filename);
137 return -1;
138 }
139
140 if (i && (infile[i].GetWidth() != infile[0].GetWidth() ||
141 infile[i].GetHeight() != infile[i-1].GetHeight() ||
142 infile[i].GetBitsPerSample() != infile[i-1].GetBitsPerSample() ||
143 infile[i].GetPhoto() != infile[i-1].GetPhoto() ||
144 infile[i].GetXRes() != infile[i-1].GetXRes() ||
145 infile[i].GetYRes() != infile[i-1].GetYRes())) {
146 printf("%s doesn't have same format as other files\n", filename);
147 return -1;
148 }
149 }
152
154 invert = true;
156 printf("Photometric must be MinIsWhite or MinIsBlack\n");
157 return -1;
158 }
159
161
165
166 if (!inbuf || !buf) {
167 printf("Memory allocation error!\n");
168 goto cleanup;
169 }
170
173
174 if (xRes<1)
175 xRes = 72;
176 if (yRes<1)
177 yRes = 72;
178
180 n, xRes, yRes, bCompress, bSep)) {
181
182 if (argc>8) {
183 unsigned long length = 0;
185
187 if (io.
Open(argv[8],
"r")) {
190 if (pDestProfile) {
191 io.
Read8(pDestProfile, length);
193 free(pDestProfile);
194 }
196 }
197 }
198
200 for (j=0; j<n; j++) {
201 sptr = inbuf + j*bpl;
202 if (!infile[j].ReadLine(sptr)) {
203 printf("Error reading line %d of file %d\n", i, j);
204 goto cleanup;
205 }
206 if (invert) {
207 for (k=bpl; k>0; k--) {
208 *sptr ^= 0xff;
209 sptr++;
210 }
211 }
212 }
213 tptr = buf;
214 for (k=0; k<(int)f->
GetWidth(); k++) {
215 for (j=0; j<n; j++) {
216 sptr = inbuf + j*bpl + k*bps;
217 memcpy(tptr, sptr, bps);
218 tptr+=bps;
219 }
220 }
222 }
223 printf("Image successfully written!\n");
224 }
225 else {
226 printf("Unable to create %s\n", argv[1]);
227 }
228
229cleanup:
230 if (inbuf)
231 free(inbuf);
232
233 if (buf)
234 free(buf);
235
236 for (i=0; i<n; i++)
237 infile[i].Close();
238
240
241 return 0;
242}
virtual icInt32Number Read8(void *pBuf, icInt32Number nNum=1)
virtual icInt32Number GetLength()
bool Open(const icChar *szFilename, const icChar *szAttr)
unsigned int GetBitsPerSample()
bool Create(const char *szFname, unsigned int nWidth, unsigned int nHeight, unsigned int nBPS, unsigned int nPhoto, unsigned int nSamples, float fXRes, float fYRes, bool bCompress=true, bool bSep=false)
bool WriteLine(unsigned char *pBuf)
unsigned int GetBytesPerLine()
bool SetIccProfile(unsigned char *pProfile, unsigned int nLen)