summaryrefslogtreecommitdiffstats
path: root/common/ih264_padding.c
blob: 8e8f3e25abc5ed60cced9c893c084204875eeff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/******************************************************************************
 *
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *****************************************************************************
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/

/**
*******************************************************************************
* @file
*  ih264_padding.c
*
* @brief
*  Contains function definitions for Padding
*
* @author
*  Ittiam
*
* @par List of Functions:
*   - ih264_pad_top()
*   - ih264_pad_bottom()
*   - ih264_pad_left_luma()
*   - ih264_pad_left_chroma()
*   - ih264_pad_right_luma()
*   - ih264_pad_right_chroma()
*
* @remarks
*  None
*
*******************************************************************************
*/

/*****************************************************************************/
/* File Includes                                                             */
/*****************************************************************************/

/* System include files */
#include <stddef.h>
#include <string.h>

/* User include files */
#include "ih264_typedefs.h"
#include "ih264_macros.h"
#include "ih264_padding.h"


/*****************************************************************************/
/* Function Definitions                                                      */
/*****************************************************************************/

/**
*******************************************************************************
*
* @brief pad at the top of a 2d array
*
* @par Description:
*  The top row of a 2d array is replicated for pad_size times at the top
*
* @param[in] pu1_src
*  UWORD8 pointer to the source
*
* @param[in] src_strd
*  integer source stride
*
* @param[in] wd
*  integer width of the array
*
* @param[in] pad_size
*  integer -padding size of the array
*
* @returns none
*
* @remarks none
*
*******************************************************************************
*/
void ih264_pad_top(UWORD8 *pu1_src,
                   WORD32 src_strd,
                   WORD32 wd,
                   WORD32 pad_size)
{
    WORD32 row;

    for(row = 1; row <= pad_size; row++)
    {
        memcpy(pu1_src - row * src_strd, pu1_src, wd);
    }
}



/**
*******************************************************************************
*
* @brief pad at the bottom of a 2d array
*
* @par Description:
*  The bottom row of a 2d array is replicated for pad_size times at the bottom
*
* @param[in] pu1_src
*  UWORD8 pointer to the source
*
* @param[in] src_strd
*  integer source stride
*
* @param[in] wd
*  integer width of the array
*
* @param[in] pad_size
*  integer -padding size of the array
*
* @returns none
*
* @remarks none
*
*******************************************************************************
*/
void ih264_pad_bottom(UWORD8 *pu1_src,
                      WORD32 src_strd,
                      WORD32 wd,
                      WORD32 pad_size)
{
    WORD32 row;

    for(row = 1; row <= pad_size; row++)
    {
        memcpy(pu1_src + (row - 1) * src_strd, pu1_src - 1 * src_strd, wd);
    }
}

/**
*******************************************************************************
*
* @brief pad (luma block) at the left of a 2d array
*
* @par Description:
*   The left column of a 2d array is replicated for pad_size times to the left
*
* @param[in] pu1_src
*  UWORD8 pointer to the source
*
* @param[in] src_strd
*  integer source stride
*
* @param[in] ht
*  integer height of the array
*
* @param[in] pad_size
*  integer -padding size of the array
*
* @returns none
*
* @remarks none
*
*******************************************************************************
 */
void ih264_pad_left_luma(UWORD8 *pu1_src,
                         WORD32 src_strd,
                         WORD32 ht,
                         WORD32 pad_size)
{
    WORD32 row;

    for(row = 0; row < ht; row++)
    {

        memset(pu1_src - pad_size, *pu1_src, pad_size);

        pu1_src += src_strd;
    }
}

/**
*******************************************************************************
*
* @brief pad (chroma block) at the left of a 2d array
*
* @par Description:
*   The left column of a 2d array is replicated for pad_size times to the left
*
* @param[in] pu1_src
*  UWORD8 pointer to the source
*
* @param[in] src_strd
*  integer source stride
*
* @param[in] ht
*  integer height of the array
*
* @param[in] pad_size
*  integer -padding size of the array
*
* @returns none
*
* @remarks none
*
*******************************************************************************
*/
void ih264_pad_left_chroma(UWORD8 *pu1_src,
                           WORD32 src_strd,
                           WORD32 ht,
                           WORD32 pad_size)
{
    /* temp var */
    WORD32 row, col;
    UWORD16 u2_uv_val;

    /* pointer to src */
    UWORD16 *pu2_src = (UWORD16 *)pu1_src;

    src_strd >>= 1;
    pad_size >>= 1;

    for(row = 0; row < ht; row++)
    {
        u2_uv_val = pu2_src[0];

        for (col = -pad_size; col < 0; col++)
        {
            pu2_src[col] = u2_uv_val;
        }

        pu2_src += src_strd;
    }
}

/**
*******************************************************************************
*
* @brief pad (luma block) at the right of a 2d array
*
* @par Description:
*  The right column of a 2d array is replicated for pad_size times at the right
*
* @param[in] pu1_src
*  UWORD8 pointer to the source
*
* @param[in] src_strd
*  integer source stride
*
* @param[in] ht
*  integer height of the array
*
* @param[in] pad_size
*  integer -padding size of the array
*
* @returns none
*
* @remarks none
*
*******************************************************************************
*/
void ih264_pad_right_luma(UWORD8 *pu1_src,
                          WORD32 src_strd,
                          WORD32 ht,
                          WORD32 pad_size)
{
    WORD32 row;

    for(row = 0; row < ht; row++)
    {
        memset(pu1_src, *(pu1_src -1), pad_size);

        pu1_src += src_strd;
    }
}

/**
*******************************************************************************
*
* @brief pad (chroma block) at the right of a 2d array
*
* @par Description:
*  The right column of a 2d array is replicated for pad_size times at the right
*
* @param[in] pu1_src
*  UWORD8 pointer to the source
*
* @param[in] src_strd
*  integer source stride
*
* @param[in] ht
*  integer height of the array
*
* @param[in] pad_size
*  integer -padding size of the array
*
* @returns none
*
* @remarks none
*
*******************************************************************************
*/
void ih264_pad_right_chroma(UWORD8 *pu1_src,
                            WORD32 src_strd,
                            WORD32 ht,
                            WORD32 pad_size)
{
    WORD32 row, col;
    UWORD16 u2_uv_val;
    UWORD16 *pu2_src = (UWORD16 *)pu1_src;

    src_strd >>= 1;
    pad_size >>= 1;

    for(row = 0; row < ht; row++)
    {
        u2_uv_val = pu2_src[-1];

        for (col = 0; col < pad_size; col++)
        {
            pu2_src[col] = u2_uv_val;
        }

        pu2_src += src_strd;
    }
}