diff --git a/Startcode/imageInput.c b/Startcode/imageInput.c index 54c6891..ae1966e 100644 --- a/Startcode/imageInput.c +++ b/Startcode/imageInput.c @@ -7,56 +7,9 @@ #define FILE_HEADER_STRING "__info2_image_file_format__" // TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei - -static FILE *openImageFile(const char *path) -{ - - FILE *file = fopen(path, "rb"); - - if (file == NULL) - { - - printf("Fehler: Datei %s konnte nicht geöffnet werden", path); - return NULL; - } - return file; -} - -static int checkFileHeader(FILE *file) -{ - - char buffer[strlen(FILE_HEADER_STRING) + 1]; - - fread(buffer, sizeof(char), strlen(FILE_HEADER_STRING), file); - - buffer[strlen(FILE_HEADER_STRING)] = '\0'; - - if (strcmp(buffer, FILE_HEADER_STRING) == 0) - { - - return 1; - } - return 0; -} - -static GrayScaleImageSeries *createSeries(unsigned int count) -{ - - GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries)); - - if (series == NULL) - { - return 0; - } - - series->count = count; - - series->labels = malloc(count * sizeof(unsigned char)); - - series->images = malloc(count * sizeof(GrayScaleImage)); - - return series; -} +static FILE *openImageFile(const char *path); +static int checkFileHeader(FILE *file); +static GrayScaleImageSeries *createSeries(unsigned int count); // TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen GrayScaleImageSeries *readImages(const char *path) @@ -133,4 +86,54 @@ void clearSeries(GrayScaleImageSeries *series) free(series->labels); free(series); +} + +static FILE *openImageFile(const char *path) +{ + + FILE *file = fopen(path, "rb"); + + if (file == NULL) + { + + printf("Fehler: Datei %s konnte nicht geöffnet werden", path); + return NULL; + } + return file; +} + +static int checkFileHeader(FILE *file) +{ + + char buffer[strlen(FILE_HEADER_STRING) + 1]; + + fread(buffer, sizeof(char), strlen(FILE_HEADER_STRING), file); + + buffer[strlen(FILE_HEADER_STRING)] = '\0'; + + if (strcmp(buffer, FILE_HEADER_STRING) == 0) + { + + return 1; + } + return 0; +} + +static GrayScaleImageSeries *createSeries(unsigned int count) +{ + + GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries)); + + if (series == NULL) + { + return 0; + } + + series->count = count; + + series->labels = malloc(count * sizeof(unsigned char)); + + series->images = malloc(count * sizeof(GrayScaleImage)); + + return series; } \ No newline at end of file