You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

678 lines
22KB

  1. /*
  2. * DSP functions for Indeo Video Interactive codecs (Indeo4 and Indeo5)
  3. *
  4. * Copyright (c) 2009-2011 Maxim Poliakovski
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /**
  23. * @file
  24. * DSP functions (inverse transforms, motion compensation, wavelet recompostions)
  25. * for Indeo Video Interactive codecs.
  26. */
  27. #include "avcodec.h"
  28. #include "ivi_common.h"
  29. #include "ivi_dsp.h"
  30. void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst,
  31. const int dst_pitch)
  32. {
  33. int x, y, indx;
  34. int32_t p0, p1, p2, p3, tmp0, tmp1, tmp2;
  35. int32_t b0_1, b0_2, b1_1, b1_2, b1_3, b2_1, b2_2, b2_3, b2_4, b2_5, b2_6;
  36. int32_t b3_1, b3_2, b3_3, b3_4, b3_5, b3_6, b3_7, b3_8, b3_9;
  37. int32_t pitch, back_pitch;
  38. const short *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr;
  39. const int num_bands = 4;
  40. /* all bands should have the same pitch */
  41. pitch = plane->bands[0].pitch;
  42. /* pixels at the position "y-1" will be set to pixels at the "y" for the 1st iteration */
  43. back_pitch = 0;
  44. /* get pointers to the wavelet bands */
  45. b0_ptr = plane->bands[0].buf;
  46. b1_ptr = plane->bands[1].buf;
  47. b2_ptr = plane->bands[2].buf;
  48. b3_ptr = plane->bands[3].buf;
  49. for (y = 0; y < plane->height; y += 2) {
  50. if (y+2 >= plane->height)
  51. pitch= 0;
  52. /* load storage variables with values */
  53. if (num_bands > 0) {
  54. b0_1 = b0_ptr[0];
  55. b0_2 = b0_ptr[pitch];
  56. }
  57. if (num_bands > 1) {
  58. b1_1 = b1_ptr[back_pitch];
  59. b1_2 = b1_ptr[0];
  60. b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch];
  61. }
  62. if (num_bands > 2) {
  63. b2_2 = b2_ptr[0]; // b2[x, y ]
  64. b2_3 = b2_2; // b2[x+1,y ] = b2[x,y]
  65. b2_5 = b2_ptr[pitch]; // b2[x ,y+1]
  66. b2_6 = b2_5; // b2[x+1,y+1] = b2[x,y+1]
  67. }
  68. if (num_bands > 3) {
  69. b3_2 = b3_ptr[back_pitch]; // b3[x ,y-1]
  70. b3_3 = b3_2; // b3[x+1,y-1] = b3[x ,y-1]
  71. b3_5 = b3_ptr[0]; // b3[x ,y ]
  72. b3_6 = b3_5; // b3[x+1,y ] = b3[x ,y ]
  73. b3_8 = b3_2 - b3_5*6 + b3_ptr[pitch];
  74. b3_9 = b3_8;
  75. }
  76. for (x = 0, indx = 0; x < plane->width; x+=2, indx++) {
  77. if (x+2 >= plane->width) {
  78. b0_ptr --;
  79. b1_ptr --;
  80. b2_ptr --;
  81. b3_ptr --;
  82. }
  83. /* some values calculated in the previous iterations can */
  84. /* be reused in the next ones, so do appropriate copying */
  85. b2_1 = b2_2; // b2[x-1,y ] = b2[x, y ]
  86. b2_2 = b2_3; // b2[x ,y ] = b2[x+1,y ]
  87. b2_4 = b2_5; // b2[x-1,y+1] = b2[x ,y+1]
  88. b2_5 = b2_6; // b2[x ,y+1] = b2[x+1,y+1]
  89. b3_1 = b3_2; // b3[x-1,y-1] = b3[x ,y-1]
  90. b3_2 = b3_3; // b3[x ,y-1] = b3[x+1,y-1]
  91. b3_4 = b3_5; // b3[x-1,y ] = b3[x ,y ]
  92. b3_5 = b3_6; // b3[x ,y ] = b3[x+1,y ]
  93. b3_7 = b3_8; // vert_HPF(x-1)
  94. b3_8 = b3_9; // vert_HPF(x )
  95. p0 = p1 = p2 = p3 = 0;
  96. /* process the LL-band by applying LPF both vertically and horizontally */
  97. if (num_bands > 0) {
  98. tmp0 = b0_1;
  99. tmp2 = b0_2;
  100. b0_1 = b0_ptr[indx+1];
  101. b0_2 = b0_ptr[pitch+indx+1];
  102. tmp1 = tmp0 + b0_1;
  103. p0 = tmp0 << 4;
  104. p1 = tmp1 << 3;
  105. p2 = (tmp0 + tmp2) << 3;
  106. p3 = (tmp1 + tmp2 + b0_2) << 2;
  107. }
  108. /* process the HL-band by applying HPF vertically and LPF horizontally */
  109. if (num_bands > 1) {
  110. tmp0 = b1_2;
  111. tmp1 = b1_1;
  112. b1_2 = b1_ptr[indx+1];
  113. b1_1 = b1_ptr[back_pitch+indx+1];
  114. tmp2 = tmp1 - tmp0*6 + b1_3;
  115. b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch+indx+1];
  116. p0 += (tmp0 + tmp1) << 3;
  117. p1 += (tmp0 + tmp1 + b1_1 + b1_2) << 2;
  118. p2 += tmp2 << 2;
  119. p3 += (tmp2 + b1_3) << 1;
  120. }
  121. /* process the LH-band by applying LPF vertically and HPF horizontally */
  122. if (num_bands > 2) {
  123. b2_3 = b2_ptr[indx+1];
  124. b2_6 = b2_ptr[pitch+indx+1];
  125. tmp0 = b2_1 + b2_2;
  126. tmp1 = b2_1 - b2_2*6 + b2_3;
  127. p0 += tmp0 << 3;
  128. p1 += tmp1 << 2;
  129. p2 += (tmp0 + b2_4 + b2_5) << 2;
  130. p3 += (tmp1 + b2_4 - b2_5*6 + b2_6) << 1;
  131. }
  132. /* process the HH-band by applying HPF both vertically and horizontally */
  133. if (num_bands > 3) {
  134. b3_6 = b3_ptr[indx+1]; // b3[x+1,y ]
  135. b3_3 = b3_ptr[back_pitch+indx+1]; // b3[x+1,y-1]
  136. tmp0 = b3_1 + b3_4;
  137. tmp1 = b3_2 + b3_5;
  138. tmp2 = b3_3 + b3_6;
  139. b3_9 = b3_3 - b3_6*6 + b3_ptr[pitch+indx+1];
  140. p0 += (tmp0 + tmp1) << 2;
  141. p1 += (tmp0 - tmp1*6 + tmp2) << 1;
  142. p2 += (b3_7 + b3_8) << 1;
  143. p3 += b3_7 - b3_8*6 + b3_9;
  144. }
  145. /* output four pixels */
  146. dst[x] = av_clip_uint8((p0 >> 6) + 128);
  147. dst[x+1] = av_clip_uint8((p1 >> 6) + 128);
  148. dst[dst_pitch+x] = av_clip_uint8((p2 >> 6) + 128);
  149. dst[dst_pitch+x+1] = av_clip_uint8((p3 >> 6) + 128);
  150. }// for x
  151. dst += dst_pitch << 1;
  152. back_pitch = -pitch;
  153. b0_ptr += pitch + 1;
  154. b1_ptr += pitch + 1;
  155. b2_ptr += pitch + 1;
  156. b3_ptr += pitch + 1;
  157. }
  158. }
  159. void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst,
  160. const int dst_pitch)
  161. {
  162. int x, y, indx, b0, b1, b2, b3, p0, p1, p2, p3;
  163. const short *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr;
  164. int32_t pitch;
  165. /* all bands should have the same pitch */
  166. pitch = plane->bands[0].pitch;
  167. /* get pointers to the wavelet bands */
  168. b0_ptr = plane->bands[0].buf;
  169. b1_ptr = plane->bands[1].buf;
  170. b2_ptr = plane->bands[2].buf;
  171. b3_ptr = plane->bands[3].buf;
  172. for (y = 0; y < plane->height; y += 2) {
  173. for (x = 0, indx = 0; x < plane->width; x += 2, indx++) {
  174. /* load coefficients */
  175. b0 = b0_ptr[indx]; //should be: b0 = (num_bands > 0) ? b0_ptr[indx] : 0;
  176. b1 = b1_ptr[indx]; //should be: b1 = (num_bands > 1) ? b1_ptr[indx] : 0;
  177. b2 = b2_ptr[indx]; //should be: b2 = (num_bands > 2) ? b2_ptr[indx] : 0;
  178. b3 = b3_ptr[indx]; //should be: b3 = (num_bands > 3) ? b3_ptr[indx] : 0;
  179. /* haar wavelet recomposition */
  180. p0 = (b0 + b1 + b2 + b3 + 2) >> 2;
  181. p1 = (b0 + b1 - b2 - b3 + 2) >> 2;
  182. p2 = (b0 - b1 + b2 - b3 + 2) >> 2;
  183. p3 = (b0 - b1 - b2 + b3 + 2) >> 2;
  184. /* bias, convert and output four pixels */
  185. dst[x] = av_clip_uint8(p0 + 128);
  186. dst[x + 1] = av_clip_uint8(p1 + 128);
  187. dst[dst_pitch + x] = av_clip_uint8(p2 + 128);
  188. dst[dst_pitch + x + 1] = av_clip_uint8(p3 + 128);
  189. }// for x
  190. dst += dst_pitch << 1;
  191. b0_ptr += pitch;
  192. b1_ptr += pitch;
  193. b2_ptr += pitch;
  194. b3_ptr += pitch;
  195. }// for y
  196. }
  197. /** butterfly operation for the inverse Haar transform */
  198. #define IVI_HAAR_BFLY(s1, s2, o1, o2, t) \
  199. t = (s1 - s2) >> 1;\
  200. o1 = (s1 + s2) >> 1;\
  201. o2 = t;\
  202. /** inverse 8-point Haar transform */
  203. #define INV_HAAR8(s1, s5, s3, s7, s2, s4, s6, s8,\
  204. d1, d2, d3, d4, d5, d6, d7, d8,\
  205. t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
  206. t1 = s1 << 1; t5 = s5 << 1;\
  207. IVI_HAAR_BFLY(t1, t5, t1, t5, t0); IVI_HAAR_BFLY(t1, s3, t1, t3, t0);\
  208. IVI_HAAR_BFLY(t5, s7, t5, t7, t0); IVI_HAAR_BFLY(t1, s2, t1, t2, t0);\
  209. IVI_HAAR_BFLY(t3, s4, t3, t4, t0); IVI_HAAR_BFLY(t5, s6, t5, t6, t0);\
  210. IVI_HAAR_BFLY(t7, s8, t7, t8, t0);\
  211. d1 = COMPENSATE(t1);\
  212. d2 = COMPENSATE(t2);\
  213. d3 = COMPENSATE(t3);\
  214. d4 = COMPENSATE(t4);\
  215. d5 = COMPENSATE(t5);\
  216. d6 = COMPENSATE(t6);\
  217. d7 = COMPENSATE(t7);\
  218. d8 = COMPENSATE(t8); }
  219. /** inverse 4-point Haar transform */
  220. #define INV_HAAR4(s1, s3, s5, s7) {\
  221. HAAR_BFLY(s1, s5); HAAR_BFLY(s1, s3); HAAR_BFLY(s5, s7);\
  222. s1 = COMPENSATE(s1);\
  223. s3 = COMPENSATE(s3);\
  224. s5 = COMPENSATE(s5);\
  225. s7 = COMPENSATE(s7); }
  226. void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
  227. const uint8_t *flags)
  228. {
  229. int i, shift, sp1, sp2, sp3, sp4;
  230. const int32_t *src;
  231. int32_t *dst;
  232. int tmp[64];
  233. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  234. /* apply the InvHaar8 to all columns */
  235. #define COMPENSATE(x) (x)
  236. src = in;
  237. dst = tmp;
  238. for (i = 0; i < 8; i++) {
  239. if (flags[i]) {
  240. /* pre-scaling */
  241. shift = !(i & 4);
  242. sp1 = src[ 0] << shift;
  243. sp2 = src[ 8] << shift;
  244. sp3 = src[16] << shift;
  245. sp4 = src[24] << shift;
  246. INV_HAAR8( sp1, sp2, sp3, sp4,
  247. src[32], src[40], src[48], src[56],
  248. dst[ 0], dst[ 8], dst[16], dst[24],
  249. dst[32], dst[40], dst[48], dst[56],
  250. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  251. } else
  252. dst[ 0] = dst[ 8] = dst[16] = dst[24] =
  253. dst[32] = dst[40] = dst[48] = dst[56] = 0;
  254. src++;
  255. dst++;
  256. }
  257. #undef COMPENSATE
  258. /* apply the InvHaar8 to all rows */
  259. #define COMPENSATE(x) (x)
  260. src = tmp;
  261. for (i = 0; i < 8; i++) {
  262. if ( !src[0] && !src[1] && !src[2] && !src[3]
  263. && !src[4] && !src[5] && !src[6] && !src[7]) {
  264. memset(out, 0, 8 * sizeof(out[0]));
  265. } else {
  266. INV_HAAR8(src[0], src[1], src[2], src[3],
  267. src[4], src[5], src[6], src[7],
  268. out[0], out[1], out[2], out[3],
  269. out[4], out[5], out[6], out[7],
  270. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  271. }
  272. src += 8;
  273. out += pitch;
  274. }
  275. #undef COMPENSATE
  276. }
  277. void ff_ivi_inverse_haar_1x8(const int32_t *in, int16_t *out, uint32_t pitch,
  278. const uint8_t *flags)
  279. {
  280. int i;
  281. const int32_t *src;
  282. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  283. /* apply the InvHaar8 to all columns */
  284. #define COMPENSATE(x) (x)
  285. src = in;
  286. for (i = 0; i < 8; i++) {
  287. if (flags[i]) {
  288. INV_HAAR8(src[ 0], src[ 8], src[16], src[24],
  289. src[32], src[40], src[48], src[56],
  290. out[ 0], out[pitch], out[2*pitch], out[3*pitch],
  291. out[4*pitch], out[5*pitch], out[6*pitch], out[7*pitch],
  292. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  293. } else
  294. out[ 0]= out[ pitch]= out[2*pitch]= out[3*pitch]=
  295. out[4*pitch]= out[5*pitch]= out[6*pitch]= out[7*pitch]= 0;
  296. src++;
  297. out++;
  298. }
  299. #undef COMPENSATE
  300. }
  301. void ff_ivi_inverse_haar_8x1(const int32_t *in, int16_t *out, uint32_t pitch,
  302. const uint8_t *flags)
  303. {
  304. int i;
  305. const int32_t *src;
  306. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  307. /* apply the InvHaar8 to all rows */
  308. #define COMPENSATE(x) (x)
  309. src = in;
  310. for (i = 0; i < 8; i++) {
  311. if ( !src[0] && !src[1] && !src[2] && !src[3]
  312. && !src[4] && !src[5] && !src[6] && !src[7]) {
  313. memset(out, 0, 8 * sizeof(out[0]));
  314. } else {
  315. INV_HAAR8(src[0], src[1], src[2], src[3],
  316. src[4], src[5], src[6], src[7],
  317. out[0], out[1], out[2], out[3],
  318. out[4], out[5], out[6], out[7],
  319. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  320. }
  321. src += 8;
  322. out += pitch;
  323. }
  324. #undef COMPENSATE
  325. }
  326. void ff_ivi_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch,
  327. int blk_size)
  328. {
  329. int x, y;
  330. int16_t dc_coeff;
  331. dc_coeff = (*in + 0) >> 3;
  332. for (y = 0; y < blk_size; out += pitch, y++) {
  333. for (x = 0; x < blk_size; x++)
  334. out[x] = dc_coeff;
  335. }
  336. }
  337. /** butterfly operation for the inverse slant transform */
  338. #define IVI_SLANT_BFLY(s1, s2, o1, o2, t) \
  339. t = s1 - s2;\
  340. o1 = s1 + s2;\
  341. o2 = t;\
  342. /** This is a reflection a,b = 1/2, 5/4 for the inverse slant transform */
  343. #define IVI_IREFLECT(s1, s2, o1, o2, t) \
  344. t = ((s1 + s2*2 + 2) >> 2) + s1;\
  345. o2 = ((s1*2 - s2 + 2) >> 2) - s2;\
  346. o1 = t;\
  347. /** This is a reflection a,b = 1/2, 7/8 for the inverse slant transform */
  348. #define IVI_SLANT_PART4(s1, s2, o1, o2, t) \
  349. t = s2 + ((s1*4 - s2 + 4) >> 3);\
  350. o2 = s1 + ((-s1 - s2*4 + 4) >> 3);\
  351. o1 = t;\
  352. /** inverse slant8 transform */
  353. #define IVI_INV_SLANT8(s1, s4, s8, s5, s2, s6, s3, s7,\
  354. d1, d2, d3, d4, d5, d6, d7, d8,\
  355. t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
  356. IVI_SLANT_PART4(s4, s5, t4, t5, t0);\
  357. \
  358. IVI_SLANT_BFLY(s1, t5, t1, t5, t0); IVI_SLANT_BFLY(s2, s6, t2, t6, t0);\
  359. IVI_SLANT_BFLY(s7, s3, t7, t3, t0); IVI_SLANT_BFLY(t4, s8, t4, t8, t0);\
  360. \
  361. IVI_SLANT_BFLY(t1, t2, t1, t2, t0); IVI_IREFLECT (t4, t3, t4, t3, t0);\
  362. IVI_SLANT_BFLY(t5, t6, t5, t6, t0); IVI_IREFLECT (t8, t7, t8, t7, t0);\
  363. IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\
  364. IVI_SLANT_BFLY(t5, t8, t5, t8, t0); IVI_SLANT_BFLY(t6, t7, t6, t7, t0);\
  365. d1 = COMPENSATE(t1);\
  366. d2 = COMPENSATE(t2);\
  367. d3 = COMPENSATE(t3);\
  368. d4 = COMPENSATE(t4);\
  369. d5 = COMPENSATE(t5);\
  370. d6 = COMPENSATE(t6);\
  371. d7 = COMPENSATE(t7);\
  372. d8 = COMPENSATE(t8);}
  373. /** inverse slant4 transform */
  374. #define IVI_INV_SLANT4(s1, s4, s2, s3, d1, d2, d3, d4, t0, t1, t2, t3, t4) {\
  375. IVI_SLANT_BFLY(s1, s2, t1, t2, t0); IVI_IREFLECT (s4, s3, t4, t3, t0);\
  376. \
  377. IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\
  378. d1 = COMPENSATE(t1);\
  379. d2 = COMPENSATE(t2);\
  380. d3 = COMPENSATE(t3);\
  381. d4 = COMPENSATE(t4);}
  382. void ff_ivi_inverse_slant_8x8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  383. {
  384. int i;
  385. const int32_t *src;
  386. int32_t *dst;
  387. int tmp[64];
  388. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  389. #define COMPENSATE(x) (x)
  390. src = in;
  391. dst = tmp;
  392. for (i = 0; i < 8; i++) {
  393. if (flags[i]) {
  394. IVI_INV_SLANT8(src[0], src[8], src[16], src[24], src[32], src[40], src[48], src[56],
  395. dst[0], dst[8], dst[16], dst[24], dst[32], dst[40], dst[48], dst[56],
  396. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  397. } else
  398. dst[0] = dst[8] = dst[16] = dst[24] = dst[32] = dst[40] = dst[48] = dst[56] = 0;
  399. src++;
  400. dst++;
  401. }
  402. #undef COMPENSATE
  403. #define COMPENSATE(x) ((x + 1)>>1)
  404. src = tmp;
  405. for (i = 0; i < 8; i++) {
  406. if (!src[0] && !src[1] && !src[2] && !src[3] && !src[4] && !src[5] && !src[6] && !src[7]) {
  407. memset(out, 0, 8*sizeof(out[0]));
  408. } else {
  409. IVI_INV_SLANT8(src[0], src[1], src[2], src[3], src[4], src[5], src[6], src[7],
  410. out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
  411. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  412. }
  413. src += 8;
  414. out += pitch;
  415. }
  416. #undef COMPENSATE
  417. }
  418. void ff_ivi_inverse_slant_4x4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  419. {
  420. int i;
  421. const int32_t *src;
  422. int32_t *dst;
  423. int tmp[16];
  424. int t0, t1, t2, t3, t4;
  425. #define COMPENSATE(x) (x)
  426. src = in;
  427. dst = tmp;
  428. for (i = 0; i < 4; i++) {
  429. if (flags[i]) {
  430. IVI_INV_SLANT4(src[0], src[4], src[8], src[12],
  431. dst[0], dst[4], dst[8], dst[12],
  432. t0, t1, t2, t3, t4);
  433. } else
  434. dst[0] = dst[4] = dst[8] = dst[12] = 0;
  435. src++;
  436. dst++;
  437. }
  438. #undef COMPENSATE
  439. #define COMPENSATE(x) ((x + 1)>>1)
  440. src = tmp;
  441. for (i = 0; i < 4; i++) {
  442. if (!src[0] && !src[1] && !src[2] && !src[3]) {
  443. out[0] = out[1] = out[2] = out[3] = 0;
  444. } else {
  445. IVI_INV_SLANT4(src[0], src[1], src[2], src[3],
  446. out[0], out[1], out[2], out[3],
  447. t0, t1, t2, t3, t4);
  448. }
  449. src += 4;
  450. out += pitch;
  451. }
  452. #undef COMPENSATE
  453. }
  454. void ff_ivi_dc_slant_2d(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
  455. {
  456. int x, y;
  457. int16_t dc_coeff;
  458. dc_coeff = (*in + 1) >> 1;
  459. for (y = 0; y < blk_size; out += pitch, y++) {
  460. for (x = 0; x < blk_size; x++)
  461. out[x] = dc_coeff;
  462. }
  463. }
  464. void ff_ivi_row_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  465. {
  466. int i;
  467. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  468. #define COMPENSATE(x) ((x + 1)>>1)
  469. for (i = 0; i < 8; i++) {
  470. if (!in[0] && !in[1] && !in[2] && !in[3] && !in[4] && !in[5] && !in[6] && !in[7]) {
  471. memset(out, 0, 8*sizeof(out[0]));
  472. } else {
  473. IVI_INV_SLANT8( in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7],
  474. out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
  475. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  476. }
  477. in += 8;
  478. out += pitch;
  479. }
  480. #undef COMPENSATE
  481. }
  482. void ff_ivi_dc_row_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
  483. {
  484. int x, y;
  485. int16_t dc_coeff;
  486. dc_coeff = (*in + 1) >> 1;
  487. for (x = 0; x < blk_size; x++)
  488. out[x] = dc_coeff;
  489. out += pitch;
  490. for (y = 1; y < blk_size; out += pitch, y++) {
  491. for (x = 0; x < blk_size; x++)
  492. out[x] = 0;
  493. }
  494. }
  495. void ff_ivi_col_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  496. {
  497. int i, row2, row4, row8;
  498. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  499. row2 = pitch << 1;
  500. row4 = pitch << 2;
  501. row8 = pitch << 3;
  502. #define COMPENSATE(x) ((x + 1)>>1)
  503. for (i = 0; i < 8; i++) {
  504. if (flags[i]) {
  505. IVI_INV_SLANT8(in[0], in[8], in[16], in[24], in[32], in[40], in[48], in[56],
  506. out[0], out[pitch], out[row2], out[row2 + pitch], out[row4],
  507. out[row4 + pitch], out[row4 + row2], out[row8 - pitch],
  508. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  509. } else {
  510. out[0] = out[pitch] = out[row2] = out[row2 + pitch] = out[row4] =
  511. out[row4 + pitch] = out[row4 + row2] = out[row8 - pitch] = 0;
  512. }
  513. in++;
  514. out++;
  515. }
  516. #undef COMPENSATE
  517. }
  518. void ff_ivi_dc_col_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
  519. {
  520. int x, y;
  521. int16_t dc_coeff;
  522. dc_coeff = (*in + 1) >> 1;
  523. for (y = 0; y < blk_size; out += pitch, y++) {
  524. out[0] = dc_coeff;
  525. for (x = 1; x < blk_size; x++)
  526. out[x] = 0;
  527. }
  528. }
  529. void ff_ivi_put_pixels_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
  530. const uint8_t *flags)
  531. {
  532. int x, y;
  533. for (y = 0; y < 8; out += pitch, in += 8, y++)
  534. for (x = 0; x < 8; x++)
  535. out[x] = in[x];
  536. }
  537. void ff_ivi_put_dc_pixel_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
  538. int blk_size)
  539. {
  540. int y;
  541. out[0] = in[0];
  542. memset(out + 1, 0, 7*sizeof(out[0]));
  543. out += pitch;
  544. for (y = 1; y < 8; out += pitch, y++)
  545. memset(out, 0, 8*sizeof(out[0]));
  546. }
  547. #define IVI_MC_TEMPLATE(size, suffix, OP) \
  548. void ff_ivi_mc_ ## size ##x## size ## suffix (int16_t *buf, const int16_t *ref_buf, \
  549. uint32_t pitch, int mc_type) \
  550. { \
  551. int i, j; \
  552. const int16_t *wptr; \
  553. \
  554. switch (mc_type) { \
  555. case 0: /* fullpel (no interpolation) */ \
  556. for (i = 0; i < size; i++, buf += pitch, ref_buf += pitch) { \
  557. for (j = 0; j < size; j++) {\
  558. OP(buf[j], ref_buf[j]); \
  559. } \
  560. } \
  561. break; \
  562. case 1: /* horizontal halfpel interpolation */ \
  563. for (i = 0; i < size; i++, buf += pitch, ref_buf += pitch) \
  564. for (j = 0; j < size; j++) \
  565. OP(buf[j], (ref_buf[j] + ref_buf[j+1]) >> 1); \
  566. break; \
  567. case 2: /* vertical halfpel interpolation */ \
  568. wptr = ref_buf + pitch; \
  569. for (i = 0; i < size; i++, buf += pitch, wptr += pitch, ref_buf += pitch) \
  570. for (j = 0; j < size; j++) \
  571. OP(buf[j], (ref_buf[j] + wptr[j]) >> 1); \
  572. break; \
  573. case 3: /* vertical and horizontal halfpel interpolation */ \
  574. wptr = ref_buf + pitch; \
  575. for (i = 0; i < size; i++, buf += pitch, wptr += pitch, ref_buf += pitch) \
  576. for (j = 0; j < size; j++) \
  577. OP(buf[j], (ref_buf[j] + ref_buf[j+1] + wptr[j] + wptr[j+1]) >> 2); \
  578. break; \
  579. } \
  580. } \
  581. #define OP_PUT(a, b) (a) = (b)
  582. #define OP_ADD(a, b) (a) += (b)
  583. IVI_MC_TEMPLATE(8, _no_delta, OP_PUT)
  584. IVI_MC_TEMPLATE(8, _delta, OP_ADD)
  585. IVI_MC_TEMPLATE(4, _no_delta, OP_PUT)
  586. IVI_MC_TEMPLATE(4, _delta, OP_ADD)