From 489bd3dc23ddb4dc2a7d4542a6be370c5b41a6c6 Mon Sep 17 00:00:00 2001 From: Lukas Dotterweich Date: Wed, 11 Nov 2026 21:30:22 +0100 Subject: [PATCH] Implement ImageInput --- Startcode/imageInput.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/Startcode/imageInput.c b/Startcode/imageInput.c index 4548438..50b1b0d 100644 --- a/Startcode/imageInput.c +++ b/Startcode/imageInput.c @@ -25,7 +25,7 @@ static unsigned int readNumber(FILE *file) { } return number; } - +// TODO:alles in innere Funktion äußere Funktion nur fopen / fclose // fillBuffer und readLabel muss immer in einer Schleife zusammen stehen static int fillBuffer(unsigned char buffer[], unsigned int bufferSize, FILE *file) { @@ -50,14 +50,19 @@ GrayScaleImageSeries *readImages(const char *path) { if (!controlFile(file)) { return NULL; } - GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries)); - series->count = readNumber(file); + unsigned int count = readNumber(file); unsigned int width = readNumber(file); unsigned int height = readNumber(file); - if (width == 0 || height == 0 || series->count == 0 || series == NULL) { + if (width == 0 || height == 0 || count == 0) { return NULL; } // Füllen des structs series + GrayScaleImageSeries *series = malloc(sizeof(GrayScaleImageSeries)); + if (series == NULL) { + return NULL; + } + + series->count = count; series->labels = malloc(series->count * sizeof(unsigned char)); series->images = malloc(series->count * sizeof(GrayScaleImage)); series->addrSourceTxt = file; @@ -66,19 +71,20 @@ GrayScaleImageSeries *readImages(const char *path) { } // struct grayScaleImage füllen als Teil eines Arrays innerhalb series - int readBufferFault = 1; - int readLabelFault = 1; unsigned int const bufferSize = width * height; - for (unsigned int i = 0; i < series - ->count && readBufferFault && readLabelFault; i++) { + for (unsigned int i = 0; i < series->count; i++) { + GrayScaleImage *grayScaleImage = &series->images[i]; grayScaleImage->buffer = calloc(bufferSize, width * height * sizeof(GrayScalePixelType)); + if (grayScaleImage->buffer == NULL) { + return NULL; + } + grayScaleImage->width = width; grayScaleImage->height = height; - readBufferFault = fillBuffer(grayScaleImage->buffer, bufferSize, file);// frage an tobi kann ich readbufferfault auch schöner initialisieren - readLabelFault = readLabels(file, series->labels, i); - - if (grayScaleImage->buffer == NULL) { + int readBufferFault = fillBuffer(grayScaleImage->buffer, bufferSize, file); + int readLabelFault = readLabels(file, series->labels, i); + if (!readLabelFault || !readBufferFault) { return NULL; } }