diff --git a/imageInput.c b/imageInput.c index bb30de1..ecc2734 100644 --- a/imageInput.c +++ b/imageInput.c @@ -7,6 +7,25 @@ #define FILE_HEADER_STRING "__info2_image_file_format__" // TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei +static int checkFileHeader(FILE *fp) +{ + if (!fp) // Datei konnte nicht geöffnet werden + return 0; + + char buffer[BUFFER_SIZE]; + size_t headerLen = strlen(FILE_HEADER_STRING); + if (headerLen >= BUFFER_SIZE) // Safety Check + return 0; + + if (fread(buffer, 1, headerLen, fp) != headerLen) + return 0; + + buffer[headerLen] = '\0'; + if (strcmp(buffer, FILE_HEADER_STRING) != 0) + return 0; + + return 1; // Header stimmt +} // TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen GrayScaleImageSeries *readImages(const char *path) @@ -19,4 +38,10 @@ GrayScaleImageSeries *readImages(const char *path) // TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt void clearSeries(GrayScaleImageSeries *series) { + if (series == NULL) + return; + + free(series->images); + free(series->labels); + free(series); } \ No newline at end of file diff --git a/matrix.c b/matrix.c index 9a5fb4c..557a5ee 100644 --- a/matrix.c +++ b/matrix.c @@ -16,12 +16,29 @@ void clearMatrix(Matrix *matrix) void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + if (matrix.buffer != NULL) + { + if (rowIdx < matrix.rows && colIdx < matrix.cols) + { + matrix.buffer[rowIdx * matrix.cols + colIdx] = value; + } + } } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - + if (matrix.buffer != NULL) + { + if (rowIdx < matrix.rows && colIdx < matrix.cols) + { + return matrix.buffer[rowIdx * matrix.cols + colIdx]; + } + + } + else + { + return 0; + } } Matrix add(const Matrix matrix1, const Matrix matrix2)