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