summaryrefslogtreecommitdiffstats
path: root/third_party/aom/aom_scale/generic/gen_scalers.c
blob: 549e2aa69099adcfb1f83c935b76116bcdb918b6 (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
/*
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
 *
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
 */

#include "config/aom_scale_rtcd.h"

#include "aom_scale/aom_scale.h"
#include "aom_mem/aom_mem.h"
/****************************************************************************
 *  Imports
 ****************************************************************************/

/****************************************************************************
 *
 *
 *  INPUTS        : const unsigned char *source : Pointer to source data.
 *                  unsigned int source_width   : Stride of source.
 *                  unsigned char *dest         : Pointer to destination data.
 *                  unsigned int dest_width     : Stride of destination
 *                                                (NOT USED).
 *
 *  OUTPUTS       : None.
 *
 *  RETURNS       : void
 *
 *  FUNCTION      : Copies horizontal line of pixels from source to
 *                  destination scaling up by 4 to 5.
 *
 *  SPECIAL NOTES : None.
 *
 ****************************************************************************/
void aom_horizontal_line_5_4_scale_c(const unsigned char *source,
                                     unsigned int source_width,
                                     unsigned char *dest,
                                     unsigned int dest_width) {
  const unsigned char *const source_end = source + source_width;
  (void)dest_width;

  while (source < source_end) {
    const unsigned int a = source[0];
    const unsigned int b = source[1];
    const unsigned int c = source[2];
    const unsigned int d = source[3];
    const unsigned int e = source[4];

    dest[0] = (unsigned char)a;
    dest[1] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
    dest[2] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
    dest[3] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);

    source += 5;
    dest += 4;
  }
}

void aom_vertical_band_5_4_scale_c(unsigned char *source, int src_pitch,
                                   unsigned char *dest, int dest_pitch,
                                   unsigned int dest_width) {
  const unsigned char *const dest_end = dest + dest_width;
  while (dest < dest_end) {
    const unsigned int a = source[0 * src_pitch];
    const unsigned int b = source[1 * src_pitch];
    const unsigned int c = source[2 * src_pitch];
    const unsigned int d = source[3 * src_pitch];
    const unsigned int e = source[4 * src_pitch];

    dest[0 * dest_pitch] = (unsigned char)a;
    dest[1 * dest_pitch] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
    dest[2 * dest_pitch] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
    dest[3 * dest_pitch] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);

    ++source;
    ++dest;
  }
}

/*7***************************************************************************
 *
 *  ROUTINE       : aom_horizontal_line_3_5_scale_c
 *
 *  INPUTS        : const unsigned char *source : Pointer to source data.
 *                  unsigned int source_width   : Stride of source.
 *                  unsigned char *dest         : Pointer to destination data.
 *                  unsigned int dest_width     : Stride of destination
 *                                                (NOT USED).
 *
 *  OUTPUTS       : None.
 *
 *  RETURNS       : void
 *
 *  FUNCTION      : Copies horizontal line of pixels from source to
 *                  destination scaling up by 3 to 5.
 *
 *  SPECIAL NOTES : None.
 *
 *
 ****************************************************************************/
void aom_horizontal_line_5_3_scale_c(const unsigned char *source,
                                     unsigned int source_width,
                                     unsigned char *dest,
                                     unsigned int dest_width) {
  const unsigned char *const source_end = source + source_width;
  (void)dest_width;
  while (source < source_end) {
    const unsigned int a = source[0];
    const unsigned int b = source[1];
    const unsigned int c = source[2];
    const unsigned int d = source[3];
    const unsigned int e = source[4];

    dest[0] = (unsigned char)a;
    dest[1] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
    dest[2] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);

    source += 5;
    dest += 3;
  }
}

void aom_vertical_band_5_3_scale_c(unsigned char *source, int src_pitch,
                                   unsigned char *dest, int dest_pitch,
                                   unsigned int dest_width) {
  const unsigned char *const dest_end = dest + dest_width;
  while (dest < dest_end) {
    const unsigned int a = source[0 * src_pitch];
    const unsigned int b = source[1 * src_pitch];
    const unsigned int c = source[2 * src_pitch];
    const unsigned int d = source[3 * src_pitch];
    const unsigned int e = source[4 * src_pitch];

    dest[0 * dest_pitch] = (unsigned char)a;
    dest[1 * dest_pitch] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
    dest[2 * dest_pitch] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);

    ++source;
    ++dest;
  }
}

/****************************************************************************
 *
 *  ROUTINE       : aom_horizontal_line_1_2_scale_c
 *
 *  INPUTS        : const unsigned char *source : Pointer to source data.
 *                  unsigned int source_width   : Stride of source.
 *                  unsigned char *dest         : Pointer to destination data.
 *                  unsigned int dest_width     : Stride of destination
 *                                                (NOT USED).
 *
 *  OUTPUTS       : None.
 *
 *  RETURNS       : void
 *
 *  FUNCTION      : Copies horizontal line of pixels from source to
 *                  destination scaling up by 1 to 2.
 *
 *  SPECIAL NOTES : None.
 *
 ****************************************************************************/
void aom_horizontal_line_2_1_scale_c(const unsigned char *source,
                                     unsigned int source_width,
                                     unsigned char *dest,
                                     unsigned int dest_width) {
  const unsigned char *const source_end = source + source_width;
  (void)dest_width;
  while (source < source_end) {
    dest[0] = source[0];
    source += 2;
    ++dest;
  }
}

void aom_vertical_band_2_1_scale_c(unsigned char *source, int src_pitch,
                                   unsigned char *dest, int dest_pitch,
                                   unsigned int dest_width) {
  (void)dest_pitch;
  (void)src_pitch;
  memcpy(dest, source, dest_width);
}

void aom_vertical_band_2_1_scale_i_c(unsigned char *source, int src_pitch,
                                     unsigned char *dest, int dest_pitch,
                                     unsigned int dest_width) {
  const unsigned char *const dest_end = dest + dest_width;
  (void)dest_pitch;
  while (dest < dest_end) {
    const unsigned int a = source[-src_pitch] * 3;
    const unsigned int b = source[0] * 10;
    const unsigned int c = source[src_pitch] * 3;
    dest[0] = (unsigned char)((8 + a + b + c) >> 4);
    ++source;
    ++dest;
  }
}