postprocess.c 37 KB

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