2
0

gen_scalers.c 7.1 KB

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