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.

609 lines
20KB

  1. /*
  2. * Copyright (C) 2004-2010 Michael Niedermayer <michaelni@gmx.at>
  3. * Copyright (C) 2008 David Conrad
  4. * Copyright (C) 2015 Open Broadcast Systems Ltd.
  5. * Author (C) 2015 Rostislav Pehlivanov <atomnuker@gmail.com>
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #if defined(TEMPLATE_8bit)
  24. # define RENAME(N) N ## _8bit
  25. # define TYPE int16_t
  26. # undef TEMPLATE_8bit
  27. #elif defined(TEMPLATE_10bit)
  28. # define RENAME(N) N ## _10bit
  29. # define TYPE int32_t
  30. # undef TEMPLATE_10bit
  31. #elif defined(TEMPLATE_12bit)
  32. # define RENAME(N) N ## _12bit
  33. # define TYPE int32_t
  34. # undef TEMPLATE_12bit
  35. #endif
  36. static void RENAME(vertical_compose53iL0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
  37. int width)
  38. {
  39. int i;
  40. TYPE *b0 = (TYPE *)_b0;
  41. TYPE *b1 = (TYPE *)_b1;
  42. TYPE *b2 = (TYPE *)_b2;
  43. for (i = 0; i < width; i++)
  44. b1[i] -= (unsigned)((int)(b0[i] + (unsigned)b2[i] + 2) >> 2);
  45. }
  46. static av_always_inline void RENAME(interleave)(TYPE *dst, TYPE *src0, TYPE *src1, int w2,
  47. int add, int shift)
  48. {
  49. int i;
  50. for (i = 0; i < w2; i++) {
  51. dst[2*i ] = (src0[i] + add) >> shift;
  52. dst[2*i+1] = (src1[i] + add) >> shift;
  53. }
  54. }
  55. static void RENAME(horizontal_compose_dirac53i)(uint8_t *_b, uint8_t *_temp, int w)
  56. {
  57. int x;
  58. const int w2 = w >> 1;
  59. TYPE *b = (TYPE *)_b;
  60. TYPE *temp = (TYPE *)_temp;
  61. temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
  62. for (x = 1; x < w2; x++) {
  63. temp[x ] = COMPOSE_53iL0 (b[x+w2-1], b[x ], b[x+w2]);
  64. temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]);
  65. }
  66. temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]);
  67. RENAME(interleave)(b, temp, temp+w2, w2, 1, 1);
  68. }
  69. static void RENAME(horizontal_compose_dd97i)(uint8_t *_b, uint8_t *_tmp, int w)
  70. {
  71. int x;
  72. const int w2 = w >> 1;
  73. TYPE *b = (TYPE *)_b;
  74. TYPE *tmp = (TYPE *)_tmp;
  75. tmp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]);
  76. for (x = 1; x < w2; x++)
  77. tmp[x] = COMPOSE_53iL0(b[x+w2-1], b[x], b[x+w2]);
  78. // extend the edges
  79. tmp[-1] = tmp[0];
  80. tmp[w2+1] = tmp[w2] = tmp[w2-1];
  81. for (x = 0; x < w2; x++) {
  82. b[2*x ] = (tmp[x] + 1)>>1;
  83. b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
  84. }
  85. }
  86. static void RENAME(horizontal_compose_dd137i)(uint8_t *_b, uint8_t *_tmp, int w)
  87. {
  88. const int w2 = w >> 1;
  89. int x;
  90. TYPE *b = (TYPE *)_b;
  91. TYPE *tmp = (TYPE *)_tmp;
  92. tmp[0] = COMPOSE_DD137iL0(b[w2], b[w2], b[0], b[w2 ], b[w2+1]);
  93. tmp[1] = COMPOSE_DD137iL0(b[w2], b[w2], b[1], b[w2+1], b[w2+2]);
  94. for (x = 2; x < w2-1; x++)
  95. tmp[x] = COMPOSE_DD137iL0(b[x+w2-2], b[x+w2-1], b[x], b[x+w2], b[x+w2+1]);
  96. tmp[w2-1] = COMPOSE_DD137iL0(b[w-3], b[w-2], b[w2-1], b[w-1], b[w-1]);
  97. // extend the edges
  98. tmp[-1] = tmp[0];
  99. tmp[w2+1] = tmp[w2] = tmp[w2-1];
  100. for (x = 0; x < w2; x++) {
  101. b[2*x ] = (tmp[x] + 1)>>1;
  102. b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1;
  103. }
  104. }
  105. static av_always_inline void RENAME(horizontal_compose_haari)(TYPE *b, TYPE *temp,
  106. int w, int shift)
  107. {
  108. const int w2 = w >> 1;
  109. int x;
  110. for (x = 0; x < w2; x++) {
  111. temp[x ] = COMPOSE_HAARiL0(b[x ], b[x+w2]);
  112. temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]);
  113. }
  114. RENAME(interleave)(b, temp, temp+w2, w2, shift, shift);
  115. }
  116. static void RENAME(horizontal_compose_haar0i)(uint8_t *_b, uint8_t *_temp, int w)
  117. {
  118. TYPE *b = (TYPE *)_b;
  119. TYPE *temp = (TYPE *)_temp;
  120. RENAME(horizontal_compose_haari)(b, temp, w, 0);
  121. }
  122. static void RENAME(horizontal_compose_haar1i)(uint8_t *_b, uint8_t *_temp, int w)
  123. {
  124. TYPE *b = (TYPE *)_b;
  125. TYPE *temp = (TYPE *)_temp;
  126. RENAME(horizontal_compose_haari)(b, temp, w, 1);
  127. }
  128. static void RENAME(horizontal_compose_fidelityi)(uint8_t *_b, uint8_t *_tmp, int w)
  129. {
  130. const int w2 = w >> 1;
  131. int i, x;
  132. TYPE v[8];
  133. TYPE *b = (TYPE *)_b;
  134. TYPE *tmp = (TYPE *)_tmp;
  135. for (x = 0; x < w2; x++) {
  136. for (i = 0; i < 8; i++)
  137. v[i] = b[av_clip(x-3+i, 0, w2-1)];
  138. tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]);
  139. }
  140. for (x = 0; x < w2; x++) {
  141. for (i = 0; i < 8; i++)
  142. v[i] = tmp[av_clip(x-4+i, 0, w2-1)];
  143. tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]);
  144. }
  145. RENAME(interleave)(b, tmp+w2, tmp, w2, 0, 0);
  146. }
  147. static void RENAME(horizontal_compose_daub97i)(uint8_t *_b, uint8_t *_temp, int w)
  148. {
  149. const int w2 = w >> 1;
  150. int x, b0, b1, b2;
  151. TYPE *b = (TYPE *)_b;
  152. TYPE *temp = (TYPE *)_temp;
  153. temp[0] = COMPOSE_DAUB97iL1(b[w2], b[0], b[w2]);
  154. for (x = 1; x < w2; x++) {
  155. temp[x ] = COMPOSE_DAUB97iL1(b[x+w2-1], b[x ], b[x+w2]);
  156. temp[x+w2-1] = COMPOSE_DAUB97iH1(temp[x-1], b[x+w2-1], temp[x]);
  157. }
  158. temp[w-1] = COMPOSE_DAUB97iH1(temp[w2-1], b[w-1], temp[w2-1]);
  159. // second stage combined with interleave and shift
  160. b0 = b2 = COMPOSE_DAUB97iL0(temp[w2], temp[0], temp[w2]);
  161. b[0] = (b0 + 1) >> 1;
  162. for (x = 1; x < w2; x++) {
  163. b2 = COMPOSE_DAUB97iL0(temp[x+w2-1], temp[x ], temp[x+w2]);
  164. b1 = COMPOSE_DAUB97iH0( b0, temp[x+w2-1], b2 );
  165. b[2*x-1] = (b1 + 1) >> 1;
  166. b[2*x ] = (b2 + 1) >> 1;
  167. b0 = b2;
  168. }
  169. b[w-1] = (COMPOSE_DAUB97iH0(b2, temp[w-1], b2) + 1) >> 1;
  170. }
  171. static void RENAME(vertical_compose_dirac53iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
  172. int width)
  173. {
  174. int i;
  175. TYPE *b0 = (TYPE *)_b0;
  176. TYPE *b1 = (TYPE *)_b1;
  177. TYPE *b2 = (TYPE *)_b2;
  178. for(i=0; i<width; i++){
  179. b1[i] = COMPOSE_DIRAC53iH0(b0[i], b1[i], b2[i]);
  180. }
  181. }
  182. static void RENAME(vertical_compose_dd97iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
  183. uint8_t *_b3, uint8_t *_b4, int width)
  184. {
  185. int i;
  186. TYPE *b0 = (TYPE *)_b0;
  187. TYPE *b1 = (TYPE *)_b1;
  188. TYPE *b2 = (TYPE *)_b2;
  189. TYPE *b3 = (TYPE *)_b3;
  190. TYPE *b4 = (TYPE *)_b4;
  191. for(i=0; i<width; i++){
  192. b2[i] = COMPOSE_DD97iH0(b0[i], b1[i], b2[i], b3[i], b4[i]);
  193. }
  194. }
  195. static void RENAME(vertical_compose_dd137iL0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2,
  196. uint8_t *_b3, uint8_t *_b4, int width)
  197. {
  198. int i;
  199. TYPE *b0 = (TYPE *)_b0;
  200. TYPE *b1 = (TYPE *)_b1;
  201. TYPE *b2 = (TYPE *)_b2;
  202. TYPE *b3 = (TYPE *)_b3;
  203. TYPE *b4 = (TYPE *)_b4;
  204. for(i=0; i<width; i++){
  205. b2[i] = COMPOSE_DD137iL0(b0[i], b1[i], b2[i], b3[i], b4[i]);
  206. }
  207. }
  208. static void RENAME(vertical_compose_haar)(uint8_t *_b0, uint8_t *_b1, int width)
  209. {
  210. int i;
  211. TYPE *b0 = (TYPE *)_b0;
  212. TYPE *b1 = (TYPE *)_b1;
  213. for (i = 0; i < width; i++) {
  214. b0[i] = COMPOSE_HAARiL0(b0[i], b1[i]);
  215. b1[i] = COMPOSE_HAARiH0(b1[i], b0[i]);
  216. }
  217. }
  218. static void RENAME(vertical_compose_fidelityiH0)(uint8_t *_dst, uint8_t *_b[8], int width)
  219. {
  220. int i;
  221. TYPE *dst = (TYPE *)_dst;
  222. TYPE *b0 = (TYPE *)_b[0];
  223. TYPE *b1 = (TYPE *)_b[1];
  224. TYPE *b2 = (TYPE *)_b[2];
  225. TYPE *b3 = (TYPE *)_b[3];
  226. TYPE *b4 = (TYPE *)_b[4];
  227. TYPE *b5 = (TYPE *)_b[5];
  228. TYPE *b6 = (TYPE *)_b[6];
  229. TYPE *b7 = (TYPE *)_b[7];
  230. for(i=0; i<width; i++){
  231. dst[i] = COMPOSE_FIDELITYiH0(b0[i], b1[i], b2[i], b3[i], dst[i], b4[i], b5[i], b6[i], b7[i]);
  232. }
  233. }
  234. static void RENAME(vertical_compose_fidelityiL0)(uint8_t *_dst, uint8_t *_b[8], int width)
  235. {
  236. int i;
  237. TYPE *dst = (TYPE *)_dst;
  238. TYPE *b0 = (TYPE *)_b[0];
  239. TYPE *b1 = (TYPE *)_b[1];
  240. TYPE *b2 = (TYPE *)_b[2];
  241. TYPE *b3 = (TYPE *)_b[3];
  242. TYPE *b4 = (TYPE *)_b[4];
  243. TYPE *b5 = (TYPE *)_b[5];
  244. TYPE *b6 = (TYPE *)_b[6];
  245. TYPE *b7 = (TYPE *)_b[7];
  246. for(i=0; i<width; i++){
  247. dst[i] = COMPOSE_FIDELITYiL0(b0[i], b1[i], b2[i], b3[i], dst[i], b4[i], b5[i], b6[i], b7[i]);
  248. }
  249. }
  250. static void RENAME(vertical_compose_daub97iH0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width)
  251. {
  252. int i;
  253. TYPE *b0 = (TYPE *)_b0;
  254. TYPE *b1 = (TYPE *)_b1;
  255. TYPE *b2 = (TYPE *)_b2;
  256. for(i=0; i<width; i++){
  257. b1[i] = COMPOSE_DAUB97iH0(b0[i], b1[i], b2[i]);
  258. }
  259. }
  260. static void RENAME(vertical_compose_daub97iH1)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width)
  261. {
  262. int i;
  263. TYPE *b0 = (TYPE *)_b0;
  264. TYPE *b1 = (TYPE *)_b1;
  265. TYPE *b2 = (TYPE *)_b2;
  266. for(i=0; i<width; i++){
  267. b1[i] = COMPOSE_DAUB97iH1(b0[i], b1[i], b2[i]);
  268. }
  269. }
  270. static void RENAME(vertical_compose_daub97iL0)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width)
  271. {
  272. int i;
  273. TYPE *b0 = (TYPE *)_b0;
  274. TYPE *b1 = (TYPE *)_b1;
  275. TYPE *b2 = (TYPE *)_b2;
  276. for(i=0; i<width; i++){
  277. b1[i] = COMPOSE_DAUB97iL0(b0[i], b1[i], b2[i]);
  278. }
  279. }
  280. static void RENAME(vertical_compose_daub97iL1)(uint8_t *_b0, uint8_t *_b1, uint8_t *_b2, int width)
  281. {
  282. int i;
  283. TYPE *b0 = (TYPE *)_b0;
  284. TYPE *b1 = (TYPE *)_b1;
  285. TYPE *b2 = (TYPE *)_b2;
  286. for(i=0; i<width; i++){
  287. b1[i] = COMPOSE_DAUB97iL1(b0[i], b1[i], b2[i]);
  288. }
  289. }
  290. static void RENAME(spatial_compose_dd97i_dy)(DWTContext *d, int level, int width, int height, int stride)
  291. {
  292. vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
  293. vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
  294. DWTCompose *cs = d->cs + level;
  295. int i, y = cs->y;
  296. uint8_t *b[8];
  297. for (i = 0; i < 6; i++)
  298. b[i] = cs->b[i];
  299. b[6] = d->buffer + av_clip(y+5, 0, height-2)*stride;
  300. b[7] = d->buffer + av_clip(y+6, 1, height-1)*stride;
  301. if(y+5<(unsigned)height) vertical_compose_l0( b[5], b[6], b[7], width);
  302. if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
  303. if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
  304. if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
  305. for (i = 0; i < 6; i++)
  306. cs->b[i] = b[i+2];
  307. cs->y += 2;
  308. }
  309. static void RENAME(spatial_compose_dirac53i_dy)(DWTContext *d, int level, int width, int height, int stride)
  310. {
  311. vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
  312. vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
  313. DWTCompose *cs = d->cs + level;
  314. int y= cs->y;
  315. uint8_t *b[4] = { cs->b[0], cs->b[1] };
  316. b[2] = d->buffer + avpriv_mirror(y+1, height-1)*stride;
  317. b[3] = d->buffer + avpriv_mirror(y+2, height-1)*stride;
  318. if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
  319. if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
  320. if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
  321. if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
  322. cs->b[0] = b[2];
  323. cs->b[1] = b[3];
  324. cs->y += 2;
  325. }
  326. static void RENAME(spatial_compose_dd137i_dy)(DWTContext *d, int level, int width, int height, int stride)
  327. {
  328. vertical_compose_5tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
  329. vertical_compose_5tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
  330. DWTCompose *cs = d->cs + level;
  331. int i, y = cs->y;
  332. uint8_t *b[10];
  333. for (i = 0; i < 8; i++)
  334. b[i] = cs->b[i];
  335. b[8] = d->buffer + av_clip(y+7, 0, height-2)*stride;
  336. b[9] = d->buffer + av_clip(y+8, 1, height-1)*stride;
  337. if(y+5<(unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width);
  338. if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width);
  339. if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
  340. if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
  341. for (i = 0; i < 8; i++)
  342. cs->b[i] = b[i+2];
  343. cs->y += 2;
  344. }
  345. // haar makes the assumption that height is even (always true for dirac)
  346. static void RENAME(spatial_compose_haari_dy)(DWTContext *d, int level, int width, int height, int stride)
  347. {
  348. vertical_compose_2tap vertical_compose = (void*)d->vertical_compose;
  349. int y = d->cs[level].y;
  350. uint8_t *b0 = d->buffer + (y-1)*stride;
  351. uint8_t *b1 = d->buffer + (y )*stride;
  352. vertical_compose(b0, b1, width);
  353. d->horizontal_compose(b0, d->temp, width);
  354. d->horizontal_compose(b1, d->temp, width);
  355. d->cs[level].y += 2;
  356. }
  357. // Don't do sliced idwt for fidelity; the 9 tap filter makes it a bit annoying
  358. // Fortunately, this filter isn't used in practice.
  359. static void RENAME(spatial_compose_fidelity)(DWTContext *d, int level, int width, int height, int stride)
  360. {
  361. vertical_compose_9tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
  362. vertical_compose_9tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
  363. int i, y;
  364. uint8_t *b[8];
  365. for (y = 1; y < height; y += 2) {
  366. for (i = 0; i < 8; i++)
  367. b[i] = d->buffer + av_clip((y-7 + 2*i), 0, height-2)*stride;
  368. vertical_compose_h0(d->buffer + y*stride, b, width);
  369. }
  370. for (y = 0; y < height; y += 2) {
  371. for (i = 0; i < 8; i++)
  372. b[i] = d->buffer + av_clip((y-7 + 2*i), 1, height-1)*stride;
  373. vertical_compose_l0(d->buffer + y*stride, b, width);
  374. }
  375. for (y = 0; y < height; y++)
  376. d->horizontal_compose(d->buffer + y*stride, d->temp, width);
  377. d->cs[level].y = height+1;
  378. }
  379. static void RENAME(spatial_compose_daub97i_dy)(DWTContext *d, int level, int width, int height, int stride)
  380. {
  381. vertical_compose_3tap vertical_compose_l0 = (void*)d->vertical_compose_l0;
  382. vertical_compose_3tap vertical_compose_h0 = (void*)d->vertical_compose_h0;
  383. vertical_compose_3tap vertical_compose_l1 = (void*)d->vertical_compose_l1;
  384. vertical_compose_3tap vertical_compose_h1 = (void*)d->vertical_compose_h1;
  385. DWTCompose *cs = d->cs + level;
  386. int i, y = cs->y;
  387. uint8_t *b[6];
  388. for (i = 0; i < 4; i++)
  389. b[i] = cs->b[i];
  390. b[4] = d->buffer + avpriv_mirror(y+3, height-1)*stride;
  391. b[5] = d->buffer + avpriv_mirror(y+4, height-1)*stride;
  392. if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width);
  393. if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width);
  394. if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width);
  395. if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width);
  396. if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width);
  397. if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width);
  398. for (i = 0; i < 4; i++)
  399. cs->b[i] = b[i+2];
  400. cs->y += 2;
  401. }
  402. static void RENAME(spatial_compose97i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride)
  403. {
  404. cs->b[0] = buffer + avpriv_mirror(-3-1, height-1)*stride;
  405. cs->b[1] = buffer + avpriv_mirror(-3 , height-1)*stride;
  406. cs->b[2] = buffer + avpriv_mirror(-3+1, height-1)*stride;
  407. cs->b[3] = buffer + avpriv_mirror(-3+2, height-1)*stride;
  408. cs->y = -3;
  409. }
  410. static void RENAME(spatial_compose53i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride)
  411. {
  412. cs->b[0] = buffer + avpriv_mirror(-1-1, height-1)*stride;
  413. cs->b[1] = buffer + avpriv_mirror(-1 , height-1)*stride;
  414. cs->y = -1;
  415. }
  416. static void RENAME(spatial_compose_dd97i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride)
  417. {
  418. cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
  419. cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride;
  420. cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
  421. cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
  422. cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
  423. cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
  424. cs->y = -5;
  425. }
  426. static void RENAME(spatial_compose_dd137i_init)(DWTCompose *cs, uint8_t *buffer, int height, int stride)
  427. {
  428. cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride;
  429. cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride;
  430. cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride;
  431. cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride;
  432. cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride;
  433. cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride;
  434. cs->b[6] = buffer + av_clip(-5+5, 0, height-2)*stride;
  435. cs->b[7] = buffer + av_clip(-5+6, 1, height-1)*stride;
  436. cs->y = -5;
  437. }
  438. static int RENAME(ff_spatial_idwt_init)(DWTContext *d, enum dwt_type type)
  439. {
  440. int level;
  441. d->temp = (uint8_t *)(((TYPE *)d->temp) + 8);
  442. for (level = d->decomposition_count - 1; level >= 0; level--){
  443. int hl = d->height >> level;
  444. int stride_l = d->stride << level;
  445. switch(type){
  446. case DWT_DIRAC_DD9_7:
  447. RENAME(spatial_compose_dd97i_init)(d->cs+level, d->buffer, hl, stride_l);
  448. break;
  449. case DWT_DIRAC_LEGALL5_3:
  450. RENAME(spatial_compose53i_init)(d->cs+level, d->buffer, hl, stride_l);
  451. break;
  452. case DWT_DIRAC_DD13_7:
  453. RENAME(spatial_compose_dd137i_init)(d->cs+level, d->buffer, hl, stride_l);
  454. break;
  455. case DWT_DIRAC_HAAR0:
  456. case DWT_DIRAC_HAAR1:
  457. d->cs[level].y = 1;
  458. break;
  459. case DWT_DIRAC_DAUB9_7:
  460. RENAME(spatial_compose97i_init)(d->cs+level, d->buffer, hl, stride_l);
  461. break;
  462. default:
  463. d->cs[level].y = 0;
  464. break;
  465. }
  466. }
  467. switch (type) {
  468. case DWT_DIRAC_DD9_7:
  469. d->spatial_compose = RENAME(spatial_compose_dd97i_dy);
  470. d->vertical_compose_l0 = (void*)RENAME(vertical_compose53iL0);
  471. d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dd97iH0);
  472. d->horizontal_compose = RENAME(horizontal_compose_dd97i);
  473. d->support = 7;
  474. break;
  475. case DWT_DIRAC_LEGALL5_3:
  476. d->spatial_compose = RENAME(spatial_compose_dirac53i_dy);
  477. d->vertical_compose_l0 = (void*)RENAME(vertical_compose53iL0);
  478. d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dirac53iH0);
  479. d->horizontal_compose = RENAME(horizontal_compose_dirac53i);
  480. d->support = 3;
  481. break;
  482. case DWT_DIRAC_DD13_7:
  483. d->spatial_compose = RENAME(spatial_compose_dd137i_dy);
  484. d->vertical_compose_l0 = (void*)RENAME(vertical_compose_dd137iL0);
  485. d->vertical_compose_h0 = (void*)RENAME(vertical_compose_dd97iH0);
  486. d->horizontal_compose = RENAME(horizontal_compose_dd137i);
  487. d->support = 7;
  488. break;
  489. case DWT_DIRAC_HAAR0:
  490. case DWT_DIRAC_HAAR1:
  491. d->spatial_compose = RENAME(spatial_compose_haari_dy);
  492. d->vertical_compose = (void*)RENAME(vertical_compose_haar);
  493. if (type == DWT_DIRAC_HAAR0)
  494. d->horizontal_compose = RENAME(horizontal_compose_haar0i);
  495. else
  496. d->horizontal_compose = RENAME(horizontal_compose_haar1i);
  497. d->support = 1;
  498. break;
  499. case DWT_DIRAC_FIDELITY:
  500. d->spatial_compose = RENAME(spatial_compose_fidelity);
  501. d->vertical_compose_l0 = (void*)RENAME(vertical_compose_fidelityiL0);
  502. d->vertical_compose_h0 = (void*)RENAME(vertical_compose_fidelityiH0);
  503. d->horizontal_compose = RENAME(horizontal_compose_fidelityi);
  504. d->support = 0; // not really used
  505. break;
  506. case DWT_DIRAC_DAUB9_7:
  507. d->spatial_compose = RENAME(spatial_compose_daub97i_dy);
  508. d->vertical_compose_l0 = (void*)RENAME(vertical_compose_daub97iL0);
  509. d->vertical_compose_h0 = (void*)RENAME(vertical_compose_daub97iH0);
  510. d->vertical_compose_l1 = (void*)RENAME(vertical_compose_daub97iL1);
  511. d->vertical_compose_h1 = (void*)RENAME(vertical_compose_daub97iH1);
  512. d->horizontal_compose = RENAME(horizontal_compose_daub97i);
  513. d->support = 5;
  514. break;
  515. default:
  516. return AVERROR_INVALIDDATA;
  517. }
  518. return 0;
  519. }
  520. #undef RENAME
  521. #undef TYPE