78 {
80 SCANNED_ARG *s_arg;
81 TIFF *tif;
82 char *input = NULL, *output = NULL;
83 char **column_names = NULL;
84 int32_t **data;
85 int32_t *indexes = NULL;
86 long rgb[3];
87 long i, j, n = 0, single_column_mode = 0;
88
90
91 rgb[0] = rgb[1] = rgb[2] = 1;
92
94 if (argc < 3) {
95 fprintf(stderr, "%s", usage);
96 return 1;
97 }
98
99 for (i = 1; i < argc; i++) {
100 if (s_arg[i].arg_type == OPTION) {
101 switch (
match_string(s_arg[i].list[0], option, N_OPTIONS, 0)) {
102 case OPT_REDONLY:
103 rgb[0] = 1;
104 rgb[1] = rgb[2] = 0;
105 break;
106 case OPT_GREENONLY:
107 rgb[1] = 1;
108 rgb[0] = rgb[2] = 0;
109 break;
110 case OPT_BLUEONLY:
111 rgb[2] = 1;
112 rgb[0] = rgb[1] = 0;
113 break;
114 case OPT_SINGLECOLUMNMODE:
115 single_column_mode = 1;
116 break;
117 default:
118 fprintf(stderr, "invalid option seen\n%s", usage);
119 return 1;
120 }
121 } else {
122 if (!input)
123 input = s_arg[i].list[0];
124 else if (!output)
125 output = s_arg[i].list[0];
126 else {
127 fprintf(stderr, "too many filenames\n%s", usage);
128 return 1;
129 }
130 }
131 }
132
133 tif = TIFFOpen(input, "r");
134 if (tif) {
135 uint32_t w, h;
136 size_t npixels;
137 uint32_t *raster;
138 double tmp;
139 int32_t tmp2;
140
141 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
142 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
143 npixels = w * h;
144 raster = (uint32_t *)_TIFFmalloc(npixels * sizeof(uint32_t));
145 if (raster != NULL) {
146 if (TIFFReadRGBAImage(tif, w, h, raster, 0)) {
147
150 if (single_column_mode) {
151
153 fprintf(stderr, "Problem defining parameter Variable1Name.\n");
154 return 1;
155 }
157 fprintf(stderr, "Problem defining parameter Variable2Name.\n");
158 return 1;
159 }
160 tmp = 1;
162 fprintf(stderr, "Problem defining parameter xInterval.\n");
163 return 1;
164 }
166 fprintf(stderr, "Problem defining parameter yInterval.\n");
167 return 1;
168 }
169 tmp2 = w;
171 fprintf(stderr, "Problem defining parameter xDimension.\n");
172 return 1;
173 }
174 tmp2 = h;
176 fprintf(stderr, "Problem defining parameter yDimension.\n");
177 return 1;
178 }
179 tmp = 0;
181 fprintf(stderr, "Problem defining parameter xMinimum.\n");
182 return 1;
183 }
185 fprintf(stderr, "Problem defining parameter yMinimum.\n");
186 return 1;
187 }
189 fprintf(stderr, "Problem defining column z.\n");
190 return 1;
191 }
192 data = malloc(sizeof(*data) * 1);
193 data[0] = malloc(sizeof(*(data[0])) * npixels);
194 } else {
195
197 fprintf(stderr, "Problem defining column Index.\n");
198 return 1;
199 }
200 indexes = malloc(sizeof(*indexes) * w);
201 column_names = malloc(sizeof(char **) * h);
202 data = malloc(sizeof(*data) * h);
203 for (i = 0; i < h; i++) {
204 column_names[i] = malloc(sizeof(char *) * 15);
205 data[i] = malloc(sizeof(*(data[i])) * w);
206 sprintf(column_names[i], "Line%05ld", i);
208 fprintf(stderr, "Problem defining column %s.\n", column_names[i]);
209 return 1;
210 }
211 }
212 }
213
216 if (single_column_mode) {
219 for (i = 0; i < h; i++) {
220 for (j = 0; j < w; j++) {
221
222 data[0][j * h + i] = TIFFGetR(raster[n]) * rgb[0] + TIFFGetG(raster[n]) * rgb[1] + TIFFGetB(raster[n]) * rgb[2];
223 n++;
224 }
225 }
226
229 } else {
232 for (i = 0; i < w; i++)
233 indexes[i] = i;
234 for (i = 0; i < h; i++) {
235 for (j = 0; j < w; j++) {
236
237 data[i][j] = TIFFGetR(raster[n]) * rgb[0] + TIFFGetG(raster[n]) * rgb[1] + TIFFGetB(raster[n]) * rgb[2];
238 n++;
239 }
240 }
243 for (i = 0; i < h; i++) {
246 }
247 }
248
251
252 if (single_column_mode) {
253 free(data[0]);
254 free(data);
255 } else {
256 for (i = 0; i < h; i++) {
257 free(column_names[i]);
258 free(data[i]);
259 }
260 free(column_names);
261 free(data);
262 }
263 }
264 _TIFFfree(raster);
265 }
266 TIFFClose(tif);
267 }
268 if (indexes)
269 free(indexes);
271 return 0;
272}
int32_t SDDS_StartPage(SDDS_DATASET *SDDS_dataset, int64_t expected_n_rows)
int32_t SDDS_SetColumnFromLongs(SDDS_DATASET *SDDS_dataset, int32_t mode, int32_t *data, int64_t rows,...)
Sets the values for a single data column using long integer numbers.
int32_t SDDS_DefineParameter1(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, void *fixed_value)
Defines a data parameter with a fixed numerical value.
int32_t SDDS_InitializeOutput(SDDS_DATASET *SDDS_dataset, int32_t data_mode, int32_t lines_per_row, const char *description, const char *contents, const char *filename)
Initializes the SDDS output dataset.
int32_t SDDS_DefineSimpleColumn(SDDS_DATASET *SDDS_dataset, const char *name, const char *unit, int32_t type)
Defines a simple data column within the SDDS dataset.
int32_t SDDS_WritePage(SDDS_DATASET *SDDS_dataset)
Writes the current data table to the output file.
int32_t SDDS_WriteLayout(SDDS_DATASET *SDDS_dataset)
Writes the SDDS layout header to the output file.
int32_t SDDS_DefineParameter(SDDS_DATASET *SDDS_dataset, const char *name, const char *symbol, const char *units, const char *description, const char *format_string, int32_t type, char *fixed_value)
Defines a data parameter with a fixed string value.
void SDDS_PrintErrors(FILE *fp, int32_t mode)
Prints recorded error messages to a specified file stream.
void SDDS_RegisterProgramName(const char *name)
Registers the executable program name for use in error messages.
#define SDDS_STRING
Identifier for the string data type.
#define SDDS_LONG
Identifier for the signed 32-bit integer data type.
#define SDDS_DOUBLE
Identifier for the double data type.
long match_string(char *string, char **option, long n_options, long mode)
Matches a given string against an array of option strings based on specified modes.
int scanargs(SCANNED_ARG **scanned, int argc, char **argv)
void free_scanargs(SCANNED_ARG **scanned, int argc)