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*  UWORD8 pointer to the source
74*
75* @param[in] src_strd
76*  integer source stride
77*
78* @param[in] wd
79*  integer width of the array
80*
81* @param[in] pad_size
82*  integer -padding size of the array
83*
84* @returns none
85*
86* @remarks none
87*
88*******************************************************************************
89*/
90void 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*******************************************************************************
107*
108* @brief pad at the bottom of a 2d array
109*
110* @par Description:
111*  The bottom row of a 2d array is replicated for pad_size times at the bottom
112*
113* @param[in] pu1_src
114*  UWORD8 pointer to the source
115*
116* @param[in] src_strd
117*  integer source stride
118*
119* @param[in] wd
120*  integer width of the array
121*
122* @param[in] pad_size
123*  integer -padding size of the array
124*
125* @returns none
126*
127* @remarks none
128*
129*******************************************************************************
130*/
131void ih264_pad_bottom(UWORD8 *pu1_src,
132                      WORD32 src_strd,
133                      WORD32 wd,
134                      WORD32 pad_size)
135{
136    WORD32 row;
137
138    for(row = 1; row <= pad_size; row++)
139    {
140        memcpy(pu1_src + (row - 1) * src_strd, pu1_src - 1 * src_strd, wd);
141    }
142}
143
144/**
145*******************************************************************************
146*
147* @brief pad (luma block) at the left of a 2d array
148*
149* @par Description:
150*   The left column of a 2d array is replicated for pad_size times to the left
151*
152* @param[in] pu1_src
153*  UWORD8 pointer to the source
154*
155* @param[in] src_strd
156*  integer source stride
157*
158* @param[in] ht
159*  integer height of the array
160*
161* @param[in] pad_size
162*  integer -padding size of the array
163*
164* @returns none
165*
166* @remarks none
167*
168*******************************************************************************
169 */
170void ih264_pad_left_luma(UWORD8 *pu1_src,
171                         WORD32 src_strd,
172                         WORD32 ht,
173                         WORD32 pad_size)
174{
175    WORD32 row;
176
177    for(row = 0; row < ht; row++)
178    {
179
180        memset(pu1_src - pad_size, *pu1_src, pad_size);
181
182        pu1_src += src_strd;
183    }
184}
185
186/**
187*******************************************************************************
188*
189* @brief pad (chroma block) at the left of a 2d array
190*
191* @par Description:
192*   The left column of a 2d array is replicated for pad_size times to the left
193*
194* @param[in] pu1_src
195*  UWORD8 pointer to the source
196*
197* @param[in] src_strd
198*  integer source stride
199*
200* @param[in] ht
201*  integer height of the array
202*
203* @param[in] pad_size
204*  integer -padding size of the array
205*
206* @returns none
207*
208* @remarks none
209*
210*******************************************************************************
211*/
212void ih264_pad_left_chroma(UWORD8 *pu1_src,
213                           WORD32 src_strd,
214                           WORD32 ht,
215                           WORD32 pad_size)
216{
217    /* temp var */
218    WORD32 row, col;
219    UWORD16 u2_uv_val;
220
221    /* pointer to src */
222    UWORD16 *pu2_src = (UWORD16 *)pu1_src;
223
224    src_strd >>= 1;
225    pad_size >>= 1;
226
227    for(row = 0; row < ht; row++)
228    {
229        u2_uv_val = pu2_src[0];
230
231        for (col = -pad_size; col < 0; col++)
232        {
233            pu2_src[col] = u2_uv_val;
234        }
235
236        pu2_src += src_strd;
237    }
238}
239
240/**
241*******************************************************************************
242*
243* @brief pad (luma block) at the right of a 2d array
244*
245* @par Description:
246*  The right column of a 2d array is replicated for pad_size times at the right
247*
248* @param[in] pu1_src
249*  UWORD8 pointer to the source
250*
251* @param[in] src_strd
252*  integer source stride
253*
254* @param[in] ht
255*  integer height of the array
256*
257* @param[in] pad_size
258*  integer -padding size of the array
259*
260* @returns none
261*
262* @remarks none
263*
264*******************************************************************************
265*/
266void ih264_pad_right_luma(UWORD8 *pu1_src,
267                          WORD32 src_strd,
268                          WORD32 ht,
269                          WORD32 pad_size)
270{
271    WORD32 row;
272
273    for(row = 0; row < ht; row++)
274    {
275        memset(pu1_src, *(pu1_src -1), pad_size);
276
277        pu1_src += src_strd;
278    }
279}
280
281/**
282*******************************************************************************
283*
284* @brief pad (chroma block) at the right of a 2d array
285*
286* @par Description:
287*  The right column of a 2d array is replicated for pad_size times at the right
288*
289* @param[in] pu1_src
290*  UWORD8 pointer to the source
291*
292* @param[in] src_strd
293*  integer source stride
294*
295* @param[in] ht
296*  integer height of the array
297*
298* @param[in] pad_size
299*  integer -padding size of the array
300*
301* @returns none
302*
303* @remarks none
304*
305*******************************************************************************
306*/
307void ih264_pad_right_chroma(UWORD8 *pu1_src,
308                            WORD32 src_strd,
309                            WORD32 ht,
310                            WORD32 pad_size)
311{
312    WORD32 row, col;
313    UWORD16 u2_uv_val;
314    UWORD16 *pu2_src = (UWORD16 *)pu1_src;
315
316    src_strd >>= 1;
317    pad_size >>= 1;
318
319    for(row = 0; row < ht; row++)
320    {
321        u2_uv_val = pu2_src[-1];
322
323        for (col = 0; col < pad_size; col++)
324        {
325            pu2_src[col] = u2_uv_val;
326        }
327
328        pu2_src += src_strd;
329    }
330}
331
332