Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
iccSpecSepToTiff.cpp
Go to the documentation of this file.
1/*
2 File: iccSpecSepToTiff.cpp
3
4 Contains: Console app to concatenate several separated spectral tiff
5 files into a single tiff file optionally including an
6 embedded profile
7
8 Version: V1
9
10 Copyright: (c) see below
11*/
12
13/*
14 * The ICC Software License, Version 0.2
15 *
16 *
17 * Copyright (c) 2003-2013 The International Color Consortium. All rights
18 * reserved.
19 *
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
22 * are met:
23 *
24 * 1. Redistributions of source code must retain the above copyright
25 * notice, this list of conditions and the following disclaimer.
26 *
27 * 2. Redistributions in binary form must reproduce the above copyright
28 * notice, this list of conditions and the following disclaimer in
29 * the documentation and/or other materials provided with the
30 * distribution.
31 *
32 * 3. In the absence of prior written permission, the names "ICC" and "The
33 * International Color Consortium" must not be used to imply that the
34 * ICC organization endorses or promotes products derived from this
35 * software.
36 *
37 *
38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 * DISCLAIMED. IN NO EVENT SHALL THE INTERNATIONAL COLOR CONSORTIUM OR
42 * ITS CONTRIBUTING MEMBERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This software consists of voluntary contributions made by many
53 * individuals on behalf of the The International Color Consortium.
54 *
55 *
56 * Membership in the ICC is encouraged when this software is used for
57 * commercial purposes.
58 *
59 *
60 * For more information on The International Color Consortium, please
61 * see <http://www.color.org/>.
62 *
63 *
64 */
65
66//////////////////////////////////////////////////////////////////////
67// HISTORY:
68//
69// -Initial implementation by Max Derhak 12-7-2013
70//
71//////////////////////////////////////////////////////////////////////
72
73
74#include <iostream>
75#include <cstdlib>
76#include <stdio.h>
77#include "IccCmm.h"
78#include "IccUtil.h"
79#include "IccDefs.h"
80#include "IccApplyBPC.h"
81#include "TiffImg.h"
82
83void Usage()
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}
87
88#ifndef _MAX_PATH
89#define _MAX_PATH 510
90#endif
91
92//===================================================
93
94int main(int argc, char* argv[]) {
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}
File: IccApplyBPC.h.
File: IccCmm.h.
File: IccDefs.h
File: IccUtil.h.
int main()
Core and external libraries necessary for the fuzzer functionality.
#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.
void Usage()
#define _MAX_PATH