1 | /* vector/gsl_vector_uchar.h |
2 | * |
3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Gerard Jungman, Brian Gough |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 3 of the License, or (at |
8 | * your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, but |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef __GSL_VECTOR_UCHAR_H__ |
21 | #define __GSL_VECTOR_UCHAR_H__ |
22 | |
23 | #include <stdlib.h> |
24 | #include <gsl/gsl_types.h> |
25 | #include <gsl/gsl_errno.h> |
26 | #include <gsl/gsl_inline.h> |
27 | #include <gsl/gsl_check_range.h> |
28 | #include <gsl/gsl_block_uchar.h> |
29 | |
30 | #undef __BEGIN_DECLS |
31 | #undef __END_DECLS |
32 | #ifdef __cplusplus |
33 | # define __BEGIN_DECLS extern "C" { |
34 | # define __END_DECLS } |
35 | #else |
36 | # define __BEGIN_DECLS /* empty */ |
37 | # define __END_DECLS /* empty */ |
38 | #endif |
39 | |
40 | __BEGIN_DECLS |
41 | |
42 | typedef struct |
43 | { |
44 | size_t size; |
45 | size_t stride; |
46 | unsigned char *data; |
47 | gsl_block_uchar *block; |
48 | int owner; |
49 | } |
50 | gsl_vector_uchar; |
51 | |
52 | typedef struct |
53 | { |
54 | gsl_vector_uchar vector; |
55 | } _gsl_vector_uchar_view; |
56 | |
57 | typedef _gsl_vector_uchar_view gsl_vector_uchar_view; |
58 | |
59 | typedef struct |
60 | { |
61 | gsl_vector_uchar vector; |
62 | } _gsl_vector_uchar_const_view; |
63 | |
64 | typedef const _gsl_vector_uchar_const_view gsl_vector_uchar_const_view; |
65 | |
66 | |
67 | /* Allocation */ |
68 | |
69 | gsl_vector_uchar *gsl_vector_uchar_alloc (const size_t n); |
70 | gsl_vector_uchar *gsl_vector_uchar_calloc (const size_t n); |
71 | |
72 | gsl_vector_uchar *gsl_vector_uchar_alloc_from_block (gsl_block_uchar * b, |
73 | const size_t offset, |
74 | const size_t n, |
75 | const size_t stride); |
76 | |
77 | gsl_vector_uchar *gsl_vector_uchar_alloc_from_vector (gsl_vector_uchar * v, |
78 | const size_t offset, |
79 | const size_t n, |
80 | const size_t stride); |
81 | |
82 | void gsl_vector_uchar_free (gsl_vector_uchar * v); |
83 | |
84 | /* Views */ |
85 | |
86 | _gsl_vector_uchar_view |
87 | gsl_vector_uchar_view_array (unsigned char *v, size_t n); |
88 | |
89 | _gsl_vector_uchar_view |
90 | gsl_vector_uchar_view_array_with_stride (unsigned char *base, |
91 | size_t stride, |
92 | size_t n); |
93 | |
94 | _gsl_vector_uchar_const_view |
95 | gsl_vector_uchar_const_view_array (const unsigned char *v, size_t n); |
96 | |
97 | _gsl_vector_uchar_const_view |
98 | gsl_vector_uchar_const_view_array_with_stride (const unsigned char *base, |
99 | size_t stride, |
100 | size_t n); |
101 | |
102 | _gsl_vector_uchar_view |
103 | gsl_vector_uchar_subvector (gsl_vector_uchar *v, |
104 | size_t i, |
105 | size_t n); |
106 | |
107 | _gsl_vector_uchar_view |
108 | gsl_vector_uchar_subvector_with_stride (gsl_vector_uchar *v, |
109 | size_t i, |
110 | size_t stride, |
111 | size_t n); |
112 | |
113 | _gsl_vector_uchar_const_view |
114 | gsl_vector_uchar_const_subvector (const gsl_vector_uchar *v, |
115 | size_t i, |
116 | size_t n); |
117 | |
118 | _gsl_vector_uchar_const_view |
119 | gsl_vector_uchar_const_subvector_with_stride (const gsl_vector_uchar *v, |
120 | size_t i, |
121 | size_t stride, |
122 | size_t n); |
123 | |
124 | /* Operations */ |
125 | |
126 | void gsl_vector_uchar_set_zero (gsl_vector_uchar * v); |
127 | void gsl_vector_uchar_set_all (gsl_vector_uchar * v, unsigned char x); |
128 | int gsl_vector_uchar_set_basis (gsl_vector_uchar * v, size_t i); |
129 | |
130 | int gsl_vector_uchar_fread (FILE * stream, gsl_vector_uchar * v); |
131 | int gsl_vector_uchar_fwrite (FILE * stream, const gsl_vector_uchar * v); |
132 | int gsl_vector_uchar_fscanf (FILE * stream, gsl_vector_uchar * v); |
133 | int gsl_vector_uchar_fprintf (FILE * stream, const gsl_vector_uchar * v, |
134 | const char *format); |
135 | |
136 | int gsl_vector_uchar_memcpy (gsl_vector_uchar * dest, const gsl_vector_uchar * src); |
137 | |
138 | int gsl_vector_uchar_reverse (gsl_vector_uchar * v); |
139 | |
140 | int gsl_vector_uchar_swap (gsl_vector_uchar * v, gsl_vector_uchar * w); |
141 | int gsl_vector_uchar_swap_elements (gsl_vector_uchar * v, const size_t i, const size_t j); |
142 | |
143 | unsigned char gsl_vector_uchar_max (const gsl_vector_uchar * v); |
144 | unsigned char gsl_vector_uchar_min (const gsl_vector_uchar * v); |
145 | void gsl_vector_uchar_minmax (const gsl_vector_uchar * v, unsigned char * min_out, unsigned char * max_out); |
146 | |
147 | size_t gsl_vector_uchar_max_index (const gsl_vector_uchar * v); |
148 | size_t gsl_vector_uchar_min_index (const gsl_vector_uchar * v); |
149 | void gsl_vector_uchar_minmax_index (const gsl_vector_uchar * v, size_t * imin, size_t * imax); |
150 | |
151 | int gsl_vector_uchar_add (gsl_vector_uchar * a, const gsl_vector_uchar * b); |
152 | int gsl_vector_uchar_sub (gsl_vector_uchar * a, const gsl_vector_uchar * b); |
153 | int gsl_vector_uchar_mul (gsl_vector_uchar * a, const gsl_vector_uchar * b); |
154 | int gsl_vector_uchar_div (gsl_vector_uchar * a, const gsl_vector_uchar * b); |
155 | int gsl_vector_uchar_scale (gsl_vector_uchar * a, const double x); |
156 | int gsl_vector_uchar_add_constant (gsl_vector_uchar * a, const double x); |
157 | |
158 | int gsl_vector_uchar_equal (const gsl_vector_uchar * u, |
159 | const gsl_vector_uchar * v); |
160 | |
161 | int gsl_vector_uchar_isnull (const gsl_vector_uchar * v); |
162 | int gsl_vector_uchar_ispos (const gsl_vector_uchar * v); |
163 | int gsl_vector_uchar_isneg (const gsl_vector_uchar * v); |
164 | int gsl_vector_uchar_isnonneg (const gsl_vector_uchar * v); |
165 | |
166 | INLINE_DECL unsigned char gsl_vector_uchar_get (const gsl_vector_uchar * v, const size_t i); |
167 | INLINE_DECL void gsl_vector_uchar_set (gsl_vector_uchar * v, const size_t i, unsigned char x); |
168 | INLINE_DECL unsigned char * gsl_vector_uchar_ptr (gsl_vector_uchar * v, const size_t i); |
169 | INLINE_DECL const unsigned char * gsl_vector_uchar_const_ptr (const gsl_vector_uchar * v, const size_t i); |
170 | |
171 | #ifdef HAVE_INLINE |
172 | |
173 | INLINE_FUN |
174 | unsigned char |
175 | gsl_vector_uchar_get (const gsl_vector_uchar * v, const size_t i) |
176 | { |
177 | #if GSL_RANGE_CHECK |
178 | if (GSL_RANGE_COND(i >= v->size)) |
179 | { |
180 | GSL_ERROR_VAL ("index out of range" , GSL_EINVAL, 0); |
181 | } |
182 | #endif |
183 | return v->data[i * v->stride]; |
184 | } |
185 | |
186 | INLINE_FUN |
187 | void |
188 | gsl_vector_uchar_set (gsl_vector_uchar * v, const size_t i, unsigned char x) |
189 | { |
190 | #if GSL_RANGE_CHECK |
191 | if (GSL_RANGE_COND(i >= v->size)) |
192 | { |
193 | GSL_ERROR_VOID ("index out of range" , GSL_EINVAL); |
194 | } |
195 | #endif |
196 | v->data[i * v->stride] = x; |
197 | } |
198 | |
199 | INLINE_FUN |
200 | unsigned char * |
201 | gsl_vector_uchar_ptr (gsl_vector_uchar * v, const size_t i) |
202 | { |
203 | #if GSL_RANGE_CHECK |
204 | if (GSL_RANGE_COND(i >= v->size)) |
205 | { |
206 | GSL_ERROR_NULL ("index out of range" , GSL_EINVAL); |
207 | } |
208 | #endif |
209 | return (unsigned char *) (v->data + i * v->stride); |
210 | } |
211 | |
212 | INLINE_FUN |
213 | const unsigned char * |
214 | gsl_vector_uchar_const_ptr (const gsl_vector_uchar * v, const size_t i) |
215 | { |
216 | #if GSL_RANGE_CHECK |
217 | if (GSL_RANGE_COND(i >= v->size)) |
218 | { |
219 | GSL_ERROR_NULL ("index out of range" , GSL_EINVAL); |
220 | } |
221 | #endif |
222 | return (const unsigned char *) (v->data + i * v->stride); |
223 | } |
224 | #endif /* HAVE_INLINE */ |
225 | |
226 | __END_DECLS |
227 | |
228 | #endif /* __GSL_VECTOR_UCHAR_H__ */ |
229 | |
230 | |
231 | |