Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | |
michael@0 | 12 | #include "vpx_scale/vpx_scale.h" |
michael@0 | 13 | #include "vpx_mem/vpx_mem.h" |
michael@0 | 14 | /**************************************************************************** |
michael@0 | 15 | * Imports |
michael@0 | 16 | ****************************************************************************/ |
michael@0 | 17 | |
michael@0 | 18 | /**************************************************************************** |
michael@0 | 19 | * |
michael@0 | 20 | * |
michael@0 | 21 | * INPUTS : const unsigned char *source : Pointer to source data. |
michael@0 | 22 | * unsigned int source_width : Stride of source. |
michael@0 | 23 | * unsigned char *dest : Pointer to destination data. |
michael@0 | 24 | * unsigned int dest_width : Stride of destination (NOT USED). |
michael@0 | 25 | * |
michael@0 | 26 | * OUTPUTS : None. |
michael@0 | 27 | * |
michael@0 | 28 | * RETURNS : void |
michael@0 | 29 | * |
michael@0 | 30 | * FUNCTION : Copies horizontal line of pixels from source to |
michael@0 | 31 | * destination scaling up by 4 to 5. |
michael@0 | 32 | * |
michael@0 | 33 | * SPECIAL NOTES : None. |
michael@0 | 34 | * |
michael@0 | 35 | ****************************************************************************/ |
michael@0 | 36 | void vp8_horizontal_line_5_4_scale_c(const unsigned char *source, |
michael@0 | 37 | unsigned int source_width, |
michael@0 | 38 | unsigned char *dest, |
michael@0 | 39 | unsigned int dest_width) { |
michael@0 | 40 | unsigned i; |
michael@0 | 41 | unsigned int a, b, c, d, e; |
michael@0 | 42 | unsigned char *des = dest; |
michael@0 | 43 | const unsigned char *src = source; |
michael@0 | 44 | |
michael@0 | 45 | (void) dest_width; |
michael@0 | 46 | |
michael@0 | 47 | for (i = 0; i < source_width; i += 5) { |
michael@0 | 48 | a = src[0]; |
michael@0 | 49 | b = src[1]; |
michael@0 | 50 | c = src[2]; |
michael@0 | 51 | d = src[3]; |
michael@0 | 52 | e = src[4]; |
michael@0 | 53 | |
michael@0 | 54 | des[0] = (unsigned char) a; |
michael@0 | 55 | des[1] = (unsigned char)((b * 192 + c * 64 + 128) >> 8); |
michael@0 | 56 | des[2] = (unsigned char)((c * 128 + d * 128 + 128) >> 8); |
michael@0 | 57 | des[3] = (unsigned char)((d * 64 + e * 192 + 128) >> 8); |
michael@0 | 58 | |
michael@0 | 59 | src += 5; |
michael@0 | 60 | des += 4; |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | void vp8_vertical_band_5_4_scale_c(unsigned char *source, |
michael@0 | 68 | unsigned int src_pitch, |
michael@0 | 69 | unsigned char *dest, |
michael@0 | 70 | unsigned int dest_pitch, |
michael@0 | 71 | unsigned int dest_width) { |
michael@0 | 72 | unsigned int i; |
michael@0 | 73 | unsigned int a, b, c, d, e; |
michael@0 | 74 | unsigned char *des = dest; |
michael@0 | 75 | unsigned char *src = source; |
michael@0 | 76 | |
michael@0 | 77 | for (i = 0; i < dest_width; i++) { |
michael@0 | 78 | |
michael@0 | 79 | a = src[0 * src_pitch]; |
michael@0 | 80 | b = src[1 * src_pitch]; |
michael@0 | 81 | c = src[2 * src_pitch]; |
michael@0 | 82 | d = src[3 * src_pitch]; |
michael@0 | 83 | e = src[4 * src_pitch]; |
michael@0 | 84 | |
michael@0 | 85 | des[0 * dest_pitch] = (unsigned char) a; |
michael@0 | 86 | des[1 * dest_pitch] = (unsigned char)((b * 192 + c * 64 + 128) >> 8); |
michael@0 | 87 | des[2 * dest_pitch] = (unsigned char)((c * 128 + d * 128 + 128) >> 8); |
michael@0 | 88 | des[3 * dest_pitch] = (unsigned char)((d * 64 + e * 192 + 128) >> 8); |
michael@0 | 89 | |
michael@0 | 90 | src++; |
michael@0 | 91 | des++; |
michael@0 | 92 | |
michael@0 | 93 | } |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | |
michael@0 | 97 | /*7*************************************************************************** |
michael@0 | 98 | * |
michael@0 | 99 | * ROUTINE : vp8_horizontal_line_3_5_scale_c |
michael@0 | 100 | * |
michael@0 | 101 | * INPUTS : const unsigned char *source : Pointer to source data. |
michael@0 | 102 | * unsigned int source_width : Stride of source. |
michael@0 | 103 | * unsigned char *dest : Pointer to destination data. |
michael@0 | 104 | * unsigned int dest_width : Stride of destination (NOT USED). |
michael@0 | 105 | * |
michael@0 | 106 | * OUTPUTS : None. |
michael@0 | 107 | * |
michael@0 | 108 | * RETURNS : void |
michael@0 | 109 | * |
michael@0 | 110 | * FUNCTION : Copies horizontal line of pixels from source to |
michael@0 | 111 | * destination scaling up by 3 to 5. |
michael@0 | 112 | * |
michael@0 | 113 | * SPECIAL NOTES : None. |
michael@0 | 114 | * |
michael@0 | 115 | * |
michael@0 | 116 | ****************************************************************************/ |
michael@0 | 117 | void vp8_horizontal_line_5_3_scale_c(const unsigned char *source, |
michael@0 | 118 | unsigned int source_width, |
michael@0 | 119 | unsigned char *dest, |
michael@0 | 120 | unsigned int dest_width) { |
michael@0 | 121 | unsigned int i; |
michael@0 | 122 | unsigned int a, b, c, d, e; |
michael@0 | 123 | unsigned char *des = dest; |
michael@0 | 124 | const unsigned char *src = source; |
michael@0 | 125 | |
michael@0 | 126 | (void) dest_width; |
michael@0 | 127 | |
michael@0 | 128 | for (i = 0; i < source_width; i += 5) { |
michael@0 | 129 | a = src[0]; |
michael@0 | 130 | b = src[1]; |
michael@0 | 131 | c = src[2]; |
michael@0 | 132 | d = src[3]; |
michael@0 | 133 | e = src[4]; |
michael@0 | 134 | |
michael@0 | 135 | des[0] = (unsigned char) a; |
michael@0 | 136 | des[1] = (unsigned char)((b * 85 + c * 171 + 128) >> 8); |
michael@0 | 137 | des[2] = (unsigned char)((d * 171 + e * 85 + 128) >> 8); |
michael@0 | 138 | |
michael@0 | 139 | src += 5; |
michael@0 | 140 | des += 3; |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | void vp8_vertical_band_5_3_scale_c(unsigned char *source, |
michael@0 | 146 | unsigned int src_pitch, |
michael@0 | 147 | unsigned char *dest, |
michael@0 | 148 | unsigned int dest_pitch, |
michael@0 | 149 | unsigned int dest_width) { |
michael@0 | 150 | unsigned int i; |
michael@0 | 151 | unsigned int a, b, c, d, e; |
michael@0 | 152 | unsigned char *des = dest; |
michael@0 | 153 | unsigned char *src = source; |
michael@0 | 154 | |
michael@0 | 155 | for (i = 0; i < dest_width; i++) { |
michael@0 | 156 | |
michael@0 | 157 | a = src[0 * src_pitch]; |
michael@0 | 158 | b = src[1 * src_pitch]; |
michael@0 | 159 | c = src[2 * src_pitch]; |
michael@0 | 160 | d = src[3 * src_pitch]; |
michael@0 | 161 | e = src[4 * src_pitch]; |
michael@0 | 162 | |
michael@0 | 163 | des[0 * dest_pitch] = (unsigned char) a; |
michael@0 | 164 | des[1 * dest_pitch] = (unsigned char)((b * 85 + c * 171 + 128) >> 8); |
michael@0 | 165 | des[2 * dest_pitch] = (unsigned char)((d * 171 + e * 85 + 128) >> 8); |
michael@0 | 166 | |
michael@0 | 167 | src++; |
michael@0 | 168 | des++; |
michael@0 | 169 | |
michael@0 | 170 | } |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | /**************************************************************************** |
michael@0 | 174 | * |
michael@0 | 175 | * ROUTINE : vp8_horizontal_line_1_2_scale_c |
michael@0 | 176 | * |
michael@0 | 177 | * INPUTS : const unsigned char *source : Pointer to source data. |
michael@0 | 178 | * unsigned int source_width : Stride of source. |
michael@0 | 179 | * unsigned char *dest : Pointer to destination data. |
michael@0 | 180 | * unsigned int dest_width : Stride of destination (NOT USED). |
michael@0 | 181 | * |
michael@0 | 182 | * OUTPUTS : None. |
michael@0 | 183 | * |
michael@0 | 184 | * RETURNS : void |
michael@0 | 185 | * |
michael@0 | 186 | * FUNCTION : Copies horizontal line of pixels from source to |
michael@0 | 187 | * destination scaling up by 1 to 2. |
michael@0 | 188 | * |
michael@0 | 189 | * SPECIAL NOTES : None. |
michael@0 | 190 | * |
michael@0 | 191 | ****************************************************************************/ |
michael@0 | 192 | void vp8_horizontal_line_2_1_scale_c(const unsigned char *source, |
michael@0 | 193 | unsigned int source_width, |
michael@0 | 194 | unsigned char *dest, |
michael@0 | 195 | unsigned int dest_width) { |
michael@0 | 196 | unsigned int i; |
michael@0 | 197 | unsigned int a; |
michael@0 | 198 | unsigned char *des = dest; |
michael@0 | 199 | const unsigned char *src = source; |
michael@0 | 200 | |
michael@0 | 201 | (void) dest_width; |
michael@0 | 202 | |
michael@0 | 203 | for (i = 0; i < source_width; i += 2) { |
michael@0 | 204 | a = src[0]; |
michael@0 | 205 | des [0] = (unsigned char)(a); |
michael@0 | 206 | src += 2; |
michael@0 | 207 | des += 1; |
michael@0 | 208 | } |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | void vp8_vertical_band_2_1_scale_c(unsigned char *source, |
michael@0 | 212 | unsigned int src_pitch, |
michael@0 | 213 | unsigned char *dest, |
michael@0 | 214 | unsigned int dest_pitch, |
michael@0 | 215 | unsigned int dest_width) { |
michael@0 | 216 | (void) dest_pitch; |
michael@0 | 217 | (void) src_pitch; |
michael@0 | 218 | vpx_memcpy(dest, source, dest_width); |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | void vp8_vertical_band_2_1_scale_i_c(unsigned char *source, |
michael@0 | 222 | unsigned int src_pitch, |
michael@0 | 223 | unsigned char *dest, |
michael@0 | 224 | unsigned int dest_pitch, |
michael@0 | 225 | unsigned int dest_width) { |
michael@0 | 226 | int i; |
michael@0 | 227 | int temp; |
michael@0 | 228 | int width = dest_width; |
michael@0 | 229 | |
michael@0 | 230 | (void) dest_pitch; |
michael@0 | 231 | |
michael@0 | 232 | for (i = 0; i < width; i++) { |
michael@0 | 233 | temp = 8; |
michael@0 | 234 | temp += source[i - (int)src_pitch] * 3; |
michael@0 | 235 | temp += source[i] * 10; |
michael@0 | 236 | temp += source[i + src_pitch] * 3; |
michael@0 | 237 | temp >>= 4; |
michael@0 | 238 | dest[i] = (unsigned char)(temp); |
michael@0 | 239 | } |
michael@0 | 240 | } |