68 {
70 SCANNED_ARG *s_arg;
71 TIFF *tif;
72 char *input = NULL, *output = NULL;
73 char **column_names = NULL;
74 int32_t **data;
75 int32_t *indexes = NULL;
76 long rgb[3];
77 long i, j, n = 0, single_column_mode = 0;
78
80
81 rgb[0] = rgb[1] = rgb[2] = 1;
82
84 if (argc < 3) {
85 fprintf(stderr, "%s", usage);
86 return 1;
87 }
88
89 for (i = 1; i < argc; i++) {
90 if (s_arg[i].arg_type == OPTION) {
91 switch (
match_string(s_arg[i].list[0], option, N_OPTIONS, 0)) {
92 case OPT_REDONLY:
93 rgb[0] = 1;
94 rgb[1] = rgb[2] = 0;
95 break;
96 case OPT_GREENONLY:
97 rgb[1] = 1;
98 rgb[0] = rgb[2] = 0;
99 break;
100 case OPT_BLUEONLY:
101 rgb[2] = 1;
102 rgb[0] = rgb[1] = 0;
103 break;
104 case OPT_SINGLECOLUMNMODE:
105 single_column_mode = 1;
106 break;
107 default:
108 fprintf(stderr, "invalid option seen\n%s", usage);
109 return 1;
110 }
111 } else {
112 if (!input)
113 input = s_arg[i].list[0];
114 else if (!output)
115 output = s_arg[i].list[0];
116 else {
117 fprintf(stderr, "too many filenames\n%s", usage);
118 return 1;
119 }
120 }
121 }
122
123 tif = TIFFOpen(input, "r");
124 if (tif) {
125 uint32 w, h;
126 size_t npixels;
127 uint32 *raster;
128 double tmp;
129 int32_t tmp2;
130
131 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
132 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
133 npixels = w * h;
134 raster = (uint32 *)_TIFFmalloc(npixels * sizeof(uint32));
135 if (raster != NULL) {
136 if (TIFFReadRGBAImage(tif, w, h, raster, 0)) {
137
140 if (single_column_mode) {
141
143 fprintf(stderr, "Problem defining parameter Variable1Name.\n");
144 return 1;
145 }
147 fprintf(stderr, "Problem defining parameter Variable2Name.\n");
148 return 1;
149 }
150 tmp = 1;
152 fprintf(stderr, "Problem defining parameter xInterval.\n");
153 return 1;
154 }
156 fprintf(stderr, "Problem defining parameter yInterval.\n");
157 return 1;
158 }
159 tmp2 = w;
161 fprintf(stderr, "Problem defining parameter xDimension.\n");
162 return 1;
163 }
164 tmp2 = h;
166 fprintf(stderr, "Problem defining parameter yDimension.\n");
167 return 1;
168 }
169 tmp = 0;
171 fprintf(stderr, "Problem defining parameter xMinimum.\n");
172 return 1;
173 }
175 fprintf(stderr, "Problem defining parameter yMinimum.\n");
176 return 1;
177 }
179 fprintf(stderr, "Problem defining column z.\n");
180 return 1;
181 }
182 data = malloc(sizeof(*data) * 1);
183 data[0] = malloc(sizeof(*(data[0])) * npixels);
184 } else {
185
187 fprintf(stderr, "Problem defining column Index.\n");
188 return 1;
189 }
190 indexes = malloc(sizeof(*indexes) * w);
191 column_names = malloc(sizeof(char **) * h);
192 data = malloc(sizeof(*data) * h);
193 for (i = 0; i < h; i++) {
194 column_names[i] = malloc(sizeof(char *) * 15);
195 data[i] = malloc(sizeof(*(data[i])) * w);
196 sprintf(column_names[i], "Line%05ld", i);
198 fprintf(stderr, "Problem defining column %s.\n", column_names[i]);
199 return 1;
200 }
201 }
202 }
203
206 if (single_column_mode) {
209 for (i = 0; i < h; i++) {
210 for (j = 0; j < w; j++) {
211
212 data[0][j * h + i] = TIFFGetR(raster[n]) * rgb[0] + TIFFGetG(raster[n]) * rgb[1] + TIFFGetB(raster[n]) * rgb[2];
213 n++;
214 }
215 }
216
219 } else {
222 for (i = 0; i < w; i++)
223 indexes[i] = i;
224 for (i = 0; i < h; i++) {
225 for (j = 0; j < w; j++) {
226
227 data[i][j] = TIFFGetR(raster[n]) * rgb[0] + TIFFGetG(raster[n]) * rgb[1] + TIFFGetB(raster[n]) * rgb[2];
228 n++;
229 }
230 }
233 for (i = 0; i < h; i++) {
236 }
237 }
238
241
242 if (single_column_mode) {
243 free(data[0]);
244 free(data);
245 } else {
246 for (i = 0; i < h; i++) {
247 free(column_names[i]);
248 free(data[i]);
249 }
250 free(column_names);
251 free(data);
252 }
253 }
254 _TIFFfree(raster);
255 }
256 TIFFClose(tif);
257 }
258 if (indexes)
259 free(indexes);
261 return 0;
262}
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)