Changeset 23992 for trunk/ppSkycell/src/ppSkycellCamera.c
- Timestamp:
- Apr 28, 2009, 3:31:25 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/ppSkycell/src/ppSkycellCamera.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppSkycell/src/ppSkycellCamera.c
r23982 r23992 9 9 #include "ppSkycell.h" 10 10 11 /// Read list of images 12 static psArray *fileList(const char *filename // Filename 13 ) 14 { 15 psString input = psSlurpFilename(filename); 16 if (!input) { 17 psError(PS_ERR_IO, false, "Unable to read %s", filename); 18 return false; 19 } 20 psArray *inputs = psStringSplitArray(input, "\n", false); // Input filenames 21 psFree(input); 22 if (!inputs || inputs->n == 0) { 23 psError(PS_ERR_IO, false, "Unable to read filenames from %s", filename); 24 psFree(inputs); 25 return NULL; 26 } 27 return inputs; 28 } 29 11 30 /// Add a single filename to the arguments as an array, so that it can be used with pmFPAfileBindFromArgs, etc 12 static void file List(const char *file, // The symbolic name for the file13 const char *name, // The name of the file14 const char *comment, // Description of the file15 pmConfig *config // Configuration31 static void fileArguments(const char *file, // The symbolic name for the file 32 const char *name, // The name of the file 33 const char *comment, // Description of the file 34 pmConfig *config // Configuration 16 35 ) 17 36 { 18 37 psArray *files = psArrayAlloc(1); // Array with file names 19 38 files->data[0] = psStringCopy(name); 39 if (psMetadataLookup(config->arguments, file)) { 40 psMetadataRemoveKey(config->arguments, file); 41 } 20 42 psMetadataAddArray(config->arguments, PS_LIST_TAIL, file, 0, comment, files); 21 43 psFree(files); … … 27 49 ) 28 50 { 29 ps String input = psSlurpFilename(data->inName);30 if (!i nput) {31 psError( PS_ERR_IO, false, "Unable to read %s", data->inName);51 psArray *images = fileList(data->imagesName); // Image names 52 if (!images) { 53 psError(psErrorCodeLast(), false, "No images provided."); 32 54 return false; 33 55 } 56 data->numInputs = images->n; 34 57 35 psArray *inputs = psStringSplitArray(input, "\n", false); // Input filenames 36 psFree(input); 37 if (!inputs || inputs->n == 0) { 38 psError(PS_ERR_IO, false, "Unable to read filenames from %s", data->inName); 39 psFree(inputs); 40 return false; 41 } 42 43 data->numInputs = inputs->n; 44 psMetadataAddArray(config->arguments, PS_LIST_TAIL, "INPUTS", 0, "Input files", inputs); 45 psFree(inputs); 46 psMetadataAddString(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Output root", data->outRoot); 47 48 pmFPAfile *inFile = NULL; // Representative input file 49 for (int i = 0; i < data->numInputs; i++) { 50 bool found = false; // Found file definition? 51 pmFPAfile *file = pmFPAfileDefineSingleFromArgs(&found, data->config, "PPSKYCELL.INPUT", 52 "INPUTS", i); // Input file 53 if (!file || !found) { 54 psError(psErrorCodeLast(), false, "Unable to define input %d\n", i); 58 psArray *masks = NULL; // Mask names 59 if (data->masksName) { 60 masks = fileList(data->masksName); 61 if (!masks) { 62 psError(psErrorCodeLast(), false, "No masks provided."); 63 psFree(images); 55 64 return false; 56 65 } 57 if (!inFile) { 58 inFile = file; 66 if (masks->n != data->numInputs) { 67 psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Number of images (%ld) and masks (%ld) do not match", 68 images->n, masks->n); 69 psFree(images); 70 psFree(masks); 71 return false; 59 72 } 60 73 } 61 74 62 pmFPAfile *outFile = pmFPAfileDefineFromFile(data->config, inFile, data->bin1, data->bin1, 63 "PPSKYCELL.JPEG1"); // Output file 64 if (!outFile) { 75 psMetadataAddStr(data->config->arguments, PS_LIST_TAIL, "OUTPUT", 0, "Output root", data->outRoot); 76 77 for (int i = 0; i < data->numInputs; i++) { 78 bool status = false; // Status of file definition 79 fileArguments("IMAGE", images->data[i], "Name of the image", data->config); 80 pmFPAfile *image = pmFPAfileDefineFromArgs(&status, data->config, "PPSKYCELL.IMAGE", "IMAGE"); // File 81 if (!status || !image) { 82 psError(PS_ERR_IO, false, "Failed to build file from PPSKYCELL.IMAGE"); 83 // XXX Cleanup 84 return false; 85 } 86 87 if (data->masksName) { 88 fileArguments("MASK", masks->data[i], "Name of the mask", data->config); 89 if (!pmFPAfileBindFromArgs(&status, image, data->config, "PPSKYCELL.MASK", "MASK") || !status) { 90 psError(PS_ERR_IO, false, "Failed to build file from PPSKYCELL.MASK"); 91 // XXX Cleanup 92 return false; 93 } 94 } 95 } 96 97 if (!pmFPAfileDefineOutput(data->config, NULL, "PPSKYCELL.JPEG1")) { 65 98 psError(psErrorCodeLast(), false, "Unable to define output."); 66 99 return false; 67 100 } 68 if (!pmFPAfileDefine FromFile(data->config, outFile, data->bin2, data->bin2, "PPSKYCELL.JPEG2")) {101 if (!pmFPAfileDefineOutput(data->config, NULL, "PPSKYCELL.JPEG2")) { 69 102 psError(psErrorCodeLast(), false, "Unable to define output."); 70 103 return false;
Note:
See TracChangeset
for help on using the changeset viewer.
