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.

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