Home | History | Annotate | Download | only in generic
      1 /*
      2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 
     12 #include "vpx_scale/vpxscale.h"
     13 #include "vpx_mem/vpx_mem.h"
     14 /****************************************************************************
     15 *  Imports
     16 ****************************************************************************/
     17 
     18 /****************************************************************************
     19  *
     20  *  ROUTINE       : vp8cx_horizontal_line_4_5_scale_c
     21  *
     22  *  INPUTS        : const unsigned char *source : Pointer to source data.
     23  *                  unsigned int source_width    : Stride of source.
     24  *                  unsigned char *dest         : Pointer to destination data.
     25  *                  unsigned int dest_width      : Stride of destination (NOT USED).
     26  *
     27  *  OUTPUTS       : None.
     28  *
     29  *  RETURNS       : void
     30  *
     31  *  FUNCTION      : Copies horizontal line of pixels from source to
     32  *                  destination scaling up by 4 to 5.
     33  *
     34  *  SPECIAL NOTES : None.
     35  *
     36  ****************************************************************************/
     37 void vp8cx_horizontal_line_4_5_scale_c
     38 (
     39     const unsigned char *source,
     40     unsigned int source_width,
     41     unsigned char *dest,
     42     unsigned int dest_width
     43 )
     44 {
     45     unsigned i;
     46     unsigned int a, b, c;
     47     unsigned char *des = dest;
     48     const unsigned char *src = source;
     49 
     50     (void) dest_width;
     51 
     52     for (i = 0; i < source_width - 4; i += 4)
     53     {
     54         a = src[0];
     55         b = src[1];
     56         des [0] = (unsigned char) a;
     57         des [1] = (unsigned char)((a * 51 + 205 * b + 128) >> 8);
     58         c = src[2] * 154;
     59         a = src[3];
     60         des [2] = (unsigned char)((b * 102 + c + 128) >> 8);
     61         des [3] = (unsigned char)((c + 102 * a + 128) >> 8);
     62         b = src[4];
     63         des [4] = (unsigned char)((a * 205 + 51 * b + 128) >> 8);
     64 
     65         src += 4;
     66         des += 5;
     67     }
     68 
     69     a = src[0];
     70     b = src[1];
     71     des [0] = (unsigned char)(a);
     72     des [1] = (unsigned char)((a * 51 + 205 * b + 128) >> 8);
     73     c = src[2] * 154;
     74     a = src[3];
     75     des [2] = (unsigned char)((b * 102 + c + 128) >> 8);
     76     des [3] = (unsigned char)((c + 102 * a + 128) >> 8);
     77     des [4] = (unsigned char)(a);
     78 
     79 }
     80 
     81 /****************************************************************************
     82  *
     83  *  ROUTINE       : vp8cx_vertical_band_4_5_scale_c
     84  *
     85  *  INPUTS        : unsigned char *dest    : Pointer to destination data.
     86  *                  unsigned int dest_pitch : Stride of destination data.
     87  *                  unsigned int dest_width : Width of destination data.
     88  *
     89  *  OUTPUTS       : None.
     90  *
     91  *  RETURNS       : void
     92  *
     93  *  FUNCTION      : Scales vertical band of pixels by scale 4 to 5. The
     94  *                  height of the band scaled is 4-pixels.
     95  *
     96  *  SPECIAL NOTES : The routine uses the first line of the band below
     97  *                  the current band.
     98  *
     99  ****************************************************************************/
    100 void vp8cx_vertical_band_4_5_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    101 {
    102     unsigned int i;
    103     unsigned int a, b, c, d;
    104     unsigned char *des = dest;
    105 
    106     for (i = 0; i < dest_width; i++)
    107     {
    108         a = des [0];
    109         b = des [dest_pitch];
    110 
    111         des[dest_pitch] = (unsigned char)((a * 51 + 205 * b + 128) >> 8);
    112 
    113         c = des[dest_pitch*2] * 154;
    114         d = des[dest_pitch*3];
    115 
    116         des [dest_pitch*2] = (unsigned char)((b * 102 + c + 128) >> 8);
    117         des [dest_pitch*3] = (unsigned char)((c + 102 * d + 128) >> 8);
    118 
    119         /* First line in next band */
    120         a = des [dest_pitch * 5];
    121         des [dest_pitch * 4] = (unsigned char)((d * 205 + 51 * a + 128) >> 8);
    122 
    123         des ++;
    124     }
    125 }
    126 
    127 /****************************************************************************
    128  *
    129  *  ROUTINE       : vp8cx_last_vertical_band_4_5_scale_c
    130  *
    131  *  INPUTS        : unsigned char *dest    : Pointer to destination data.
    132  *                  unsigned int dest_pitch : Stride of destination data.
    133  *                  unsigned int dest_width : Width of destination data.
    134  *
    135  *  OUTPUTS       : None.
    136  *
    137  *  RETURNS       : void
    138  *
    139  *  FUNCTION      : Scales last vertical band of pixels by scale 4 to 5. The
    140  *                  height of the band scaled is 4-pixels.
    141  *
    142  *  SPECIAL NOTES : The routine does not have available the first line of
    143  *                  the band below the current band, since this is the
    144  *                  last band.
    145  *
    146  ****************************************************************************/
    147 void vp8cx_last_vertical_band_4_5_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    148 {
    149     unsigned int i;
    150     unsigned int a, b, c, d;
    151     unsigned char *des = dest;
    152 
    153     for (i = 0; i < dest_width; ++i)
    154     {
    155         a = des[0];
    156         b = des[dest_pitch];
    157 
    158         des[dest_pitch] = (unsigned char)((a * 51 + 205 * b + 128) >> 8);
    159 
    160         c = des[dest_pitch*2] * 154;
    161         d = des[dest_pitch*3];
    162 
    163         des [dest_pitch*2] = (unsigned char)((b * 102 + c + 128) >> 8);
    164         des [dest_pitch*3] = (unsigned char)((c + 102 * d + 128) >> 8);
    165 
    166         /* No other line for interplation of this line, so .. */
    167         des[dest_pitch*4] = (unsigned char) d;
    168 
    169         des++;
    170     }
    171 }
    172 
    173 /****************************************************************************
    174  *
    175  *  ROUTINE       : vp8cx_horizontal_line_2_3_scale_c
    176  *
    177  *  INPUTS        : const unsigned char *source : Pointer to source data.
    178  *                  unsigned int source_width    : Stride of source.
    179  *                  unsigned char *dest         : Pointer to destination data.
    180  *                  unsigned int dest_width      : Stride of destination (NOT USED).
    181  *
    182  *  OUTPUTS       : None.
    183  *
    184  *  RETURNS       : void
    185  *
    186  *  FUNCTION      : Copies horizontal line of pixels from source to
    187  *                  destination scaling up by 2 to 3.
    188  *
    189  *  SPECIAL NOTES : None.
    190  *
    191  *
    192  ****************************************************************************/
    193 void vp8cx_horizontal_line_2_3_scale_c
    194 (
    195     const unsigned char *source,
    196     unsigned int source_width,
    197     unsigned char *dest,
    198     unsigned int dest_width
    199 )
    200 {
    201     unsigned int i;
    202     unsigned int a, b, c;
    203     unsigned char *des = dest;
    204     const unsigned char *src = source;
    205 
    206     (void) dest_width;
    207 
    208     for (i = 0; i < source_width - 2; i += 2)
    209     {
    210         a = src[0];
    211         b = src[1];
    212         c = src[2];
    213 
    214         des [0] = (unsigned char)(a);
    215         des [1] = (unsigned char)((a * 85 + 171 * b + 128) >> 8);
    216         des [2] = (unsigned char)((b * 171 + 85 * c + 128) >> 8);
    217 
    218         src += 2;
    219         des += 3;
    220     }
    221 
    222     a = src[0];
    223     b = src[1];
    224     des [0] = (unsigned char)(a);
    225     des [1] = (unsigned char)((a * 85 + 171 * b + 128) >> 8);
    226     des [2] = (unsigned char)(b);
    227 }
    228 
    229 
    230 /****************************************************************************
    231  *
    232  *  ROUTINE       : vp8cx_vertical_band_2_3_scale_c
    233  *
    234  *  INPUTS        : unsigned char *dest    : Pointer to destination data.
    235  *                  unsigned int dest_pitch : Stride of destination data.
    236  *                  unsigned int dest_width : Width of destination data.
    237  *
    238  *  OUTPUTS       : None.
    239  *
    240  *  RETURNS       : void
    241  *
    242  *  FUNCTION      : Scales vertical band of pixels by scale 2 to 3. The
    243  *                  height of the band scaled is 2-pixels.
    244  *
    245  *  SPECIAL NOTES : The routine uses the first line of the band below
    246  *                  the current band.
    247  *
    248  ****************************************************************************/
    249 void vp8cx_vertical_band_2_3_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    250 {
    251     unsigned int i;
    252     unsigned int a, b, c;
    253     unsigned char *des = dest;
    254 
    255     for (i = 0; i < dest_width; i++)
    256     {
    257         a = des [0];
    258         b = des [dest_pitch];
    259         c = des[dest_pitch*3];
    260         des [dest_pitch  ] = (unsigned char)((a * 85 + 171 * b + 128) >> 8);
    261         des [dest_pitch*2] = (unsigned char)((b * 171 + 85 * c + 128) >> 8);
    262 
    263         des++;
    264     }
    265 }
    266 
    267 /****************************************************************************
    268  *
    269  *  ROUTINE       : vp8cx_last_vertical_band_2_3_scale_c
    270  *
    271  *  INPUTS        : unsigned char *dest    : Pointer to destination data.
    272  *                  unsigned int dest_pitch : Stride of destination data.
    273  *                  unsigned int dest_width : Width of destination data.
    274  *
    275  *  OUTPUTS       : None.
    276  *
    277  *  RETURNS       : void
    278  *
    279  *  FUNCTION      : Scales last vertical band of pixels by scale 2 to 3. The
    280  *                  height of the band scaled is 2-pixels.
    281  *
    282  *  SPECIAL NOTES : The routine does not have available the first line of
    283  *                  the band below the current band, since this is the
    284  *                  last band.
    285  *
    286  ****************************************************************************/
    287 void vp8cx_last_vertical_band_2_3_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    288 {
    289     unsigned int i;
    290     unsigned int a, b;
    291     unsigned char *des = dest;
    292 
    293     for (i = 0; i < dest_width; ++i)
    294     {
    295         a = des [0];
    296         b = des [dest_pitch];
    297 
    298         des [dest_pitch  ] = (unsigned char)((a * 85 + 171 * b + 128) >> 8);
    299         des [dest_pitch*2] = (unsigned char)(b);
    300         des++;
    301     }
    302 }
    303 
    304 /****************************************************************************
    305  *
    306  *  ROUTINE       : vp8cx_horizontal_line_3_5_scale_c
    307  *
    308  *  INPUTS        : const unsigned char *source : Pointer to source data.
    309  *                  unsigned int source_width    : Stride of source.
    310  *                  unsigned char *dest         : Pointer to destination data.
    311  *                  unsigned int dest_width      : Stride of destination (NOT USED).
    312  *
    313  *  OUTPUTS       : None.
    314  *
    315  *  RETURNS       : void
    316  *
    317  *  FUNCTION      : Copies horizontal line of pixels from source to
    318  *                  destination scaling up by 3 to 5.
    319  *
    320  *  SPECIAL NOTES : None.
    321  *
    322  *
    323  ****************************************************************************/
    324 void vp8cx_horizontal_line_3_5_scale_c
    325 (
    326     const unsigned char *source,
    327     unsigned int source_width,
    328     unsigned char *dest,
    329     unsigned int dest_width
    330 )
    331 {
    332     unsigned int i;
    333     unsigned int a, b, c;
    334     unsigned char *des = dest;
    335     const unsigned char *src = source;
    336 
    337     (void) dest_width;
    338 
    339     for (i = 0; i < source_width - 3; i += 3)
    340     {
    341         a = src[0];
    342         b = src[1];
    343         des [0] = (unsigned char)(a);
    344         des [1] = (unsigned char)((a * 102 + 154 * b + 128) >> 8);
    345 
    346         c = src[2] ;
    347         des [2] = (unsigned char)((b * 205 + c * 51 + 128) >> 8);
    348         des [3] = (unsigned char)((b * 51 + c * 205 + 128) >> 8);
    349 
    350         a = src[3];
    351         des [4] = (unsigned char)((c * 154 + a * 102 + 128) >> 8);
    352 
    353         src += 3;
    354         des += 5;
    355     }
    356 
    357     a = src[0];
    358     b = src[1];
    359     des [0] = (unsigned char)(a);
    360 
    361     des [1] = (unsigned char)((a * 102 + 154 * b + 128) >> 8);
    362     c = src[2] ;
    363     des [2] = (unsigned char)((b * 205 + c * 51 + 128) >> 8);
    364     des [3] = (unsigned char)((b * 51 + c * 205 + 128) >> 8);
    365 
    366     des [4] = (unsigned char)(c);
    367 }
    368 
    369 /****************************************************************************
    370  *
    371  *  ROUTINE       : vp8cx_vertical_band_3_5_scale_c
    372  *
    373  *  INPUTS        : unsigned char *dest    : Pointer to destination data.
    374  *                  unsigned int dest_pitch : Stride of destination data.
    375  *                  unsigned int dest_width : Width of destination data.
    376  *
    377  *  OUTPUTS       : None.
    378  *
    379  *  RETURNS       : void
    380  *
    381  *  FUNCTION      : Scales vertical band of pixels by scale 3 to 5. The
    382  *                  height of the band scaled is 3-pixels.
    383  *
    384  *  SPECIAL NOTES : The routine uses the first line of the band below
    385  *                  the current band.
    386  *
    387  ****************************************************************************/
    388 void vp8cx_vertical_band_3_5_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    389 {
    390     unsigned int i;
    391     unsigned int a, b, c;
    392     unsigned char *des = dest;
    393 
    394     for (i = 0; i < dest_width; i++)
    395     {
    396         a = des [0];
    397         b = des [dest_pitch];
    398         des [dest_pitch] = (unsigned char)((a * 102 + 154 * b + 128) >> 8);
    399 
    400         c = des[dest_pitch*2];
    401         des [dest_pitch*2] = (unsigned char)((b * 205 + c * 51 + 128) >> 8);
    402         des [dest_pitch*3] = (unsigned char)((b * 51 + c * 205 + 128) >> 8);
    403 
    404         /* First line in next band... */
    405         a = des [dest_pitch * 5];
    406         des [dest_pitch * 4] = (unsigned char)((c * 154 + a * 102 + 128) >> 8);
    407 
    408         des++;
    409     }
    410 }
    411 
    412 /****************************************************************************
    413  *
    414  *  ROUTINE       : vp8cx_last_vertical_band_3_5_scale_c
    415  *
    416  *  INPUTS        : unsigned char *dest    : Pointer to destination data.
    417  *                  unsigned int dest_pitch : Stride of destination data.
    418  *                  unsigned int dest_width : Width of destination data.
    419  *
    420  *  OUTPUTS       : None.
    421  *
    422  *  RETURNS       : void
    423  *
    424  *  FUNCTION      : Scales last vertical band of pixels by scale 3 to 5. The
    425  *                  height of the band scaled is 3-pixels.
    426  *
    427  *  SPECIAL NOTES : The routine does not have available the first line of
    428  *                  the band below the current band, since this is the
    429  *                  last band.
    430  *
    431  ****************************************************************************/
    432 void vp8cx_last_vertical_band_3_5_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    433 {
    434     unsigned int i;
    435     unsigned int a, b, c;
    436     unsigned char *des = dest;
    437 
    438     for (i = 0; i < dest_width; ++i)
    439     {
    440         a = des [0];
    441         b = des [dest_pitch];
    442 
    443         des [ dest_pitch ] = (unsigned char)((a * 102 + 154 * b + 128) >> 8);
    444 
    445         c = des[dest_pitch*2];
    446         des [dest_pitch*2] = (unsigned char)((b * 205 + c * 51 + 128) >> 8);
    447         des [dest_pitch*3] = (unsigned char)((b * 51 + c * 205 + 128) >> 8);
    448 
    449         /* No other line for interplation of this line, so .. */
    450         des [ dest_pitch * 4 ] = (unsigned char)(c) ;
    451 
    452         des++;
    453     }
    454 }
    455 
    456 /****************************************************************************
    457  *
    458  *  ROUTINE       : vp8cx_horizontal_line_3_4_scale_c
    459  *
    460  *  INPUTS        : const unsigned char *source : Pointer to source data.
    461  *                  unsigned int source_width    : Stride of source.
    462  *                  unsigned char *dest         : Pointer to destination data.
    463  *                  unsigned int dest_width      : Stride of destination (NOT USED).
    464  *
    465  *  OUTPUTS       : None.
    466  *
    467  *  RETURNS       : void
    468  *
    469  *  FUNCTION      : Copies horizontal line of pixels from source to
    470  *                  destination scaling up by 3 to 4.
    471  *
    472  *  SPECIAL NOTES : None.
    473  *
    474  *
    475  ****************************************************************************/
    476 void vp8cx_horizontal_line_3_4_scale_c
    477 (
    478     const unsigned char *source,
    479     unsigned int source_width,
    480     unsigned char *dest,
    481     unsigned int dest_width
    482 )
    483 {
    484     unsigned int i;
    485     unsigned int a, b, c;
    486     unsigned char *des = dest;
    487     const unsigned char *src = source;
    488 
    489     (void) dest_width;
    490 
    491     for (i = 0; i < source_width - 3; i += 3)
    492     {
    493         a = src[0];
    494         b = src[1];
    495         des [0] = (unsigned char)(a);
    496         des [1] = (unsigned char)((a * 64 + b * 192 + 128) >> 8);
    497 
    498         c = src[2];
    499         des [2] = (unsigned char)((b + c + 1) >> 1);
    500 
    501         a = src[3];
    502         des [3] = (unsigned char)((c * 192 + a * 64 + 128) >> 8);
    503 
    504         src += 3;
    505         des += 4;
    506     }
    507 
    508     a = src[0];
    509     b = src[1];
    510     des [0] = (unsigned char)(a);
    511     des [1] = (unsigned char)((a * 64 + b * 192 + 128) >> 8);
    512 
    513     c = src[2] ;
    514     des [2] = (unsigned char)((b + c + 1) >> 1);
    515     des [3] = (unsigned char)(c);
    516 }
    517 
    518 /****************************************************************************
    519  *
    520  *  ROUTINE       : vp8cx_vertical_band_3_4_scale_c
    521  *
    522  *  INPUTS        : unsigned char *dest    : Pointer to destination data.
    523  *                  unsigned int dest_pitch : Stride of destination data.
    524  *                  unsigned int dest_width : Width of destination data.
    525  *
    526  *  OUTPUTS       : None.
    527  *
    528  *  RETURNS       : void
    529  *
    530  *  FUNCTION      : Scales vertical band of pixels by scale 3 to 4. The
    531  *                  height of the band scaled is 3-pixels.
    532  *
    533  *  SPECIAL NOTES : The routine uses the first line of the band below
    534  *                  the current band.
    535  *
    536  ****************************************************************************/
    537 void vp8cx_vertical_band_3_4_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    538 {
    539     unsigned int i;
    540     unsigned int a, b, c;
    541     unsigned char *des = dest;
    542 
    543     for (i = 0; i < dest_width; i++)
    544     {
    545         a = des [0];
    546         b = des [dest_pitch];
    547         des [dest_pitch]   = (unsigned char)((a * 64 + b * 192 + 128) >> 8);
    548 
    549         c = des[dest_pitch*2];
    550         des [dest_pitch*2] = (unsigned char)((b + c + 1) >> 1);
    551 
    552         /* First line in next band... */
    553         a = des [dest_pitch*4];
    554         des [dest_pitch*3] = (unsigned char)((c * 192 + a * 64 + 128) >> 8);
    555 
    556         des++;
    557     }
    558 }
    559 
    560 /****************************************************************************
    561  *
    562  *  ROUTINE       : vp8cx_last_vertical_band_3_4_scale_c
    563  *
    564  *  INPUTS        : unsigned char *dest    : Pointer to destination data.
    565  *                  unsigned int dest_pitch : Stride of destination data.
    566  *                  unsigned int dest_width : Width of destination data.
    567  *
    568  *  OUTPUTS       : None.
    569  *
    570  *  RETURNS       : void
    571  *
    572  *  FUNCTION      : Scales last vertical band of pixels by scale 3 to 4. The
    573  *                  height of the band scaled is 3-pixels.
    574  *
    575  *  SPECIAL NOTES : The routine does not have available the first line of
    576  *                  the band below the current band, since this is the
    577  *                  last band.
    578  *
    579  ****************************************************************************/
    580 void vp8cx_last_vertical_band_3_4_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    581 {
    582     unsigned int i;
    583     unsigned int a, b, c;
    584     unsigned char *des = dest;
    585 
    586     for (i = 0; i < dest_width; ++i)
    587     {
    588         a = des [0];
    589         b = des [dest_pitch];
    590 
    591         des [dest_pitch]   = (unsigned char)((a * 64 + b * 192 + 128) >> 8);
    592 
    593         c = des[dest_pitch*2];
    594         des [dest_pitch*2] = (unsigned char)((b + c + 1) >> 1);
    595 
    596         /* No other line for interplation of this line, so .. */
    597         des [dest_pitch*3] = (unsigned char)(c);
    598 
    599         des++;
    600     }
    601 }
    602 
    603 /****************************************************************************
    604  *
    605  *  ROUTINE       : vp8cx_horizontal_line_1_2_scale_c
    606  *
    607  *  INPUTS        : const unsigned char *source : Pointer to source data.
    608  *                  unsigned int source_width    : Stride of source.
    609  *                  unsigned char *dest         : Pointer to destination data.
    610  *                  unsigned int dest_width      : Stride of destination (NOT USED).
    611  *
    612  *  OUTPUTS       : None.
    613  *
    614  *  RETURNS       : void
    615  *
    616  *  FUNCTION      : Copies horizontal line of pixels from source to
    617  *                  destination scaling up by 1 to 2.
    618  *
    619  *  SPECIAL NOTES : None.
    620  *
    621  ****************************************************************************/
    622 void vp8cx_horizontal_line_1_2_scale_c
    623 (
    624     const unsigned char *source,
    625     unsigned int source_width,
    626     unsigned char *dest,
    627     unsigned int dest_width
    628 )
    629 {
    630     unsigned int i;
    631     unsigned int a, b;
    632     unsigned char *des = dest;
    633     const unsigned char *src = source;
    634 
    635     (void) dest_width;
    636 
    637     for (i = 0; i < source_width - 1; i += 1)
    638     {
    639         a = src[0];
    640         b = src[1];
    641         des [0] = (unsigned char)(a);
    642         des [1] = (unsigned char)((a + b + 1) >> 1);
    643         src += 1;
    644         des += 2;
    645     }
    646 
    647     a = src[0];
    648     des [0] = (unsigned char)(a);
    649     des [1] = (unsigned char)(a);
    650 }
    651 
    652 /****************************************************************************
    653  *
    654  *  ROUTINE       : vp8cx_vertical_band_1_2_scale_c
    655  *
    656  *  INPUTS        : unsigned char *dest    : Pointer to destination data.
    657  *                  unsigned int dest_pitch : Stride of destination data.
    658  *                  unsigned int dest_width : Width of destination data.
    659  *
    660  *  OUTPUTS       : None.
    661  *
    662  *  RETURNS       : void
    663  *
    664  *  FUNCTION      : Scales vertical band of pixels by scale 1 to 2. The
    665  *                  height of the band scaled is 1-pixel.
    666  *
    667  *  SPECIAL NOTES : The routine uses the first line of the band below
    668  *                  the current band.
    669  *
    670  ****************************************************************************/
    671 void vp8cx_vertical_band_1_2_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    672 {
    673     unsigned int i;
    674     unsigned int a, b;
    675     unsigned char *des = dest;
    676 
    677     for (i = 0; i < dest_width; i++)
    678     {
    679         a = des [0];
    680         b = des [dest_pitch * 2];
    681 
    682         des[dest_pitch] = (unsigned char)((a + b + 1) >> 1);
    683 
    684         des++;
    685     }
    686 }
    687 
    688 /****************************************************************************
    689  *
    690  *  ROUTINE       : vp8cx_last_vertical_band_1_2_scale_c
    691  *
    692  *  INPUTS        : unsigned char *dest    : Pointer to destination data.
    693  *                  unsigned int dest_pitch : Stride of destination data.
    694  *                  unsigned int dest_width : Width of destination data.
    695  *
    696  *  OUTPUTS       : None.
    697  *
    698  *  RETURNS       : void
    699  *
    700  *  FUNCTION      : Scales last vertical band of pixels by scale 1 to 2. The
    701  *                  height of the band scaled is 1-pixel.
    702  *
    703  *  SPECIAL NOTES : The routine does not have available the first line of
    704  *                  the band below the current band, since this is the
    705  *                  last band.
    706  *
    707  ****************************************************************************/
    708 void vp8cx_last_vertical_band_1_2_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    709 {
    710     unsigned int i;
    711     unsigned char *des = dest;
    712 
    713     for (i = 0; i < dest_width; ++i)
    714     {
    715         des[dest_pitch] = des[0];
    716         des++;
    717     }
    718 }
    719 
    720 
    721 
    722 
    723 
    724 /****************************************************************************
    725  *
    726  *  ROUTINE       : vp8cx_horizontal_line_4_5_scale_c
    727  *
    728  *  INPUTS        : const unsigned char *source : Pointer to source data.
    729  *                  unsigned int source_width    : Stride of source.
    730  *                  unsigned char *dest         : Pointer to destination data.
    731  *                  unsigned int dest_width      : Stride of destination (NOT USED).
    732  *
    733  *  OUTPUTS       : None.
    734  *
    735  *  RETURNS       : void
    736  *
    737  *  FUNCTION      : Copies horizontal line of pixels from source to
    738  *                  destination scaling up by 4 to 5.
    739  *
    740  *  SPECIAL NOTES : None.
    741  *
    742  ****************************************************************************/
    743 void vp8cx_horizontal_line_5_4_scale_c
    744 (
    745     const unsigned char *source,
    746     unsigned int source_width,
    747     unsigned char *dest,
    748     unsigned int dest_width
    749 )
    750 {
    751     unsigned i;
    752     unsigned int a, b, c, d, e;
    753     unsigned char *des = dest;
    754     const unsigned char *src = source;
    755 
    756     (void) dest_width;
    757 
    758     for (i = 0; i < source_width; i += 5)
    759     {
    760         a = src[0];
    761         b = src[1];
    762         c = src[2];
    763         d = src[3];
    764         e = src[4];
    765 
    766         des[0] = (unsigned char) a;
    767         des[1] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
    768         des[2] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
    769         des[3] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);
    770 
    771         src += 5;
    772         des += 4;
    773     }
    774 }
    775 
    776 
    777 
    778 
    779 void vp8cx_vertical_band_5_4_scale_c(unsigned char *source, unsigned int src_pitch, unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    780 {
    781     unsigned int i;
    782     unsigned int a, b, c, d, e;
    783     unsigned char *des = dest;
    784     unsigned char *src = source;
    785 
    786     for (i = 0; i < dest_width; i++)
    787     {
    788 
    789         a = src[0 * src_pitch];
    790         b = src[1 * src_pitch];
    791         c = src[2 * src_pitch];
    792         d = src[3 * src_pitch];
    793         e = src[4 * src_pitch];
    794 
    795         des[0 * dest_pitch] = (unsigned char) a;
    796         des[1 * dest_pitch] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
    797         des[2 * dest_pitch] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
    798         des[3 * dest_pitch] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);
    799 
    800         src ++;
    801         des ++;
    802 
    803     }
    804 }
    805 
    806 
    807 /*7***************************************************************************
    808  *
    809  *  ROUTINE       : vp8cx_horizontal_line_3_5_scale_c
    810  *
    811  *  INPUTS        : const unsigned char *source : Pointer to source data.
    812  *                  unsigned int source_width    : Stride of source.
    813  *                  unsigned char *dest         : Pointer to destination data.
    814  *                  unsigned int dest_width      : Stride of destination (NOT USED).
    815  *
    816  *  OUTPUTS       : None.
    817  *
    818  *  RETURNS       : void
    819  *
    820  *  FUNCTION      : Copies horizontal line of pixels from source to
    821  *                  destination scaling up by 3 to 5.
    822  *
    823  *  SPECIAL NOTES : None.
    824  *
    825  *
    826  ****************************************************************************/
    827 void vp8cx_horizontal_line_5_3_scale_c
    828 (
    829     const unsigned char *source,
    830     unsigned int source_width,
    831     unsigned char *dest,
    832     unsigned int dest_width
    833 )
    834 {
    835     unsigned int i;
    836     unsigned int a, b, c, d , e;
    837     unsigned char *des = dest;
    838     const unsigned char *src = source;
    839 
    840     (void) dest_width;
    841 
    842     for (i = 0; i < source_width; i += 5)
    843     {
    844         a = src[0];
    845         b = src[1];
    846         c = src[2];
    847         d = src[3];
    848         e = src[4];
    849 
    850         des[0] = (unsigned char) a;
    851         des[1] = (unsigned char)((b * 85  + c * 171 + 128) >> 8);
    852         des[2] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
    853 
    854         src += 5;
    855         des += 3;
    856     }
    857 
    858 }
    859 
    860 void vp8cx_vertical_band_5_3_scale_c(unsigned char *source, unsigned int src_pitch, unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    861 {
    862     unsigned int i;
    863     unsigned int a, b, c, d, e;
    864     unsigned char *des = dest;
    865     unsigned char *src = source;
    866 
    867     for (i = 0; i < dest_width; i++)
    868     {
    869 
    870         a = src[0 * src_pitch];
    871         b = src[1 * src_pitch];
    872         c = src[2 * src_pitch];
    873         d = src[3 * src_pitch];
    874         e = src[4 * src_pitch];
    875 
    876         des[0 * dest_pitch] = (unsigned char) a;
    877         des[1 * dest_pitch] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
    878         des[2 * dest_pitch] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
    879 
    880         src ++;
    881         des ++;
    882 
    883     }
    884 }
    885 
    886 /****************************************************************************
    887  *
    888  *  ROUTINE       : vp8cx_horizontal_line_1_2_scale_c
    889  *
    890  *  INPUTS        : const unsigned char *source : Pointer to source data.
    891  *                  unsigned int source_width    : Stride of source.
    892  *                  unsigned char *dest         : Pointer to destination data.
    893  *                  unsigned int dest_width      : Stride of destination (NOT USED).
    894  *
    895  *  OUTPUTS       : None.
    896  *
    897  *  RETURNS       : void
    898  *
    899  *  FUNCTION      : Copies horizontal line of pixels from source to
    900  *                  destination scaling up by 1 to 2.
    901  *
    902  *  SPECIAL NOTES : None.
    903  *
    904  ****************************************************************************/
    905 void vp8cx_horizontal_line_2_1_scale_c
    906 (
    907     const unsigned char *source,
    908     unsigned int source_width,
    909     unsigned char *dest,
    910     unsigned int dest_width
    911 )
    912 {
    913     unsigned int i;
    914     unsigned int a;
    915     unsigned char *des = dest;
    916     const unsigned char *src = source;
    917 
    918     (void) dest_width;
    919 
    920     for (i = 0; i < source_width; i += 2)
    921     {
    922         a = src[0];
    923         des [0] = (unsigned char)(a);
    924         src += 2;
    925         des += 1;
    926     }
    927 
    928 
    929 
    930 }
    931 void vp8cx_vertical_band_2_1_scale_c(unsigned char *source, unsigned int src_pitch, unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    932 {
    933     (void) dest_pitch;
    934     (void) src_pitch;
    935     vpx_memcpy(dest, source, dest_width);
    936 }
    937 
    938 void vp8cx_vertical_band_2_1_scale_i_c(unsigned char *source, unsigned int src_pitch, unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
    939 {
    940     int i;
    941     int temp;
    942     int width = dest_width;
    943 
    944     (void) dest_pitch;
    945 
    946     for (i = 0; i < width; i++)
    947     {
    948         temp = 8;
    949         temp += source[i-(int)src_pitch] * 3;
    950         temp += source[i] * 10;
    951         temp += source[i+src_pitch] * 3;
    952         temp >>= 4 ;
    953         dest[i] = (unsigned char)(temp);
    954     }
    955 
    956 }
    957