From 96b3d72848b0326d690d72d6095dcfd17eb6a894 Mon Sep 17 00:00:00 2001 From: Pia Keil Date: Fri, 21 Nov 2025 04:54:54 +0100 Subject: [PATCH] Implement header check helper function --- imageInput.c | 72 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 61 insertions(+), 11 deletions(-) diff --git a/imageInput.c b/imageInput.c index bb30de1..8875ad4 100644 --- a/imageInput.c +++ b/imageInput.c @@ -1,4 +1,4 @@ -#include +##include #include #include #include "imageInput.h" @@ -6,17 +6,67 @@ #define BUFFER_SIZE 100 #define FILE_HEADER_STRING "__info2_image_file_format__" -// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei -// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen -GrayScaleImageSeries *readImages(const char *path) -{ - GrayScaleImageSeries *series = NULL; - - return series; +/* + * Hilfsfunktionen + */ + + +static FILE *openImageFile(const char *path) // Checks if the given filename pointer is valid (not NULL). +{ +if (path == NULL) + { + return NULL; + } + + return fopen(path, "rb"); //opening document in binear } -// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt -void clearSeries(GrayScaleImageSeries *series) +static int readAndCheckHeader(FILE *file) // gets the length of the header text { -} \ No newline at end of file + size_t headerLength = strlen(FILE_HEADER_STRING); + char buffer[BUFFER_SIZE]; + + if (headerLength + 1 > BUFFER_SIZE) //checks if buffer is big enough for header size + { + return 0; + } + + if (fread(buffer, 1, headerLength, file) != headerLength) // Checks if reading the expected number of header bytes from the file succeeded + + return 0; + + + buffer[headerLength] = '\0'; // add string terminator so the header becomes a valid C-string + + if (strcmp(buffer, FILE_HEADER_STRING) != 0) // checks if the expected header matches the header read from the file + + { + return 0; + } + + return 1; /* Header ok */ +} + + + + +static int readImageMetaData(FILE *file, // reads the metadata (count, width, height) from the file and stores them in the provided pointers + unsigned short *count, + unsigned short *width, + unsigned short *height) +{ + + + + + + + /* + Hauptfunktion + */ + + + + + \ No newline at end of file