vcgencmd: Apply ASLR
[platform/adaptation/broadcom/libomxil-vc4.git] / helpers / vc_image / vc_image_helper.h
1 /*
2 Copyright (c) 2012, Broadcom Europe Ltd
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, 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
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON 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
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef VC_IMAGE_HELPER_H
29 #define VC_IMAGE_HELPER_H
30
31 #include "interface/vctypes/vc_image_structs.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /**
38  * \brief Image buffer object, with image data locked in memory and ready for access.
39  *
40  * This data type is fully compatible with \c VC_IMAGE_T for backwards
41  * compatibility.  New code should use this type where the object refers to
42  * a locked image.
43  */
44 typedef VC_IMAGE_T VC_IMAGE_BUF_T;
45
46 /* Macros to determine which format a vc_image is */
47
48 typedef struct
49 {
50    unsigned bits_per_pixel : 8,
51    is_rgb            : 1,
52    is_yuv            : 1,
53    is_raster_order   : 1,
54    is_tformat_order  : 1,
55    has_alpha         : 1;
56 } VC_IMAGE_TYPE_INFO_T;
57
58 #define VC_IMAGE_COMPONENT_ORDER(red_lsb, green_lsb, blue_lsb, alpha_lsb) \
59             ( (((red_lsb)   & 0x1f) <<  0) \
60             | (((green_lsb) & 0x1f) <<  6) \
61             | (((blue_lsb)  & 0x1f) << 12) \
62             | (((alpha_lsb) & 0x1f) << 18) )
63 #define VC_IMAGE_RED_OFFSET(component_order)    (((component_order) >>  0) & 0x1f)
64 #define VC_IMAGE_GREEN_OFFSET(component_order)  (((component_order) >>  6) & 0x1f)
65 #define VC_IMAGE_BLUE_OFFSET(component_order)   (((component_order) >> 12) & 0x1f)
66 #define VC_IMAGE_ALPHA_OFFSET(component_order)  (((component_order) >> 18) & 0x1f)
67
68 extern const VC_IMAGE_TYPE_INFO_T vc_image_type_info[VC_IMAGE_MAX + 1];
69 extern const unsigned int vc_image_rgb_component_order[VC_IMAGE_MAX + 1];
70
71 #define VC_IMAGE_IS_YUV(type) (vc_image_type_info[type].is_yuv)
72 #define VC_IMAGE_IS_RGB(type) (vc_image_type_info[type].is_rgb)
73 #define VC_IMAGE_IS_RASTER(type) (vc_image_type_info[type].is_raster_order)
74 #define VC_IMAGE_IS_TFORMAT(type) (vc_image_type_info[type].is_tformat_order)
75 #define VC_IMAGE_BITS_PER_PIXEL(type) (vc_image_type_info[type].bits_per_pixel)
76 #define VC_IMAGE_HAS_ALPHA(type) (vc_image_type_info[type].has_alpha)
77
78 #define case_VC_IMAGE_ANY_YUV \
79    case VC_IMAGE_YUV420:      \
80    case VC_IMAGE_YUV420SP:    \
81    case VC_IMAGE_YUV422:      \
82    case VC_IMAGE_YUV_UV:      \
83    case VC_IMAGE_YUV_UV32:    \
84    case VC_IMAGE_YUV422PLANAR: \
85    case VC_IMAGE_YUV444PLANAR: \
86    case VC_IMAGE_YUV420_16:   \
87    case VC_IMAGE_YUV_UV_16
88
89 #define case_VC_IMAGE_ANY_RGB \
90    case VC_IMAGE_RGB565:      \
91    case VC_IMAGE_RGB2X9:      \
92    case VC_IMAGE_RGB666:      \
93    case VC_IMAGE_RGBA32:      \
94    case VC_IMAGE_RGBX32:      \
95    case VC_IMAGE_RGBA16:      \
96    case VC_IMAGE_RGBA565:     \
97    case VC_IMAGE_RGB888:      \
98    case VC_IMAGE_TF_RGBA32:   \
99    case VC_IMAGE_TF_RGBX32:   \
100    case VC_IMAGE_TF_RGBA16:   \
101    case VC_IMAGE_TF_RGBA5551: \
102    case VC_IMAGE_TF_RGB565:   \
103    case VC_IMAGE_BGR888:      \
104    case VC_IMAGE_BGR888_NP:   \
105    case VC_IMAGE_ARGB8888:    \
106    case VC_IMAGE_XRGB8888
107
108 #define case_VC_IMAGE_ANY_RGB_NOT_TF \
109    case VC_IMAGE_RGB565:      \
110    case VC_IMAGE_RGB2X9:      \
111    case VC_IMAGE_RGB666:      \
112    case VC_IMAGE_RGBA32:      \
113    case VC_IMAGE_RGBX32:      \
114    case VC_IMAGE_RGBA16:      \
115    case VC_IMAGE_RGBA565:     \
116    case VC_IMAGE_RGB888:      \
117    case VC_IMAGE_BGR888:      \
118    case VC_IMAGE_BGR888_NP:   \
119    case VC_IMAGE_ARGB8888:    \
120    case VC_IMAGE_XRGB8888:    \
121    case VC_IMAGE_RGBX8888:    \
122    case VC_IMAGE_BGRX8888
123
124 #define case_VC_IMAGE_ANY_TFORMAT \
125    case VC_IMAGE_TF_RGBA32:   \
126    case VC_IMAGE_TF_RGBX32:   \
127    case VC_IMAGE_TF_FLOAT:    \
128    case VC_IMAGE_TF_RGBA16:   \
129    case VC_IMAGE_TF_RGBA5551: \
130    case VC_IMAGE_TF_RGB565:   \
131    case VC_IMAGE_TF_YA88:     \
132    case VC_IMAGE_TF_BYTE:     \
133    case VC_IMAGE_TF_PAL8:     \
134    case VC_IMAGE_TF_PAL4:     \
135    case VC_IMAGE_TF_ETC1:     \
136    case VC_IMAGE_TF_Y8:       \
137    case VC_IMAGE_TF_A8:       \
138    case VC_IMAGE_TF_SHORT:    \
139    case VC_IMAGE_TF_1BPP
140
141 /******************************************************************************
142 General functions.
143 ******************************************************************************/
144
145 int vc_image_bits_per_pixel(VC_IMAGE_TYPE_T type);
146
147 int calculate_pitch(VC_IMAGE_TYPE_T type, int width, int height, uint8_t num_channels, VC_IMAGE_INFO_T *info, VC_IMAGE_EXTRA_T *extra);
148
149 /* Check if an image will use an alternate memory layout, in order to cope with
150  * codec limitation. Applies to YUV_UV images taller than 1344 lines. */
151 int vc_image_is_tall_yuv_uv(VC_IMAGE_TYPE_T type, int height);
152
153 /******************************************************************************
154 Data member access.
155 ******************************************************************************/
156
157 /* Set the type of the VC_IMAGE_T. */
158 void vc_image_set_type(VC_IMAGE_T *image, VC_IMAGE_TYPE_T type);
159
160 /* Set the image_data field, noting how big it is. */
161 void vc_image_set_image_data(VC_IMAGE_BUF_T *image, int size, void *image_data);
162
163 /* Set the image data with added u and v pointers */
164 void vc_image_set_image_data_yuv(VC_IMAGE_BUF_T *image, int size, void *image_y, void *image_u, void *image_v);
165
166 /* Set the dimensions of the image. */
167 void vc_image_set_dimensions(VC_IMAGE_T *image, int width, int height);
168
169 /* Check the integrity of a VC_IMAGE_T structure - checks structure values + data ptr */
170 int vc_image_verify(const VC_IMAGE_T *image);
171
172 /* Set the pitch (internal_width) of the image. */
173 void vc_image_set_pitch(VC_IMAGE_T *image, int pitch);
174
175 /* Specify the vertical pitch for YUV planar images */
176 void vc_image_set_vpitch(VC_IMAGE_T *image, int vpitch);
177
178 /* Specify that the YUV image is V/U interleaved. */
179 void vc_image_set_is_vu(VC_IMAGE_T *image);
180
181 /* Return 1 if the YUV image is V/U interleaved, else return 0. */
182 int vc_image_get_is_vu(const VC_IMAGE_T *image);
183 int vc_image_info_get_is_vu(const VC_IMAGE_INFO_T *info);
184
185 /* Reset the shape of an image */
186 int vc_image_reshape(VC_IMAGE_T *image, VC_IMAGE_TYPE_T type, int width, int height);
187
188 /* Return the space required (in bytes) for an image of this type and dimensions. */
189 int vc_image_required_size(VC_IMAGE_T *image);
190
191 /* Return the space required (in bytes) for an image of this type's palette. */
192 int vc_image_palette_size (VC_IMAGE_T *image);
193
194 /* Return 1 if image is high-definition, else return 0. */
195 int vc_image_is_high_definition(const VC_IMAGE_T *image);
196
197 /* Return true if palette is 32bpp */
198 int vc_image_palette_is_32bit(VC_IMAGE_T *image);
199
200 /* Retrieve Y, U and V pointers from a YUV image. Note that these are macros. */
201
202 #define vc_image_get_y(p) ((unsigned char *)((p)->image_data))
203
204 // replaced with functions to allow assert - revert to #define when fixed
205 //#define vc_image_get_u(p) ((unsigned char *)((p)->extra.uv.u))
206 //#define vc_image_get_v(p) ((unsigned char *)((p)->extra.uv.v))
207 unsigned char *vc_image_get_u(const VC_IMAGE_BUF_T *image);
208 unsigned char *vc_image_get_v(const VC_IMAGE_BUF_T *image);
209
210 /* Calculate the address of the given pixel coordinate -- the result may point
211  * to a word containing data for several pixels (ie., for sub-8bpp and
212  * compressed formats).
213  */
214 void *vc_image_pixel_addr(VC_IMAGE_BUF_T *image, int x, int y);
215 void *vc_image_pixel_addr_mm(VC_IMAGE_BUF_T *image, int x, int y, int miplevel);
216 void *vc_image_pixel_addr_u(VC_IMAGE_BUF_T *image, int x, int y);
217 void *vc_image_pixel_addr_v(VC_IMAGE_BUF_T *image, int x, int y);
218
219 /* As above, but with (0,0) in the bottom-left corner */
220 void *vc_image_pixel_addr_gl(VC_IMAGE_BUF_T *image, int x, int y, int miplevel);
221
222 #define vc_image_get_y_422(p) vc_image_get_y(p)
223 #define vc_image_get_u_422(p) vc_image_get_u(p)
224 #define vc_image_get_v_422(p) vc_image_get_v(p)
225
226 #define vc_image_get_y_422planar(p) vc_image_get_y(p)
227 #define vc_image_get_u_422planar(p) vc_image_get_u(p)
228 #define vc_image_get_v_422planar(p) vc_image_get_v(p)
229
230 /* Mipmap-related functions. Image must be t-format. */
231
232 /* Return the pitch of the selected mipmap */
233 unsigned int vc_image_get_mipmap_pitch(VC_IMAGE_T *image, int miplvl);
234
235 /* Return the padded height of the selected mipmap (mipmaps must be padded to a
236  * power of 2) */
237 unsigned int vc_image_get_mipmap_padded_height(VC_IMAGE_T *image, int miplvl);
238
239 /* Return the offset, in bytes, of the selected mipmap. */
240 int vc_image_get_mipmap_offset(VC_IMAGE_T *image, int miplvl);
241
242 /* Return whether the selected mipmap is stored in t-format or linear microtile
243  * format. */
244 #define VC_IMAGE_MIPMAP_TFORMAT 0
245 #define VC_IMAGE_MIPMAP_LINEAR_TILE 1
246 int vc_image_get_mipmap_type(VC_IMAGE_T const *image, int miplvl);
247
248 #ifdef __cplusplus
249 }
250 #endif
251
252 #endif