From c2a26bc3adb3af29ea9746aa796970c87b1d2ef7 Mon Sep 17 00:00:00 2001 From: sengpielto Date: Thu, 5 Nov 2026 15:33:39 +0100 Subject: [PATCH] =?UTF-8?q?noch=20probleme=20bei=20=C3=BCbergabe=20von=20u?= =?UTF-8?q?nterfunktion=20readIndividualImage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Startcode/imageInput.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Startcode/imageInput.c b/Startcode/imageInput.c index bc2cfa2..9262337 100644 --- a/Startcode/imageInput.c +++ b/Startcode/imageInput.c @@ -10,7 +10,7 @@ static GrayScaleImage *readIndividualImage(unsigned int width, unsigned int height, FILE *file){ - char *buf = calloc(width * height, sizeof(char)); + GrayScalePixelType *buf = calloc(width * height, sizeof(unsigned char)); if(!buf){ fprintf(stderr, "calloc failed!\n"); return NULL; @@ -21,7 +21,7 @@ static GrayScaleImage *readIndividualImage(unsigned int width, unsigned int heig return NULL; } - GrayScaleImage *gimage = calloc(sizeof(GrayScaleImage, 1)); + GrayScaleImage *gimage = calloc(sizeof(GrayScaleImage), 1); if(gimage == NULL){ fprintf(stderr, "calloc failed!\n"); free(buf); @@ -45,6 +45,7 @@ GrayScaleImageSeries *readImages(const char *path) fprintf(stderr, "Couldn't allocate enough space!\n"); return NULL; } + series->count = 0; FILE *file = fopen(path, "rb"); if(file == NULL){ @@ -62,29 +63,31 @@ GrayScaleImageSeries *readImages(const char *path) return NULL; } - if(bytes = fread(buffer, sizeof(short), 3, file) != (3*szieof(short))){ + if((bytes = fread(buffer, sizeof(short), 3, file)) != (3*sizeof(short))){ fprintf(stderr, "Couldn't read number of images/sizes of Images!\n"); clearSeries(series); return NULL; } + //Merke menge an Bildern und Länge und Breite der Bilder series->count = (short)buffer[0]; unsigned int width = (short)buffer[1]; unsigned int height = (short)buffer[2]; - series->labels = calloc(count, sizeof(char)); + series->labels = calloc(series->count, sizeof(char)); if(series->labels == NULL){ fprintf(stderr, "calloc failed!\n"); clearSeries(series); return NULL; } - for (int i = 0; i < count; i++){ - if(series->images[i] = readIndividualImage(width, heigth, file) == NULL){ + //Lies Bilder aus + for (int i = 0; i < series->count; i++){ + if((series->images[i] = *readIndividualImage(width, height, file))){ clearSeries(series); return NULL; } - fread(series->labels[i], sizeof(char), 1, file); + fread(&series->labels[i], sizeof(char), 1, file); } return series; @@ -94,7 +97,8 @@ GrayScaleImageSeries *readImages(const char *path) void clearSeries(GrayScaleImageSeries *series) { for(int i = 0; i < series->count; i++){ - free(series->GrayScaleImage[i]); + free(&series->images[i]); } + free(series->labels); free(series); } \ No newline at end of file