diff --git a/Startcode/imageInput.c b/Startcode/imageInput.c index bb30de1..84c28f4 100644 --- a/Startcode/imageInput.c +++ b/Startcode/imageInput.c @@ -7,16 +7,54 @@ #define FILE_HEADER_STRING "__info2_image_file_format__" // TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei +GrayScaleImage *readSingleImage(size_t widht, size_t height) { + +} + // TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen GrayScaleImageSeries *readImages(const char *path) { GrayScaleImageSeries *series = NULL; + unsigned short NumberOfImages; + unsigned short PictureWidth; + unsigned short PictureHeight; + char* verifyWord; + size_t bufferCount = 0; + FILE *file = fopen("mnist_test.info2", "rb"); // opening the file + + bufferCount = fread(&verifyWord, 27, 1, file); + if (bufferCount != 1 || verifyWord != FILE_HEADER_STRING) { + strerror("Error: wrong file or unable to read the file!"); + // return error code; + } + + bufferCount = 0; + bufferCount = fread(&NumberOfImages, 2, 1, file); + if (bufferCount != 1) { + strerror("Error: failed to read number of pictures"); + // return error code + } + + bufferCount = 0; + bufferCount = fread(&PictureWidth, 2, 1, file); + if (bufferCount != 1) { + strerror("Error: failed to read the picture width!"); + // return error code + } + + bufferCount = 0; + bufferCount = fread(&PictureHeight, 2, 1, file); + if (bufferCount != 1) { + strerror("Error: failed to read the picture height!"); + // return error code + } + return series; } // TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt void clearSeries(GrayScaleImageSeries *series) { -} \ No newline at end of file +}