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.

624 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 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_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch,
  278. int blk_size)
  279. {
  280. int x, y;
  281. int16_t dc_coeff;
  282. dc_coeff = (*in + 0) >> 3;
  283. for (y = 0; y < blk_size; out += pitch, y++) {
  284. for (x = 0; x < blk_size; x++)
  285. out[x] = dc_coeff;
  286. }
  287. }
  288. /** butterfly operation for the inverse slant transform */
  289. #define IVI_SLANT_BFLY(s1, s2, o1, o2, t) \
  290. t = s1 - s2;\
  291. o1 = s1 + s2;\
  292. o2 = t;\
  293. /** This is a reflection a,b = 1/2, 5/4 for the inverse slant transform */
  294. #define IVI_IREFLECT(s1, s2, o1, o2, t) \
  295. t = ((s1 + s2*2 + 2) >> 2) + s1;\
  296. o2 = ((s1*2 - s2 + 2) >> 2) - s2;\
  297. o1 = t;\
  298. /** This is a reflection a,b = 1/2, 7/8 for the inverse slant transform */
  299. #define IVI_SLANT_PART4(s1, s2, o1, o2, t) \
  300. t = s2 + ((s1*4 - s2 + 4) >> 3);\
  301. o2 = s1 + ((-s1 - s2*4 + 4) >> 3);\
  302. o1 = t;\
  303. /** inverse slant8 transform */
  304. #define IVI_INV_SLANT8(s1, s4, s8, s5, s2, s6, s3, s7,\
  305. d1, d2, d3, d4, d5, d6, d7, d8,\
  306. t0, t1, t2, t3, t4, t5, t6, t7, t8) {\
  307. IVI_SLANT_PART4(s4, s5, t4, t5, t0);\
  308. \
  309. IVI_SLANT_BFLY(s1, t5, t1, t5, t0); IVI_SLANT_BFLY(s2, s6, t2, t6, t0);\
  310. IVI_SLANT_BFLY(s7, s3, t7, t3, t0); IVI_SLANT_BFLY(t4, s8, t4, t8, t0);\
  311. \
  312. IVI_SLANT_BFLY(t1, t2, t1, t2, t0); IVI_IREFLECT (t4, t3, t4, t3, t0);\
  313. IVI_SLANT_BFLY(t5, t6, t5, t6, t0); IVI_IREFLECT (t8, t7, t8, t7, t0);\
  314. IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\
  315. IVI_SLANT_BFLY(t5, t8, t5, t8, t0); IVI_SLANT_BFLY(t6, t7, t6, t7, t0);\
  316. d1 = COMPENSATE(t1);\
  317. d2 = COMPENSATE(t2);\
  318. d3 = COMPENSATE(t3);\
  319. d4 = COMPENSATE(t4);\
  320. d5 = COMPENSATE(t5);\
  321. d6 = COMPENSATE(t6);\
  322. d7 = COMPENSATE(t7);\
  323. d8 = COMPENSATE(t8);}
  324. /** inverse slant4 transform */
  325. #define IVI_INV_SLANT4(s1, s4, s2, s3, d1, d2, d3, d4, t0, t1, t2, t3, t4) {\
  326. IVI_SLANT_BFLY(s1, s2, t1, t2, t0); IVI_IREFLECT (s4, s3, t4, t3, t0);\
  327. \
  328. IVI_SLANT_BFLY(t1, t4, t1, t4, t0); IVI_SLANT_BFLY(t2, t3, t2, t3, t0);\
  329. d1 = COMPENSATE(t1);\
  330. d2 = COMPENSATE(t2);\
  331. d3 = COMPENSATE(t3);\
  332. d4 = COMPENSATE(t4);}
  333. void ff_ivi_inverse_slant_8x8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  334. {
  335. int i;
  336. const int32_t *src;
  337. int32_t *dst;
  338. int tmp[64];
  339. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  340. #define COMPENSATE(x) (x)
  341. src = in;
  342. dst = tmp;
  343. for (i = 0; i < 8; i++) {
  344. if (flags[i]) {
  345. IVI_INV_SLANT8(src[0], src[8], src[16], src[24], src[32], src[40], src[48], src[56],
  346. dst[0], dst[8], dst[16], dst[24], dst[32], dst[40], dst[48], dst[56],
  347. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  348. } else
  349. dst[0] = dst[8] = dst[16] = dst[24] = dst[32] = dst[40] = dst[48] = dst[56] = 0;
  350. src++;
  351. dst++;
  352. }
  353. #undef COMPENSATE
  354. #define COMPENSATE(x) ((x + 1)>>1)
  355. src = tmp;
  356. for (i = 0; i < 8; i++) {
  357. if (!src[0] && !src[1] && !src[2] && !src[3] && !src[4] && !src[5] && !src[6] && !src[7]) {
  358. memset(out, 0, 8*sizeof(out[0]));
  359. } else {
  360. IVI_INV_SLANT8(src[0], src[1], src[2], src[3], src[4], src[5], src[6], src[7],
  361. out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
  362. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  363. }
  364. src += 8;
  365. out += pitch;
  366. }
  367. #undef COMPENSATE
  368. }
  369. void ff_ivi_inverse_slant_4x4(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  370. {
  371. int i;
  372. const int32_t *src;
  373. int32_t *dst;
  374. int tmp[16];
  375. int t0, t1, t2, t3, t4;
  376. #define COMPENSATE(x) (x)
  377. src = in;
  378. dst = tmp;
  379. for (i = 0; i < 4; i++) {
  380. if (flags[i]) {
  381. IVI_INV_SLANT4(src[0], src[4], src[8], src[12],
  382. dst[0], dst[4], dst[8], dst[12],
  383. t0, t1, t2, t3, t4);
  384. } else
  385. dst[0] = dst[4] = dst[8] = dst[12] = 0;
  386. src++;
  387. dst++;
  388. }
  389. #undef COMPENSATE
  390. #define COMPENSATE(x) ((x + 1)>>1)
  391. src = tmp;
  392. for (i = 0; i < 4; i++) {
  393. if (!src[0] && !src[1] && !src[2] && !src[3]) {
  394. out[0] = out[1] = out[2] = out[3] = 0;
  395. } else {
  396. IVI_INV_SLANT4(src[0], src[1], src[2], src[3],
  397. out[0], out[1], out[2], out[3],
  398. t0, t1, t2, t3, t4);
  399. }
  400. src += 4;
  401. out += pitch;
  402. }
  403. #undef COMPENSATE
  404. }
  405. void ff_ivi_dc_slant_2d(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
  406. {
  407. int x, y;
  408. int16_t dc_coeff;
  409. dc_coeff = (*in + 1) >> 1;
  410. for (y = 0; y < blk_size; out += pitch, y++) {
  411. for (x = 0; x < blk_size; x++)
  412. out[x] = dc_coeff;
  413. }
  414. }
  415. void ff_ivi_row_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  416. {
  417. int i;
  418. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  419. #define COMPENSATE(x) ((x + 1)>>1)
  420. for (i = 0; i < 8; i++) {
  421. if (!in[0] && !in[1] && !in[2] && !in[3] && !in[4] && !in[5] && !in[6] && !in[7]) {
  422. memset(out, 0, 8*sizeof(out[0]));
  423. } else {
  424. IVI_INV_SLANT8( in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7],
  425. out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7],
  426. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  427. }
  428. in += 8;
  429. out += pitch;
  430. }
  431. #undef COMPENSATE
  432. }
  433. void ff_ivi_dc_row_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
  434. {
  435. int x, y;
  436. int16_t dc_coeff;
  437. dc_coeff = (*in + 1) >> 1;
  438. for (x = 0; x < blk_size; x++)
  439. out[x] = dc_coeff;
  440. out += pitch;
  441. for (y = 1; y < blk_size; out += pitch, y++) {
  442. for (x = 0; x < blk_size; x++)
  443. out[x] = 0;
  444. }
  445. }
  446. void ff_ivi_col_slant8(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags)
  447. {
  448. int i, row2, row4, row8;
  449. int t0, t1, t2, t3, t4, t5, t6, t7, t8;
  450. row2 = pitch << 1;
  451. row4 = pitch << 2;
  452. row8 = pitch << 3;
  453. #define COMPENSATE(x) ((x + 1)>>1)
  454. for (i = 0; i < 8; i++) {
  455. if (flags[i]) {
  456. IVI_INV_SLANT8(in[0], in[8], in[16], in[24], in[32], in[40], in[48], in[56],
  457. out[0], out[pitch], out[row2], out[row2 + pitch], out[row4],
  458. out[row4 + pitch], out[row4 + row2], out[row8 - pitch],
  459. t0, t1, t2, t3, t4, t5, t6, t7, t8);
  460. } else {
  461. out[0] = out[pitch] = out[row2] = out[row2 + pitch] = out[row4] =
  462. out[row4 + pitch] = out[row4 + row2] = out[row8 - pitch] = 0;
  463. }
  464. in++;
  465. out++;
  466. }
  467. #undef COMPENSATE
  468. }
  469. void ff_ivi_dc_col_slant(const int32_t *in, int16_t *out, uint32_t pitch, int blk_size)
  470. {
  471. int x, y;
  472. int16_t dc_coeff;
  473. dc_coeff = (*in + 1) >> 1;
  474. for (y = 0; y < blk_size; out += pitch, y++) {
  475. out[0] = dc_coeff;
  476. for (x = 1; x < blk_size; x++)
  477. out[x] = 0;
  478. }
  479. }
  480. void ff_ivi_put_pixels_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
  481. const uint8_t *flags)
  482. {
  483. int x, y;
  484. for (y = 0; y < 8; out += pitch, in += 8, y++)
  485. for (x = 0; x < 8; x++)
  486. out[x] = in[x];
  487. }
  488. void ff_ivi_put_dc_pixel_8x8(const int32_t *in, int16_t *out, uint32_t pitch,
  489. int blk_size)
  490. {
  491. int y;
  492. out[0] = in[0];
  493. memset(out + 1, 0, 7*sizeof(out[0]));
  494. out += pitch;
  495. for (y = 1; y < 8; out += pitch, y++)
  496. memset(out, 0, 8*sizeof(out[0]));
  497. }
  498. #define IVI_MC_TEMPLATE(size, suffix, OP) \
  499. void ff_ivi_mc_ ## size ##x## size ## suffix (int16_t *buf, const int16_t *ref_buf, \
  500. uint32_t pitch, int mc_type) \
  501. { \
  502. int i, j; \
  503. const int16_t *wptr; \
  504. \
  505. switch (mc_type) { \
  506. case 0: /* fullpel (no 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]); \
  510. } \
  511. } \
  512. break; \
  513. case 1: /* horizontal halfpel interpolation */ \
  514. for (i = 0; i < size; i++, buf += pitch, ref_buf += pitch) \
  515. for (j = 0; j < size; j++) \
  516. OP(buf[j], (ref_buf[j] + ref_buf[j+1]) >> 1); \
  517. break; \
  518. case 2: /* vertical 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] + wptr[j]) >> 1); \
  523. break; \
  524. case 3: /* vertical and horizontal halfpel interpolation */ \
  525. wptr = ref_buf + pitch; \
  526. for (i = 0; i < size; i++, buf += pitch, wptr += pitch, ref_buf += pitch) \
  527. for (j = 0; j < size; j++) \
  528. OP(buf[j], (ref_buf[j] + ref_buf[j+1] + wptr[j] + wptr[j+1]) >> 2); \
  529. break; \
  530. } \
  531. } \
  532. #define OP_PUT(a, b) (a) = (b)
  533. #define OP_ADD(a, b) (a) += (b)
  534. IVI_MC_TEMPLATE(8, _no_delta, OP_PUT)
  535. IVI_MC_TEMPLATE(8, _delta, OP_ADD)
  536. IVI_MC_TEMPLATE(4, _no_delta, OP_PUT)
  537. IVI_MC_TEMPLATE(4, _delta, OP_ADD)