51char *option[N_OPTIONS] =
63 "tiff2sdds <input> <output>\n"
64 " [-redOnly] [-greenOnly] [-blueOnly]\n"
65 " [-singleColumnMode]\n"
66 "Program by Robert Soliday. (" __DATE__
" " __TIME__
", SVN revision: " SVN_VERSION
")\n\n";
68int main(
int argc,
char *argv[]) {
72 char *input = NULL, *output = NULL;
73 char **column_names = NULL;
75 int32_t *indexes = NULL;
77 long i, j, n = 0, single_column_mode = 0;
81 rgb[0] = rgb[1] = rgb[2] = 1;
85 fprintf(stderr,
"%s", usage);
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)) {
104 case OPT_SINGLECOLUMNMODE:
105 single_column_mode = 1;
108 fprintf(stderr,
"invalid option seen\n%s", usage);
113 input = s_arg[i].list[0];
115 output = s_arg[i].list[0];
117 fprintf(stderr,
"too many filenames\n%s", usage);
123 tif = TIFFOpen(input,
"r");
131 TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
132 TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
134 raster = (uint32 *)_TIFFmalloc(npixels *
sizeof(uint32));
135 if (raster != NULL) {
136 if (TIFFReadRGBAImage(tif, w, h, raster, 0)) {
140 if (single_column_mode) {
143 fprintf(stderr,
"Problem defining parameter Variable1Name.\n");
147 fprintf(stderr,
"Problem defining parameter Variable2Name.\n");
152 fprintf(stderr,
"Problem defining parameter xInterval.\n");
156 fprintf(stderr,
"Problem defining parameter yInterval.\n");
161 fprintf(stderr,
"Problem defining parameter xDimension.\n");
166 fprintf(stderr,
"Problem defining parameter yDimension.\n");
171 fprintf(stderr,
"Problem defining parameter xMinimum.\n");
175 fprintf(stderr,
"Problem defining parameter yMinimum.\n");
179 fprintf(stderr,
"Problem defining column z.\n");
182 data = malloc(
sizeof(*data) * 1);
183 data[0] = malloc(
sizeof(*(data[0])) * npixels);
187 fprintf(stderr,
"Problem defining column Index.\n");
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]);
206 if (single_column_mode) {
209 for (i = 0; i < h; i++) {
210 for (j = 0; j < w; j++) {
212 data[0][j * h + i] = TIFFGetR(raster[n]) * rgb[0] + TIFFGetG(raster[n]) * rgb[1] + TIFFGetB(raster[n]) * rgb[2];
222 for (i = 0; i < w; i++)
224 for (i = 0; i < h; i++) {
225 for (j = 0; j < w; j++) {
227 data[i][j] = TIFFGetR(raster[n]) * rgb[0] + TIFFGetG(raster[n]) * rgb[1] + TIFFGetB(raster[n]) * rgb[2];
233 for (i = 0; i < h; i++) {
242 if (single_column_mode) {
246 for (i = 0; i < h; i++) {
247 free(column_names[i]);
SDDS (Self Describing Data Set) Data Types Definitions and Function Prototypes.
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)
OptionType
Enumeration for command-line options.