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.

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