From f403d4ffa8fe0fbeaf785c1eb4d80137994c2b9d Mon Sep 17 00:00:00 2001 From: Hofmann Jonas Date: Tue, 18 Nov 2025 00:22:57 +0100 Subject: [PATCH] continued debugging 'readStatusInfo()' in 'imageInput.c' not yet working correctly, see comment --- imageInput.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/imageInput.c b/imageInput.c index 6eb7ecf..da49d25 100644 --- a/imageInput.c +++ b/imageInput.c @@ -10,8 +10,9 @@ // übersichtlich aufgeteilt werden! // TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei -int readStatusInfo(FILE **source, char *const headerString, unsigned int *const imageCount, unsigned int *const imageWidth, unsigned int *const imageHeight, int const amountToRead); -void readImagedata(FILE **source, unsigned char *const imageBuffer, unsigned char *const labelBuffer,int const imageCount ,int const amountToRead); +//void setupMemory(); +unsigned int readStatusInfo(FILE *source, char *const headerString, unsigned int *const imageCount, unsigned int *const imageWidth, unsigned int *const imageHeight, int const amountToRead); +void readImagedata(FILE *source, unsigned char *const imageBuffer, unsigned char *const labelBuffer,int const imageCount ,int const amountToRead); // TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen @@ -23,20 +24,24 @@ GrayScaleImageSeries *readImages(const char *path) FILE *readSource; unsigned int numberOfBytesToRead = 0; const unsigned int amountOfStatusInfoToRead = 1; - char headerString[sizeof("__info2_image_file_format__")]; + char headerString[sizeof("__info2_image_file_format__")] = "__info2_image_file_format__"; + //speicher allocaten weil *series auf null zeigt !!!!!!!! readSource = fopen(path, "rb"); if (readSource != NULL) { - printf("hier\n"); - numberOfBytesToRead = readStatusInfo(&readSource, headerString, &series->count, &series->images->width, &series->images->height, amountOfStatusInfoToRead); + + series = calloc(sizeof(GrayScaleImageSeries), amountOfStatusInfoToRead); + series->images = calloc(sizeof(GrayScaleImage), amountOfStatusInfoToRead); + + numberOfBytesToRead = readStatusInfo(readSource, headerString, &(series->count), &(series->images->width), &(series->images->height), amountOfStatusInfoToRead); series->images->buffer = calloc((series->count) * numberOfBytesToRead, sizeof(GrayScalePixelType)); series->labels = calloc((series->count), sizeof(&(series->labels))); - readImagedata(&readSource, series->images->buffer, series->labels, series->count, numberOfBytesToRead); + readImagedata(readSource, series->images->buffer, series->labels, series->count, numberOfBytesToRead); } fclose(readSource); @@ -79,29 +84,35 @@ void clearSeries(GrayScaleImageSeries *series) // reads string, pictureCount, pictureWidth, pictureHight -int readStatusInfo(FILE **source, char *const headerString, unsigned int *const imageCount, unsigned int *const imageWidth, unsigned int *const imageHeight, int const amountToRead) +unsigned int readStatusInfo(FILE *source, char *const headerString, unsigned int *const imageCount, unsigned int *const imageWidth, unsigned int *const imageHeight, int const amountToRead) { - int bytesToRead = 0; - - fread(headerString, sizeof(*headerString), amountToRead, *source); - fread(imageCount, sizeof(*imageCount), amountToRead, *source); - fread(imageWidth, sizeof(*imageWidth), amountToRead, *source); - fread(imageHeight, sizeof(*imageHeight), amountToRead, *source); - + unsigned int bytesToRead = 0; + + fread(headerString, sizeof(*headerString), amountToRead, source); + fread(imageCount, sizeof(*imageCount), amountToRead, source); + fread(imageWidth, sizeof(*imageWidth), amountToRead, source); + fread(imageHeight, sizeof(*imageHeight), amountToRead, source); + bytesToRead = (*imageWidth) * (*imageHeight); - + // state of debugging: + // stopped here, + // read width and height + // return nonsensical numbers + // is the sizeof() command correct?? + printf("hier\n"); + printf("bytes to read = %u", bytesToRead); return bytesToRead; } // reads the imagebytes and the label of all images -void readImagedata(FILE **source, unsigned char *const imageBuffer, unsigned char *const labelBuffer,int const imageCount , int const amountOfBytes) +void readImagedata(FILE *source, unsigned char *const imageBuffer, unsigned char *const labelBuffer,int const imageCount , int const amountOfBytes) { int i = 0; for (i = 0; i <= imageCount; i++) { - fread((imageBuffer + i * amountOfBytes), sizeof(&(imageBuffer)), amountOfBytes, *source); - fread((labelBuffer + i), sizeof(&(labelBuffer)), 1, *source); + fread((imageBuffer + i * amountOfBytes), sizeof(&(imageBuffer)), amountOfBytes, source); + fread((labelBuffer + i), sizeof(&(labelBuffer)), 1, source); } }