1 /*
2 * PTtiff2psd
3 *
4 * Based on the program PTStitcher by Helmut Dersch.
5 *
6 * Converts a set of TIFF files into a Photoshop PSD file
7 *
8 * Jan 2006
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This software is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this software; see the file COPYING. If not, a copy
22 * can be downloaded from http://www.gnu.org/licenses/gpl.html, or
23 * obtained by writing to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 *
26 *
27 * Author: Daniel M German dmgerman at uvic doooot ca
28 *
29 */
30
31
32 #include <stdlib.h>
33 #include <assert.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <sys/types.h>
37
38 #ifndef _MSC_VER
39 #include <unistd.h>
40 #else
41 #include "compat_win32/getopt.h"
42 #endif
43
44 #include <assert.h>
45 #include <errno.h>
46
47
48 #include "filter.h"
49 #include "panorama.h"
50 #include "PTcommon.h"
51 #include "ColourBrightness.h"
52 #include "ptstitch.h"
53 #include "pttiff.h"
54 #include "file.h"
55
56 #define PT_TIFF2PSD_USAGE "PTtiff2psd [options] <tiffFiles>+\n\n"\
57 "Options:\n"\
58 "\t-o <filename>\t\tOutput filename (default merged.psd)\n"\
59 "\t-b <blendingmode>\tSpecify blending mode for layers (use -h to display them)\n"\
60 "\t-f\t\tForce processing (do not stop at warnings)\n"\
61 "\t-s\t\t\tStack them\n"\
62 "\t-q\t\t\tQuiet run\n"\
63 "\t-r\t\t\tReverse layers\n"\
64 "\t-8\t\t\tReduce image to 8bit per channel\n"\
65 "\t-B\t\t\tForce Big, PSB file format\n"\
66 "\t-h\t\t\tShow this message\n"\
67 "\n"
68
69 #define PT_TIFF2PSD_VERSION "PTtiff2psd Version " VERSION ", based on code by Helmut Dersch, rewritten by Daniel M German and Jim Watters\n"
70
71 #define DEFAULT_OUTPUT_FILENAME "merged.psd"
72
main(int argc,char * argv[])73 int main(int argc,char *argv[])
74 {
75 int opt;
76 char *endPtr;
77 fullPath *ptrInputFiles;
78 int counter;
79 fullPath outputFilename;
80 int filesCount;
81 int base = 0;
82 int reverseLayers = 0;
83 int i;
84 int temp;
85 int ptForceProcessing = 0;
86
87 pano_flattening_parms flatteningParms;
88
89 // clean up struct
90 bzero(&flatteningParms, sizeof(flatteningParms));
91
92 ptrInputFiles = NULL;
93 counter = 0;
94
95 printf(PT_TIFF2PSD_VERSION);
96
97 if (StringtoFullPath(&outputFilename, DEFAULT_OUTPUT_FILENAME)) {
98 PrintError("Not a valid pathnamefor output filename [%s]", DEFAULT_OUTPUT_FILENAME);
99 return(-1);
100 }
101
102 while ((opt = getopt(argc, argv, "o:sb:qhfmr8B")) != -1) {
103
104 // o and f -> set output file
105 // h -> help
106 // q -> quiet?
107 // k -> base image, defaults to first
108
109 switch(opt) { // fhoqs f: 102 h:104 111 113 115 o:f:hsq
110 case 'o':
111 if (StringtoFullPath(&outputFilename, optarg) !=0) { // success
112 PrintError("Not a valid pathname for output filename");
113 return(-1);
114 }
115 break;
116 case 'b':
117 temp = strtol(optarg, &endPtr, 10);
118 if (errno != 0 || (temp < 0 || temp >= PSD_NUMBER_BLENDING_MODES)) {
119 PrintError("Invalid value in blending mode. Use -h to see possible values ");
120 return -1;
121 }
122 printf("Here %d\n", temp);
123 flatteningParms.psdBlendingMode = temp;
124 break;
125 case 's':
126 flatteningParms.stacked = 1;
127 break;
128 case 'f':
129 ptForceProcessing = 1;
130 break;
131 case 'r':
132 reverseLayers = 1;
133 break;
134 case '8':
135 flatteningParms.force8bit = 1;
136 break;
137 case 'B':
138 flatteningParms.forceBig = 1;
139 break;
140 case 'q':
141 ptQuietFlag = 1;
142 break;
143 case 'h':
144 printf(PT_TIFF2PSD_USAGE);
145 printf("\tValid blending modes:\n");
146 for (i=0;i<PSD_NUMBER_BLENDING_MODES;i++) {
147 printf("\t%2d\t%s\n", i, psdBlendingModesNames[i]);
148 }
149 exit(0);
150 default:
151 break;
152 }
153 }
154
155
156
157 filesCount = argc - optind;
158
159 if ((ptrInputFiles = calloc(filesCount, sizeof(fullPath))) == NULL) {
160 PrintError("Not enough memory");
161 return -1;
162 }
163
164 base = optind;
165 for (; optind < argc; optind++) {
166 char *currentParm;
167 int index;
168
169 currentParm = argv[optind];
170
171 // By default files are layered with the first at the bottom, and last at the top
172 // This option reverses that
173 index = optind - base;
174 if (reverseLayers) {
175 index = filesCount - 1 - index;
176 //just in case
177 assert(index >= 0);
178 assert(index < filesCount);
179 }
180
181 if (StringtoFullPath(&ptrInputFiles[index], currentParm) !=0) { // success
182 PrintError("Syntax error: Not a valid pathname");
183 return(-1);
184 }
185 }
186
187 if (filesCount <= 0) {
188 PrintError("No files specified in the command line");
189 fprintf(stderr, PT_TIFF2PSD_USAGE);
190 return -1;
191 }
192
193 if (!ptForceProcessing) {
194 if (filesCount > 1 && !panoTiffVerifyAreCompatible(ptrInputFiles, filesCount, TRUE)) {
195 PrintError("TIFFs are not compatible. Use -f to force processing");
196 return -1;
197 }
198 }
199
200 // Finally create the PSD
201
202 if (!ptQuietFlag) {
203 char tempString[MAX_PATH_LENGTH + 40];
204 sprintf(tempString, "Creating output file %s", outputFilename.name);
205 Progress(_initProgress, tempString);
206 }
207
208 //if (panoPSDCreate(ptrInputFiles, filesCount, &outputFilename, &flatteningParms) != 0) {
209 if (panoCreateLayeredPSD(ptrInputFiles, filesCount, &outputFilename, &flatteningParms) != 0) {
210 PrintError("Error while creating PSD file");
211 return -1;
212 }
213
214 free(ptrInputFiles);
215
216 return 0;
217
218 }
219
220