Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
iccSpecSepToTiff.cpp File Reference
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include "IccCmm.h"
#include "IccUtil.h"
#include "IccDefs.h"
#include "IccApplyBPC.h"
#include "TiffImg.h"
+ Include dependency graph for iccSpecSepToTiff.cpp:

Go to the source code of this file.

Macros

#define _MAX_PATH   510
 

Functions

int main (int argc, char *argv[])
 
void Usage ()
 

Macro Definition Documentation

◆ _MAX_PATH

#define _MAX_PATH   510

Definition at line 89 of file iccSpecSepToTiff.cpp.

Referenced by main().

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 94 of file iccSpecSepToTiff.cpp.

94 {
95 int minargs = 8; // Minimum number of arguments should account for the optional ICC profile
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
101 CTiffImg infile[100], outfile;
102 char filename[_MAX_PATH];
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; // Exit the program with an error code
119 }
120
121 n = (end - start) / step + 1; // Safe to perform division now
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 }
150 bpl = infile[0].GetBytesPerLine();
151 CTiffImg *f = &infile[0];
152
153 if (f->GetPhoto()==PHOTO_MINISWHITE)
154 invert = true;
155 else if (f->GetPhoto()!=PHOTO_MINISBLACK) {
156 printf("Photometric must be MinIsWhite or MinIsBlack\n");
157 return -1;
158 }
159
160 bps = f->GetBitsPerSample()/8;
161
162 icUInt8Number *inbuf = (icUInt8Number*)malloc(bpl*n);
163 icUInt8Number *buf = (icUInt8Number*)malloc(f->GetWidth() * bps * n );
164 icUInt8Number *sptr, *tptr;
165
166 if (!inbuf || !buf) {
167 printf("Memory allocation error!\n");
168 goto cleanup;
169 }
170
171 xRes=f->GetXRes();
172 yRes=f->GetYRes();
173
174 if (xRes<1)
175 xRes = 72;
176 if (yRes<1)
177 yRes = 72;
178
179 if (outfile.Create(argv[1], f->GetWidth(), f->GetHeight(), f->GetBitsPerSample(), PHOTO_MINISBLACK,
180 n, xRes, yRes, bCompress, bSep)) {
181
182 if (argc>8) {
183 unsigned long length = 0;
184 icUInt8Number *pDestProfile = NULL;
185
186 CIccFileIO io;
187 if (io.Open(argv[8], "r")) {
188 length = io.GetLength();
189 pDestProfile = (icUInt8Number *)malloc(length);
190 if (pDestProfile) {
191 io.Read8(pDestProfile, length);
192 outfile.SetIccProfile(pDestProfile, length);
193 free(pDestProfile);
194 }
195 io.Close();
196 }
197 }
198
199 for (i=0; i<(int)f->GetHeight(); i++) {
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 }
221 outfile.WriteLine(buf);
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
239 outfile.Close();
240
241 return 0;
242}
#define PHOTO_MINISBLACK
Definition TiffImg.h:78
#define PHOTO_MINISWHITE
Definition TiffImg.h:79
Type: Class.
Definition IccIO.h:150
virtual void Close()
Definition IccIO.cpp:443
virtual icInt32Number Read8(void *pBuf, icInt32Number nNum=1)
Definition IccIO.cpp:452
virtual icInt32Number GetLength()
Definition IccIO.cpp:470
bool Open(const icChar *szFilename, const icChar *szAttr)
Definition IccIO.cpp:382
float GetYRes()
Definition TiffImg.h:110
void Close()
Definition TiffImg.cpp:104
unsigned int GetBitsPerSample()
Definition TiffImg.h:103
unsigned int GetWidth()
Definition TiffImg.h:99
float GetXRes()
Definition TiffImg.h:109
unsigned int GetPhoto()
Definition TiffImg.cpp:391
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)
Definition TiffImg.cpp:124
unsigned int GetHeight()
Definition TiffImg.h:100
bool WriteLine(unsigned char *pBuf)
Definition TiffImg.cpp:353
unsigned int GetBytesPerLine()
Definition TiffImg.h:112
bool SetIccProfile(unsigned char *pProfile, unsigned int nLen)
Definition TiffImg.cpp:420
unsigned char icUInt8Number
Number definitions.
#define _MAX_PATH

References _MAX_PATH, CIccFileIO::Close(), CTiffImg::Close(), CTiffImg::Create(), CTiffImg::GetBitsPerSample(), CTiffImg::GetBytesPerLine(), CTiffImg::GetHeight(), CIccFileIO::GetLength(), CTiffImg::GetPhoto(), CTiffImg::GetWidth(), CTiffImg::GetXRes(), CTiffImg::GetYRes(), CIccFileIO::Open(), PHOTO_MINISBLACK, PHOTO_MINISWHITE, CIccFileIO::Read8(), CTiffImg::SetIccProfile(), and CTiffImg::WriteLine().

+ Here is the call graph for this function:

◆ Usage()

void Usage ( )

Definition at line 83 of file iccSpecSepToTiff.cpp.

84{
85 printf("Usage: SpecSep2Tiff output_file compress_flag sep_flag infile_fmt_file start_nm end_nm inc_nm {embedded_icc_profile_file}\n\n");
86}