postprocess.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. /*
  2. * Copyright (C) 2001-2003 Michael Niedermayer (michaelni@gmx.at)
  3. *
  4. * AltiVec optimizations (C) 2004 Romain Dolbeau <romain@dolbeau.org>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (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
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * 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. * postprocessing.
  25. */
  26. /*
  27. C MMX MMX2 3DNow AltiVec
  28. isVertDC Ec Ec Ec
  29. isVertMinMaxOk Ec Ec Ec
  30. doVertLowPass E e e Ec
  31. doVertDefFilter Ec Ec e e Ec
  32. isHorizDC Ec Ec Ec
  33. isHorizMinMaxOk a E Ec
  34. doHorizLowPass E e e Ec
  35. doHorizDefFilter Ec Ec e e Ec
  36. do_a_deblock Ec E Ec E
  37. deRing E e e* Ecp
  38. Vertical RKAlgo1 E a a
  39. Horizontal RKAlgo1 a a
  40. Vertical X1# a E E
  41. Horizontal X1# a E E
  42. LinIpolDeinterlace e E E*
  43. CubicIpolDeinterlace a e e*
  44. LinBlendDeinterlace e E E*
  45. MedianDeinterlace# E Ec Ec
  46. TempDeNoiser# E e e Ec
  47. * I do not have a 3DNow! CPU -> it is untested, but no one said it does not work so it seems to work
  48. # more or less selfinvented filters so the exactness is not too meaningful
  49. E = Exact implementation
  50. e = almost exact implementation (slightly different rounding,...)
  51. a = alternative / approximate impl
  52. c = checked against the other implementations (-vo md5)
  53. p = partially optimized, still some work to do
  54. */
  55. /*
  56. TODO:
  57. reduce the time wasted on the mem transfer
  58. unroll stuff if instructions depend too much on the prior one
  59. move YScale thing to the end instead of fixing QP
  60. write a faster and higher quality deblocking filter :)
  61. make the mainloop more flexible (variable number of blocks at once
  62. (the if/else stuff per block is slowing things down)
  63. compare the quality & speed of all filters
  64. split this huge file
  65. optimize c versions
  66. try to unroll inner for(x=0 ... loop to avoid these damn if(x ... checks
  67. ...
  68. */
  69. //Changelog: use git log
  70. #include "config.h"
  71. #include "libavutil/avutil.h"
  72. #include <inttypes.h>
  73. #include <stdio.h>
  74. #include <stdlib.h>
  75. #include <string.h>
  76. //#undef HAVE_MMX2
  77. //#define HAVE_AMD3DNOW
  78. //#undef HAVE_MMX
  79. //#undef ARCH_X86
  80. //#define DEBUG_BRIGHTNESS
  81. #include "postprocess.h"
  82. #include "postprocess_internal.h"
  83. #include "libavutil/avstring.h"
  84. unsigned postproc_version(void)
  85. {
  86. return LIBPOSTPROC_VERSION_INT;
  87. }
  88. const char *postproc_configuration(void)
  89. {
  90. return FFMPEG_CONFIGURATION;
  91. }
  92. const char *postproc_license(void)
  93. {
  94. #define LICENSE_PREFIX "libpostproc license: "
  95. return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  96. }
  97. #if HAVE_ALTIVEC_H
  98. #include <altivec.h>
  99. #endif
  100. #define GET_MODE_BUFFER_SIZE 500
  101. #define OPTIONS_ARRAY_SIZE 10
  102. #define BLOCK_SIZE 8
  103. #define TEMP_STRIDE 8
  104. //#define NUM_BLOCKS_AT_ONCE 16 //not used yet
  105. #if ARCH_X86
  106. DECLARE_ASM_CONST(8, uint64_t, w05)= 0x0005000500050005LL;
  107. DECLARE_ASM_CONST(8, uint64_t, w04)= 0x0004000400040004LL;
  108. DECLARE_ASM_CONST(8, uint64_t, w20)= 0x0020002000200020LL;
  109. DECLARE_ASM_CONST(8, uint64_t, b00)= 0x0000000000000000LL;
  110. DECLARE_ASM_CONST(8, uint64_t, b01)= 0x0101010101010101LL;
  111. DECLARE_ASM_CONST(8, uint64_t, b02)= 0x0202020202020202LL;
  112. DECLARE_ASM_CONST(8, uint64_t, b08)= 0x0808080808080808LL;
  113. DECLARE_ASM_CONST(8, uint64_t, b80)= 0x8080808080808080LL;
  114. #endif
  115. DECLARE_ASM_CONST(8, int, deringThreshold)= 20;
  116. static struct PPFilter filters[]=
  117. {
  118. {"hb", "hdeblock", 1, 1, 3, H_DEBLOCK},
  119. {"vb", "vdeblock", 1, 2, 4, V_DEBLOCK},
  120. /* {"hr", "rkhdeblock", 1, 1, 3, H_RK1_FILTER},
  121. {"vr", "rkvdeblock", 1, 2, 4, V_RK1_FILTER},*/
  122. {"h1", "x1hdeblock", 1, 1, 3, H_X1_FILTER},
  123. {"v1", "x1vdeblock", 1, 2, 4, V_X1_FILTER},
  124. {"ha", "ahdeblock", 1, 1, 3, H_A_DEBLOCK},
  125. {"va", "avdeblock", 1, 2, 4, V_A_DEBLOCK},
  126. {"dr", "dering", 1, 5, 6, DERING},
  127. {"al", "autolevels", 0, 1, 2, LEVEL_FIX},
  128. {"lb", "linblenddeint", 1, 1, 4, LINEAR_BLEND_DEINT_FILTER},
  129. {"li", "linipoldeint", 1, 1, 4, LINEAR_IPOL_DEINT_FILTER},
  130. {"ci", "cubicipoldeint", 1, 1, 4, CUBIC_IPOL_DEINT_FILTER},
  131. {"md", "mediandeint", 1, 1, 4, MEDIAN_DEINT_FILTER},
  132. {"fd", "ffmpegdeint", 1, 1, 4, FFMPEG_DEINT_FILTER},
  133. {"l5", "lowpass5", 1, 1, 4, LOWPASS5_DEINT_FILTER},
  134. {"tn", "tmpnoise", 1, 7, 8, TEMP_NOISE_FILTER},
  135. {"fq", "forcequant", 1, 0, 0, FORCE_QUANT},
  136. {NULL, NULL,0,0,0,0} //End Marker
  137. };
  138. static const char *replaceTable[]=
  139. {
  140. "default", "hb:a,vb:a,dr:a",
  141. "de", "hb:a,vb:a,dr:a",
  142. "fast", "h1:a,v1:a,dr:a",
  143. "fa", "h1:a,v1:a,dr:a",
  144. "ac", "ha:a:128:7,va:a,dr:a",
  145. NULL //End Marker
  146. };
  147. #if ARCH_X86
  148. static inline void prefetchnta(void *p)
  149. {
  150. __asm__ volatile( "prefetchnta (%0)\n\t"
  151. : : "r" (p)
  152. );
  153. }
  154. static inline void prefetcht0(void *p)
  155. {
  156. __asm__ volatile( "prefetcht0 (%0)\n\t"
  157. : : "r" (p)
  158. );
  159. }
  160. static inline void prefetcht1(void *p)
  161. {
  162. __asm__ volatile( "prefetcht1 (%0)\n\t"
  163. : : "r" (p)
  164. );
  165. }
  166. static inline void prefetcht2(void *p)
  167. {
  168. __asm__ volatile( "prefetcht2 (%0)\n\t"
  169. : : "r" (p)
  170. );
  171. }
  172. #endif
  173. /* The horizontal functions exist only in C because the MMX
  174. * code is faster with vertical filters and transposing. */
  175. /**
  176. * Check if the given 8x8 Block is mostly "flat"
  177. */
  178. static inline int isHorizDC_C(uint8_t src[], int stride, PPContext *c)
  179. {
  180. int numEq= 0;
  181. int y;
  182. const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
  183. const int dcThreshold= dcOffset*2 + 1;
  184. for(y=0; y<BLOCK_SIZE; y++){
  185. if(((unsigned)(src[0] - src[1] + dcOffset)) < dcThreshold) numEq++;
  186. if(((unsigned)(src[1] - src[2] + dcOffset)) < dcThreshold) numEq++;
  187. if(((unsigned)(src[2] - src[3] + dcOffset)) < dcThreshold) numEq++;
  188. if(((unsigned)(src[3] - src[4] + dcOffset)) < dcThreshold) numEq++;
  189. if(((unsigned)(src[4] - src[5] + dcOffset)) < dcThreshold) numEq++;
  190. if(((unsigned)(src[5] - src[6] + dcOffset)) < dcThreshold) numEq++;
  191. if(((unsigned)(src[6] - src[7] + dcOffset)) < dcThreshold) numEq++;
  192. src+= stride;
  193. }
  194. return numEq > c->ppMode.flatnessThreshold;
  195. }
  196. /**
  197. * Check if the middle 8x8 Block in the given 8x16 block is flat
  198. */
  199. static inline int isVertDC_C(uint8_t src[], int stride, PPContext *c)
  200. {
  201. int numEq= 0;
  202. int y;
  203. const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
  204. const int dcThreshold= dcOffset*2 + 1;
  205. src+= stride*4; // src points to begin of the 8x8 Block
  206. for(y=0; y<BLOCK_SIZE-1; y++){
  207. if(((unsigned)(src[0] - src[0+stride] + dcOffset)) < dcThreshold) numEq++;
  208. if(((unsigned)(src[1] - src[1+stride] + dcOffset)) < dcThreshold) numEq++;
  209. if(((unsigned)(src[2] - src[2+stride] + dcOffset)) < dcThreshold) numEq++;
  210. if(((unsigned)(src[3] - src[3+stride] + dcOffset)) < dcThreshold) numEq++;
  211. if(((unsigned)(src[4] - src[4+stride] + dcOffset)) < dcThreshold) numEq++;
  212. if(((unsigned)(src[5] - src[5+stride] + dcOffset)) < dcThreshold) numEq++;
  213. if(((unsigned)(src[6] - src[6+stride] + dcOffset)) < dcThreshold) numEq++;
  214. if(((unsigned)(src[7] - src[7+stride] + dcOffset)) < dcThreshold) numEq++;
  215. src+= stride;
  216. }
  217. return numEq > c->ppMode.flatnessThreshold;
  218. }
  219. static inline int isHorizMinMaxOk_C(uint8_t src[], int stride, int QP)
  220. {
  221. int i;
  222. for(i=0; i<2; i++){
  223. if((unsigned)(src[0] - src[5] + 2*QP) > 4*QP) return 0;
  224. src += stride;
  225. if((unsigned)(src[2] - src[7] + 2*QP) > 4*QP) return 0;
  226. src += stride;
  227. if((unsigned)(src[4] - src[1] + 2*QP) > 4*QP) return 0;
  228. src += stride;
  229. if((unsigned)(src[6] - src[3] + 2*QP) > 4*QP) return 0;
  230. src += stride;
  231. }
  232. return 1;
  233. }
  234. static inline int isVertMinMaxOk_C(uint8_t src[], int stride, int QP)
  235. {
  236. int x;
  237. src+= stride*4;
  238. for(x=0; x<BLOCK_SIZE; x+=4){
  239. if((unsigned)(src[ x + 0*stride] - src[ x + 5*stride] + 2*QP) > 4*QP) return 0;
  240. if((unsigned)(src[1+x + 2*stride] - src[1+x + 7*stride] + 2*QP) > 4*QP) return 0;
  241. if((unsigned)(src[2+x + 4*stride] - src[2+x + 1*stride] + 2*QP) > 4*QP) return 0;
  242. if((unsigned)(src[3+x + 6*stride] - src[3+x + 3*stride] + 2*QP) > 4*QP) return 0;
  243. }
  244. return 1;
  245. }
  246. static inline int horizClassify_C(uint8_t src[], int stride, PPContext *c)
  247. {
  248. if( isHorizDC_C(src, stride, c) ){
  249. if( isHorizMinMaxOk_C(src, stride, c->QP) )
  250. return 1;
  251. else
  252. return 0;
  253. }else{
  254. return 2;
  255. }
  256. }
  257. static inline int vertClassify_C(uint8_t src[], int stride, PPContext *c)
  258. {
  259. if( isVertDC_C(src, stride, c) ){
  260. if( isVertMinMaxOk_C(src, stride, c->QP) )
  261. return 1;
  262. else
  263. return 0;
  264. }else{
  265. return 2;
  266. }
  267. }
  268. static inline void doHorizDefFilter_C(uint8_t dst[], int stride, PPContext *c)
  269. {
  270. int y;
  271. for(y=0; y<BLOCK_SIZE; y++){
  272. const int middleEnergy= 5*(dst[4] - dst[3]) + 2*(dst[2] - dst[5]);
  273. if(FFABS(middleEnergy) < 8*c->QP){
  274. const int q=(dst[3] - dst[4])/2;
  275. const int leftEnergy= 5*(dst[2] - dst[1]) + 2*(dst[0] - dst[3]);
  276. const int rightEnergy= 5*(dst[6] - dst[5]) + 2*(dst[4] - dst[7]);
  277. int d= FFABS(middleEnergy) - FFMIN( FFABS(leftEnergy), FFABS(rightEnergy) );
  278. d= FFMAX(d, 0);
  279. d= (5*d + 32) >> 6;
  280. d*= FFSIGN(-middleEnergy);
  281. if(q>0)
  282. {
  283. d= d<0 ? 0 : d;
  284. d= d>q ? q : d;
  285. }
  286. else
  287. {
  288. d= d>0 ? 0 : d;
  289. d= d<q ? q : d;
  290. }
  291. dst[3]-= d;
  292. dst[4]+= d;
  293. }
  294. dst+= stride;
  295. }
  296. }
  297. /**
  298. * Do a horizontal low pass filter on the 10x8 block (dst points to middle 8x8 Block)
  299. * using the 9-Tap Filter (1,1,2,2,4,2,2,1,1)/16 (C version)
  300. */
  301. static inline void doHorizLowPass_C(uint8_t dst[], int stride, PPContext *c)
  302. {
  303. int y;
  304. for(y=0; y<BLOCK_SIZE; y++){
  305. const int first= FFABS(dst[-1] - dst[0]) < c->QP ? dst[-1] : dst[0];
  306. const int last= FFABS(dst[8] - dst[7]) < c->QP ? dst[8] : dst[7];
  307. int sums[10];
  308. sums[0] = 4*first + dst[0] + dst[1] + dst[2] + 4;
  309. sums[1] = sums[0] - first + dst[3];
  310. sums[2] = sums[1] - first + dst[4];
  311. sums[3] = sums[2] - first + dst[5];
  312. sums[4] = sums[3] - first + dst[6];
  313. sums[5] = sums[4] - dst[0] + dst[7];
  314. sums[6] = sums[5] - dst[1] + last;
  315. sums[7] = sums[6] - dst[2] + last;
  316. sums[8] = sums[7] - dst[3] + last;
  317. sums[9] = sums[8] - dst[4] + last;
  318. dst[0]= (sums[0] + sums[2] + 2*dst[0])>>4;
  319. dst[1]= (sums[1] + sums[3] + 2*dst[1])>>4;
  320. dst[2]= (sums[2] + sums[4] + 2*dst[2])>>4;
  321. dst[3]= (sums[3] + sums[5] + 2*dst[3])>>4;
  322. dst[4]= (sums[4] + sums[6] + 2*dst[4])>>4;
  323. dst[5]= (sums[5] + sums[7] + 2*dst[5])>>4;
  324. dst[6]= (sums[6] + sums[8] + 2*dst[6])>>4;
  325. dst[7]= (sums[7] + sums[9] + 2*dst[7])>>4;
  326. dst+= stride;
  327. }
  328. }
  329. /**
  330. * Experimental Filter 1 (Horizontal)
  331. * will not damage linear gradients
  332. * Flat blocks should look like they were passed through the (1,1,2,2,4,2,2,1,1) 9-Tap filter
  333. * can only smooth blocks at the expected locations (it cannot smooth them if they did move)
  334. * MMX2 version does correct clipping C version does not
  335. * not identical with the vertical one
  336. */
  337. static inline void horizX1Filter(uint8_t *src, int stride, int QP)
  338. {
  339. int y;
  340. static uint64_t *lut= NULL;
  341. if(lut==NULL)
  342. {
  343. int i;
  344. lut = av_malloc(256*8);
  345. for(i=0; i<256; i++)
  346. {
  347. int v= i < 128 ? 2*i : 2*(i-256);
  348. /*
  349. //Simulate 112242211 9-Tap filter
  350. uint64_t a= (v/16) & 0xFF;
  351. uint64_t b= (v/8) & 0xFF;
  352. uint64_t c= (v/4) & 0xFF;
  353. uint64_t d= (3*v/8) & 0xFF;
  354. */
  355. //Simulate piecewise linear interpolation
  356. uint64_t a= (v/16) & 0xFF;
  357. uint64_t b= (v*3/16) & 0xFF;
  358. uint64_t c= (v*5/16) & 0xFF;
  359. uint64_t d= (7*v/16) & 0xFF;
  360. uint64_t A= (0x100 - a)&0xFF;
  361. uint64_t B= (0x100 - b)&0xFF;
  362. uint64_t C= (0x100 - c)&0xFF;
  363. uint64_t D= (0x100 - c)&0xFF;
  364. lut[i] = (a<<56) | (b<<48) | (c<<40) | (d<<32) |
  365. (D<<24) | (C<<16) | (B<<8) | (A);
  366. //lut[i] = (v<<32) | (v<<24);
  367. }
  368. }
  369. for(y=0; y<BLOCK_SIZE; y++){
  370. int a= src[1] - src[2];
  371. int b= src[3] - src[4];
  372. int c= src[5] - src[6];
  373. int d= FFMAX(FFABS(b) - (FFABS(a) + FFABS(c))/2, 0);
  374. if(d < QP){
  375. int v = d * FFSIGN(-b);
  376. src[1] +=v/8;
  377. src[2] +=v/4;
  378. src[3] +=3*v/8;
  379. src[4] -=3*v/8;
  380. src[5] -=v/4;
  381. src[6] -=v/8;
  382. }
  383. src+=stride;
  384. }
  385. }
  386. /**
  387. * accurate deblock filter
  388. */
  389. static av_always_inline void do_a_deblock_C(uint8_t *src, int step, int stride, PPContext *c){
  390. int y;
  391. const int QP= c->QP;
  392. const int dcOffset= ((c->nonBQP*c->ppMode.baseDcDiff)>>8) + 1;
  393. const int dcThreshold= dcOffset*2 + 1;
  394. //START_TIMER
  395. src+= step*4; // src points to begin of the 8x8 Block
  396. for(y=0; y<8; y++){
  397. int numEq= 0;
  398. if(((unsigned)(src[-1*step] - src[0*step] + dcOffset)) < dcThreshold) numEq++;
  399. if(((unsigned)(src[ 0*step] - src[1*step] + dcOffset)) < dcThreshold) numEq++;
  400. if(((unsigned)(src[ 1*step] - src[2*step] + dcOffset)) < dcThreshold) numEq++;
  401. if(((unsigned)(src[ 2*step] - src[3*step] + dcOffset)) < dcThreshold) numEq++;
  402. if(((unsigned)(src[ 3*step] - src[4*step] + dcOffset)) < dcThreshold) numEq++;
  403. if(((unsigned)(src[ 4*step] - src[5*step] + dcOffset)) < dcThreshold) numEq++;
  404. if(((unsigned)(src[ 5*step] - src[6*step] + dcOffset)) < dcThreshold) numEq++;
  405. if(((unsigned)(src[ 6*step] - src[7*step] + dcOffset)) < dcThreshold) numEq++;
  406. if(((unsigned)(src[ 7*step] - src[8*step] + dcOffset)) < dcThreshold) numEq++;
  407. if(numEq > c->ppMode.flatnessThreshold){
  408. int min, max, x;
  409. if(src[0] > src[step]){
  410. max= src[0];
  411. min= src[step];
  412. }else{
  413. max= src[step];
  414. min= src[0];
  415. }
  416. for(x=2; x<8; x+=2){
  417. if(src[x*step] > src[(x+1)*step]){
  418. if(src[x *step] > max) max= src[ x *step];
  419. if(src[(x+1)*step] < min) min= src[(x+1)*step];
  420. }else{
  421. if(src[(x+1)*step] > max) max= src[(x+1)*step];
  422. if(src[ x *step] < min) min= src[ x *step];
  423. }
  424. }
  425. if(max-min < 2*QP){
  426. const int first= FFABS(src[-1*step] - src[0]) < QP ? src[-1*step] : src[0];
  427. const int last= FFABS(src[8*step] - src[7*step]) < QP ? src[8*step] : src[7*step];
  428. int sums[10];
  429. sums[0] = 4*first + src[0*step] + src[1*step] + src[2*step] + 4;
  430. sums[1] = sums[0] - first + src[3*step];
  431. sums[2] = sums[1] - first + src[4*step];
  432. sums[3] = sums[2] - first + src[5*step];
  433. sums[4] = sums[3] - first + src[6*step];
  434. sums[5] = sums[4] - src[0*step] + src[7*step];
  435. sums[6] = sums[5] - src[1*step] + last;
  436. sums[7] = sums[6] - src[2*step] + last;
  437. sums[8] = sums[7] - src[3*step] + last;
  438. sums[9] = sums[8] - src[4*step] + last;
  439. src[0*step]= (sums[0] + sums[2] + 2*src[0*step])>>4;
  440. src[1*step]= (sums[1] + sums[3] + 2*src[1*step])>>4;
  441. src[2*step]= (sums[2] + sums[4] + 2*src[2*step])>>4;
  442. src[3*step]= (sums[3] + sums[5] + 2*src[3*step])>>4;
  443. src[4*step]= (sums[4] + sums[6] + 2*src[4*step])>>4;
  444. src[5*step]= (sums[5] + sums[7] + 2*src[5*step])>>4;
  445. src[6*step]= (sums[6] + sums[8] + 2*src[6*step])>>4;
  446. src[7*step]= (sums[7] + sums[9] + 2*src[7*step])>>4;
  447. }
  448. }else{
  449. const int middleEnergy= 5*(src[4*step] - src[3*step]) + 2*(src[2*step] - src[5*step]);
  450. if(FFABS(middleEnergy) < 8*QP){
  451. const int q=(src[3*step] - src[4*step])/2;
  452. const int leftEnergy= 5*(src[2*step] - src[1*step]) + 2*(src[0*step] - src[3*step]);
  453. const int rightEnergy= 5*(src[6*step] - src[5*step]) + 2*(src[4*step] - src[7*step]);
  454. int d= FFABS(middleEnergy) - FFMIN( FFABS(leftEnergy), FFABS(rightEnergy) );
  455. d= FFMAX(d, 0);
  456. d= (5*d + 32) >> 6;
  457. d*= FFSIGN(-middleEnergy);
  458. if(q>0){
  459. d= d<0 ? 0 : d;
  460. d= d>q ? q : d;
  461. }else{
  462. d= d>0 ? 0 : d;
  463. d= d<q ? q : d;
  464. }
  465. src[3*step]-= d;
  466. src[4*step]+= d;
  467. }
  468. }
  469. src += stride;
  470. }
  471. /*if(step==16){
  472. STOP_TIMER("step16")
  473. }else{
  474. STOP_TIMER("stepX")
  475. }*/
  476. }
  477. //Note: we have C, MMX, MMX2, 3DNOW version there is no 3DNOW+MMX2 one
  478. //Plain C versions
  479. #if !(HAVE_MMX || HAVE_ALTIVEC) || CONFIG_RUNTIME_CPUDETECT
  480. #define COMPILE_C
  481. #endif
  482. #if HAVE_ALTIVEC
  483. #define COMPILE_ALTIVEC
  484. #endif //HAVE_ALTIVEC
  485. #if ARCH_X86
  486. #if (HAVE_MMX && !HAVE_AMD3DNOW && !HAVE_MMX2) || CONFIG_RUNTIME_CPUDETECT
  487. #define COMPILE_MMX
  488. #endif
  489. #if HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT
  490. #define COMPILE_MMX2
  491. #endif
  492. #if (HAVE_AMD3DNOW && !HAVE_MMX2) || CONFIG_RUNTIME_CPUDETECT
  493. #define COMPILE_3DNOW
  494. #endif
  495. #endif /* ARCH_X86 */
  496. #undef HAVE_MMX
  497. #define HAVE_MMX 0
  498. #undef HAVE_MMX2
  499. #define HAVE_MMX2 0
  500. #undef HAVE_AMD3DNOW
  501. #define HAVE_AMD3DNOW 0
  502. #undef HAVE_ALTIVEC
  503. #define HAVE_ALTIVEC 0
  504. #ifdef COMPILE_C
  505. #define RENAME(a) a ## _C
  506. #include "postprocess_template.c"
  507. #endif
  508. #ifdef COMPILE_ALTIVEC
  509. #undef RENAME
  510. #undef HAVE_ALTIVEC
  511. #define HAVE_ALTIVEC 1
  512. #define RENAME(a) a ## _altivec
  513. #include "postprocess_altivec_template.c"
  514. #include "postprocess_template.c"
  515. #endif
  516. //MMX versions
  517. #ifdef COMPILE_MMX
  518. #undef RENAME
  519. #undef HAVE_MMX
  520. #define HAVE_MMX 1
  521. #define RENAME(a) a ## _MMX
  522. #include "postprocess_template.c"
  523. #endif
  524. //MMX2 versions
  525. #ifdef COMPILE_MMX2
  526. #undef RENAME
  527. #undef HAVE_MMX
  528. #undef HAVE_MMX2
  529. #define HAVE_MMX 1
  530. #define HAVE_MMX2 1
  531. #define RENAME(a) a ## _MMX2
  532. #include "postprocess_template.c"
  533. #endif
  534. //3DNOW versions
  535. #ifdef COMPILE_3DNOW
  536. #undef RENAME
  537. #undef HAVE_MMX
  538. #undef HAVE_MMX2
  539. #undef HAVE_AMD3DNOW
  540. #define HAVE_MMX 1
  541. #define HAVE_MMX2 0
  542. #define HAVE_AMD3DNOW 1
  543. #define RENAME(a) a ## _3DNow
  544. #include "postprocess_template.c"
  545. #endif
  546. // minor note: the HAVE_xyz is messed up after that line so do not use it.
  547. static inline void postProcess(const uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
  548. const QP_STORE_T QPs[], int QPStride, int isColor, pp_mode *vm, pp_context *vc)
  549. {
  550. PPContext *c= (PPContext *)vc;
  551. PPMode *ppMode= (PPMode *)vm;
  552. c->ppMode= *ppMode; //FIXME
  553. // Using ifs here as they are faster than function pointers although the
  554. // difference would not be measurable here but it is much better because
  555. // someone might exchange the CPU whithout restarting MPlayer ;)
  556. #if CONFIG_RUNTIME_CPUDETECT
  557. #if ARCH_X86
  558. // ordered per speed fastest first
  559. if(c->cpuCaps & PP_CPU_CAPS_MMX2)
  560. postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  561. else if(c->cpuCaps & PP_CPU_CAPS_3DNOW)
  562. postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  563. else if(c->cpuCaps & PP_CPU_CAPS_MMX)
  564. postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  565. else
  566. postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  567. #else
  568. #if HAVE_ALTIVEC
  569. if(c->cpuCaps & PP_CPU_CAPS_ALTIVEC)
  570. postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  571. else
  572. #endif
  573. postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  574. #endif
  575. #else //CONFIG_RUNTIME_CPUDETECT
  576. #if HAVE_MMX2
  577. postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  578. #elif HAVE_AMD3DNOW
  579. postProcess_3DNow(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  580. #elif HAVE_MMX
  581. postProcess_MMX(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  582. #elif HAVE_ALTIVEC
  583. postProcess_altivec(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  584. #else
  585. postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c);
  586. #endif
  587. #endif //!CONFIG_RUNTIME_CPUDETECT
  588. }
  589. //static void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height,
  590. // QP_STORE_T QPs[], int QPStride, int isColor, struct PPMode *ppMode);
  591. /* -pp Command line Help
  592. */
  593. #if LIBPOSTPROC_VERSION_INT < (52<<16)
  594. const char *const pp_help=
  595. #else
  596. const char pp_help[] =
  597. #endif
  598. "Available postprocessing filters:\n"
  599. "Filters Options\n"
  600. "short long name short long option Description\n"
  601. "* * a autoq CPU power dependent enabler\n"
  602. " c chrom chrominance filtering enabled\n"
  603. " y nochrom chrominance filtering disabled\n"
  604. " n noluma luma filtering disabled\n"
  605. "hb hdeblock (2 threshold) horizontal deblocking filter\n"
  606. " 1. difference factor: default=32, higher -> more deblocking\n"
  607. " 2. flatness threshold: default=39, lower -> more deblocking\n"
  608. " the h & v deblocking filters share these\n"
  609. " so you can't set different thresholds for h / v\n"
  610. "vb vdeblock (2 threshold) vertical deblocking filter\n"
  611. "ha hadeblock (2 threshold) horizontal deblocking filter\n"
  612. "va vadeblock (2 threshold) vertical deblocking filter\n"
  613. "h1 x1hdeblock experimental h deblock filter 1\n"
  614. "v1 x1vdeblock experimental v deblock filter 1\n"
  615. "dr dering deringing filter\n"
  616. "al autolevels automatic brightness / contrast\n"
  617. " f fullyrange stretch luminance to (0..255)\n"
  618. "lb linblenddeint linear blend deinterlacer\n"
  619. "li linipoldeint linear interpolating deinterlace\n"
  620. "ci cubicipoldeint cubic interpolating deinterlacer\n"
  621. "md mediandeint median deinterlacer\n"
  622. "fd ffmpegdeint ffmpeg deinterlacer\n"
  623. "l5 lowpass5 FIR lowpass deinterlacer\n"
  624. "de default hb:a,vb:a,dr:a\n"
  625. "fa fast h1:a,v1:a,dr:a\n"
  626. "ac ha:a:128:7,va:a,dr:a\n"
  627. "tn tmpnoise (3 threshold) temporal noise reducer\n"
  628. " 1. <= 2. <= 3. larger -> stronger filtering\n"
  629. "fq forceQuant <quantizer> force quantizer\n"
  630. "Usage:\n"
  631. "<filterName>[:<option>[:<option>...]][[,|/][-]<filterName>[:<option>...]]...\n"
  632. "long form example:\n"
  633. "vdeblock:autoq/hdeblock:autoq/linblenddeint default,-vdeblock\n"
  634. "short form example:\n"
  635. "vb:a/hb:a/lb de,-vb\n"
  636. "more examples:\n"
  637. "tn:64:128:256\n"
  638. "\n"
  639. ;
  640. pp_mode *pp_get_mode_by_name_and_quality(const char *name, int quality)
  641. {
  642. char temp[GET_MODE_BUFFER_SIZE];
  643. char *p= temp;
  644. static const char filterDelimiters[] = ",/";
  645. static const char optionDelimiters[] = ":";
  646. struct PPMode *ppMode;
  647. char *filterToken;
  648. ppMode= av_malloc(sizeof(PPMode));
  649. ppMode->lumMode= 0;
  650. ppMode->chromMode= 0;
  651. ppMode->maxTmpNoise[0]= 700;
  652. ppMode->maxTmpNoise[1]= 1500;
  653. ppMode->maxTmpNoise[2]= 3000;
  654. ppMode->maxAllowedY= 234;
  655. ppMode->minAllowedY= 16;
  656. ppMode->baseDcDiff= 256/8;
  657. ppMode->flatnessThreshold= 56-16-1;
  658. ppMode->maxClippedThreshold= 0.01;
  659. ppMode->error=0;
  660. memset(temp, 0, GET_MODE_BUFFER_SIZE);
  661. av_strlcpy(temp, name, GET_MODE_BUFFER_SIZE - 1);
  662. av_log(NULL, AV_LOG_DEBUG, "pp: %s\n", name);
  663. for(;;){
  664. char *filterName;
  665. int q= 1000000; //PP_QUALITY_MAX;
  666. int chrom=-1;
  667. int luma=-1;
  668. char *option;
  669. char *options[OPTIONS_ARRAY_SIZE];
  670. int i;
  671. int filterNameOk=0;
  672. int numOfUnknownOptions=0;
  673. int enable=1; //does the user want us to enabled or disabled the filter
  674. filterToken= strtok(p, filterDelimiters);
  675. if(filterToken == NULL) break;
  676. p+= strlen(filterToken) + 1; // p points to next filterToken
  677. filterName= strtok(filterToken, optionDelimiters);
  678. av_log(NULL, AV_LOG_DEBUG, "pp: %s::%s\n", filterToken, filterName);
  679. if(*filterName == '-'){
  680. enable=0;
  681. filterName++;
  682. }
  683. for(;;){ //for all options
  684. option= strtok(NULL, optionDelimiters);
  685. if(option == NULL) break;
  686. av_log(NULL, AV_LOG_DEBUG, "pp: option: %s\n", option);
  687. if(!strcmp("autoq", option) || !strcmp("a", option)) q= quality;
  688. else if(!strcmp("nochrom", option) || !strcmp("y", option)) chrom=0;
  689. else if(!strcmp("chrom", option) || !strcmp("c", option)) chrom=1;
  690. else if(!strcmp("noluma", option) || !strcmp("n", option)) luma=0;
  691. else{
  692. options[numOfUnknownOptions] = option;
  693. numOfUnknownOptions++;
  694. }
  695. if(numOfUnknownOptions >= OPTIONS_ARRAY_SIZE-1) break;
  696. }
  697. options[numOfUnknownOptions] = NULL;
  698. /* replace stuff from the replace Table */
  699. for(i=0; replaceTable[2*i]!=NULL; i++){
  700. if(!strcmp(replaceTable[2*i], filterName)){
  701. int newlen= strlen(replaceTable[2*i + 1]);
  702. int plen;
  703. int spaceLeft;
  704. p--, *p=',';
  705. plen= strlen(p);
  706. spaceLeft= p - temp + plen;
  707. if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE - 1){
  708. ppMode->error++;
  709. break;
  710. }
  711. memmove(p + newlen, p, plen+1);
  712. memcpy(p, replaceTable[2*i + 1], newlen);
  713. filterNameOk=1;
  714. }
  715. }
  716. for(i=0; filters[i].shortName!=NULL; i++){
  717. if( !strcmp(filters[i].longName, filterName)
  718. || !strcmp(filters[i].shortName, filterName)){
  719. ppMode->lumMode &= ~filters[i].mask;
  720. ppMode->chromMode &= ~filters[i].mask;
  721. filterNameOk=1;
  722. if(!enable) break; // user wants to disable it
  723. if(q >= filters[i].minLumQuality && luma)
  724. ppMode->lumMode|= filters[i].mask;
  725. if(chrom==1 || (chrom==-1 && filters[i].chromDefault))
  726. if(q >= filters[i].minChromQuality)
  727. ppMode->chromMode|= filters[i].mask;
  728. if(filters[i].mask == LEVEL_FIX){
  729. int o;
  730. ppMode->minAllowedY= 16;
  731. ppMode->maxAllowedY= 234;
  732. for(o=0; options[o]!=NULL; o++){
  733. if( !strcmp(options[o],"fullyrange")
  734. ||!strcmp(options[o],"f")){
  735. ppMode->minAllowedY= 0;
  736. ppMode->maxAllowedY= 255;
  737. numOfUnknownOptions--;
  738. }
  739. }
  740. }
  741. else if(filters[i].mask == TEMP_NOISE_FILTER)
  742. {
  743. int o;
  744. int numOfNoises=0;
  745. for(o=0; options[o]!=NULL; o++){
  746. char *tail;
  747. ppMode->maxTmpNoise[numOfNoises]=
  748. strtol(options[o], &tail, 0);
  749. if(tail!=options[o]){
  750. numOfNoises++;
  751. numOfUnknownOptions--;
  752. if(numOfNoises >= 3) break;
  753. }
  754. }
  755. }
  756. else if(filters[i].mask == V_DEBLOCK || filters[i].mask == H_DEBLOCK
  757. || filters[i].mask == V_A_DEBLOCK || filters[i].mask == H_A_DEBLOCK){
  758. int o;
  759. for(o=0; options[o]!=NULL && o<2; o++){
  760. char *tail;
  761. int val= strtol(options[o], &tail, 0);
  762. if(tail==options[o]) break;
  763. numOfUnknownOptions--;
  764. if(o==0) ppMode->baseDcDiff= val;
  765. else ppMode->flatnessThreshold= val;
  766. }
  767. }
  768. else if(filters[i].mask == FORCE_QUANT){
  769. int o;
  770. ppMode->forcedQuant= 15;
  771. for(o=0; options[o]!=NULL && o<1; o++){
  772. char *tail;
  773. int val= strtol(options[o], &tail, 0);
  774. if(tail==options[o]) break;
  775. numOfUnknownOptions--;
  776. ppMode->forcedQuant= val;
  777. }
  778. }
  779. }
  780. }
  781. if(!filterNameOk) ppMode->error++;
  782. ppMode->error += numOfUnknownOptions;
  783. }
  784. av_log(NULL, AV_LOG_DEBUG, "pp: lumMode=%X, chromMode=%X\n", ppMode->lumMode, ppMode->chromMode);
  785. if(ppMode->error){
  786. av_log(NULL, AV_LOG_ERROR, "%d errors in postprocess string \"%s\"\n", ppMode->error, name);
  787. av_free(ppMode);
  788. return NULL;
  789. }
  790. return ppMode;
  791. }
  792. void pp_free_mode(pp_mode *mode){
  793. av_free(mode);
  794. }
  795. static void reallocAlign(void **p, int alignment, int size){
  796. av_free(*p);
  797. *p= av_mallocz(size);
  798. }
  799. static void reallocBuffers(PPContext *c, int width, int height, int stride, int qpStride){
  800. int mbWidth = (width+15)>>4;
  801. int mbHeight= (height+15)>>4;
  802. int i;
  803. c->stride= stride;
  804. c->qpStride= qpStride;
  805. reallocAlign((void **)&c->tempDst, 8, stride*24);
  806. reallocAlign((void **)&c->tempSrc, 8, stride*24);
  807. reallocAlign((void **)&c->tempBlocks, 8, 2*16*8);
  808. reallocAlign((void **)&c->yHistogram, 8, 256*sizeof(uint64_t));
  809. for(i=0; i<256; i++)
  810. c->yHistogram[i]= width*height/64*15/256;
  811. for(i=0; i<3; i++){
  812. //Note: The +17*1024 is just there so i do not have to worry about r/w over the end.
  813. reallocAlign((void **)&c->tempBlurred[i], 8, stride*mbHeight*16 + 17*1024);
  814. reallocAlign((void **)&c->tempBlurredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size
  815. }
  816. reallocAlign((void **)&c->deintTemp, 8, 2*width+32);
  817. reallocAlign((void **)&c->nonBQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T));
  818. reallocAlign((void **)&c->stdQPTable, 8, qpStride*mbHeight*sizeof(QP_STORE_T));
  819. reallocAlign((void **)&c->forcedQPTable, 8, mbWidth*sizeof(QP_STORE_T));
  820. }
  821. static const char * context_to_name(void * ptr) {
  822. return "postproc";
  823. }
  824. static const AVClass av_codec_context_class = { "Postproc", context_to_name, NULL };
  825. pp_context *pp_get_context(int width, int height, int cpuCaps){
  826. PPContext *c= av_malloc(sizeof(PPContext));
  827. int stride= FFALIGN(width, 16); //assumed / will realloc if needed
  828. int qpStride= (width+15)/16 + 2; //assumed / will realloc if needed
  829. memset(c, 0, sizeof(PPContext));
  830. c->av_class = &av_codec_context_class;
  831. c->cpuCaps= cpuCaps;
  832. if(cpuCaps&PP_FORMAT){
  833. c->hChromaSubSample= cpuCaps&0x3;
  834. c->vChromaSubSample= (cpuCaps>>4)&0x3;
  835. }else{
  836. c->hChromaSubSample= 1;
  837. c->vChromaSubSample= 1;
  838. }
  839. reallocBuffers(c, width, height, stride, qpStride);
  840. c->frameNum=-1;
  841. return c;
  842. }
  843. void pp_free_context(void *vc){
  844. PPContext *c = (PPContext*)vc;
  845. int i;
  846. for(i=0; i<3; i++) av_free(c->tempBlurred[i]);
  847. for(i=0; i<3; i++) av_free(c->tempBlurredPast[i]);
  848. av_free(c->tempBlocks);
  849. av_free(c->yHistogram);
  850. av_free(c->tempDst);
  851. av_free(c->tempSrc);
  852. av_free(c->deintTemp);
  853. av_free(c->stdQPTable);
  854. av_free(c->nonBQPTable);
  855. av_free(c->forcedQPTable);
  856. memset(c, 0, sizeof(PPContext));
  857. av_free(c);
  858. }
  859. void pp_postprocess(const uint8_t * src[3], const int srcStride[3],
  860. uint8_t * dst[3], const int dstStride[3],
  861. int width, int height,
  862. const QP_STORE_T *QP_store, int QPStride,
  863. pp_mode *vm, void *vc, int pict_type)
  864. {
  865. int mbWidth = (width+15)>>4;
  866. int mbHeight= (height+15)>>4;
  867. PPMode *mode = (PPMode*)vm;
  868. PPContext *c = (PPContext*)vc;
  869. int minStride= FFMAX(FFABS(srcStride[0]), FFABS(dstStride[0]));
  870. int absQPStride = FFABS(QPStride);
  871. // c->stride and c->QPStride are always positive
  872. if(c->stride < minStride || c->qpStride < absQPStride)
  873. reallocBuffers(c, width, height,
  874. FFMAX(minStride, c->stride),
  875. FFMAX(c->qpStride, absQPStride));
  876. if(QP_store==NULL || (mode->lumMode & FORCE_QUANT)){
  877. int i;
  878. QP_store= c->forcedQPTable;
  879. absQPStride = QPStride = 0;
  880. if(mode->lumMode & FORCE_QUANT)
  881. for(i=0; i<mbWidth; i++) c->forcedQPTable[i]= mode->forcedQuant;
  882. else
  883. for(i=0; i<mbWidth; i++) c->forcedQPTable[i]= 1;
  884. }
  885. if(pict_type & PP_PICT_TYPE_QP2){
  886. int i;
  887. const int count= mbHeight * absQPStride;
  888. for(i=0; i<(count>>2); i++){
  889. ((uint32_t*)c->stdQPTable)[i] = (((const uint32_t*)QP_store)[i]>>1) & 0x7F7F7F7F;
  890. }
  891. for(i<<=2; i<count; i++){
  892. c->stdQPTable[i] = QP_store[i]>>1;
  893. }
  894. QP_store= c->stdQPTable;
  895. QPStride= absQPStride;
  896. }
  897. if(0){
  898. int x,y;
  899. for(y=0; y<mbHeight; y++){
  900. for(x=0; x<mbWidth; x++){
  901. av_log(c, AV_LOG_INFO, "%2d ", QP_store[x + y*QPStride]);
  902. }
  903. av_log(c, AV_LOG_INFO, "\n");
  904. }
  905. av_log(c, AV_LOG_INFO, "\n");
  906. }
  907. if((pict_type&7)!=3){
  908. if (QPStride >= 0){
  909. int i;
  910. const int count= mbHeight * QPStride;
  911. for(i=0; i<(count>>2); i++){
  912. ((uint32_t*)c->nonBQPTable)[i] = ((const uint32_t*)QP_store)[i] & 0x3F3F3F3F;
  913. }
  914. for(i<<=2; i<count; i++){
  915. c->nonBQPTable[i] = QP_store[i] & 0x3F;
  916. }
  917. } else {
  918. int i,j;
  919. for(i=0; i<mbHeight; i++) {
  920. for(j=0; j<absQPStride; j++) {
  921. c->nonBQPTable[i*absQPStride+j] = QP_store[i*QPStride+j] & 0x3F;
  922. }
  923. }
  924. }
  925. }
  926. av_log(c, AV_LOG_DEBUG, "using npp filters 0x%X/0x%X\n",
  927. mode->lumMode, mode->chromMode);
  928. postProcess(src[0], srcStride[0], dst[0], dstStride[0],
  929. width, height, QP_store, QPStride, 0, mode, c);
  930. width = (width )>>c->hChromaSubSample;
  931. height = (height)>>c->vChromaSubSample;
  932. if(mode->chromMode){
  933. postProcess(src[1], srcStride[1], dst[1], dstStride[1],
  934. width, height, QP_store, QPStride, 1, mode, c);
  935. postProcess(src[2], srcStride[2], dst[2], dstStride[2],
  936. width, height, QP_store, QPStride, 2, mode, c);
  937. }
  938. else if(srcStride[1] == dstStride[1] && srcStride[2] == dstStride[2]){
  939. linecpy(dst[1], src[1], height, srcStride[1]);
  940. linecpy(dst[2], src[2], height, srcStride[2]);
  941. }else{
  942. int y;
  943. for(y=0; y<height; y++){
  944. memcpy(&(dst[1][y*dstStride[1]]), &(src[1][y*srcStride[1]]), width);
  945. memcpy(&(dst[2][y*dstStride[2]]), &(src[2][y*srcStride[2]]), width);
  946. }
  947. }
  948. }