diff --git a/imageInput.c b/imageInput.c index 3558607..e84a8d4 100644 --- a/imageInput.c +++ b/imageInput.c @@ -29,22 +29,20 @@ int checkString (FILE *file){ //Checks if String at the start of File equals exp } } -void setParameters(const char buffer[], unsigned int* imageCount, unsigned int* width, unsigned int* height); +void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height); void allocateMemory(GrayScaleImageSeries *s, const int imageCount, const int width, const int height); // TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen GrayScaleImageSeries *readImages(const char *path) { + FILE * file; + // TODO open binary file from file name GrayScaleImageSeries *series = NULL; + if(!(checkString(file))) + return NULL; - // hier Niko Stuff - // create char array buffer with bytes containing initialization information - // TODO some kind of logic to get correct address in binary file - char initBuffer[3]; - /* - int readBytes = fread(initBuffer, 1, 3, //file); - */ unsigned int* imageCount = &(series->count); // sets a pointer for int variable count in struct - setParameters(initBuffer, imageCount, &(series->images->width), &(series->images->height)); + + setParameters(file, imageCount, &(series->images->width), &(series->images->height)); allocateMemory(series, *imageCount, series->images->width, series->images->height); return series; @@ -61,7 +59,12 @@ void clearSeries(GrayScaleImageSeries *series) series->images = NULL; series->labels = NULL; } -void setParameters(const char buffer[], unsigned int* imageCount, unsigned int* width, unsigned int* height) { // sets the parameters +void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height) { // sets the parameters + char buffer[3]; + + fseek(file, 27, SEEK_SET); + fread(buffer, 1, 3, file); + *imageCount = (int) buffer[0]; *width = (int) buffer[1]; *height = (int) buffer[2];