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/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 destination (NOT USED).
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 
64 
65 
66 
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)67 void vp8_vertical_band_5_4_scale_c(unsigned char *source,
68                                    unsigned int src_pitch,
69                                    unsigned char *dest,
70                                    unsigned int dest_pitch,
71                                    unsigned int dest_width) {
72   unsigned int i;
73   unsigned int a, b, c, d, e;
74   unsigned char *des = dest;
75   unsigned char *src = source;
76 
77   for (i = 0; i < dest_width; i++) {
78 
79     a = src[0 * src_pitch];
80     b = src[1 * src_pitch];
81     c = src[2 * src_pitch];
82     d = src[3 * src_pitch];
83     e = src[4 * src_pitch];
84 
85     des[0 * dest_pitch] = (unsigned char) a;
86     des[1 * dest_pitch] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
87     des[2 * dest_pitch] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
88     des[3 * dest_pitch] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);
89 
90     src++;
91     des++;
92 
93   }
94 }
95 
96 
97 /*7***************************************************************************
98  *
99  *  ROUTINE       : vp8_horizontal_line_3_5_scale_c
100  *
101  *  INPUTS        : const unsigned char *source : Pointer to source data.
102  *                  unsigned int source_width    : Stride of source.
103  *                  unsigned char *dest         : Pointer to destination data.
104  *                  unsigned int dest_width      : Stride of destination (NOT USED).
105  *
106  *  OUTPUTS       : None.
107  *
108  *  RETURNS       : void
109  *
110  *  FUNCTION      : Copies horizontal line of pixels from source to
111  *                  destination scaling up by 3 to 5.
112  *
113  *  SPECIAL NOTES : None.
114  *
115  *
116  ****************************************************************************/
vp8_horizontal_line_5_3_scale_c(const unsigned char * source,unsigned int source_width,unsigned char * dest,unsigned int dest_width)117 void vp8_horizontal_line_5_3_scale_c(const unsigned char *source,
118                                      unsigned int source_width,
119                                      unsigned char *dest,
120                                      unsigned int dest_width) {
121   unsigned int i;
122   unsigned int a, b, c, d, e;
123   unsigned char *des = dest;
124   const unsigned char *src = source;
125 
126   (void) dest_width;
127 
128   for (i = 0; i < source_width; i += 5) {
129     a = src[0];
130     b = src[1];
131     c = src[2];
132     d = src[3];
133     e = src[4];
134 
135     des[0] = (unsigned char) a;
136     des[1] = (unsigned char)((b * 85  + c * 171 + 128) >> 8);
137     des[2] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
138 
139     src += 5;
140     des += 3;
141   }
142 
143 }
144 
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)145 void vp8_vertical_band_5_3_scale_c(unsigned char *source,
146                                    unsigned int src_pitch,
147                                    unsigned char *dest,
148                                    unsigned int dest_pitch,
149                                    unsigned int dest_width) {
150   unsigned int i;
151   unsigned int a, b, c, d, e;
152   unsigned char *des = dest;
153   unsigned char *src = source;
154 
155   for (i = 0; i < dest_width; i++) {
156 
157     a = src[0 * src_pitch];
158     b = src[1 * src_pitch];
159     c = src[2 * src_pitch];
160     d = src[3 * src_pitch];
161     e = src[4 * src_pitch];
162 
163     des[0 * dest_pitch] = (unsigned char) a;
164     des[1 * dest_pitch] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
165     des[2 * dest_pitch] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
166 
167     src++;
168     des++;
169 
170   }
171 }
172 
173 /****************************************************************************
174  *
175  *  ROUTINE       : vp8_horizontal_line_1_2_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 1 to 2.
188  *
189  *  SPECIAL NOTES : None.
190  *
191  ****************************************************************************/
vp8_horizontal_line_2_1_scale_c(const unsigned char * source,unsigned int source_width,unsigned char * dest,unsigned int dest_width)192 void vp8_horizontal_line_2_1_scale_c(const unsigned char *source,
193                                      unsigned int source_width,
194                                      unsigned char *dest,
195                                      unsigned int dest_width) {
196   unsigned int i;
197   unsigned int a;
198   unsigned char *des = dest;
199   const unsigned char *src = source;
200 
201   (void) dest_width;
202 
203   for (i = 0; i < source_width; i += 2) {
204     a = src[0];
205     des [0] = (unsigned char)(a);
206     src += 2;
207     des += 1;
208   }
209 }
210 
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)211 void vp8_vertical_band_2_1_scale_c(unsigned char *source,
212                                    unsigned int src_pitch,
213                                    unsigned char *dest,
214                                    unsigned int dest_pitch,
215                                    unsigned int dest_width) {
216   (void) dest_pitch;
217   (void) src_pitch;
218   vpx_memcpy(dest, source, dest_width);
219 }
220 
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)221 void vp8_vertical_band_2_1_scale_i_c(unsigned char *source,
222                                      unsigned int src_pitch,
223                                      unsigned char *dest,
224                                      unsigned int dest_pitch,
225                                      unsigned int dest_width) {
226   int i;
227   int temp;
228   int width = dest_width;
229 
230   (void) dest_pitch;
231 
232   for (i = 0; i < width; i++) {
233     temp = 8;
234     temp += source[i - (int)src_pitch] * 3;
235     temp += source[i] * 10;
236     temp += source[i + src_pitch] * 3;
237     temp >>= 4;
238     dest[i] = (unsigned char)(temp);
239   }
240 }
241