gen_scalers.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 destination (NOT USED).
  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,
  59. unsigned char *dest,
  60. unsigned int dest_pitch,
  61. unsigned int dest_width) {
  62. unsigned int i;
  63. unsigned int a, b, c, d, e;
  64. unsigned char *des = dest;
  65. unsigned char *src = source;
  66. for (i = 0; i < dest_width; i++) {
  67. a = src[0 * src_pitch];
  68. b = src[1 * src_pitch];
  69. c = src[2 * src_pitch];
  70. d = src[3 * src_pitch];
  71. e = src[4 * src_pitch];
  72. des[0 * dest_pitch] = (unsigned char) a;
  73. des[1 * dest_pitch] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
  74. des[2 * dest_pitch] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
  75. des[3 * dest_pitch] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);
  76. src++;
  77. des++;
  78. }
  79. }
  80. /*7***************************************************************************
  81. *
  82. * ROUTINE : vp8_horizontal_line_3_5_scale_c
  83. *
  84. * INPUTS : const unsigned char *source : Pointer to source data.
  85. * unsigned int source_width : Stride of source.
  86. * unsigned char *dest : Pointer to destination data.
  87. * unsigned int dest_width : Stride of destination (NOT USED).
  88. *
  89. * OUTPUTS : None.
  90. *
  91. * RETURNS : void
  92. *
  93. * FUNCTION : Copies horizontal line of pixels from source to
  94. * destination scaling up by 3 to 5.
  95. *
  96. * SPECIAL NOTES : None.
  97. *
  98. *
  99. ****************************************************************************/
  100. void vp8_horizontal_line_5_3_scale_c(const unsigned char *source,
  101. unsigned int source_width,
  102. unsigned char *dest,
  103. unsigned int dest_width) {
  104. unsigned int i;
  105. unsigned int a, b, c, d, e;
  106. unsigned char *des = dest;
  107. const unsigned char *src = source;
  108. (void) dest_width;
  109. for (i = 0; i < source_width; i += 5) {
  110. a = src[0];
  111. b = src[1];
  112. c = src[2];
  113. d = src[3];
  114. e = src[4];
  115. des[0] = (unsigned char) a;
  116. des[1] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
  117. des[2] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
  118. src += 5;
  119. des += 3;
  120. }
  121. }
  122. void vp8_vertical_band_5_3_scale_c(unsigned char *source,
  123. unsigned int src_pitch,
  124. unsigned char *dest,
  125. unsigned int dest_pitch,
  126. unsigned int dest_width) {
  127. unsigned int i;
  128. unsigned int a, b, c, d, e;
  129. unsigned char *des = dest;
  130. unsigned char *src = source;
  131. for (i = 0; i < dest_width; i++) {
  132. a = src[0 * src_pitch];
  133. b = src[1 * src_pitch];
  134. c = src[2 * src_pitch];
  135. d = src[3 * src_pitch];
  136. e = src[4 * src_pitch];
  137. des[0 * dest_pitch] = (unsigned char) a;
  138. des[1 * dest_pitch] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
  139. des[2 * dest_pitch] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
  140. src++;
  141. des++;
  142. }
  143. }
  144. /****************************************************************************
  145. *
  146. * ROUTINE : vp8_horizontal_line_1_2_scale_c
  147. *
  148. * INPUTS : const unsigned char *source : Pointer to source data.
  149. * unsigned int source_width : Stride of source.
  150. * unsigned char *dest : Pointer to destination data.
  151. * unsigned int dest_width : Stride of destination (NOT USED).
  152. *
  153. * OUTPUTS : None.
  154. *
  155. * RETURNS : void
  156. *
  157. * FUNCTION : Copies horizontal line of pixels from source to
  158. * destination scaling up by 1 to 2.
  159. *
  160. * SPECIAL NOTES : None.
  161. *
  162. ****************************************************************************/
  163. void vp8_horizontal_line_2_1_scale_c(const unsigned char *source,
  164. unsigned int source_width,
  165. unsigned char *dest,
  166. unsigned int dest_width) {
  167. unsigned int i;
  168. unsigned int a;
  169. unsigned char *des = dest;
  170. const unsigned char *src = source;
  171. (void) dest_width;
  172. for (i = 0; i < source_width; i += 2) {
  173. a = src[0];
  174. des [0] = (unsigned char)(a);
  175. src += 2;
  176. des += 1;
  177. }
  178. }
  179. void vp8_vertical_band_2_1_scale_c(unsigned char *source,
  180. unsigned int src_pitch,
  181. unsigned char *dest,
  182. unsigned int dest_pitch,
  183. unsigned int dest_width) {
  184. (void) dest_pitch;
  185. (void) src_pitch;
  186. memcpy(dest, source, dest_width);
  187. }
  188. void vp8_vertical_band_2_1_scale_i_c(unsigned char *source,
  189. unsigned int src_pitch,
  190. unsigned char *dest,
  191. unsigned int dest_pitch,
  192. unsigned int dest_width) {
  193. int i;
  194. int temp;
  195. int width = dest_width;
  196. (void) dest_pitch;
  197. for (i = 0; i < width; i++) {
  198. temp = 8;
  199. temp += source[i - (int)src_pitch] * 3;
  200. temp += source[i] * 10;
  201. temp += source[i + src_pitch] * 3;
  202. temp >>= 4;
  203. dest[i] = (unsigned char)(temp);
  204. }
  205. }