diff --git a/matrix.c b/matrix.c index bfc9173..8df1d37 100644 --- a/matrix.c +++ b/matrix.c @@ -93,5 +93,29 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) Matrix multiply(const Matrix matrix1, const Matrix matrix2) { - return matrix1; -} \ No newline at end of file + if (matrix1.cols != matrix2.rows) { + Matrix invalid = {0,0, NULL}; + return invalid; + } + + Matrix result = createMatrix(matrix1.rows, matrix2.cols); + if (result.buffer == NULL) + return result; + + + for (unsigned int i = 0; i < matrix1.rows; i++){ + for (unsigned int j = 0; j < matrix2.cols; j++){ + *(result.buffer + (i * result.cols + j)) = 0; + + for (unsigned int k = 0; k < matrix1.cols; k++){ + *(result.buffer + (i * result.cols + j)) += *(matrix1.buffer + (i * matrix1.cols + k)) * *(matrix2.buffer + (k * matrix2.cols + j)); + } + } + } + +return result; +} + + //Für imageInput.c + //size_t fread(void *buffer, size_t elementSize, size_t count, FILE *FILE_HEADER_STRING) + //elementSize = width * height; \ No newline at end of file