/media/libvpx/vpx_scale/generic/gen_scalers.c

http://github.com/zpao/v8monkey · C · 956 lines · 462 code · 125 blank · 369 comment · 21 complexity · 8c175e68df5eeff4bb86d29933c8ea76 MD5 · raw file

  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/vpxscale.h"
  11. #include "vpx_mem/vpx_mem.h"
  12. /****************************************************************************
  13. * Imports
  14. ****************************************************************************/
  15. /****************************************************************************
  16. *
  17. * ROUTINE : vp8cx_horizontal_line_4_5_scale_c
  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 vp8cx_horizontal_line_4_5_scale_c
  35. (
  36. const unsigned char *source,
  37. unsigned int source_width,
  38. unsigned char *dest,
  39. unsigned int dest_width
  40. )
  41. {
  42. unsigned i;
  43. unsigned int a, b, c;
  44. unsigned char *des = dest;
  45. const unsigned char *src = source;
  46. (void) dest_width;
  47. for (i = 0; i < source_width - 4; i += 4)
  48. {
  49. a = src[0];
  50. b = src[1];
  51. des [0] = (unsigned char) a;
  52. des [1] = (unsigned char)((a * 51 + 205 * b + 128) >> 8);
  53. c = src[2] * 154;
  54. a = src[3];
  55. des [2] = (unsigned char)((b * 102 + c + 128) >> 8);
  56. des [3] = (unsigned char)((c + 102 * a + 128) >> 8);
  57. b = src[4];
  58. des [4] = (unsigned char)((a * 205 + 51 * b + 128) >> 8);
  59. src += 4;
  60. des += 5;
  61. }
  62. a = src[0];
  63. b = src[1];
  64. des [0] = (unsigned char)(a);
  65. des [1] = (unsigned char)((a * 51 + 205 * b + 128) >> 8);
  66. c = src[2] * 154;
  67. a = src[3];
  68. des [2] = (unsigned char)((b * 102 + c + 128) >> 8);
  69. des [3] = (unsigned char)((c + 102 * a + 128) >> 8);
  70. des [4] = (unsigned char)(a);
  71. }
  72. /****************************************************************************
  73. *
  74. * ROUTINE : vp8cx_vertical_band_4_5_scale_c
  75. *
  76. * INPUTS : unsigned char *dest : Pointer to destination data.
  77. * unsigned int dest_pitch : Stride of destination data.
  78. * unsigned int dest_width : Width of destination data.
  79. *
  80. * OUTPUTS : None.
  81. *
  82. * RETURNS : void
  83. *
  84. * FUNCTION : Scales vertical band of pixels by scale 4 to 5. The
  85. * height of the band scaled is 4-pixels.
  86. *
  87. * SPECIAL NOTES : The routine uses the first line of the band below
  88. * the current band.
  89. *
  90. ****************************************************************************/
  91. void vp8cx_vertical_band_4_5_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  92. {
  93. unsigned int i;
  94. unsigned int a, b, c, d;
  95. unsigned char *des = dest;
  96. for (i = 0; i < dest_width; i++)
  97. {
  98. a = des [0];
  99. b = des [dest_pitch];
  100. des[dest_pitch] = (unsigned char)((a * 51 + 205 * b + 128) >> 8);
  101. c = des[dest_pitch*2] * 154;
  102. d = des[dest_pitch*3];
  103. des [dest_pitch*2] = (unsigned char)((b * 102 + c + 128) >> 8);
  104. des [dest_pitch*3] = (unsigned char)((c + 102 * d + 128) >> 8);
  105. /* First line in next band */
  106. a = des [dest_pitch * 5];
  107. des [dest_pitch * 4] = (unsigned char)((d * 205 + 51 * a + 128) >> 8);
  108. des ++;
  109. }
  110. }
  111. /****************************************************************************
  112. *
  113. * ROUTINE : vp8cx_last_vertical_band_4_5_scale_c
  114. *
  115. * INPUTS : unsigned char *dest : Pointer to destination data.
  116. * unsigned int dest_pitch : Stride of destination data.
  117. * unsigned int dest_width : Width of destination data.
  118. *
  119. * OUTPUTS : None.
  120. *
  121. * RETURNS : void
  122. *
  123. * FUNCTION : Scales last vertical band of pixels by scale 4 to 5. The
  124. * height of the band scaled is 4-pixels.
  125. *
  126. * SPECIAL NOTES : The routine does not have available the first line of
  127. * the band below the current band, since this is the
  128. * last band.
  129. *
  130. ****************************************************************************/
  131. void vp8cx_last_vertical_band_4_5_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  132. {
  133. unsigned int i;
  134. unsigned int a, b, c, d;
  135. unsigned char *des = dest;
  136. for (i = 0; i < dest_width; ++i)
  137. {
  138. a = des[0];
  139. b = des[dest_pitch];
  140. des[dest_pitch] = (unsigned char)((a * 51 + 205 * b + 128) >> 8);
  141. c = des[dest_pitch*2] * 154;
  142. d = des[dest_pitch*3];
  143. des [dest_pitch*2] = (unsigned char)((b * 102 + c + 128) >> 8);
  144. des [dest_pitch*3] = (unsigned char)((c + 102 * d + 128) >> 8);
  145. /* No other line for interplation of this line, so .. */
  146. des[dest_pitch*4] = (unsigned char) d;
  147. des++;
  148. }
  149. }
  150. /****************************************************************************
  151. *
  152. * ROUTINE : vp8cx_horizontal_line_2_3_scale_c
  153. *
  154. * INPUTS : const unsigned char *source : Pointer to source data.
  155. * unsigned int source_width : Stride of source.
  156. * unsigned char *dest : Pointer to destination data.
  157. * unsigned int dest_width : Stride of destination (NOT USED).
  158. *
  159. * OUTPUTS : None.
  160. *
  161. * RETURNS : void
  162. *
  163. * FUNCTION : Copies horizontal line of pixels from source to
  164. * destination scaling up by 2 to 3.
  165. *
  166. * SPECIAL NOTES : None.
  167. *
  168. *
  169. ****************************************************************************/
  170. void vp8cx_horizontal_line_2_3_scale_c
  171. (
  172. const unsigned char *source,
  173. unsigned int source_width,
  174. unsigned char *dest,
  175. unsigned int dest_width
  176. )
  177. {
  178. unsigned int i;
  179. unsigned int a, b, c;
  180. unsigned char *des = dest;
  181. const unsigned char *src = source;
  182. (void) dest_width;
  183. for (i = 0; i < source_width - 2; i += 2)
  184. {
  185. a = src[0];
  186. b = src[1];
  187. c = src[2];
  188. des [0] = (unsigned char)(a);
  189. des [1] = (unsigned char)((a * 85 + 171 * b + 128) >> 8);
  190. des [2] = (unsigned char)((b * 171 + 85 * c + 128) >> 8);
  191. src += 2;
  192. des += 3;
  193. }
  194. a = src[0];
  195. b = src[1];
  196. des [0] = (unsigned char)(a);
  197. des [1] = (unsigned char)((a * 85 + 171 * b + 128) >> 8);
  198. des [2] = (unsigned char)(b);
  199. }
  200. /****************************************************************************
  201. *
  202. * ROUTINE : vp8cx_vertical_band_2_3_scale_c
  203. *
  204. * INPUTS : unsigned char *dest : Pointer to destination data.
  205. * unsigned int dest_pitch : Stride of destination data.
  206. * unsigned int dest_width : Width of destination data.
  207. *
  208. * OUTPUTS : None.
  209. *
  210. * RETURNS : void
  211. *
  212. * FUNCTION : Scales vertical band of pixels by scale 2 to 3. The
  213. * height of the band scaled is 2-pixels.
  214. *
  215. * SPECIAL NOTES : The routine uses the first line of the band below
  216. * the current band.
  217. *
  218. ****************************************************************************/
  219. void vp8cx_vertical_band_2_3_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  220. {
  221. unsigned int i;
  222. unsigned int a, b, c;
  223. unsigned char *des = dest;
  224. for (i = 0; i < dest_width; i++)
  225. {
  226. a = des [0];
  227. b = des [dest_pitch];
  228. c = des[dest_pitch*3];
  229. des [dest_pitch ] = (unsigned char)((a * 85 + 171 * b + 128) >> 8);
  230. des [dest_pitch*2] = (unsigned char)((b * 171 + 85 * c + 128) >> 8);
  231. des++;
  232. }
  233. }
  234. /****************************************************************************
  235. *
  236. * ROUTINE : vp8cx_last_vertical_band_2_3_scale_c
  237. *
  238. * INPUTS : unsigned char *dest : Pointer to destination data.
  239. * unsigned int dest_pitch : Stride of destination data.
  240. * unsigned int dest_width : Width of destination data.
  241. *
  242. * OUTPUTS : None.
  243. *
  244. * RETURNS : void
  245. *
  246. * FUNCTION : Scales last vertical band of pixels by scale 2 to 3. The
  247. * height of the band scaled is 2-pixels.
  248. *
  249. * SPECIAL NOTES : The routine does not have available the first line of
  250. * the band below the current band, since this is the
  251. * last band.
  252. *
  253. ****************************************************************************/
  254. void vp8cx_last_vertical_band_2_3_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  255. {
  256. unsigned int i;
  257. unsigned int a, b;
  258. unsigned char *des = dest;
  259. for (i = 0; i < dest_width; ++i)
  260. {
  261. a = des [0];
  262. b = des [dest_pitch];
  263. des [dest_pitch ] = (unsigned char)((a * 85 + 171 * b + 128) >> 8);
  264. des [dest_pitch*2] = (unsigned char)(b);
  265. des++;
  266. }
  267. }
  268. /****************************************************************************
  269. *
  270. * ROUTINE : vp8cx_horizontal_line_3_5_scale_c
  271. *
  272. * INPUTS : const unsigned char *source : Pointer to source data.
  273. * unsigned int source_width : Stride of source.
  274. * unsigned char *dest : Pointer to destination data.
  275. * unsigned int dest_width : Stride of destination (NOT USED).
  276. *
  277. * OUTPUTS : None.
  278. *
  279. * RETURNS : void
  280. *
  281. * FUNCTION : Copies horizontal line of pixels from source to
  282. * destination scaling up by 3 to 5.
  283. *
  284. * SPECIAL NOTES : None.
  285. *
  286. *
  287. ****************************************************************************/
  288. void vp8cx_horizontal_line_3_5_scale_c
  289. (
  290. const unsigned char *source,
  291. unsigned int source_width,
  292. unsigned char *dest,
  293. unsigned int dest_width
  294. )
  295. {
  296. unsigned int i;
  297. unsigned int a, b, c;
  298. unsigned char *des = dest;
  299. const unsigned char *src = source;
  300. (void) dest_width;
  301. for (i = 0; i < source_width - 3; i += 3)
  302. {
  303. a = src[0];
  304. b = src[1];
  305. des [0] = (unsigned char)(a);
  306. des [1] = (unsigned char)((a * 102 + 154 * b + 128) >> 8);
  307. c = src[2] ;
  308. des [2] = (unsigned char)((b * 205 + c * 51 + 128) >> 8);
  309. des [3] = (unsigned char)((b * 51 + c * 205 + 128) >> 8);
  310. a = src[3];
  311. des [4] = (unsigned char)((c * 154 + a * 102 + 128) >> 8);
  312. src += 3;
  313. des += 5;
  314. }
  315. a = src[0];
  316. b = src[1];
  317. des [0] = (unsigned char)(a);
  318. des [1] = (unsigned char)((a * 102 + 154 * b + 128) >> 8);
  319. c = src[2] ;
  320. des [2] = (unsigned char)((b * 205 + c * 51 + 128) >> 8);
  321. des [3] = (unsigned char)((b * 51 + c * 205 + 128) >> 8);
  322. des [4] = (unsigned char)(c);
  323. }
  324. /****************************************************************************
  325. *
  326. * ROUTINE : vp8cx_vertical_band_3_5_scale_c
  327. *
  328. * INPUTS : unsigned char *dest : Pointer to destination data.
  329. * unsigned int dest_pitch : Stride of destination data.
  330. * unsigned int dest_width : Width of destination data.
  331. *
  332. * OUTPUTS : None.
  333. *
  334. * RETURNS : void
  335. *
  336. * FUNCTION : Scales vertical band of pixels by scale 3 to 5. The
  337. * height of the band scaled is 3-pixels.
  338. *
  339. * SPECIAL NOTES : The routine uses the first line of the band below
  340. * the current band.
  341. *
  342. ****************************************************************************/
  343. void vp8cx_vertical_band_3_5_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  344. {
  345. unsigned int i;
  346. unsigned int a, b, c;
  347. unsigned char *des = dest;
  348. for (i = 0; i < dest_width; i++)
  349. {
  350. a = des [0];
  351. b = des [dest_pitch];
  352. des [dest_pitch] = (unsigned char)((a * 102 + 154 * b + 128) >> 8);
  353. c = des[dest_pitch*2];
  354. des [dest_pitch*2] = (unsigned char)((b * 205 + c * 51 + 128) >> 8);
  355. des [dest_pitch*3] = (unsigned char)((b * 51 + c * 205 + 128) >> 8);
  356. /* First line in next band... */
  357. a = des [dest_pitch * 5];
  358. des [dest_pitch * 4] = (unsigned char)((c * 154 + a * 102 + 128) >> 8);
  359. des++;
  360. }
  361. }
  362. /****************************************************************************
  363. *
  364. * ROUTINE : vp8cx_last_vertical_band_3_5_scale_c
  365. *
  366. * INPUTS : unsigned char *dest : Pointer to destination data.
  367. * unsigned int dest_pitch : Stride of destination data.
  368. * unsigned int dest_width : Width of destination data.
  369. *
  370. * OUTPUTS : None.
  371. *
  372. * RETURNS : void
  373. *
  374. * FUNCTION : Scales last vertical band of pixels by scale 3 to 5. The
  375. * height of the band scaled is 3-pixels.
  376. *
  377. * SPECIAL NOTES : The routine does not have available the first line of
  378. * the band below the current band, since this is the
  379. * last band.
  380. *
  381. ****************************************************************************/
  382. void vp8cx_last_vertical_band_3_5_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  383. {
  384. unsigned int i;
  385. unsigned int a, b, c;
  386. unsigned char *des = dest;
  387. for (i = 0; i < dest_width; ++i)
  388. {
  389. a = des [0];
  390. b = des [dest_pitch];
  391. des [ dest_pitch ] = (unsigned char)((a * 102 + 154 * b + 128) >> 8);
  392. c = des[dest_pitch*2];
  393. des [dest_pitch*2] = (unsigned char)((b * 205 + c * 51 + 128) >> 8);
  394. des [dest_pitch*3] = (unsigned char)((b * 51 + c * 205 + 128) >> 8);
  395. /* No other line for interplation of this line, so .. */
  396. des [ dest_pitch * 4 ] = (unsigned char)(c) ;
  397. des++;
  398. }
  399. }
  400. /****************************************************************************
  401. *
  402. * ROUTINE : vp8cx_horizontal_line_3_4_scale_c
  403. *
  404. * INPUTS : const unsigned char *source : Pointer to source data.
  405. * unsigned int source_width : Stride of source.
  406. * unsigned char *dest : Pointer to destination data.
  407. * unsigned int dest_width : Stride of destination (NOT USED).
  408. *
  409. * OUTPUTS : None.
  410. *
  411. * RETURNS : void
  412. *
  413. * FUNCTION : Copies horizontal line of pixels from source to
  414. * destination scaling up by 3 to 4.
  415. *
  416. * SPECIAL NOTES : None.
  417. *
  418. *
  419. ****************************************************************************/
  420. void vp8cx_horizontal_line_3_4_scale_c
  421. (
  422. const unsigned char *source,
  423. unsigned int source_width,
  424. unsigned char *dest,
  425. unsigned int dest_width
  426. )
  427. {
  428. unsigned int i;
  429. unsigned int a, b, c;
  430. unsigned char *des = dest;
  431. const unsigned char *src = source;
  432. (void) dest_width;
  433. for (i = 0; i < source_width - 3; i += 3)
  434. {
  435. a = src[0];
  436. b = src[1];
  437. des [0] = (unsigned char)(a);
  438. des [1] = (unsigned char)((a * 64 + b * 192 + 128) >> 8);
  439. c = src[2];
  440. des [2] = (unsigned char)((b + c + 1) >> 1);
  441. a = src[3];
  442. des [3] = (unsigned char)((c * 192 + a * 64 + 128) >> 8);
  443. src += 3;
  444. des += 4;
  445. }
  446. a = src[0];
  447. b = src[1];
  448. des [0] = (unsigned char)(a);
  449. des [1] = (unsigned char)((a * 64 + b * 192 + 128) >> 8);
  450. c = src[2] ;
  451. des [2] = (unsigned char)((b + c + 1) >> 1);
  452. des [3] = (unsigned char)(c);
  453. }
  454. /****************************************************************************
  455. *
  456. * ROUTINE : vp8cx_vertical_band_3_4_scale_c
  457. *
  458. * INPUTS : unsigned char *dest : Pointer to destination data.
  459. * unsigned int dest_pitch : Stride of destination data.
  460. * unsigned int dest_width : Width of destination data.
  461. *
  462. * OUTPUTS : None.
  463. *
  464. * RETURNS : void
  465. *
  466. * FUNCTION : Scales vertical band of pixels by scale 3 to 4. The
  467. * height of the band scaled is 3-pixels.
  468. *
  469. * SPECIAL NOTES : The routine uses the first line of the band below
  470. * the current band.
  471. *
  472. ****************************************************************************/
  473. void vp8cx_vertical_band_3_4_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  474. {
  475. unsigned int i;
  476. unsigned int a, b, c;
  477. unsigned char *des = dest;
  478. for (i = 0; i < dest_width; i++)
  479. {
  480. a = des [0];
  481. b = des [dest_pitch];
  482. des [dest_pitch] = (unsigned char)((a * 64 + b * 192 + 128) >> 8);
  483. c = des[dest_pitch*2];
  484. des [dest_pitch*2] = (unsigned char)((b + c + 1) >> 1);
  485. /* First line in next band... */
  486. a = des [dest_pitch*4];
  487. des [dest_pitch*3] = (unsigned char)((c * 192 + a * 64 + 128) >> 8);
  488. des++;
  489. }
  490. }
  491. /****************************************************************************
  492. *
  493. * ROUTINE : vp8cx_last_vertical_band_3_4_scale_c
  494. *
  495. * INPUTS : unsigned char *dest : Pointer to destination data.
  496. * unsigned int dest_pitch : Stride of destination data.
  497. * unsigned int dest_width : Width of destination data.
  498. *
  499. * OUTPUTS : None.
  500. *
  501. * RETURNS : void
  502. *
  503. * FUNCTION : Scales last vertical band of pixels by scale 3 to 4. The
  504. * height of the band scaled is 3-pixels.
  505. *
  506. * SPECIAL NOTES : The routine does not have available the first line of
  507. * the band below the current band, since this is the
  508. * last band.
  509. *
  510. ****************************************************************************/
  511. void vp8cx_last_vertical_band_3_4_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  512. {
  513. unsigned int i;
  514. unsigned int a, b, c;
  515. unsigned char *des = dest;
  516. for (i = 0; i < dest_width; ++i)
  517. {
  518. a = des [0];
  519. b = des [dest_pitch];
  520. des [dest_pitch] = (unsigned char)((a * 64 + b * 192 + 128) >> 8);
  521. c = des[dest_pitch*2];
  522. des [dest_pitch*2] = (unsigned char)((b + c + 1) >> 1);
  523. /* No other line for interplation of this line, so .. */
  524. des [dest_pitch*3] = (unsigned char)(c);
  525. des++;
  526. }
  527. }
  528. /****************************************************************************
  529. *
  530. * ROUTINE : vp8cx_horizontal_line_1_2_scale_c
  531. *
  532. * INPUTS : const unsigned char *source : Pointer to source data.
  533. * unsigned int source_width : Stride of source.
  534. * unsigned char *dest : Pointer to destination data.
  535. * unsigned int dest_width : Stride of destination (NOT USED).
  536. *
  537. * OUTPUTS : None.
  538. *
  539. * RETURNS : void
  540. *
  541. * FUNCTION : Copies horizontal line of pixels from source to
  542. * destination scaling up by 1 to 2.
  543. *
  544. * SPECIAL NOTES : None.
  545. *
  546. ****************************************************************************/
  547. void vp8cx_horizontal_line_1_2_scale_c
  548. (
  549. const unsigned char *source,
  550. unsigned int source_width,
  551. unsigned char *dest,
  552. unsigned int dest_width
  553. )
  554. {
  555. unsigned int i;
  556. unsigned int a, b;
  557. unsigned char *des = dest;
  558. const unsigned char *src = source;
  559. (void) dest_width;
  560. for (i = 0; i < source_width - 1; i += 1)
  561. {
  562. a = src[0];
  563. b = src[1];
  564. des [0] = (unsigned char)(a);
  565. des [1] = (unsigned char)((a + b + 1) >> 1);
  566. src += 1;
  567. des += 2;
  568. }
  569. a = src[0];
  570. des [0] = (unsigned char)(a);
  571. des [1] = (unsigned char)(a);
  572. }
  573. /****************************************************************************
  574. *
  575. * ROUTINE : vp8cx_vertical_band_1_2_scale_c
  576. *
  577. * INPUTS : unsigned char *dest : Pointer to destination data.
  578. * unsigned int dest_pitch : Stride of destination data.
  579. * unsigned int dest_width : Width of destination data.
  580. *
  581. * OUTPUTS : None.
  582. *
  583. * RETURNS : void
  584. *
  585. * FUNCTION : Scales vertical band of pixels by scale 1 to 2. The
  586. * height of the band scaled is 1-pixel.
  587. *
  588. * SPECIAL NOTES : The routine uses the first line of the band below
  589. * the current band.
  590. *
  591. ****************************************************************************/
  592. void vp8cx_vertical_band_1_2_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  593. {
  594. unsigned int i;
  595. unsigned int a, b;
  596. unsigned char *des = dest;
  597. for (i = 0; i < dest_width; i++)
  598. {
  599. a = des [0];
  600. b = des [dest_pitch * 2];
  601. des[dest_pitch] = (unsigned char)((a + b + 1) >> 1);
  602. des++;
  603. }
  604. }
  605. /****************************************************************************
  606. *
  607. * ROUTINE : vp8cx_last_vertical_band_1_2_scale_c
  608. *
  609. * INPUTS : unsigned char *dest : Pointer to destination data.
  610. * unsigned int dest_pitch : Stride of destination data.
  611. * unsigned int dest_width : Width of destination data.
  612. *
  613. * OUTPUTS : None.
  614. *
  615. * RETURNS : void
  616. *
  617. * FUNCTION : Scales last vertical band of pixels by scale 1 to 2. The
  618. * height of the band scaled is 1-pixel.
  619. *
  620. * SPECIAL NOTES : The routine does not have available the first line of
  621. * the band below the current band, since this is the
  622. * last band.
  623. *
  624. ****************************************************************************/
  625. void vp8cx_last_vertical_band_1_2_scale_c(unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  626. {
  627. unsigned int i;
  628. unsigned char *des = dest;
  629. for (i = 0; i < dest_width; ++i)
  630. {
  631. des[dest_pitch] = des[0];
  632. des++;
  633. }
  634. }
  635. /****************************************************************************
  636. *
  637. * ROUTINE : vp8cx_horizontal_line_4_5_scale_c
  638. *
  639. * INPUTS : const unsigned char *source : Pointer to source data.
  640. * unsigned int source_width : Stride of source.
  641. * unsigned char *dest : Pointer to destination data.
  642. * unsigned int dest_width : Stride of destination (NOT USED).
  643. *
  644. * OUTPUTS : None.
  645. *
  646. * RETURNS : void
  647. *
  648. * FUNCTION : Copies horizontal line of pixels from source to
  649. * destination scaling up by 4 to 5.
  650. *
  651. * SPECIAL NOTES : None.
  652. *
  653. ****************************************************************************/
  654. void vp8cx_horizontal_line_5_4_scale_c
  655. (
  656. const unsigned char *source,
  657. unsigned int source_width,
  658. unsigned char *dest,
  659. unsigned int dest_width
  660. )
  661. {
  662. unsigned i;
  663. unsigned int a, b, c, d, e;
  664. unsigned char *des = dest;
  665. const unsigned char *src = source;
  666. (void) dest_width;
  667. for (i = 0; i < source_width; i += 5)
  668. {
  669. a = src[0];
  670. b = src[1];
  671. c = src[2];
  672. d = src[3];
  673. e = src[4];
  674. des[0] = (unsigned char) a;
  675. des[1] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
  676. des[2] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
  677. des[3] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);
  678. src += 5;
  679. des += 4;
  680. }
  681. }
  682. void vp8cx_vertical_band_5_4_scale_c(unsigned char *source, unsigned int src_pitch, unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  683. {
  684. unsigned int i;
  685. unsigned int a, b, c, d, e;
  686. unsigned char *des = dest;
  687. unsigned char *src = source;
  688. for (i = 0; i < dest_width; i++)
  689. {
  690. a = src[0 * src_pitch];
  691. b = src[1 * src_pitch];
  692. c = src[2 * src_pitch];
  693. d = src[3 * src_pitch];
  694. e = src[4 * src_pitch];
  695. des[0 * dest_pitch] = (unsigned char) a;
  696. des[1 * dest_pitch] = (unsigned char)((b * 192 + c * 64 + 128) >> 8);
  697. des[2 * dest_pitch] = (unsigned char)((c * 128 + d * 128 + 128) >> 8);
  698. des[3 * dest_pitch] = (unsigned char)((d * 64 + e * 192 + 128) >> 8);
  699. src ++;
  700. des ++;
  701. }
  702. }
  703. /*7***************************************************************************
  704. *
  705. * ROUTINE : vp8cx_horizontal_line_3_5_scale_c
  706. *
  707. * INPUTS : const unsigned char *source : Pointer to source data.
  708. * unsigned int source_width : Stride of source.
  709. * unsigned char *dest : Pointer to destination data.
  710. * unsigned int dest_width : Stride of destination (NOT USED).
  711. *
  712. * OUTPUTS : None.
  713. *
  714. * RETURNS : void
  715. *
  716. * FUNCTION : Copies horizontal line of pixels from source to
  717. * destination scaling up by 3 to 5.
  718. *
  719. * SPECIAL NOTES : None.
  720. *
  721. *
  722. ****************************************************************************/
  723. void vp8cx_horizontal_line_5_3_scale_c
  724. (
  725. const unsigned char *source,
  726. unsigned int source_width,
  727. unsigned char *dest,
  728. unsigned int dest_width
  729. )
  730. {
  731. unsigned int i;
  732. unsigned int a, b, c, d , e;
  733. unsigned char *des = dest;
  734. const unsigned char *src = source;
  735. (void) dest_width;
  736. for (i = 0; i < source_width; i += 5)
  737. {
  738. a = src[0];
  739. b = src[1];
  740. c = src[2];
  741. d = src[3];
  742. e = src[4];
  743. des[0] = (unsigned char) a;
  744. des[1] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
  745. des[2] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
  746. src += 5;
  747. des += 3;
  748. }
  749. }
  750. void vp8cx_vertical_band_5_3_scale_c(unsigned char *source, unsigned int src_pitch, unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  751. {
  752. unsigned int i;
  753. unsigned int a, b, c, d, e;
  754. unsigned char *des = dest;
  755. unsigned char *src = source;
  756. for (i = 0; i < dest_width; i++)
  757. {
  758. a = src[0 * src_pitch];
  759. b = src[1 * src_pitch];
  760. c = src[2 * src_pitch];
  761. d = src[3 * src_pitch];
  762. e = src[4 * src_pitch];
  763. des[0 * dest_pitch] = (unsigned char) a;
  764. des[1 * dest_pitch] = (unsigned char)((b * 85 + c * 171 + 128) >> 8);
  765. des[2 * dest_pitch] = (unsigned char)((d * 171 + e * 85 + 128) >> 8);
  766. src ++;
  767. des ++;
  768. }
  769. }
  770. /****************************************************************************
  771. *
  772. * ROUTINE : vp8cx_horizontal_line_1_2_scale_c
  773. *
  774. * INPUTS : const unsigned char *source : Pointer to source data.
  775. * unsigned int source_width : Stride of source.
  776. * unsigned char *dest : Pointer to destination data.
  777. * unsigned int dest_width : Stride of destination (NOT USED).
  778. *
  779. * OUTPUTS : None.
  780. *
  781. * RETURNS : void
  782. *
  783. * FUNCTION : Copies horizontal line of pixels from source to
  784. * destination scaling up by 1 to 2.
  785. *
  786. * SPECIAL NOTES : None.
  787. *
  788. ****************************************************************************/
  789. void vp8cx_horizontal_line_2_1_scale_c
  790. (
  791. const unsigned char *source,
  792. unsigned int source_width,
  793. unsigned char *dest,
  794. unsigned int dest_width
  795. )
  796. {
  797. unsigned int i;
  798. unsigned int a;
  799. unsigned char *des = dest;
  800. const unsigned char *src = source;
  801. (void) dest_width;
  802. for (i = 0; i < source_width; i += 2)
  803. {
  804. a = src[0];
  805. des [0] = (unsigned char)(a);
  806. src += 2;
  807. des += 1;
  808. }
  809. }
  810. void vp8cx_vertical_band_2_1_scale_c(unsigned char *source, unsigned int src_pitch, unsigned char *dest, unsigned int dest_pitch, unsigned int dest_width)
  811. {
  812. (void) dest_pitch;
  813. (void) src_pitch;
  814. vpx_memcpy(dest, source, dest_width);
  815. }
  816. void vp8cx_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)
  817. {
  818. int i;
  819. int temp;
  820. int width = dest_width;
  821. (void) dest_pitch;
  822. for (i = 0; i < width; i++)
  823. {
  824. temp = 8;
  825. temp += source[i-(int)src_pitch] * 3;
  826. temp += source[i] * 10;
  827. temp += source[i+src_pitch] * 3;
  828. temp >>= 4 ;
  829. dest[i] = (unsigned char)(temp);
  830. }
  831. }