postprocess.c 37 KB

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