From 0a8349d7221cbf8f102ff877e2b95c4ee1916f36 Mon Sep 17 00:00:00 2001 From: Lukas Weber Date: Mon, 24 Nov 2025 18:26:34 +0100 Subject: [PATCH] Finished testing, no more Failures in imageInputTests --- imageInput.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/imageInput.c b/imageInput.c index 9be1440..ca8ae61 100644 --- a/imageInput.c +++ b/imageInput.c @@ -28,8 +28,8 @@ int checkString (FILE *file){ //Checks if String at the start of File equals exp } } -void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height); -int allocateMemory(GrayScaleImageSeries *series, const int imageCount, const int width, const int height); +static void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height); +static int allocateMemory(GrayScaleImageSeries *series, const int imageCount, const int width, const int height); GrayScaleImageSeries *readImages(const char *path) @@ -59,10 +59,8 @@ GrayScaleImageSeries *readImages(const char *path) for(unsigned int i = 0; i < series->count ; i++){ //Iterating for every image for(unsigned int j = 0; j < width * height; j++){ //Iterating for every pixel fread(&(series->images[i].buffer[j]), sizeof(GrayScalePixelType), 1, file); - printf("Wrote in buffer: %d", series->images[i].buffer[j]); } - fread(&(series->labels[i]), sizeof(unsigned char), 1, file); - printf("Wrote in labels: %d", series->labels[i]); + fread(&(series->labels[i]), sizeof(unsigned char), 1, file); // TODO Added writing in labels array } fclose(file); return series; @@ -84,27 +82,26 @@ void clearSeries(GrayScaleImageSeries *series) free(series); //Freeing Main Structure } -void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height) { // sets the parameters +static void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, unsigned int* height) { // sets the parameters - char buffer[3]; + unsigned short buffer[3]; fseek(file, 27, SEEK_SET); - if(fread(buffer, 1, 3, file) != 3){ // TODO changed some stuff here + if(fread(buffer, sizeof(unsigned short), 3, file) != 3){ // TODO changed some stuff here, used UNSIGNED SHORT instead of UNSIGNED CHAR!! *imageCount = 0; *width = 0; *height = 0; return; } //Stops if file is too short and clean up - *imageCount = (int) buffer[0]; + *imageCount = (unsigned int) buffer[0]; + *width = (unsigned int) buffer[1]; - *width = (int) buffer[1]; - - *height = (int) buffer[2]; + *height = (unsigned int) buffer[2]; } -int allocateMemory(GrayScaleImageSeries *series, const int imageCount, const int width, const int height) { +static int allocateMemory(GrayScaleImageSeries *series, const int imageCount, const int width, const int height) { series->count = imageCount; //counts number of images in series series->images = malloc (sizeof(GrayScaleImage) * imageCount); //Reserving Memory for Images Array