1 /******************************************************************************
2 *
3 * Copyright (C) 2022 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************
18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 /**
21 *******************************************************************************
22 * @file
23 * isvc_mem_fns.c
24 *
25 * @brief
26 * Functions used for memory operations
27 *
28 * @author
29 * Ittiam
30 *
31 * @par List of Functions:
32 * isvc_memcpy()
33 * isvc_memcpy_mul_8()
34 * isvc_memset()
35 * isvc_memset_mul_8()
36 * isvc_memset_16bit()
37 * isvc_memset_16bit_mul_8()
38 * isvc_memory_alloc()
39 * isvc_memory_free()
40 *
41 * @remarks
42 * None
43 *
44 ******************************************************************************
45 */
46
47 /*****************************************************************************/
48 /* File Includes */
49 /*****************************************************************************/
50 /* System include files */
51 #include <stdio.h>
52 #include <stddef.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <assert.h>
56
57 /* User include files */
58 #include "ih264_typedefs.h"
59 #include "isvc_mem_fns.h"
60
61 /**
62 ********************************************************************************
63 * @brief copies a 2d blk from one location to another
64 *
65 * @param[out] pu1_dst : dst pointer
66 *
67 * @param[in] i4_dst_stride: stride of destination
68 *
69 * @param[in] pu1_src : src ptr
70 *
71 * @param[in] i4_src_stride: stride of src
72 *
73 * @param[in] i4_blk_wd : blk width
74 *
75 * @param[in] i4_blk_ht : blk height
76 *
77 * @return void
78 ********************************************************************************
79 */
80
isvc_copy_2d(UWORD8 * pu1_dst,WORD32 i4_dst_stride,UWORD8 * pu1_src,WORD32 i4_src_stride,WORD32 i4_blk_wd,WORD32 i4_blk_ht)81 void isvc_copy_2d(UWORD8 *pu1_dst, WORD32 i4_dst_stride, UWORD8 *pu1_src, WORD32 i4_src_stride,
82 WORD32 i4_blk_wd, WORD32 i4_blk_ht)
83 {
84 WORD32 i;
85
86 for(i = 0; i < i4_blk_ht; i++)
87 {
88 memmove(pu1_dst, pu1_src, i4_blk_wd * sizeof(pu1_dst[0]));
89
90 pu1_dst += i4_dst_stride;
91 pu1_src += i4_src_stride;
92 }
93 }
94
95 /**
96 ********************************************************************************
97 * @brief memsets a 2d blk
98 *
99 * @param[out] pu1_dst : dst pointer
100 *
101 * @param[in] i4_dst_stride: stride of destination
102 *
103 * @param[in] i4_blk_wd : blk width
104 *
105 * @param[in] i4_blk_ht : blk height
106 *
107 * @return void
108 ********************************************************************************
109 */
isvc_memset_2d(UWORD8 * pu1_dst,WORD32 i4_dst_stride,UWORD8 u1_val,WORD32 i4_blk_wd,WORD32 i4_blk_ht)110 void isvc_memset_2d(UWORD8 *pu1_dst, WORD32 i4_dst_stride, UWORD8 u1_val, WORD32 i4_blk_wd,
111 WORD32 i4_blk_ht)
112 {
113 WORD32 i;
114
115 for(i = 0; i < i4_blk_ht; i++)
116 {
117 memset(pu1_dst, u1_val, i4_blk_wd);
118
119 pu1_dst += i4_dst_stride;
120 }
121 }
122
123 /**
124 *******************************************************************************
125 *
126 * @brief
127 * Function for copying to an interleaved destination
128 *
129 * @par Description:
130 * Copies the array of width 'wd' and height 'ht' from the location pointed
131 * by 'src' to the location pointed by 'dst'
132 *
133 * @param[in] pu1_src
134 * UWORD8 pointer to the source
135 *
136 * @param[out] pu1_dst
137 * UWORD8 pointer to the destination
138 *
139 * @param[in] src_strd
140 * integer source stride
141 *
142 * @param[in] dst_strd
143 * integer destination stride
144 *
145 * @param[in] ht
146 * integer height of the array
147 *
148 * @param[in] wd
149 * integer width of the array
150 *
151 * @returns
152 *
153 * @remarks
154 * The alternate elements of src will be copied to alternate locations in dsr
155 * Other locations are not touched
156 *
157 *******************************************************************************
158 */
isvc_interleaved_copy(UWORD8 * pu1_src,UWORD8 * pu1_dst,WORD32 src_strd,WORD32 dst_strd,WORD32 ht,WORD32 wd)159 void isvc_interleaved_copy(UWORD8 *pu1_src, UWORD8 *pu1_dst, WORD32 src_strd, WORD32 dst_strd,
160 WORD32 ht, WORD32 wd)
161 {
162 WORD32 row, col;
163 wd *= 2;
164
165 for(row = 0; row < ht; row++)
166 {
167 for(col = 0; col < wd; col += 2)
168 {
169 pu1_dst[col] = pu1_src[col];
170 }
171
172 pu1_src += src_strd;
173 pu1_dst += dst_strd;
174 }
175 }
176
177 /**
178 *******************************************************************************
179 *
180 * @brief
181 * Function for copying to an interleaved destination
182 *
183 * @par Description:
184 * Copies the array of width 'wd' and height 'ht' from the location pointed
185 * by 'src' to the location pointed by 'dst'
186 *
187 * @param[in] pu1_src
188 * UWORD8 pointer to the source
189 *
190 * @param[out] pu1_dst
191 * UWORD8 pointer to the destination
192 *
193 * @param[in] src_strd
194 * integer source stride
195 *
196 * @param[in] dst_strd
197 * integer destination stride
198 *
199 * @param[in] ht
200 * integer height of the array
201 *
202 * @param[in] wd
203 * integer width of the array
204 *
205 * @returns
206 *
207 * @remarks
208 * The alternate elements of src will be copied to alternate locations in dsr
209 * Other locations are not touched
210 *
211 *******************************************************************************
212 */
isvc_16bit_interleaved_copy(WORD16 * pi2_src,WORD16 * pi2_dst,WORD32 src_strd,WORD32 dst_strd,WORD32 ht,WORD32 wd)213 void isvc_16bit_interleaved_copy(WORD16 *pi2_src, WORD16 *pi2_dst, WORD32 src_strd, WORD32 dst_strd,
214 WORD32 ht, WORD32 wd)
215 {
216 WORD32 row, col;
217 wd *= 2;
218
219 for(row = 0; row < ht; row++)
220 {
221 for(col = 0; col < wd; col += 2)
222 {
223 pi2_dst[col] = pi2_src[col];
224 }
225
226 pi2_src += src_strd;
227 pi2_dst += dst_strd;
228 }
229 }
230
231 /**
232 *******************************************************************************
233 *
234 * @brief
235 * Function for memsetting to an interleaved destination
236 *
237 * @par Description:
238 * Memsets the array of width 'wd' and height 'ht' pointed by 'src'
239 *
240 * @param[in] pu1_src
241 * UWORD8 pointer to the source
242 *
243 * @param[in] src_strd
244 * integer source stride
245 *
246 * @param[in] value
247 * Value to set
248 *
249 * @param[in] ht
250 * integer height of the array
251 *
252 * @param[in] wd
253 * integer width of the array
254 *
255 * @returns
256 *
257 * @remarks
258 * The alternate elements of src will be copied to alternate locations in dsr
259 * Other locations are not touched
260 *
261 *******************************************************************************
262 */
isvc_16bit_interleaved_memset(WORD16 * pi2_src,WORD32 i4_src_strd,WORD16 i2_value,WORD32 i4_wd,WORD32 i4_ht)263 void isvc_16bit_interleaved_memset(WORD16 *pi2_src, WORD32 i4_src_strd, WORD16 i2_value,
264 WORD32 i4_wd, WORD32 i4_ht)
265 {
266 WORD32 row, col;
267
268 i4_wd *= 2;
269
270 for(row = 0; row < i4_ht; row++)
271 {
272 for(col = 0; col < i4_wd; col += 2)
273 {
274 pi2_src[col] = i2_value;
275 }
276
277 pi2_src += i4_src_strd;
278 }
279 }
280
281 /**
282 *******************************************************************************
283 *
284 * @brief
285 * Checks if any pixel in a block is non-zero
286 *
287 * @param[in] pu1_data
288 * UWORD8 pointer to the block to be checked
289 *
290 * @param[in] i4_data_strd
291 * Stride of data buffer
292 *
293 * @param[in] u4_wd
294 * Width of the block
295 *
296 * @param[in] u4_ht
297 * Height of the block
298 *
299 *******************************************************************************
300 */
isvc_is_nonzero_blk(UWORD8 * pu1_data,WORD32 i4_data_strd,UWORD32 u4_wd,UWORD32 u4_ht)301 UWORD8 isvc_is_nonzero_blk(UWORD8 *pu1_data, WORD32 i4_data_strd, UWORD32 u4_wd, UWORD32 u4_ht)
302 {
303 UWORD32 i, j;
304
305 for(i = 0; i < u4_ht; i++)
306 {
307 for(j = 0; j < u4_wd; j++)
308 {
309 if(pu1_data[j + i * i4_data_strd])
310 {
311 return 1;
312 }
313 }
314 }
315
316 return 0;
317 }
318