2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
12 #include "vpx_scale/vpx_scale.h"
13 #include "vpx_mem/vpx_mem.h"
14 /****************************************************************************
16 ****************************************************************************/
18 /****************************************************************************
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).
30 * FUNCTION : Copies horizontal line of pixels from source to
31 * destination scaling up by 4 to 5.
33 * SPECIAL NOTES : None.
35 ****************************************************************************/
36 void vp8_horizontal_line_5_4_scale_c(const unsigned char *source,
37 unsigned int source_width,
39 unsigned int dest_width) {
41 unsigned int a, b, c, d, e;
42 unsigned char *des = dest;
43 const unsigned char *src = source;
47 for (i = 0; i < source_width; i += 5) {
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);
67 void vp8_vertical_band_5_4_scale_c(unsigned char *source,
68 unsigned int src_pitch,
70 unsigned int dest_pitch,
71 unsigned int dest_width) {
73 unsigned int a, b, c, d, e;
74 unsigned char *des = dest;
75 unsigned char *src = source;
77 for (i = 0; i < dest_width; i++) {
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];
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);
97 /*7***************************************************************************
99 * ROUTINE : vp8_horizontal_line_3_5_scale_c
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).
110 * FUNCTION : Copies horizontal line of pixels from source to
111 * destination scaling up by 3 to 5.
113 * SPECIAL NOTES : None.
116 ****************************************************************************/
117 void vp8_horizontal_line_5_3_scale_c(const unsigned char *source,
118 unsigned int source_width,
120 unsigned int dest_width) {
122 unsigned int a, b, c, d, e;
123 unsigned char *des = dest;
124 const unsigned char *src = source;
128 for (i = 0; i < source_width; i += 5) {
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);
145 void vp8_vertical_band_5_3_scale_c(unsigned char *source,
146 unsigned int src_pitch,
148 unsigned int dest_pitch,
149 unsigned int dest_width) {
151 unsigned int a, b, c, d, e;
152 unsigned char *des = dest;
153 unsigned char *src = source;
155 for (i = 0; i < dest_width; i++) {
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];
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);
173 /****************************************************************************
175 * ROUTINE : vp8_horizontal_line_1_2_scale_c
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).
186 * FUNCTION : Copies horizontal line of pixels from source to
187 * destination scaling up by 1 to 2.
189 * SPECIAL NOTES : None.
191 ****************************************************************************/
192 void vp8_horizontal_line_2_1_scale_c(const unsigned char *source,
193 unsigned int source_width,
195 unsigned int dest_width) {
198 unsigned char *des = dest;
199 const unsigned char *src = source;
203 for (i = 0; i < source_width; i += 2) {
205 des [0] = (unsigned char)(a);
211 void vp8_vertical_band_2_1_scale_c(unsigned char *source,
212 unsigned int src_pitch,
214 unsigned int dest_pitch,
215 unsigned int dest_width) {
218 memcpy(dest, source, dest_width);
221 void vp8_vertical_band_2_1_scale_i_c(unsigned char *source,
222 unsigned int src_pitch,
224 unsigned int dest_pitch,
225 unsigned int dest_width) {
228 int width = dest_width;
232 for (i = 0; i < width; i++) {
234 temp += source[i - (int)src_pitch] * 3;
235 temp += source[i] * 10;
236 temp += source[i + src_pitch] * 3;
238 dest[i] = (unsigned char)(temp);