Advertisement
Guest User

Untitled

a guest
May 26th, 2017
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.92 KB | None | 0 0
  1. Index: input/common.c
  2. ===================================================================
  3. --- input/common_orig.c
  4. +++ input/common.c
  5. @@ -21,12 +21,12 @@
  6. #include "input.h"
  7.  
  8. const x264_cli_csp_t x264_cli_csps[] = {
  9. - [X264_CSP_I420] = { "i420", 3, { 1, .5, .5 }, { 1, .5, .5 } },
  10. - [X264_CSP_I422] = { "i422", 3, { 1, .5, .5 }, { 1, 1, 1 } },
  11. - [X264_CSP_I444] = { "i444", 3, { 1, 1, 1 }, { 1, 1, 1 } },
  12. - [X264_CSP_YV12] = { "yv12", 3, { 1, .5, .5 }, { 1, .5, .5 } },
  13. - [X264_CSP_BGR] = { "bgr", 1, { 3 }, { 1 }, },
  14. - [X264_CSP_BGRA] = { "bgra", 1, { 4 }, { 1 }, }
  15. + [X264_CSP_I420] = { "i420", 3, { 1, .5, .5 }, { 1, .5, .5 }, 2, 2 },
  16. + [X264_CSP_I422] = { "i422", 3, { 1, .5, .5 }, { 1, 1, 1 }, 2, 1 },
  17. + [X264_CSP_I444] = { "i444", 3, { 1, 1, 1 }, { 1, 1, 1 }, 1, 1 },
  18. + [X264_CSP_YV12] = { "yv12", 3, { 1, .5, .5 }, { 1, .5, .5 }, 2, 2 },
  19. + [X264_CSP_BGR] = { "bgr", 1, { 3 }, { 1 }, 1, 1 },
  20. + [X264_CSP_BGRA] = { "bgra", 1, { 4 }, { 1 }, 1, 1 }
  21. };
  22.  
  23. static int is_invalid_csp( int csp )
  24. Index: input/input.h
  25. ===================================================================
  26. --- input/input_orig.h
  27. +++ input/input.h
  28. @@ -109,6 +109,8 @@
  29. int planes;
  30. float width[4];
  31. float height[4];
  32. + int mod_width;
  33. + int mod_height;
  34. } x264_cli_csp_t;
  35.  
  36. extern const x264_cli_csp_t x264_cli_csps[];
  37. Index: filter/resize.c
  38. ===================================================================
  39. --- filter/resize_orig.c
  40. +++ filter/resize.c
  41. @@ -65,12 +65,19 @@
  42.  
  43. static void help( int longhelp )
  44. {
  45. - printf( " resize:widthxheight[,method]\n" );
  46. + printf( " resize:widthxheight[,fittobox][,method]\n" );
  47. if( !longhelp )
  48. return;
  49. printf( " resizes frames to the given size using resizer [\"bicubic\"]\n"
  50. " - fastbilinear, bilinear, bicubic, experimental, point,\n"
  51. - " - area, bicublin, gauss, sinc, lanczos, spline\n" );
  52. + " - area, bicublin, gauss, sinc, lanczos, spline\n"
  53. + " special-case dimensions:\n"
  54. + " 0 -- scale this by the same factor as the other\n"
  55. + " -1 -- do not scale\n"
  56. + " -2 -- scale this to get 1:1 sample aspect ratio\n"
  57. + " the fittobox option instucts this filter to fit the image\n"
  58. + " into a box of the given size\n"
  59. + " there is no padding at present\n" );
  60. }
  61.  
  62. static uint32_t convert_cpu_to_flag( uint32_t cpu )
  63. @@ -193,11 +200,66 @@
  64. ;
  65. else if( !strcmp( opt_string, "normcsp" ) )
  66. h->dst_csp = pick_closest_supported_csp( info->csp );
  67. - else if( sscanf( opt_string, "%ux%u%n", &h->dst.width, &h->dst.height, &len ) != 2 )
  68. + else if( sscanf( opt_string, "%dx%d%n", &h->dst.width, &h->dst.height, &len ) != 2 )
  69. {
  70. fprintf( stderr, "resize [error]: invalid resolution %s\n", opt_string );
  71. return -1;
  72. }
  73. + else
  74. + {/* Start of special case values */
  75. + const int mod_w_i = x264_cli_csps[h->dst_csp].mod_width;
  76. + const int mod_h_i = x264_cli_csps[h->dst_csp].mod_height;
  77. + const float mod_w_f = mod_w_i;
  78. + const float mod_h_f = mod_h_i;
  79. +
  80. + /* a value of zero means we should scale this by the same factor as the other dimension */
  81. + if( h->dst.width == 0 )
  82. + h->dst.width = round( info->width * h->dst.height / (info->height * mod_w_f) ) * mod_w_i;
  83. +
  84. + /* a value of -1 means we should not scale this dimension */
  85. + else if( h->dst.width == -1 )
  86. + h->dst.width = info->width;
  87. +
  88. + /* a value of -2 means we should scale to square pixels */
  89. + else if( h->dst.width == -2 )
  90. + {
  91. + if( !(info->sar_width) || !(info->sar_height) )
  92. + {
  93. + fprintf(stderr, "resize [info]: cannot scale using -2 because sar is not set\n");
  94. + h->dst.width = info->width;
  95. + }
  96. + else
  97. + h->dst.width = round( info->width * info->sar_width / (info->sar_height * mod_w_f) ) * mod_w_i;
  98. + }
  99. +
  100. + /* a value of -3 means we should ... something
  101. + if( h->dst.width == -3 )
  102. + h->dst.width = (int)( info->width * ( (double)h->dst.height / (double)info->height ) ); */
  103. +
  104. + /* do the same for the height */
  105. + if( h->dst.height == 0 )
  106. + h->dst.height = round( info->height * h->dst.width / (info->width * mod_h_f) ) * mod_h_i;
  107. + else if( h->dst.height == -1 )
  108. + h->dst.height = info->height;
  109. + else if( h->dst.height == -2 )
  110. + {
  111. + if( !(info->sar_width) || !(info->sar_height) )
  112. + {
  113. + fprintf(stderr, "resize [info]: cannot scale using -2 because sar is not set\n");
  114. + h->dst.height = info->height;
  115. + }
  116. + else
  117. + h->dst.height = round( info->height * info->sar_height / (info->sar_width * mod_h_f) ) * mod_h_i;
  118. + }
  119. + if( !strcasecmp( opt_string+len+1, "fittobox" ) )
  120. + {
  121. + if( ((float)info->width / info->height) > ((float)h->dst.width / h->dst.height) )
  122. + h->dst.height = round( h->dst.width * info->height / (info->width * mod_h_f) ) * mod_h_i;
  123. + else
  124. + h->dst.width = round( h->dst.height * info->width / (info->height * mod_w_f) ) * mod_w_i;
  125. + opt_string += 9;
  126. + }
  127. + }/* End of special case values */
  128. opt_string += len;
  129. }
  130. else
  131. Index: Makefile
  132. ===================================================================
  133. --- Makefile_orig
  134. +++ Makefile
  135. @@ -17,7 +17,7 @@
  136. output/raw.c output/matroska.c output/matroska_ebml.c \
  137. output/flv.c output/flv_bytestream.c filter/source.c \
  138. filter/filter.c filter/cache.c filter/select_every.c \
  139. - filter/resize.c filter/utils.c filter/fix_vfr_pts.c
  140. + filter/resize.c filter/utils.c filter/fix_vfr_pts.c filter/crop.c filter/hqdn3d.c
  141.  
  142. SRCSO =
  143.  
  144. Index: configure
  145. ===================================================================
  146. --- configure_orig
  147. +++ configure
  148. @@ -787,7 +787,7 @@
  149. Cflags: -I$includedir
  150. EOF
  151.  
  152. -filters="select_every"
  153. +filters="select_every crop hqdn3d"
  154. [ $swscale = yes ] && filters="resize $filters"
  155.  
  156. cat > conftest.log <<EOF
  157. Index: filter/crop.c
  158. ===================================================================
  159. --- /dev/null
  160. +++ filter/crop.c
  161. @@ -0,0 +1,126 @@
  162. +/*****************************************************************************
  163. + * crop.c: x264 crop filter
  164. + *****************************************************************************
  165. + * Copyright (C) 2010 James Darnley
  166. + *
  167. + * This program is free software; you can redistribute it and/or modify
  168. + * it under the terms of the GNU General Public License as published by
  169. + * the Free Software Foundation; either version 2 of the License, or
  170. + * (at your option) any later version.
  171. + *
  172. + * This program is distributed in the hope that it will be useful,
  173. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  174. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  175. + * GNU General Public License for more details.
  176. + *
  177. + * You should have received a copy of the GNU General Public License
  178. + * along with this program; if not, write to the Free Software
  179. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
  180. + *****************************************************************************/
  181. +
  182. +#include "filter.h"
  183. +
  184. +cli_vid_filter_t crop_filter;
  185. +
  186. +typedef struct
  187. +{
  188. + hnd_t prev_hnd;
  189. + cli_vid_filter_t prev_filter;
  190. + int left;
  191. + int top;
  192. + int width;
  193. + int height;
  194. +} crop_hnd_t;
  195. +
  196. +static void help( int longhelp )
  197. +{
  198. + printf( " crop:left,top,right,bottom\n" );
  199. + if(!longhelp)
  200. + return;
  201. + printf( " Crops the picture\n"
  202. + " removes pixels from the edges of the frame\n" );
  203. +}
  204. +
  205. +static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info, x264_param_t *param, char *opt_string )
  206. +{
  207. + const int mod_w = x264_cli_csps[info->csp].mod_width;
  208. + const int mod_h = x264_cli_csps[info->csp].mod_height;
  209. + crop_hnd_t *h = calloc( 1, sizeof(crop_hnd_t) );
  210. + if(!h) return -1;
  211. +
  212. + if( sscanf( opt_string, "%u,%u,%u,%u", &h->left, &h->top, &h->width, &h->height ) != 4 )
  213. + {
  214. + fprintf( stderr, "crop [error]: invalid crop value(s) %s\n", opt_string );
  215. + return -1;
  216. + }
  217. + if( h->left % mod_w || h->top % mod_h || h->width % mod_w || h->height % mod_h )
  218. + {
  219. + fprintf( stderr, "crop [error]: crop values must be multiples of %d for width and %d for height\n", mod_w, mod_h );
  220. + return -1;
  221. + }
  222. + /* check correctness of output */
  223. + if( h->left + h->width >= info->width || h->top + h->height >= info->height )
  224. + {
  225. + fprintf( stderr, "crop [error]: invalid output size (%dx%d)\n",
  226. + info->width - h->left - h->width, info->height - h->top - h->height );
  227. + return -1;
  228. + }
  229. + if( info->interlaced && h->top % (mod_h*2) )
  230. + fprintf( stderr, "crop [warning]: top crop should be a multiple of %d for interlaced pictures\n", mod_h*2 );
  231. + //did I miss anything
  232. +
  233. + h->width = info->width - h->left - h->width;
  234. + h->height = info->height - h->top - h->height;
  235. +
  236. + fprintf( stderr, "crop [info]: output %dx%d\n", h->width, h->height );
  237. +
  238. + info->width = h->width;
  239. + info->height = h->height;
  240. +
  241. + h->prev_filter = *filter;
  242. + h->prev_hnd = *handle;
  243. + *handle = h;
  244. + *filter = crop_filter;
  245. + return 0;
  246. +}
  247. +
  248. +static int get_frame( hnd_t handle, cli_pic_t *output, int frame )
  249. +{
  250. + crop_hnd_t *h = handle;
  251. + if( h->prev_filter.get_frame( h->prev_hnd, output, frame ) )
  252. + return -1;
  253. + const int planes = output->img.planes;
  254. + const int colourspace = output->img.csp;
  255. + output->img.width = h->width;
  256. + output->img.height = h->height;
  257. + for( int i=0; i<planes; i++ )
  258. + {
  259. + float scale_w = x264_cli_csps[colourspace].width[i];
  260. + float scale_h = x264_cli_csps[colourspace].height[i];
  261. + output->img.plane[i] += (int)( (output->img.stride[i] * h->top*scale_h) + h->left*scale_w );
  262. + }
  263. + return 0;
  264. +}
  265. +
  266. +static int release_frame( hnd_t handle, cli_pic_t *pic, int frame )
  267. +{
  268. + crop_hnd_t *h = handle;
  269. + const int planes = pic->img.planes;
  270. + const int colourspace = pic->img.csp;
  271. + for( int i=0; i<planes; i++ )
  272. + {
  273. + float scale_w = x264_cli_csps[colourspace].width[i];
  274. + float scale_h = x264_cli_csps[colourspace].height[i];
  275. + pic->img.plane[i] -= (int)( (pic->img.stride[i] * h->top*scale_h) + h->left*scale_w );
  276. + }
  277. + return h->prev_filter.release_frame( h->prev_hnd, pic, frame );
  278. +}
  279. +
  280. +static void free_filter( hnd_t handle )
  281. +{
  282. + crop_hnd_t *h = handle;
  283. + h->prev_filter.free( h->prev_hnd );
  284. + free( h );
  285. +}
  286. +
  287. +cli_vid_filter_t crop_filter = { "crop", help, init, get_frame, release_frame, free_filter, NULL };
  288. Index: filter/filter.c
  289. ===================================================================
  290. --- filter/filter_orig.c
  291. +++ filter/filter.c
  292. @@ -46,6 +46,8 @@
  293. REGISTER_VFILTER( fix_vfr_pts );
  294. REGISTER_VFILTER( resize );
  295. REGISTER_VFILTER( select_every );
  296. + REGISTER_VFILTER( crop );
  297. + REGISTER_VFILTER( hqdn3d );
  298. }
  299.  
  300. int x264_init_vid_filter( const char *name, hnd_t *handle, cli_vid_filter_t *filter,
  301. Index: filter/hqdn3d.c
  302. ===================================================================
  303. --- /dev/null
  304. +++ filter/hqdn3d.c
  305. @@ -0,0 +1,297 @@
  306. +/*****************************************************************************
  307. + * hqdn3d.c: x264 hqdn3d filter
  308. + *****************************************************************************
  309. + * Copyright (C) 2003 Daniel Moreno <comac@comac.darktech.org>
  310. + * Avisynth port (C) 2005 Loren Merritt <lorenm@u.washington.edu>
  311. + * x264 port (C) 2010 James Darnley <james.darnley@gmail.com>
  312. + *
  313. + * This program is free software; you can redistribute it and/or modify
  314. + * it under the terms of the GNU General Public License as published by
  315. + * the Free Software Foundation; either version 2 of the License, or
  316. + * (at your option) any later version.
  317. + *
  318. + * This program is distributed in the hope that it will be useful,
  319. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  320. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  321. + * GNU General Public License for more details.
  322. + *
  323. + * You should have received a copy of the GNU General Public License
  324. + * along with this program; if not, write to the Free Software
  325. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
  326. + *****************************************************************************/
  327. +
  328. +#include <math.h>
  329. +#include "filter.h"
  330. +
  331. +#define PARAM1_DEFAULT 4.0
  332. +#define PARAM2_DEFAULT 3.0
  333. +#define PARAM3_DEFAULT 6.0
  334. +
  335. +cli_vid_filter_t hqdn3d_filter;
  336. +
  337. +typedef struct
  338. +{
  339. + hnd_t prev_hnd;
  340. + cli_vid_filter_t prev_filter;
  341. + int Coefs[4][512*16];
  342. + unsigned int *Line;
  343. + unsigned short *Frame[3];
  344. + int w, h, cw, ch, first_frame;
  345. +} hqdn3d_hnd_t;
  346. +
  347. +static void help( int longhelp )
  348. +{
  349. + printf( " hqdn3d:ls,cs,lt,ct\n" );
  350. + if(!longhelp)
  351. + return;
  352. + printf( " Denoises the image using mplayer's hqdn3d filter\n"
  353. + " The four arguments are floats and are optional\n"
  354. + " If any options are omitted, they will assume a\n"
  355. + " value based on any other options that you did specify\n"
  356. + " - ls = luma spatial filter strength [%.1lf]\n"
  357. + " - cs = chroma spatial filter strength [%.1lf]\n"
  358. + " - lt = luma temporal filter strength [%.1lf]\n"
  359. + " - ct = chroma temporal filter strength [%.1lf]\n",
  360. + PARAM1_DEFAULT, PARAM2_DEFAULT, PARAM3_DEFAULT,
  361. + PARAM3_DEFAULT * PARAM2_DEFAULT / PARAM1_DEFAULT);
  362. +}
  363. +
  364. +#define ABS(A) ( (A) > 0 ? (A) : -(A) )
  365. +
  366. +static void PrecalcCoefs(int *Ct, double Dist25)
  367. +{
  368. + //int i;
  369. + double Gamma, Simil, C;
  370. +
  371. + Gamma = log(0.25) / log(1.0 - Dist25/255.0 - 0.00001);
  372. +
  373. + for (int i = -255*16; i < 256*16; i++)
  374. + {
  375. + Simil = 1.0 - ABS(i) / (16*255.0);
  376. + C = pow(Simil, Gamma) * 65536.0 * (double)i / 16.0;
  377. + Ct[16*256+i] = (int)((C<0) ? (C-0.5) : (C+0.5));
  378. + }
  379. +}
  380. +
  381. +static int init( hnd_t *handle, cli_vid_filter_t *filter, video_info_t *info,
  382. + x264_param_t *param, char *opt_string )
  383. +{
  384. + double LumSpac, LumTmp, ChromSpac, ChromTmp;
  385. + double Param1, Param2, Param3, Param4;
  386. +
  387. + hqdn3d_hnd_t *h = calloc( 1, sizeof(hqdn3d_hnd_t) );
  388. + if( !h )
  389. + {
  390. + fprintf( stderr, "hqdn3d [error]: Memory allocation error (filter/hqdn3d.c:%d)\n", __LINE__ );
  391. + return -1;
  392. + }
  393. +
  394. + h->w = info->width*x264_cli_csps[info->csp].width[0];
  395. + h->h = info->height*x264_cli_csps[info->csp].height[0];
  396. + h->cw = info->width*x264_cli_csps[info->csp].width[1];
  397. + h->ch = info->height*x264_cli_csps[info->csp].height[1];
  398. +
  399. + h->Line = calloc( 1, info->width*sizeof(int) );
  400. + h->Frame[0] = malloc( h->w * h->h * sizeof(short) );
  401. + h->Frame[1] = malloc( h->cw * h->ch * sizeof(short) );
  402. + h->Frame[2] = malloc( h->cw * h->ch * sizeof(short) );
  403. + if( !h->Line || !h->Frame[0] || !h->Frame[1] || !h->Frame[2] )
  404. + {
  405. + fprintf( stderr, "hqdn3d [error]: Memory allocation error"
  406. + " (filter/hqdn3d.c:%d)\n", __LINE__ );
  407. + return -1;
  408. + }
  409. +
  410. + if( !(info->csp & ( X264_CSP_I420|X264_CSP_I422
  411. + |X264_CSP_I444|X264_CSP_YV12 )) )
  412. + {
  413. + fprintf( stderr, "hqdn3d [error]: Only planar YUV images supported\n" );
  414. + return -1;
  415. + }
  416. + if(opt_string)
  417. + {
  418. + switch(sscanf( opt_string, "%lf,%lf,%lf,%lf",
  419. + &Param1, &Param2, &Param3, &Param4 ))
  420. + {
  421. + case 1:
  422. + LumSpac = Param1;
  423. + LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT;
  424. + ChromSpac = PARAM2_DEFAULT * Param1 / PARAM1_DEFAULT;
  425. + ChromTmp = LumTmp * ChromSpac / LumSpac;
  426. + break;
  427. + case 2:
  428. + LumSpac = Param1;
  429. + LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT;
  430. + ChromSpac = Param2;
  431. + ChromTmp = LumTmp * ChromSpac / LumSpac;
  432. + break;
  433. + case 3:
  434. + LumSpac = Param1;
  435. + LumTmp = Param3;
  436. + ChromSpac = Param2;
  437. + ChromTmp = LumTmp * ChromSpac / LumSpac;
  438. + break;
  439. + case 4:
  440. + LumSpac = Param1;
  441. + LumTmp = Param3;
  442. + ChromSpac = Param2;
  443. + ChromTmp = Param4;
  444. + break;
  445. + default:
  446. + LumSpac = PARAM1_DEFAULT;
  447. + LumTmp = PARAM3_DEFAULT;
  448. + ChromSpac = PARAM2_DEFAULT;
  449. + ChromTmp = LumTmp * ChromSpac / LumSpac;
  450. + }
  451. + }
  452. + else
  453. + {
  454. + LumSpac = PARAM1_DEFAULT;
  455. + LumTmp = PARAM3_DEFAULT;
  456. + ChromSpac = PARAM2_DEFAULT;
  457. + ChromTmp = LumTmp * ChromSpac / LumSpac;
  458. + }
  459. +
  460. + PrecalcCoefs(h->Coefs[0], LumSpac);
  461. + PrecalcCoefs(h->Coefs[1], LumTmp);
  462. + PrecalcCoefs(h->Coefs[2], ChromSpac);
  463. + PrecalcCoefs(h->Coefs[3], ChromTmp);
  464. +
  465. + fprintf( stderr, "hqdn3d [info]: using strengths %.1lf,%.1lf,%.1lf,%.1lf\n",
  466. + LumSpac, ChromSpac, LumTmp, ChromTmp );
  467. +
  468. + h->first_frame = 1;
  469. + h->prev_filter = *filter;
  470. + h->prev_hnd = *handle;
  471. + *handle = h;
  472. + *filter = hqdn3d_filter;
  473. + return 0;
  474. +}
  475. +
  476. +static inline unsigned int LowPassMul(unsigned int PrevMul, unsigned int CurrMul, int* Coef)
  477. +{
  478. +// int dMul= (PrevMul&0xFFFFFF)-(CurrMul&0xFFFFFF);
  479. + int dMul= PrevMul-CurrMul;
  480. + int d=((dMul+0x10007FF)/(65536/16));
  481. + return CurrMul + Coef[d];
  482. +}
  483. +
  484. +static void deNoise(const unsigned char *Frame, // mpi->planes[x]
  485. + unsigned char *FrameDest, // dmpi->planes[x]
  486. + unsigned int *LineAnt, // vf->priv->Line (width bytes)
  487. + unsigned short *FrameAnt,
  488. + int W, int H, int sStride, int dStride,
  489. + int *Horizontal, int *Vertical, int *Temporal)
  490. +{
  491. + //int X, Y;
  492. + int sLineOffs = 0, dLineOffs = 0;
  493. + unsigned int PixelAnt;
  494. + int PixelDst;
  495. +
  496. + /* First pixel has no left nor top neightbour. Only previous frame */
  497. + LineAnt[0] = PixelAnt = Frame[0]<<16;
  498. + PixelDst = LowPassMul(FrameAnt[0]<<8, PixelAnt, Temporal);
  499. + FrameAnt[0] = ((PixelDst+0x1000007F)/256);
  500. + FrameDest[0]= ((PixelDst+0x10007FFF)/65536);
  501. +
  502. + /* Fist line has no top neightbour. Only left one for each pixel and
  503. + * last frame */
  504. + for (int X = 1; X < W; X++){
  505. + LineAnt[X] = PixelAnt = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal);
  506. + PixelDst = LowPassMul(FrameAnt[X]<<8, PixelAnt, Temporal);
  507. + FrameAnt[X] = ((PixelDst+0x1000007F)/256);
  508. + FrameDest[X]= ((PixelDst+0x10007FFF)/65536);
  509. + }
  510. +
  511. + for (int Y = 1; Y < H; Y++){
  512. + unsigned int PixelAnt;
  513. + unsigned short* LinePrev=&FrameAnt[Y*W];
  514. + sLineOffs += sStride, dLineOffs += dStride;
  515. + /* First pixel on each line doesn't have previous pixel */
  516. + PixelAnt = Frame[sLineOffs]<<16;
  517. + LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical);
  518. + PixelDst = LowPassMul(LinePrev[0]<<8, LineAnt[0], Temporal);
  519. + LinePrev[0] = ((PixelDst+0x1000007F)/256);
  520. + FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)/65536);
  521. +
  522. + for (int X = 1; X < W; X++){
  523. + int PixelDst;
  524. + /* The rest are normal */
  525. + PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal);
  526. + LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical);
  527. + PixelDst = LowPassMul(LinePrev[X]<<8, LineAnt[X], Temporal);
  528. + LinePrev[X] = ((PixelDst+0x1000007F)/256);
  529. + FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)/65536);
  530. + }
  531. + }
  532. +}
  533. +
  534. +static int get_frame( hnd_t handle, cli_pic_t *output, int frame )
  535. +{
  536. + hqdn3d_hnd_t *h = handle;
  537. +
  538. + if( h->prev_filter.get_frame( h->prev_hnd, output, frame ) )
  539. + return -1;
  540. +
  541. + if( h->first_frame )
  542. + {
  543. + int width = h->w;
  544. + int height = h->h;
  545. + int stride = output->img.stride[0];
  546. + for(int y = 0; y<height; y++)
  547. + for(int x = 0; x<width; x++)
  548. + h->Frame[0][y*width+x] = output->img.plane[0][y*stride+x] << 8;
  549. +
  550. + width = h->cw;
  551. + height = h->ch;
  552. + stride = output->img.stride[1];
  553. + for(int y = 0; y<height; y++)
  554. + for(int x = 0; x<width; x++)
  555. + h->Frame[1][y*width+x] = output->img.plane[1][y*stride+x] << 8;
  556. +
  557. + stride = output->img.stride[2];
  558. + for(int y = 0; y<height; y++)
  559. + for(int x = 0; x<width; x++)
  560. + h->Frame[2][y*width+x] = output->img.plane[2][y*stride+x] << 8;
  561. +
  562. + h->first_frame = 0;
  563. + }
  564. +
  565. + deNoise(output->img.plane[0],
  566. + output->img.plane[0],
  567. + h->Line, h->Frame[0],
  568. + h->w, h->h,
  569. + output->img.stride[0], output->img.stride[0],
  570. + h->Coefs[0], h->Coefs[0], h->Coefs[1]);
  571. + deNoise(output->img.plane[1],
  572. + output->img.plane[1],
  573. + h->Line, h->Frame[1],
  574. + h->cw, h->ch,
  575. + output->img.stride[1], output->img.stride[1],
  576. + h->Coefs[2], h->Coefs[2], h->Coefs[3]);
  577. + deNoise(output->img.plane[2],
  578. + output->img.plane[2],
  579. + h->Line, h->Frame[2],
  580. + h->cw, h->ch,
  581. + output->img.stride[2], output->img.stride[2],
  582. + h->Coefs[2], h->Coefs[2], h->Coefs[3]);
  583. + return 0;
  584. +}
  585. +
  586. +static int release_frame( hnd_t handle, cli_pic_t *pic, int frame )
  587. +{
  588. + hqdn3d_hnd_t *h = handle;
  589. + return h->prev_filter.release_frame( h->prev_hnd, pic, frame );
  590. +}
  591. +
  592. +static void free_filter( hnd_t handle )
  593. +{
  594. + hqdn3d_hnd_t *h = handle;
  595. + h->prev_filter.free( h->prev_hnd );
  596. + free( h->Line );
  597. + for(int i = 0; i<3; i++)
  598. + free( h->Frame[i] );
  599. + free( h );
  600. +}
  601. +
  602. +cli_vid_filter_t hqdn3d_filter = { "hqdn3d", help, init, get_frame, release_frame, free_filter, NULL };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement