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.

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