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.

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