Home | History | Annotate | Download | only in common
      1 /******************************************************************************
      2 *
      3 * Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
      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 /**
     19 *******************************************************************************
     20 * @file
     21 *  ihevc_padding.c
     22 *
     23 * @brief
     24 *  Contains function definitions for Padding
     25 *
     26 * @author
     27 *  Srinivas T
     28 *
     29 * @par List of Functions:
     30 *   - ihevc_pad_horz_luma()
     31 *   - ihevc_pad_horz_chroma()
     32 *   - ihevc_pad_vert()
     33 *   - ihevc_pad_left_luma()
     34 *   - ihevc_pad_left_chroma()
     35 *   - ihevc_pad_right_luma()
     36 *   - ihevc_pad_right_chroma()
     37 *   - ihevc_pad_top()
     38 *   - ihevc_pad_bottom()
     39 *
     40 * @remarks
     41 *  None
     42 *
     43 *******************************************************************************
     44 */
     45 
     46 #include <string.h>
     47 #include "ihevc_typedefs.h"
     48 #include "ihevc_func_selector.h"
     49 #include "ihevc_platform_macros.h"
     50 #include "ihevc_mem_fns.h"
     51 /**
     52 *******************************************************************************
     53 *
     54 * @brief
     55 *       Padding function for horizontal input variable
     56 *
     57 * @par Description:
     58 *
     59 *
     60 * @param[in] pu1_src
     61 *  UWORD8 pointer to the source
     62 *
     63 * @param[in] src_strd
     64 *  integer source stride
     65 *
     66 * @param[in] ht
     67 *  integer height of the array
     68 *
     69 * @param[in] wd
     70 *  integer width of the array
     71 *
     72 * @param[in] pad_size
     73 *  integer -padding size of the array
     74 *
     75 * @param[in] ht
     76 *  integer height of the array
     77 *
     78 * @param[in] wd
     79 *  integer width of the array
     80 *
     81 * @returns
     82 *
     83 * @remarks
     84 *  None
     85 *
     86 *******************************************************************************
     87 */
     88 
     89 void ihevc_pad_vert(UWORD8 *pu1_src,
     90                     WORD32 src_strd,
     91                     WORD32 ht,
     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         memcpy(pu1_src + (ht + row - 1) * src_strd,
    101                pu1_src + (ht - 1) * src_strd, wd);
    102     }
    103 }
    104 
    105 /**
    106 *******************************************************************************
    107 *
    108 * @brief
    109 *   Padding function for vertical input variable
    110 *
    111 * @par Description:
    112 *
    113 *
    114 * @param[in] pu1_src
    115 *  UWORD8 pointer to the source
    116 *
    117 * @param[in] src_strd
    118 *  integer source stride
    119 *
    120 * @param[in] ht
    121 *  integer height of the array
    122 *
    123 * @param[in] wd
    124 *  integer width of the array
    125 *
    126 * @param[in] pad_size
    127 *  integer -padding size of the array
    128 *
    129 * @param[in] ht
    130 *  integer height of the array
    131 *
    132 * @param[in] wd
    133 *  integer width of the array
    134 *
    135 * @returns
    136 *
    137 * @remarks
    138 *  None
    139 *
    140 *******************************************************************************
    141 */
    142 
    143 void ihevc_pad_horz_chroma(UWORD8 *pu1_src,
    144                            WORD32 src_strd,
    145                            WORD32 ht,
    146                            WORD32 wd,
    147                            WORD32 pad_size)
    148 {
    149     WORD32 row;
    150     //WORD32 col;
    151     UWORD16 *pu2_src = (UWORD16 *)pu1_src;
    152 
    153     src_strd >>= 1;
    154     wd >>= 1;
    155     pad_size >>= 1;
    156 
    157     for(row = 0; row < ht; row++)
    158     {
    159         UWORD16 u2_uv_val;
    160 
    161         u2_uv_val = pu2_src[0];
    162         ihevc_memset_16bit(&pu2_src[-pad_size], u2_uv_val, pad_size);
    163 
    164         u2_uv_val = pu2_src[wd - 1];
    165         ihevc_memset_16bit(&pu2_src[wd], u2_uv_val, pad_size);
    166 
    167         pu2_src += src_strd;
    168     }
    169 }
    170 
    171 
    172 /**
    173 *******************************************************************************
    174 *
    175 * @brief
    176 *   Padding function for vertical input variable
    177 *
    178 * @par Description:
    179 *
    180 *
    181 * @param[in] pu1_src
    182 *  UWORD8 pointer to the source
    183 *
    184 * @param[in] src_strd
    185 *  integer source stride
    186 *
    187 * @param[in] ht
    188 *  integer height of the array
    189 *
    190 * @param[in] wd
    191 *  integer width of the array
    192 *
    193 * @param[in] pad_size
    194 *  integer -padding size of the array
    195 *
    196 * @param[in] ht
    197 *  integer height of the array
    198 *
    199 * @param[in] wd
    200 *  integer width of the array
    201 *
    202 * @returns
    203 *
    204 * @remarks
    205 *  None
    206 *
    207 *******************************************************************************
    208 */
    209 
    210 void ihevc_pad_horz_luma(UWORD8 *pu1_src,
    211                          WORD32 src_strd,
    212                          WORD32 ht,
    213                          WORD32 wd,
    214                          WORD32 pad_size)
    215 {
    216     WORD32 row;
    217 
    218     for(row = 0; row < ht; row++)
    219     {
    220         memset(pu1_src - pad_size, *pu1_src, pad_size);
    221         memset(pu1_src + wd, *(pu1_src + wd - 1), pad_size);
    222 
    223         pu1_src += src_strd;
    224     }
    225 }
    226 
    227 
    228 
    229 /**
    230 *******************************************************************************
    231 *
    232 * @brief
    233 *       Padding at the top of a 2d array
    234 *
    235 * @par Description:
    236 *       The top row of a 2d array is replicated for pad_size times at the top
    237 *
    238 *
    239 * @param[in] pu1_src
    240 *  UWORD8 pointer to the source
    241 *
    242 * @param[in] src_strd
    243 *  integer source stride
    244 *
    245 * @param[in] ht
    246 *  integer height of the array
    247 *
    248 * @param[in] wd
    249 *  integer width of the array
    250 *
    251 * @param[in] pad_size
    252 *  integer -padding size of the array
    253 *
    254 * @param[in] ht
    255 *  integer height of the array
    256 *
    257 * @param[in] wd
    258 *  integer width of the array
    259 *
    260 * @returns
    261 *
    262 * @remarks
    263 *  None
    264 *
    265 *******************************************************************************
    266 */
    267 
    268 void ihevc_pad_top(UWORD8 *pu1_src,
    269                    WORD32 src_strd,
    270                    WORD32 wd,
    271                    WORD32 pad_size)
    272 {
    273     WORD32 row;
    274 
    275     for(row = 1; row <= pad_size; row++)
    276     {
    277         memcpy(pu1_src - row * src_strd, pu1_src, wd);
    278     }
    279 }
    280 
    281 
    282 
    283 /**
    284 *******************************************************************************
    285 *
    286 * @brief
    287 *   Padding at the bottom of a 2d array
    288 *
    289 * @par Description:
    290 *   The bottom row of a 2d array is replicated for pad_size times at the bottom
    291 *
    292 *
    293 * @param[in] pu1_src
    294 *  UWORD8 pointer to the source
    295 *
    296 * @param[in] src_strd
    297 *  integer source stride
    298 *
    299 * @param[in] ht
    300 *  integer height of the array
    301 *
    302 * @param[in] wd
    303 *  integer width of the array
    304 *
    305 * @param[in] pad_size
    306 *  integer -padding size of the array
    307 *
    308 * @param[in] ht
    309 *  integer height of the array
    310 *
    311 * @param[in] wd
    312 *  integer width of the array
    313 *
    314 * @returns
    315 *
    316 * @remarks
    317 *  None
    318 *
    319 *******************************************************************************
    320 */
    321 
    322 void ihevc_pad_bottom(UWORD8 *pu1_src,
    323                       WORD32 src_strd,
    324                       WORD32 wd,
    325                       WORD32 pad_size)
    326 {
    327     WORD32 row;
    328 
    329     for(row = 1; row <= pad_size; row++)
    330     {
    331         memcpy(pu1_src + (row - 1) * src_strd,
    332                pu1_src - 1 * src_strd, wd);
    333     }
    334 }
    335 
    336 
    337 
    338 /**
    339 *******************************************************************************
    340 *
    341 * @brief
    342 *   Padding (luma block) at the left of a 2d array
    343 *
    344 * @par Description:
    345 *   The left column of a 2d array is replicated for pad_size times at the left
    346 *
    347 *
    348 * @param[in] pu1_src
    349 *  UWORD8 pointer to the source
    350 *
    351 * @param[in] src_strd
    352 *  integer source stride
    353 *
    354 * @param[in] ht
    355 *  integer height of the array
    356 *
    357 * @param[in] wd
    358 *  integer width of the array
    359 *
    360 * @param[in] pad_size
    361 *  integer -padding size of the array
    362 *
    363 * @param[in] ht
    364 *  integer height of the array
    365 *
    366 * @param[in] wd
    367 *  integer width of the array
    368 *
    369 * @returns
    370 *
    371 * @remarks
    372 *  None
    373 *
    374 *******************************************************************************
    375 */
    376 
    377 void ihevc_pad_left_luma(UWORD8 *pu1_src,
    378                          WORD32 src_strd,
    379                          WORD32 ht,
    380                          WORD32 pad_size)
    381 {
    382     WORD32 row;
    383 
    384     for(row = 0; row < ht; row++)
    385     {
    386         memset(pu1_src - pad_size, *pu1_src, pad_size);
    387 
    388         pu1_src += src_strd;
    389     }
    390 }
    391 
    392 
    393 
    394 /**
    395 *******************************************************************************
    396 *
    397 * @brief
    398 *   Padding (chroma block) at the left of a 2d array
    399 *
    400 * @par Description:
    401 *   The left column of a 2d array is replicated for pad_size times at the left
    402 *
    403 *
    404 * @param[in] pu1_src
    405 *  UWORD8 pointer to the source
    406 *
    407 * @param[in] src_strd
    408 *  integer source stride
    409 *
    410 * @param[in] ht
    411 *  integer height of the array
    412 *
    413 * @param[in] wd
    414 *  integer width of the array (each colour component)
    415 *
    416 * @param[in] pad_size
    417 *  integer -padding size of the array
    418 *
    419 * @param[in] ht
    420 *  integer height of the array
    421 *
    422 * @param[in] wd
    423 *  integer width of the array
    424 *
    425 * @returns
    426 *
    427 * @remarks
    428 *  None
    429 *
    430 *******************************************************************************
    431 */
    432 
    433 void ihevc_pad_left_chroma(UWORD8 *pu1_src,
    434                            WORD32 src_strd,
    435                            WORD32 ht,
    436                            WORD32 pad_size)
    437 {
    438     WORD32 row;
    439     WORD32 col;
    440     UWORD16 *pu2_src = (UWORD16 *)pu1_src;
    441 
    442     src_strd >>= 1;
    443     pad_size >>= 1;
    444 
    445     for(row = 0; row < ht; row++)
    446     {
    447         UWORD16 u2_uv_val;
    448 
    449         u2_uv_val = pu2_src[0];
    450         for(col = -pad_size; col < 0; col++)
    451             pu2_src[col] = u2_uv_val;
    452 
    453         pu2_src += src_strd;
    454     }
    455 }
    456 
    457 
    458 
    459 /**
    460 *******************************************************************************
    461 *
    462 * @brief
    463 * Padding (luma block) at the right of a 2d array
    464 *
    465 * @par Description:
    466 * The right column of a 2d array is replicated for pad_size times at the right
    467 *
    468 *
    469 * @param[in] pu1_src
    470 *  UWORD8 pointer to the source
    471 *
    472 * @param[in] src_strd
    473 *  integer source stride
    474 *
    475 * @param[in] ht
    476 *  integer height of the array
    477 *
    478 * @param[in] wd
    479 *  integer width of the array
    480 *
    481 * @param[in] pad_size
    482 *  integer -padding size of the array
    483 *
    484 * @param[in] ht
    485 *  integer height of the array
    486 *
    487 * @param[in] wd
    488 *  integer width of the array
    489 *
    490 * @returns
    491 *
    492 * @remarks
    493 *  None
    494 *
    495 *******************************************************************************
    496 */
    497 
    498 void ihevc_pad_right_luma(UWORD8 *pu1_src,
    499                           WORD32 src_strd,
    500                           WORD32 ht,
    501                           WORD32 pad_size)
    502 {
    503     WORD32 row;
    504 
    505     for(row = 0; row < ht; row++)
    506     {
    507         memset(pu1_src, *(pu1_src - 1), pad_size);
    508 
    509         pu1_src += src_strd;
    510     }
    511 }
    512 
    513 
    514 
    515 /**
    516 *******************************************************************************
    517 *
    518 * @brief
    519 * Padding (chroma block) at the right of a 2d array
    520 *
    521 * @par Description:
    522 * The right column of a 2d array is replicated for pad_size times at the right
    523 *
    524 *
    525 * @param[in] pu1_src
    526 *  UWORD8 pointer to the source
    527 *
    528 * @param[in] src_strd
    529 *  integer source stride
    530 *
    531 * @param[in] ht
    532 *  integer height of the array
    533 *
    534 * @param[in] wd
    535 *  integer width of the array (each colour component)
    536 *
    537 * @param[in] pad_size
    538 *  integer -padding size of the array
    539 *
    540 * @param[in] ht
    541 *  integer height of the array
    542 *
    543 * @param[in] wd
    544 *  integer width of the array
    545 *
    546 * @returns
    547 *
    548 * @remarks
    549 *  None
    550 *
    551 *******************************************************************************
    552 */
    553 
    554 void ihevc_pad_right_chroma(UWORD8 *pu1_src,
    555                             WORD32 src_strd,
    556                             WORD32 ht,
    557                             WORD32 pad_size)
    558 {
    559     WORD32 row;
    560     WORD32 col;
    561     UWORD16 *pu2_src = (UWORD16 *)pu1_src;
    562 
    563     src_strd >>= 1;
    564     pad_size >>= 1;
    565 
    566     for(row = 0; row < ht; row++)
    567     {
    568         UWORD16 u2_uv_val;
    569 
    570         u2_uv_val = pu2_src[-1];
    571         for(col = 0; col < pad_size; col++)
    572             pu2_src[col] = u2_uv_val;
    573 
    574         pu2_src += src_strd;
    575     }
    576 }
    577 
    578