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.

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