From 7168681f1deb4b40ee27d411b1df323559d4d697 Mon Sep 17 00:00:00 2001 From: Lukas Weber Date: Thu, 20 Nov 2025 17:13:47 +0100 Subject: [PATCH] Preparation for the next workphase --- imageInput.c | 3 +++ matrix.c | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/imageInput.c b/imageInput.c index bb86925..54b4a5d 100644 --- a/imageInput.c +++ b/imageInput.c @@ -69,6 +69,9 @@ void setParameters(FILE* file, unsigned int* imageCount, unsigned int* width, un *imageCount = (int) buffer[0]; *width = (int) buffer[1]; *height = (int) buffer[2]; + // TODO allocate memory for labels array (in imageInput.h) + + // TODO read from file and write in 2d arry, write label in labels array, repeat for imageCount } // change this to createMatrix? void allocateMemory(GrayScaleImageSeries* s, const int imageCount, const int width, const int height) { diff --git a/matrix.c b/matrix.c index 55bbda1..0e34db0 100644 --- a/matrix.c +++ b/matrix.c @@ -8,12 +8,17 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { Matrix newMatrix; + if (rows == 0 || cols == 0) { + newMatrix.rows = 0; + newMatrix.cols = 0; + newMatrix.buffer = NULL; + return newMatrix; + } + newMatrix.rows = rows; newMatrix.cols = cols; - if (rows == 0 || cols == 0) - newMatrix.buffer = NULL; - else - newMatrix.buffer = calloc(rows*cols, sizeof(MatrixType)); + + newMatrix.buffer = calloc(rows*cols, sizeof(MatrixType)); return newMatrix; } @@ -21,6 +26,8 @@ void clearMatrix(Matrix *matrix) { free(matrix->buffer); matrix->buffer = NULL; + matrix->rows = 0; + matrix->cols = 0; } void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)