MythTV  master
zoom_filter_mmx.c
Go to the documentation of this file.
1 /* Prototypes to keep gcc from spewing warnings */
2 void zoom_filter_mmx (int prevX, int prevY, const unsigned int *expix1, unsigned int *expix2, const int *brutS, const int *brutD, int buffratio, int precalCoef[16][16]);
4 
5 #ifdef MMX
6 #define BUFFPOINTNB 16
7 #define BUFFPOINTMASK 0xffff
8 #define BUFFINCR 0xff
9 
10 #include "mmx.h"
11 
12 #define sqrtperte 16
13 // faire : a % sqrtperte <=> a & pertemask
14 #define PERTEMASK 0xf
15 // faire : a / sqrtperte <=> a >> PERTEDEC
16 #define PERTEDEC 4
17 
18 #include "libavutil/cpu.h"
19 
21  return (av_get_cpu_flags() & AV_CPU_FLAG_MMX);
22 }
23 
24 void zoom_filter_mmx (int prevX, int prevY,
25  const unsigned int *expix1, unsigned int *expix2,//NOLINT(readability-non-const-parameter)
26  const int *brutS, const int *brutD, int buffratio,
27  int precalCoef[16][16])
28 {
29  unsigned int ax = (prevX-1)<<PERTEDEC;
30  unsigned int ay = (prevY-1)<<PERTEDEC;
31 
32  int bufsize = prevX * prevY;
33 
34  pxor_r2r(mm7,mm7);
35 
36  for (int loop=0; loop<bufsize; loop++)
37  {
38  int pos = 0;
39  int coeffs = 0;
40 
41  int myPos = loop << 1;
42  int myPos2 = myPos + 1;
43  int brutSmypos = brutS[myPos];
44 
45  int px = brutSmypos +
46  (((brutD[myPos] - brutSmypos)*buffratio) >> BUFFPOINTNB);
47 
48  brutSmypos = brutS[myPos2];
49  int py = brutSmypos +
50  (((brutD[myPos2] - brutSmypos)*buffratio) >> BUFFPOINTNB);
51 
52  if (px < 0)
53  px = 0;
54 
55  if (py < 0)
56  py = 0;
57 
58  if ((py>=(int)ay) || (px>=(int)ax))
59  {
60  pos=coeffs=0;
61  }
62  else {
63  pos = ((px >> PERTEDEC) + prevX * (py >> PERTEDEC));
64  /* coef en modulo 15 */
65  coeffs = precalCoef [px & PERTEMASK][py & PERTEMASK];
66  }
67 
68  int posplusprevX = pos + prevX;
69 
70  movd_m2r(coeffs, mm6);
71 
72  /* recuperation des deux premiers pixels dans mm0 et mm1 */
73  movq_m2r(expix1[pos], mm0); /* b1-v1-r1-a1-b2-v2-r2-a2 */
74  movq_r2r(mm0, mm1); /* b1-v1-r1-a1-b2-v2-r2-a2 */
75 
76  /* depackage du premier pixel */
77  punpcklbw_r2r(mm7, mm0); /* 00-b2-00-v2-00-r2-00-a2 */
78  movq_r2r(mm6, mm5); /* xx-xx-xx-xx-c4-c3-c2-c1 */
79 
80  /* depackage du 2ieme pixel */
81  punpckhbw_r2r(mm7, mm1); /* 00-b1-00-v1-00-r1-00-a1 */
82 
83  /* extraction des coefficients... */
84  punpcklbw_r2r(mm5, mm6); /* c4-c4-c3-c3-c2-c2-c1-c1 */
85  movq_r2r(mm6, mm4); /* c4-c4-c3-c3-c2-c2-c1-c1 */
86  movq_r2r(mm6, mm5); /* c4-c4-c3-c3-c2-c2-c1-c1 */
87  punpcklbw_r2r(mm5, mm6); /* c2-c2-c2-c2-c1-c1-c1-c1 */
88  punpckhbw_r2r(mm5, mm4); /* c4-c4-c4-c4-c3-c3-c3-c3 */
89 
90  movq_r2r(mm6, mm3); /* c2-c2-c2-c2-c1-c1-c1-c1 */
91  punpcklbw_r2r(mm7, mm6); /* 00-c1-00-c1-00-c1-00-c1 */
92  punpckhbw_r2r(mm7, mm3); /* 00-c2-00-c2-00-c2-00-c2 */
93 
94  /* multiplication des pixels par les coefficients */
95  pmullw_r2r(mm6, mm0); /* c1*b2-c1*v2-c1*r2-c1*a2 */
96  pmullw_r2r(mm3, mm1); /* c2*b1-c2*v1-c2*r1-c2*a1 */
97  paddw_r2r(mm1, mm0);
98 
99  /* ...extraction des 2 derniers coefficients */
100  movq_r2r(mm4, mm5); /* c4-c4-c4-c4-c3-c3-c3-c3 */
101  punpcklbw_r2r(mm7, mm4); /* 00-c3-00-c3-00-c3-00-c3 */
102  punpckhbw_r2r(mm7, mm5); /* 00-c4-00-c4-00-c4-00-c4 */
103 
104  /* ajouter la longueur de ligne a esi */
105  /* recuperation des 2 derniers pixels */
106  movq_m2r(expix1[posplusprevX], mm1);
107  movq_r2r(mm1, mm2);
108 
109  /* depackage des pixels */
110  punpcklbw_r2r(mm7, mm1);
111  punpckhbw_r2r(mm7, mm2);
112 
113  /* multiplication pas les coeffs */
114  pmullw_r2r(mm4, mm1);
115  pmullw_r2r(mm5, mm2);
116 
117  /* ajout des valeurs obtenues de iso8859-15 à la valeur finale */
118  paddw_r2r(mm1, mm0);
119  paddw_r2r(mm2, mm0);
120 
121  /* division par 256 = 16+16+16+16, puis repackage du pixel final */
122  psrlw_i2r(8, mm0);
123  packuswb_r2r(mm7, mm0);
124  movd_r2m(mm0,expix2[loop]);
125  }
126  emms();
127 }
128 
129 #else
130 
132  return 0;
133 }
134 
135 void zoom_filter_mmx (int prevX, int prevY,
136  const unsigned int *expix1, unsigned int *expix2,
137  const int *brutS, const int *brutD, int buffratio,
138  int precalCoef[16][16])
139 {
140  (void)prevX;
141  (void)prevY;
142  (void)expix1;
143  (void)expix2;
144  (void)brutS;
145  (void)brutD;
146  (void)buffratio;
147  (void)precalCoef;
148  return;
149 }
150 
151 #endif
152 
153 /*
154  * vim:ts=4:sw=4:ai:et:si:sts=4
155  */
156 
int buffratio
modif by jeko : fixedpoint : buffration = (16:16) (donc 0<=buffration<=2^16)
Definition: filters.c:125
int zoom_filter_mmx_supported(void)
unsigned int * coeffs
Definition: filters.c:96
unsigned int prevY
Definition: filters.c:109
unsigned int prevX
Definition: filters.c:109
guint32 * expix2
Definition: filters.c:104
#define PERTEDEC
#define PERTEMASK
void zoom_filter_mmx(int prevX, int prevY, const unsigned int *expix1, unsigned int *expix2, const int *brutS, const int *brutD, int buffratio, int precalCoef[16][16])
#define BUFFPOINTNB
int precalCoef[16][16]
modif d'optim by Jeko : precalcul des 4 coefs résultant des 2 pos
Definition: filters.c:144
signed int * brutD
Definition: filters.c:99
signed int * brutS
Definition: filters.c:98
guint32 * expix1
Definition: filters.c:103