GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_matrix.h
Go to the documentation of this file.
1//SPDX-License-Identifier: LGPL-2.0-or-later
2/*
3
4 Copyright (C) 2020 Cyril Hrubis <metan@ucw.cz>
5
6 */
7
21#ifndef GP_MATRIX_H
22#define GP_MATRIX_H
23
24#include <core/gp_compiler.h>
25#include <utils/gp_vec.h>
26
36static inline void *gp_matrix_new(size_t cols, size_t rows, size_t unit)
37{
38 return gp_vec_new(cols * rows, unit);
39}
40
50static inline size_t gp_matrix_idx(size_t rows, size_t col, size_t row)
51{
52 return col * rows + row;
53}
54
65GP_WUR static inline void *gp_matrix_cols_ins(void *self, size_t rows, size_t col, size_t len)
66{
67 return gp_vec_ins(self, col * rows, len * rows);
68}
69
80GP_WUR static inline void *gp_matrix_cols_del(void *self, size_t rows, size_t col, size_t len)
81{
82 return gp_vec_del(self, col * rows, len * rows);
83}
84
96GP_WUR void *gp_matrix_rows_ins(void *self, size_t cols, size_t rows, size_t row, size_t len);
97
109GP_WUR void *gp_matrix_rows_del(void *self, size_t cols, size_t rows, size_t row, size_t len);
110
116static inline void gp_matrix_free(void *self)
117{
118 gp_vec_free(self);
119}
120
121#endif /* GP_MATRIX_H */
A compiler dependent macros.
#define GP_WUR
Expands to warn_unused_result attribute when supported by the compiler.
Definition gp_compiler.h:26
static void * gp_matrix_new(size_t cols, size_t rows, size_t unit)
Allocates a matrix.
Definition gp_matrix.h:36
void * gp_matrix_rows_ins(void *self, size_t cols, size_t rows, size_t row, size_t len)
Inserts len rowss at the offset row into the matrix.
static void gp_matrix_free(void *self)
Frees the matrix.
Definition gp_matrix.h:116
static void * gp_matrix_cols_del(void *self, size_t rows, size_t col, size_t len)
Deletes len columns at the offset col from the matrix.
Definition gp_matrix.h:80
static void * gp_matrix_cols_ins(void *self, size_t rows, size_t col, size_t len)
Inserts len columns at the offset col into the matrix.
Definition gp_matrix.h:65
static size_t gp_matrix_idx(size_t rows, size_t col, size_t row)
Returns an index into the vector that holds the matrix data.
Definition gp_matrix.h:50
void * gp_matrix_rows_del(void *self, size_t cols, size_t rows, size_t row, size_t len)
Deletes len rows at the offset col from the matrix.
Vector a growable array.
void * gp_vec_del(void *self, size_t off, size_t len)
Deletes a range from the vector.
void * gp_vec_new(size_t len, size_t unit)
Allocates a new vector.
void * gp_vec_ins(void *self, size_t off, size_t len)
Insert a gap into the vec of new elements, reallocating the underlying memory if more capacity is nee...
void gp_vec_free(void *self)
Frees the vector.