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.

616 lines
20KB

  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 Libav.
  7. *
  8. * Libav 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. * Libav 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 Libav; 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 "dsputil.h"
  29. #include "dwt.h"
  30. #include "ivi_common.h"
  31. #include "ivi_dsp.h"
  32. void ff_ivi_recompose53(const IVIPlaneDesc *plane, uint8_t *dst,
  33. const int dst_pitch)
  34. {
  35. int x, y, indx;
  36. int32_t p0, p1, p2, p3, tmp0, tmp1, tmp2;
  37. int32_t b0_1, b0_2, b1_1, b1_2, b1_3, b2_1, b2_2, b2_3, b2_4, b2_5, b2_6;
  38. int32_t b3_1, b3_2, b3_3, b3_4, b3_5, b3_6, b3_7, b3_8, b3_9;
  39. int32_t pitch, back_pitch;
  40. const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr;
  41. const int num_bands = 4;
  42. /* all bands should have the same pitch */
  43. pitch = plane->bands[0].pitch;
  44. /* pixels at the position "y-1" will be set to pixels at the "y" for the 1st iteration */
  45. back_pitch = 0;
  46. /* get pointers to the wavelet bands */
  47. b0_ptr = plane->bands[0].buf;
  48. b1_ptr = plane->bands[1].buf;
  49. b2_ptr = plane->bands[2].buf;
  50. b3_ptr = plane->bands[3].buf;
  51. for (y = 0; y < plane->height; y += 2) {
  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. /* some values calculated in the previous iterations can */
  78. /* be reused in the next ones, so do appropriate copying */
  79. b2_1 = b2_2; // b2[x-1,y ] = b2[x, y ]
  80. b2_2 = b2_3; // b2[x ,y ] = b2[x+1,y ]
  81. b2_4 = b2_5; // b2[x-1,y+1] = b2[x ,y+1]
  82. b2_5 = b2_6; // b2[x ,y+1] = b2[x+1,y+1]
  83. b3_1 = b3_2; // b3[x-1,y-1] = b3[x ,y-1]
  84. b3_2 = b3_3; // b3[x ,y-1] = b3[x+1,y-1]
  85. b3_4 = b3_5; // b3[x-1,y ] = b3[x ,y ]
  86. b3_5 = b3_6; // b3[x ,y ] = b3[x+1,y ]
  87. b3_7 = b3_8; // vert_HPF(x-1)
  88. b3_8 = b3_9; // vert_HPF(x )
  89. p0 = p1 = p2 = p3 = 0;
  90. /* process the LL-band by applying LPF both vertically and horizontally */
  91. if (num_bands > 0) {
  92. tmp0 = b0_1;
  93. tmp2 = b0_2;
  94. b0_1 = b0_ptr[indx+1];
  95. b0_2 = b0_ptr[pitch+indx+1];
  96. tmp1 = tmp0 + b0_1;
  97. p0 = tmp0 << 4;
  98. p1 = tmp1 << 3;
  99. p2 = (tmp0 + tmp2) << 3;
  100. p3 = (tmp1 + tmp2 + b0_2) << 2;
  101. }
  102. /* process the HL-band by applying HPF vertically and LPF horizontally */
  103. if (num_bands > 1) {
  104. tmp0 = b1_2;
  105. tmp1 = b1_1;
  106. b1_2 = b1_ptr[indx+1];
  107. b1_1 = b1_ptr[back_pitch+indx+1];
  108. tmp2 = tmp1 - tmp0*6 + b1_3;
  109. b1_3 = b1_1 - b1_2*6 + b1_ptr[pitch+indx+1];
  110. p0 += (tmp0 + tmp1) << 3;
  111. p1 += (tmp0 + tmp1 + b1_1 + b1_2) << 2;
  112. p2 += tmp2 << 2;
  113. p3 += (tmp2 + b1_3) << 1;
  114. }
  115. /* process the LH-band by applying LPF vertically and HPF horizontally */
  116. if (num_bands > 2) {
  117. b2_3 = b2_ptr[indx+1];
  118. b2_6 = b2_ptr[pitch+indx+1];
  119. tmp0 = b2_1 + b2_2;
  120. tmp1 = b2_1 - b2_2*6 + b2_3;
  121. p0 += tmp0 << 3;
  122. p1 += tmp1 << 2;
  123. p2 += (tmp0 + b2_4 + b2_5) << 2;
  124. p3 += (tmp1 + b2_4 - b2_5*6 + b2_6) << 1;
  125. }
  126. /* process the HH-band by applying HPF both vertically and horizontally */
  127. if (num_bands > 3) {
  128. b3_6 = b3_ptr[indx+1]; // b3[x+1,y ]
  129. b3_3 = b3_ptr[back_pitch+indx+1]; // b3[x+1,y-1]
  130. tmp0 = b3_1 + b3_4;
  131. tmp1 = b3_2 + b3_5;
  132. tmp2 = b3_3 + b3_6;
  133. b3_9 = b3_3 - b3_6*6 + b3_ptr[pitch+indx+1];
  134. p0 += (tmp0 + tmp1) << 2;
  135. p1 += (tmp0 - tmp1*6 + tmp2) << 1;
  136. p2 += (b3_7 + b3_8) << 1;
  137. p3 += b3_7 - b3_8*6 + b3_9;
  138. }
  139. /* output four pixels */
  140. dst[x] = av_clip_uint8((p0 >> 6) + 128);
  141. dst[x+1] = av_clip_uint8((p1 >> 6) + 128);
  142. dst[dst_pitch+x] = av_clip_uint8((p2 >> 6) + 128);
  143. dst[dst_pitch+x+1] = av_clip_uint8((p3 >> 6) + 128);
  144. }// for x
  145. dst += dst_pitch << 1;
  146. back_pitch = -pitch;
  147. b0_ptr += pitch;
  148. b1_ptr += pitch;
  149. b2_ptr += pitch;
  150. b3_ptr += pitch;
  151. }
  152. }
  153. void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst,
  154. const int dst_pitch)
  155. {
  156. int x, y, indx, b0, b1, b2, b3, p0, p1, p2, p3;
  157. const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr;
  158. int32_t pitch;
  159. /* all bands should have the same pitch */
  160. pitch = plane->bands[0].pitch;
  161. /* get pointers to the wavelet bands */
  162. b0_ptr = plane->bands[0].buf;
  163. b1_ptr = plane->bands[1].buf;
  164. b2_ptr = plane->bands[2].buf;
  165. b3_ptr = plane->bands[3].buf;
  166. for (y = 0; y < plane->height; y += 2) {
  167. for (x = 0, indx = 0; x < plane->width; x += 2, indx++) {
  168. /* load coefficients */
  169. b0 = b0_ptr[indx]; //should be: b0 = (num_bands > 0) ? b0_ptr[indx] : 0;
  170. b1 = b1_ptr[indx]; //should be: b1 = (num_bands > 1) ? b1_ptr[indx] : 0;
  171. b2 = b2_ptr[indx]; //should be: b2 = (num_bands > 2) ? b2_ptr[indx] : 0;
  172. b3 = b3_ptr[indx]; //should be: b3 = (num_bands > 3) ? b3_ptr[indx] : 0;
  173. /* haar wavelet recomposition */
  174. p0 = (b0 + b1 + b2 + b3 + 2) >> 2;
  175. p1 = (b0 + b1 - b2 - b3 + 2) >> 2;
  176. p2 = (b0 - b1 + b2 - b3 + 2) >> 2;
  177. p3 = (b0 - b1 - b2 + b3 + 2) >> 2;
  178. /* bias, convert and output four pixels */
  179. dst[x] = av_clip_uint8(p0 + 128);
  180. dst[x + 1] = av_clip_uint8(p1 + 128);
  181. dst[dst_pitch + x] = av_clip_uint8(p2 + 128);
  182. dst[dst_pitch + x + 1] = av_clip_uint8(p3 + 128);
  183. }// for x
  184. dst += dst_pitch << 1;
  185. b0_ptr += pitch;
  186. b1_ptr += pitch;
  187. b2_ptr += pitch;
  188. b3_ptr += pitch;
  189. }// for y
  190. }
  191. /** butterfly operation for the inverse Haar transform */
  192. #define IVI_HAAR_BFLY(s1, s2, o1, o2, t) \
  193. t = (s1 - s2) >> 1;\
  194. o1 = (s1 + s2) >> 1;\
  195. o2 = t;\
  196. /** inverse 8-point Haar transform */
  197. #define INV_HAAR8(s1, s5, s3, s7, s2, s4, s6, s8,\
  198. d1, d2, d3, d4, d5, d6, d7, d8,\
  199. t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
  200. t1 = s1 << 1; t5 = s5 << 1;\
  201. IVI_HAAR_BFLY(t1, t5, t1, t5, t0); IVI_HAAR_BFLY(t1, s3, t1, t3, t0);\
  202. IVI_HAAR_BFLY(t5, s7, t5, t7, t0); IVI_HAAR_BFLY(t1, s2, t1, t2, t0);\
  203. IVI_HAAR_BFLY(t3, s4, t3, t4, t0); IVI_HAAR_BFLY(t5, s6, t5, t6, t0);\
  204. IVI_HAAR_BFLY(t7, s8, t7, t8, t0);\
  205. d1 = COMPENSATE(t1);\
  206. d2 = COMPENSATE(t2);\
  207. d3 = COMPENSATE(t3);\
  208. d4 = COMPENSATE(t4);\
  209. d5 = COMPENSATE(t5);\
  210. d6 = COMPENSATE(t6);\
  211. d7 = COMPENSATE(t7);\
  212. d8 = COMPENSATE(t8); }
  213. /** inverse 4-point Haar transform */
  214. #define INV_HAAR4(s1, s3, s5, s7) {\
  215. HAAR_BFLY(s1, s5); HAAR_BFLY(s1, s3); HAAR_BFLY(s5, s7);\
  216. s1 = COMPENSATE(s1);\
  217. s3 = COMPENSATE(s3);\
  218. s5 = COMPENSATE(s5);\
  219. s7 = COMPENSATE(s7); }
  220. void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
  221. const uint8_t *flags)
  222. {
  223. int i, shift, sp1, sp2, sp3, sp4;
  224. const int32_t *src;
  225. int32_t *dst;
  226. int tmp[64];
  227. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  228. /* apply the InvHaar8 to all columns */
  229. #define COMPENSATE(x) (x)
  230. src = in;
  231. dst = tmp;
  232. for (i = 0; i < 8; i++) {
  233. if (flags[i]) {
  234. /* pre-scaling */
  235. shift = !(i & 4);
  236. sp1 = src[ 0] << shift;
  237. sp2 = src[ 8] << shift;
  238. sp3 = src[16] << shift;
  239. sp4 = src[24] << shift;
  240. INV_HAAR8( sp1, sp2, sp3, sp4,
  241. src[32], src[40], src[48], src[56],
  242. dst[ 0], dst[ 8], dst[16], dst[24],
  243. dst[32], dst[40], dst[48], dst[56],
  244. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  245. } else
  246. dst[ 0] = dst[ 8] = dst[16] = dst[24] =
  247. dst[32] = dst[40] = dst[48] = dst[56] = 0;
  248. src++;
  249. dst++;
  250. }
  251. #undef COMPENSATE
  252. /* apply the InvHaar8 to all rows */
  253. #define COMPENSATE(x) (x)
  254. src = tmp;
  255. for (i = 0; i < 8; i++) {
  256. if ( !src[0] && !src[1] && !src[2] && !src[3]
  257. && !src[4] && !src[5] && !src[6] && !src[7]) {
  258. memset(out, 0, 8 * sizeof(out[0]));
  259. } else {
  260. INV_HAAR8(src[0], src[1], src[2], src[3],
  261. src[4], src[5], src[6], src[7],
  262. out[0], out[1], out[2], out[3],
  263. out[4], out[5], out[6], out[7],
  264. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  265. }
  266. src += 8;
  267. out += pitch;
  268. }
  269. #undef COMPENSATE
  270. }
  271. void ff_ivi_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch,
  272. int blk_size)
  273. {
  274. int x, y;
  275. int16_t dc_coeff;
  276. dc_coeff = (*in + 0) >> 3;
  277. for (y = 0; y < blk_size; out += pitch, y++) {
  278. for (x = 0; x < blk_size; x++)
  279. out[x] = dc_coeff;
  280. }
  281. }
  282. /** butterfly operation for the inverse slant transform */
  283. #define IVI_SLANT_BFLY(s1, s2, o1, o2, t) \
  284. t = s1 - s2;\
  285. o1 = s1 + s2;\
  286. o2 = t;\
  287. /** This is a reflection a,b = 1/2, 5/4 for the inverse slant transform */
  288. #define IVI_IREFLECT(s1, s2, o1, o2, t) \
  289. t = ((s1 + s2*2 + 2) >> 2) + s1;\
  290. o2 = ((s1*2 - s2 + 2) >> 2) - s2;\
  291. o1 = t;\
  292. /** This is a reflection a,b = 1/2, 7/8 for the inverse slant transform */
  293. #define IVI_SLANT_PART4(s1, s2, o1, o2, t) \
  294. t = s2 + ((s1*4 - s2 + 4) >> 3);\
  295. o2 = s1 + ((-s1 - s2*4 + 4) >> 3);\
  296. o1 = t;\
  297. /** inverse slant8 transform */
  298. #define IVI_INV_SLANT8(s1, s4, s8, s5, s2, s6, s3, s7,\
  299. d1, d2, d3, d4, d5, d6, d7, d8,\
  300. t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
  301. IVI_SLANT_PART4(s4, s5, t4, t5, t0);\
  302. \
  303. IVI_SLANT_BFLY(s1, t5, t1, t5, t0); IVI_SLANT_BFLY(s2, s6, t2, t6, t0);\
  304. IVI_SLANT_BFLY(s7, s3, t7, t3, t0); IVI_SLANT_BFLY(t4, s8, t4, t8, t0);\
  305. \
  306. IVI_SLANT_BFLY(t1, t2, t1, t2, t0); IVI_IREFLECT (t4, t3, t4, t3, t0);\
  307. IVI_SLANT_BFLY(t5, t6, t5, t6, t0); IVI_IREFLECT (t8, t7, t8, t7, t0);\
  308. IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\
  309. IVI_SLANT_BFLY(t5, t8, t5, t8, t0); IVI_SLANT_BFLY(t6, t7, t6, t7, t0);\
  310. d1 = COMPENSATE(t1);\
  311. d2 = COMPENSATE(t2);\
  312. d3 = COMPENSATE(t3);\
  313. d4 = COMPENSATE(t4);\
  314. d5 = COMPENSATE(t5);\
  315. d6 = COMPENSATE(t6);\
  316. d7 = COMPENSATE(t7);\
  317. d8 = COMPENSATE(t8);}
  318. /** inverse slant4 transform */
  319. #define IVI_INV_SLANT4(s1, s4, s2, s3, d1, d2, d3, d4, t0, t1, t2, t3, t4) {\
  320. IVI_SLANT_BFLY(s1, s2, t1, t2, t0); IVI_IREFLECT (s4, s3, t4, t3, t0);\
  321. \
  322. IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\
  323. d1 = COMPENSATE(t1);\
  324. d2 = COMPENSATE(t2);\
  325. d3 = COMPENSATE(t3);\
  326. d4 = COMPENSATE(t4);}
  327. void ff_ivi_inverse_slant_8x8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  328. {
  329. int i;
  330. const int32_t *src;
  331. int32_t *dst;
  332. int tmp[64];
  333. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  334. #define COMPENSATE(x) (x)
  335. src = in;
  336. dst = tmp;
  337. for (i = 0; i < 8; i++) {
  338. if (flags[i]) {
  339. IVI_INV_SLANT8(src[0], src[8], src[16], src[24], src[32], src[40], src[48], src[56],
  340. dst[0], dst[8], dst[16], dst[24], dst[32], dst[40], dst[48], dst[56],
  341. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  342. } else
  343. dst[0] = dst[8] = dst[16] = dst[24] = dst[32] = dst[40] = dst[48] = dst[56] = 0;
  344. src++;
  345. dst++;
  346. }
  347. #undef COMPENSATE
  348. #define COMPENSATE(x) ((x + 1)>>1)
  349. src = tmp;
  350. for (i = 0; i < 8; i++) {
  351. if (!src[0] && !src[1] && !src[2] && !src[3] && !src[4] && !src[5] && !src[6] && !src[7]) {
  352. memset(out, 0, 8*sizeof(out[0]));
  353. } else {
  354. IVI_INV_SLANT8(src[0], src[1], src[2], src[3], src[4], src[5], src[6], src[7],
  355. out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
  356. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  357. }
  358. src += 8;
  359. out += pitch;
  360. }
  361. #undef COMPENSATE
  362. }
  363. void ff_ivi_inverse_slant_4x4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  364. {
  365. int i;
  366. const int32_t *src;
  367. int32_t *dst;
  368. int tmp[16];
  369. int t0, t1, t2, t3, t4;
  370. #define COMPENSATE(x) (x)
  371. src = in;
  372. dst = tmp;
  373. for (i = 0; i < 4; i++) {
  374. if (flags[i]) {
  375. IVI_INV_SLANT4(src[0], src[4], src[8], src[12],
  376. dst[0], dst[4], dst[8], dst[12],
  377. t0, t1, t2, t3, t4);
  378. } else
  379. dst[0] = dst[4] = dst[8] = dst[12] = 0;
  380. src++;
  381. dst++;
  382. }
  383. #undef COMPENSATE
  384. #define COMPENSATE(x) ((x + 1)>>1)
  385. src = tmp;
  386. for (i = 0; i < 4; i++) {
  387. if (!src[0] && !src[1] && !src[2] && !src[3]) {
  388. out[0] = out[1] = out[2] = out[3] = 0;
  389. } else {
  390. IVI_INV_SLANT4(src[0], src[1], src[2], src[3],
  391. out[0], out[1], out[2], out[3],
  392. t0, t1, t2, t3, t4);
  393. }
  394. src += 4;
  395. out += pitch;
  396. }
  397. #undef COMPENSATE
  398. }
  399. void ff_ivi_dc_slant_2d(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
  400. {
  401. int x, y;
  402. int16_t dc_coeff;
  403. dc_coeff = (*in + 1) >> 1;
  404. for (y = 0; y < blk_size; out += pitch, y++) {
  405. for (x = 0; x < blk_size; x++)
  406. out[x] = dc_coeff;
  407. }
  408. }
  409. void ff_ivi_row_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  410. {
  411. int i;
  412. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  413. #define COMPENSATE(x) ((x + 1)>>1)
  414. for (i = 0; i < 8; i++) {
  415. if (!in[0] && !in[1] && !in[2] && !in[3] && !in[4] && !in[5] && !in[6] && !in[7]) {
  416. memset(out, 0, 8*sizeof(out[0]));
  417. } else {
  418. IVI_INV_SLANT8( in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7],
  419. out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
  420. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  421. }
  422. in += 8;
  423. out += pitch;
  424. }
  425. #undef COMPENSATE
  426. }
  427. void ff_ivi_dc_row_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
  428. {
  429. int x, y;
  430. int16_t dc_coeff;
  431. dc_coeff = (*in + 1) >> 1;
  432. for (x = 0; x < blk_size; x++)
  433. out[x] = dc_coeff;
  434. out += pitch;
  435. for (y = 1; y < blk_size; out += pitch, y++) {
  436. for (x = 0; x < blk_size; x++)
  437. out[x] = 0;
  438. }
  439. }
  440. void ff_ivi_col_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  441. {
  442. int i, row2, row4, row8;
  443. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  444. row2 = pitch << 1;
  445. row4 = pitch << 2;
  446. row8 = pitch << 3;
  447. #define COMPENSATE(x) ((x + 1)>>1)
  448. for (i = 0; i < 8; i++) {
  449. if (flags[i]) {
  450. IVI_INV_SLANT8(in[0], in[8], in[16], in[24], in[32], in[40], in[48], in[56],
  451. out[0], out[pitch], out[row2], out[row2 + pitch], out[row4],
  452. out[row4 + pitch], out[row4 + row2], out[row8 - pitch],
  453. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  454. } else {
  455. out[0] = out[pitch] = out[row2] = out[row2 + pitch] = out[row4] =
  456. out[row4 + pitch] = out[row4 + row2] = out[row8 - pitch] = 0;
  457. }
  458. in++;
  459. out++;
  460. }
  461. #undef COMPENSATE
  462. }
  463. void ff_ivi_dc_col_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
  464. {
  465. int x, y;
  466. int16_t dc_coeff;
  467. dc_coeff = (*in + 1) >> 1;
  468. for (y = 0; y < blk_size; out += pitch, y++) {
  469. out[0] = dc_coeff;
  470. for (x = 1; x < blk_size; x++)
  471. out[x] = 0;
  472. }
  473. }
  474. void ff_ivi_put_pixels_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
  475. const uint8_t *flags)
  476. {
  477. int x, y;
  478. for (y = 0; y < 8; out += pitch, in += 8, y++)
  479. for (x = 0; x < 8; x++)
  480. out[x] = in[x];
  481. }
  482. void ff_ivi_put_dc_pixel_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
  483. int blk_size)
  484. {
  485. int y;
  486. out[0] = in[0];
  487. memset(out + 1, 0, 7*sizeof(out[0]));
  488. out += pitch;
  489. for (y = 1; y < 8; out += pitch, y++)
  490. memset(out, 0, 8*sizeof(out[0]));
  491. }
  492. #define IVI_MC_TEMPLATE(size, suffix, OP) \
  493. void ff_ivi_mc_ ## size ##x## size ## suffix (int16_t *buf, const int16_t *ref_buf, \
  494. uint32_t pitch, int mc_type) \
  495. { \
  496. int i, j; \
  497. const int16_t *wptr; \
  498. \
  499. switch (mc_type) { \
  500. case 0: /* fullpel (no interpolation) */ \
  501. for (i = 0; i < size; i++, buf += pitch, ref_buf += pitch) { \
  502. for (j = 0; j < size; j++) {\
  503. OP(buf[j], ref_buf[j]); \
  504. } \
  505. } \
  506. break; \
  507. case 1: /* horizontal halfpel interpolation */ \
  508. for (i = 0; i < size; i++, buf += pitch, ref_buf += pitch) \
  509. for (j = 0; j < size; j++) \
  510. OP(buf[j], (ref_buf[j] + ref_buf[j+1]) >> 1); \
  511. break; \
  512. case 2: /* vertical halfpel interpolation */ \
  513. wptr = ref_buf + pitch; \
  514. for (i = 0; i < size; i++, buf += pitch, wptr += pitch, ref_buf += pitch) \
  515. for (j = 0; j < size; j++) \
  516. OP(buf[j], (ref_buf[j] + wptr[j]) >> 1); \
  517. break; \
  518. case 3: /* vertical and horizontal halfpel interpolation */ \
  519. wptr = ref_buf + pitch; \
  520. for (i = 0; i < size; i++, buf += pitch, wptr += pitch, ref_buf += pitch) \
  521. for (j = 0; j < size; j++) \
  522. OP(buf[j], (ref_buf[j] + ref_buf[j+1] + wptr[j] + wptr[j+1]) >> 2); \
  523. break; \
  524. } \
  525. } \
  526. #define OP_PUT(a, b) (a) = (b)
  527. #define OP_ADD(a, b) (a) += (b)
  528. IVI_MC_TEMPLATE(8, _no_delta, OP_PUT)
  529. IVI_MC_TEMPLATE(8, _delta, OP_ADD)
  530. IVI_MC_TEMPLATE(4, _no_delta, OP_PUT)
  531. IVI_MC_TEMPLATE(4, _delta, OP_ADD)