1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef VG_INT_UTIL_H
29#define VG_INT_UTIL_H
30
31#include "interface/khronos/common/khrn_int_util.h"
32#include "interface/khronos/include/VG/openvg.h"
33#include "interface/khronos/include/VG/vgu.h"
34
35static INLINE bool is_matrix_mode(VGMatrixMode matrix_mode)
36{
37 return (matrix_mode >= VG_MATRIX_PATH_USER_TO_SURFACE) &&
38 (matrix_mode <= VG_MATRIX_GLYPH_USER_TO_SURFACE);
39}
40
41static INLINE bool is_fill_rule(VGFillRule fill_rule)
42{
43 return (fill_rule == VG_EVEN_ODD) ||
44 (fill_rule == VG_NON_ZERO);
45}
46
47static INLINE bool is_image_quality(VGImageQuality image_quality)
48{
49 return (image_quality == VG_IMAGE_QUALITY_NONANTIALIASED) ||
50 (image_quality == VG_IMAGE_QUALITY_FASTER) ||
51 (image_quality == VG_IMAGE_QUALITY_BETTER);
52}
53
54static INLINE bool is_rendering_quality(VGRenderingQuality rendering_quality)
55{
56 return (rendering_quality >= VG_RENDERING_QUALITY_NONANTIALIASED) &&
57 (rendering_quality <= VG_RENDERING_QUALITY_BETTER);
58}
59
60static INLINE bool is_blend_mode(VGBlendMode blend_mode)
61{
62 return (blend_mode >= VG_BLEND_SRC) &&
63 (blend_mode <= VG_BLEND_ADDITIVE);
64}
65
66static INLINE bool is_image_mode(VGImageMode image_mode)
67{
68 return (image_mode >= VG_DRAW_IMAGE_NORMAL) &&
69 (image_mode <= VG_DRAW_IMAGE_STENCIL);
70}
71
72static INLINE bool is_cap_style(VGCapStyle cap_style)
73{
74 return (cap_style >= VG_CAP_BUTT) &&
75 (cap_style <= VG_CAP_SQUARE);
76}
77
78static INLINE bool is_join_style(VGJoinStyle join_style)
79{
80 return (join_style >= VG_JOIN_MITER) &&
81 (join_style <= VG_JOIN_BEVEL);
82}
83
84static INLINE bool is_pixel_layout(VGPixelLayout pixel_layout)
85{
86 return (pixel_layout >= VG_PIXEL_LAYOUT_UNKNOWN) &&
87 (pixel_layout <= VG_PIXEL_LAYOUT_BGR_HORIZONTAL);
88}
89
90static INLINE bool is_paint_type(VGPaintType paint_type)
91{
92 return (paint_type >= VG_PAINT_TYPE_COLOR) &&
93 (paint_type <= VG_PAINT_TYPE_PATTERN);
94}
95
96static INLINE bool is_color_ramp_spread_mode(VGColorRampSpreadMode color_ramp_spread_mode)
97{
98 return (color_ramp_spread_mode >= VG_COLOR_RAMP_SPREAD_PAD) &&
99 (color_ramp_spread_mode <= VG_COLOR_RAMP_SPREAD_REFLECT);
100}
101
102static INLINE bool is_tiling_mode(VGTilingMode tiling_mode)
103{
104 return (tiling_mode >= VG_TILE_FILL) &&
105 (tiling_mode <= VG_TILE_REFLECT);
106}
107
108static INLINE bool is_vector_param_type(VGParamType param_type)
109{
110 return (param_type == VG_SCISSOR_RECTS) ||
111 (param_type == VG_COLOR_TRANSFORM_VALUES) ||
112 (param_type == VG_STROKE_DASH_PATTERN) ||
113 (param_type == VG_TILE_FILL_COLOR) ||
114 (param_type == VG_CLEAR_COLOR) ||
115 (param_type == VG_GLYPH_ORIGIN);
116}
117
118static INLINE bool is_vector_object_param_type(int32_t param_type)
119{
120 return (param_type == VG_PAINT_COLOR) ||
121 (param_type == VG_PAINT_COLOR_RAMP_STOPS) ||
122 (param_type == VG_PAINT_LINEAR_GRADIENT) ||
123 (param_type == VG_PAINT_RADIAL_GRADIENT);
124}
125
126static INLINE bool is_path_format(int32_t path_format)
127{
128 return path_format == VG_PATH_FORMAT_STANDARD;
129}
130
131static INLINE bool is_path_datatype(VGPathDatatype path_datatype)
132{
133#ifdef __HIGHC__
134 #pragma Offwarn(428) /* unsigned compare with 0 always true */
135#endif
136 return (path_datatype >= VG_PATH_DATATYPE_S_8) &&
137 (path_datatype <= VG_PATH_DATATYPE_F);
138#ifdef __HIGHC__
139 #pragma Popwarn
140#endif
141}
142
143static INLINE uint32_t get_path_datatype_size(VGPathDatatype path_datatype)
144{
145 switch (path_datatype) {
146 case VG_PATH_DATATYPE_S_8: return 1;
147 case VG_PATH_DATATYPE_S_16: return sizeof(int16_t);
148 case VG_PATH_DATATYPE_S_32: return sizeof(int32_t);
149 case VG_PATH_DATATYPE_F: return sizeof(float);
150 default: UNREACHABLE(); return 0;
151 }
152}
153
154static INLINE uint32_t get_segment_coords_count(uint32_t segment)
155{
156 switch (segment) {
157 case VG_CLOSE_PATH: return 0;
158 case VG_MOVE_TO: return 2;
159 case VG_LINE_TO: return 2;
160 case VG_HLINE_TO: return 1;
161 case VG_VLINE_TO: return 1;
162 case VG_QUAD_TO: return 4;
163 case VG_CUBIC_TO: return 6;
164 case VG_SQUAD_TO: return 2;
165 case VG_SCUBIC_TO: return 4;
166 case VG_SCCWARC_TO: return 5;
167 case VG_SCWARC_TO: return 5;
168 case VG_LCCWARC_TO: return 5;
169 case VG_LCWARC_TO: return 5;
170 default: UNREACHABLE(); return 0;
171 }
172}
173
174static INLINE float get_coord(
175 VGPathDatatype datatype, float scale, float bias,
176 const void **coords)
177{
178 switch (datatype) {
179 case VG_PATH_DATATYPE_S_8: return bias + (scale * *((*(const int8_t **)coords)++));
180 case VG_PATH_DATATYPE_S_16: return bias + (scale * *((*(const int16_t **)coords)++));
181 case VG_PATH_DATATYPE_S_32: return bias + (scale * *((*(const int32_t **)coords)++));
182 case VG_PATH_DATATYPE_F: return bias + (scale * *((*(const float **)coords)++));
183 default: UNREACHABLE(); return 0.0f;
184 }
185}
186
187static INLINE void put_coord(
188 VGPathDatatype datatype, float oo_scale, float bias,
189 void **coords, float x)
190{
191 x = oo_scale * (x - bias);
192 switch (datatype) {
193 case VG_PATH_DATATYPE_S_8: *((*(int8_t **)coords)++) = (int8_t)clampi(float_to_int(x), -0x80, 0x7f); break;
194 case VG_PATH_DATATYPE_S_16: *((*(int16_t **)coords)++) = (int16_t)clampi(float_to_int(x), -0x8000, 0x7fff); break;
195 case VG_PATH_DATATYPE_S_32: *((*(int32_t **)coords)++) = float_to_int(x); break;
196 case VG_PATH_DATATYPE_F: *((*(float **)coords)++) = x; break;
197 default: UNREACHABLE();
198 }
199}
200
201static INLINE bool is_paint_modes(uint32_t paint_modes)
202{
203 return paint_modes && !(paint_modes & ~(VG_STROKE_PATH | VG_FILL_PATH));
204}
205
206static INLINE bool is_paint_mode(VGPaintMode paint_mode)
207{
208 return (paint_mode == VG_STROKE_PATH) ||
209 (paint_mode == VG_FILL_PATH);
210}
211
212static INLINE bool is_allowed_quality(uint32_t allowed_quality)
213{
214 return allowed_quality && !(allowed_quality & ~(VG_IMAGE_QUALITY_NONANTIALIASED | VG_IMAGE_QUALITY_FASTER | VG_IMAGE_QUALITY_BETTER));
215}
216
217static INLINE bool is_hardware_query_type(VGHardwareQueryType hardware_query_type)
218{
219 return (hardware_query_type == VG_IMAGE_FORMAT_QUERY) ||
220 (hardware_query_type == VG_PATH_DATATYPE_QUERY);
221}
222
223static INLINE bool is_image_format(VGImageFormat image_format)
224{
225#ifdef __HIGHC__
226 #pragma Offwarn(428) /* unsigned compare with 0 always true */
227#endif
228 return ((image_format >= VG_sRGBX_8888) &&
229 (image_format <= VG_A_4)) ||
230 (image_format == VG_sXRGB_8888) ||
231 (image_format == VG_sARGB_8888) ||
232 (image_format == VG_sARGB_8888_PRE) ||
233 (image_format == VG_sARGB_1555) ||
234 (image_format == VG_sARGB_4444) ||
235 (image_format == VG_lXRGB_8888) ||
236 (image_format == VG_lARGB_8888) ||
237 (image_format == VG_lARGB_8888_PRE) ||
238 (image_format == VG_sBGRX_8888) ||
239 (image_format == VG_sBGRA_8888) ||
240 (image_format == VG_sBGRA_8888_PRE) ||
241 (image_format == VG_sBGR_565) ||
242 (image_format == VG_sBGRA_5551) ||
243 (image_format == VG_sBGRA_4444) ||
244 (image_format == VG_lBGRX_8888) ||
245 (image_format == VG_lBGRA_8888) ||
246 (image_format == VG_lBGRA_8888_PRE) ||
247 (image_format == VG_sXBGR_8888) ||
248 (image_format == VG_sABGR_8888) ||
249 (image_format == VG_sABGR_8888_PRE) ||
250 (image_format == VG_sABGR_1555) ||
251 (image_format == VG_sABGR_4444) ||
252 (image_format == VG_lXBGR_8888) ||
253 (image_format == VG_lABGR_8888) ||
254 (image_format == VG_lABGR_8888_PRE);
255#ifdef __HIGHC__
256 #pragma Popwarn
257#endif
258}
259
260static INLINE bool is_arc_type(VGUArcType arc_type)
261{
262 return (arc_type >= VGU_ARC_OPEN) &&
263 (arc_type <= VGU_ARC_PIE);
264}
265
266static INLINE bool is_mask_operation(VGMaskOperation mask_operation)
267{
268 return (mask_operation >= VG_CLEAR_MASK) &&
269 (mask_operation <= VG_SUBTRACT_MASK);
270}
271
272static INLINE bool is_image_channel(VGImageChannel image_channel)
273{
274 return (image_channel == VG_RED) ||
275 (image_channel == VG_GREEN) ||
276 (image_channel == VG_BLUE) ||
277 (image_channel == VG_ALPHA);
278}
279
280#endif
281