1 /******************************************************************************
2 *
3 * Copyright (C) 2015 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 *******************************************************************************
23 * @file
24 * ih264_padding.c
25 *
26 * @brief
27 * Contains function definitions for Padding
28 *
29 * @author
30 * ittiam
31 *
32 * @par List of Functions:
33 * - ih264_pad_top
34 * - ih264_pad_bottom
35 * - ih264_pad_left_luma
36 * - ih264_pad_left_chroma
37 * - ih264_pad_right_luma
38 * - ih264_pad_right_chroma
39 *
40 * @remarks
41 * none
42 *
43 *******************************************************************************
44 */
45
46 /*****************************************************************************/
47 /* File Includes */
48 /*****************************************************************************/
49
50 /* System Include Files */
51 #include <stddef.h>
52 #include <string.h>
53
54 /* User Include Files */
55 #include "ih264_typedefs.h"
56 #include "ih264_macros.h"
57 #include "ih264_padding.h"
58
59
60 /*****************************************************************************/
61 /* Function Definitions */
62 /*****************************************************************************/
63
64 /**
65 *******************************************************************************
66 *
67 * @brief pad at the top of a 2d array
68 *
69 * @par Description:
70 * The top row of a 2d array is replicated for pad_size times at the top
71 *
72 * @param[in] pu1_src
73 * pointer to the source
74 *
75 * @param[in] src_strd
76 * source stride
77 *
78 * @param[in] wd
79 * width of the array
80 *
81 * @param[in] pad_size
82 * padding size of the array
83 *
84 * @returns none
85 *
86 * @remarks none
87 *
88 *******************************************************************************
89 */
ih264_pad_top(UWORD8 * pu1_src,WORD32 src_strd,WORD32 wd,WORD32 pad_size)90 void ih264_pad_top(UWORD8 *pu1_src,
91 WORD32 src_strd,
92 WORD32 wd,
93 WORD32 pad_size)
94 {
95 WORD32 row;
96
97 for(row = 1; row <= pad_size; row++)
98 {
99 memcpy(pu1_src - row * src_strd, pu1_src, wd);
100 }
101 }
102
103 /**
104 *******************************************************************************
105 *
106 * @brief pad at the bottom of a 2d array
107 *
108 * @par Description:
109 * The bottom row of a 2d array is replicated for pad_size times at the bottom
110 *
111 * @param[in] pu1_src
112 * pointer to the source
113 *
114 * @param[in] src_strd
115 * source stride
116 *
117 * @param[in] wd
118 * width of the array
119 *
120 * @param[in] pad_size
121 * padding size of the array
122 *
123 * @returns none
124 *
125 * @remarks none
126 *
127 *******************************************************************************
128 */
ih264_pad_bottom(UWORD8 * pu1_src,WORD32 src_strd,WORD32 wd,WORD32 pad_size)129 void ih264_pad_bottom(UWORD8 *pu1_src,
130 WORD32 src_strd,
131 WORD32 wd,
132 WORD32 pad_size)
133 {
134 WORD32 row;
135
136 for(row = 1; row <= pad_size; row++)
137 {
138 memcpy(pu1_src + (row - 1) * src_strd, pu1_src - 1 * src_strd, wd);
139 }
140 }
141
142 /**
143 *******************************************************************************
144 *
145 * @brief pad (luma block) at the left of a 2d array
146 *
147 * @par Description:
148 * The left column of a 2d array is replicated for pad_size times to the left
149 *
150 * @param[in] pu1_src
151 * pointer to the source
152 *
153 * @param[in] src_strd
154 * source stride
155 *
156 * @param[in] ht
157 * height of the array
158 *
159 * @param[in] pad_size
160 * padding size of the array
161 *
162 * @returns none
163 *
164 * @remarks none
165 *
166 *******************************************************************************
167 */
ih264_pad_left_luma(UWORD8 * pu1_src,WORD32 src_strd,WORD32 ht,WORD32 pad_size)168 void ih264_pad_left_luma(UWORD8 *pu1_src,
169 WORD32 src_strd,
170 WORD32 ht,
171 WORD32 pad_size)
172 {
173 WORD32 row;
174
175 for(row = 0; row < ht; row++)
176 {
177 memset(pu1_src - pad_size, *pu1_src, pad_size);
178 pu1_src += src_strd;
179 }
180 }
181
182 /**
183 *******************************************************************************
184 *
185 * @brief pad (chroma block) at the left of a 2d array
186 *
187 * @par Description:
188 * The left column of a 2d array is replicated for pad_size times to the left
189 *
190 * @param[in] pu1_src
191 * pointer to the source
192 *
193 * @param[in] src_strd
194 * source stride
195 *
196 * @param[in] ht
197 * height of the array
198 *
199 * @param[in] pad_size
200 * padding size of the array
201 *
202 * @returns none
203 *
204 * @remarks none
205 *
206 *******************************************************************************
207 */
ih264_pad_left_chroma(UWORD8 * pu1_src,WORD32 src_strd,WORD32 ht,WORD32 pad_size)208 void ih264_pad_left_chroma(UWORD8 *pu1_src,
209 WORD32 src_strd,
210 WORD32 ht,
211 WORD32 pad_size)
212 {
213 WORD32 row, col;
214 UWORD16 u2_uv_val;
215 UWORD16 *pu2_src = (UWORD16 *)pu1_src;
216
217 src_strd >>= 1;
218 pad_size >>= 1;
219
220 for(row = 0; row < ht; row++)
221 {
222 u2_uv_val = pu2_src[0];
223 for(col = -pad_size; col < 0; col++)
224 {
225 pu2_src[col] = u2_uv_val;
226 }
227 pu2_src += src_strd;
228 }
229 }
230
231 /**
232 *******************************************************************************
233 *
234 * @brief pad (luma block) at the right of a 2d array
235 *
236 * @par Description:
237 * The right column of a 2d array is replicated for pad_size times at the right
238 *
239 * @param[in] pu1_src
240 * pointer to the source
241 *
242 * @param[in] src_strd
243 * source stride
244 *
245 * @param[in] ht
246 * height of the array
247 *
248 * @param[in] pad_size
249 * padding size of the array
250 *
251 * @returns none
252 *
253 * @remarks none
254 *
255 *******************************************************************************
256 */
ih264_pad_right_luma(UWORD8 * pu1_src,WORD32 src_strd,WORD32 ht,WORD32 pad_size)257 void ih264_pad_right_luma(UWORD8 *pu1_src,
258 WORD32 src_strd,
259 WORD32 ht,
260 WORD32 pad_size)
261 {
262 WORD32 row;
263
264 for(row = 0; row < ht; row++)
265 {
266 memset(pu1_src, *(pu1_src -1), pad_size);
267 pu1_src += src_strd;
268 }
269 }
270
271 /**
272 *******************************************************************************
273 *
274 * @brief pad (chroma block) at the right of a 2d array
275 *
276 * @par Description:
277 * The right column of a 2d array is replicated for pad_size times at the right
278 *
279 * @param[in] pu1_src
280 * pointer to the source
281 *
282 * @param[in] src_strd
283 * source stride
284 *
285 * @param[in] ht
286 * height of the array
287 *
288 * @param[in] pad_size
289 * padding size of the array
290 *
291 * @returns none
292 *
293 * @remarks none
294 *
295 *******************************************************************************
296 */
ih264_pad_right_chroma(UWORD8 * pu1_src,WORD32 src_strd,WORD32 ht,WORD32 pad_size)297 void ih264_pad_right_chroma(UWORD8 *pu1_src,
298 WORD32 src_strd,
299 WORD32 ht,
300 WORD32 pad_size)
301 {
302 WORD32 row, col;
303 UWORD16 u2_uv_val;
304 UWORD16 *pu2_src = (UWORD16 *)pu1_src;
305
306 src_strd >>= 1;
307 pad_size >>= 1;
308
309 for(row = 0; row < ht; row++)
310 {
311 u2_uv_val = pu2_src[-1];
312 for(col = 0; col < pad_size; col++)
313 {
314 pu2_src[col] = u2_uv_val;
315 }
316 pu2_src += src_strd;
317 }
318 }
319
320