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 #include "./vpx_scale_rtcd.h"
12 #include "vpx_scale/vpx_scale.h"
13 #include "vpx_mem/vpx_mem.h"
14 /****************************************************************************
15 * Imports
16 ****************************************************************************/
17
18 /****************************************************************************
19 *
20 *
21 * INPUTS : const unsigned char *source : Pointer to source data.
22 * unsigned int source_width : Stride of source.
23 * unsigned char *dest : Pointer to destination data.
24 * unsigned int dest_width : Stride of dest (UNUSED).
25 *
26 * OUTPUTS : None.
27 *
28 * RETURNS : void
29 *
30 * FUNCTION : Copies horizontal line of pixels from source to
31 * destination scaling up by 4 to 5.
32 *
33 * SPECIAL NOTES : None.
34 *
35 ****************************************************************************/
vp8_horizontal_line_5_4_scale_c(const unsigned char * source,unsigned int source_width,unsigned char * dest,unsigned int dest_width)36 void vp8_horizontal_line_5_4_scale_c(const unsigned char *source,
37 unsigned int source_width,
38 unsigned char *dest,
39 unsigned int dest_width) {
40 unsigned i;
41 unsigned int a, b, c, d, e;
42 unsigned char *des = dest;
43 const unsigned char *src = source;
44
45 (void)dest_width;
46
47 for (i = 0; i < source_width; i += 5) {
48 a = src[0];
49 b = src[1];
50 c = src[2];
51 d = src[3];
52 e = src[4];
53
54 des[0] = (unsigned char)a;
55 des[1] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
56 des[2] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
57 des[3] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);
58
59 src += 5;
60 des += 4;
61 }
62 }
63
vp8_vertical_band_5_4_scale_c(unsigned char * source,unsigned int src_pitch,unsigned char * dest,unsigned int dest_pitch,unsigned int dest_width)64 void vp8_vertical_band_5_4_scale_c(unsigned char *source,
65 unsigned int src_pitch, unsigned char *dest,
66 unsigned int dest_pitch,
67 unsigned int dest_width) {
68 unsigned int i;
69 unsigned int a, b, c, d, e;
70 unsigned char *des = dest;
71 unsigned char *src = source;
72
73 for (i = 0; i < dest_width; i++) {
74 a = src[0 * src_pitch];
75 b = src[1 * src_pitch];
76 c = src[2 * src_pitch];
77 d = src[3 * src_pitch];
78 e = src[4 * src_pitch];
79
80 des[0 * dest_pitch] = (unsigned char)a;
81 des[1 * dest_pitch] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
82 des[2 * dest_pitch] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
83 des[3 * dest_pitch] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);
84
85 src++;
86 des++;
87 }
88 }
89
90 /*7***************************************************************************
91 *
92 * ROUTINE : vp8_horizontal_line_3_5_scale_c
93 *
94 * INPUTS : const unsigned char *source : Pointer to source data.
95 * unsigned int source_width : Stride of source.
96 * unsigned char *dest : Pointer to destination data.
97 * unsigned int dest_width : Stride of dest (UNUSED).
98 *
99 * OUTPUTS : None.
100 *
101 * RETURNS : void
102 *
103 * FUNCTION : Copies horizontal line of pixels from source to
104 * destination scaling up by 3 to 5.
105 *
106 * SPECIAL NOTES : None.
107 *
108 *
109 ****************************************************************************/
vp8_horizontal_line_5_3_scale_c(const unsigned char * source,unsigned int source_width,unsigned char * dest,unsigned int dest_width)110 void vp8_horizontal_line_5_3_scale_c(const unsigned char *source,
111 unsigned int source_width,
112 unsigned char *dest,
113 unsigned int dest_width) {
114 unsigned int i;
115 unsigned int a, b, c, d, e;
116 unsigned char *des = dest;
117 const unsigned char *src = source;
118
119 (void)dest_width;
120
121 for (i = 0; i < source_width; i += 5) {
122 a = src[0];
123 b = src[1];
124 c = src[2];
125 d = src[3];
126 e = src[4];
127
128 des[0] = (unsigned char)a;
129 des[1] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
130 des[2] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
131
132 src += 5;
133 des += 3;
134 }
135 }
136
vp8_vertical_band_5_3_scale_c(unsigned char * source,unsigned int src_pitch,unsigned char * dest,unsigned int dest_pitch,unsigned int dest_width)137 void vp8_vertical_band_5_3_scale_c(unsigned char *source,
138 unsigned int src_pitch, unsigned char *dest,
139 unsigned int dest_pitch,
140 unsigned int dest_width) {
141 unsigned int i;
142 unsigned int a, b, c, d, e;
143 unsigned char *des = dest;
144 unsigned char *src = source;
145
146 for (i = 0; i < dest_width; i++) {
147 a = src[0 * src_pitch];
148 b = src[1 * src_pitch];
149 c = src[2 * src_pitch];
150 d = src[3 * src_pitch];
151 e = src[4 * src_pitch];
152
153 des[0 * dest_pitch] = (unsigned char)a;
154 des[1 * dest_pitch] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
155 des[2 * dest_pitch] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
156
157 src++;
158 des++;
159 }
160 }
161
162 /****************************************************************************
163 *
164 * ROUTINE : vp8_horizontal_line_1_2_scale_c
165 *
166 * INPUTS : const unsigned char *source : Pointer to source data.
167 * unsigned int source_width : Stride of source.
168 * unsigned char *dest : Pointer to destination data.
169 * unsigned int dest_width : Stride of dest (UNUSED).
170 *
171 * OUTPUTS : None.
172 *
173 * RETURNS : void
174 *
175 * FUNCTION : Copies horizontal line of pixels from source to
176 * destination scaling up by 1 to 2.
177 *
178 * SPECIAL NOTES : None.
179 *
180 ****************************************************************************/
vp8_horizontal_line_2_1_scale_c(const unsigned char * source,unsigned int source_width,unsigned char * dest,unsigned int dest_width)181 void vp8_horizontal_line_2_1_scale_c(const unsigned char *source,
182 unsigned int source_width,
183 unsigned char *dest,
184 unsigned int dest_width) {
185 unsigned int i;
186 unsigned int a;
187 unsigned char *des = dest;
188 const unsigned char *src = source;
189
190 (void)dest_width;
191
192 for (i = 0; i < source_width; i += 2) {
193 a = src[0];
194 des[0] = (unsigned char)(a);
195 src += 2;
196 des += 1;
197 }
198 }
199
vp8_vertical_band_2_1_scale_c(unsigned char * source,unsigned int src_pitch,unsigned char * dest,unsigned int dest_pitch,unsigned int dest_width)200 void vp8_vertical_band_2_1_scale_c(unsigned char *source,
201 unsigned int src_pitch, unsigned char *dest,
202 unsigned int dest_pitch,
203 unsigned int dest_width) {
204 (void)dest_pitch;
205 (void)src_pitch;
206 memcpy(dest, source, dest_width);
207 }
208
vp8_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)209 void vp8_vertical_band_2_1_scale_i_c(unsigned char *source,
210 unsigned int src_pitch,
211 unsigned char *dest,
212 unsigned int dest_pitch,
213 unsigned int dest_width) {
214 int i;
215 int temp;
216 int width = dest_width;
217
218 (void)dest_pitch;
219
220 for (i = 0; i < width; i++) {
221 temp = 8;
222 temp += source[i - (int)src_pitch] * 3;
223 temp += source[i] * 10;
224 temp += source[i + src_pitch] * 3;
225 temp >>= 4;
226 dest[i] = (unsigned char)(temp);
227 }
228 }
229