MythTV master
zoom_filter_mmx.cpp
Go to the documentation of this file.
1#include <algorithm>
2#include <cstdint>
3
5
6#ifdef MMX
7static constexpr uint8_t BUFFPOINTNB { 16 };
8//static constexpr uint16_t BUFFPOINTMASK { 0xffff };
9//static constexpr uint8_t BUFFINCR { 0xff };
10
11#include "mmx.h"
12
13//static constexpr uint8_t sqrtperte { 16 };
14// faire : a % sqrtperte <=> a & pertemask
15static constexpr uint8_t PERTEMASK { 0xf };
16// faire : a / sqrtperte <=> a >> PERTEDEC
17static constexpr uint8_t PERTEDEC { 4 };
18
19extern "C" {
20#include "libavutil/cpu.h"
21}
22
24 return (av_get_cpu_flags() & AV_CPU_FLAG_MMX);
25}
26
28 const unsigned int *expix1, unsigned int *expix2,//NOLINT(readability-non-const-parameter)
29 const int *brutS, const int *brutD, int buffratio,
31{
32 unsigned int ax = (prevX-1)<<PERTEDEC;
33 unsigned int ay = (prevY-1)<<PERTEDEC;
34
35 int bufsize = prevX * prevY;
36
37 pxor_r2r(mm7,mm7);
38
39 for (int loop=0; loop<bufsize; loop++)
40 {
41 int pos = 0;
42 int coeffs = 0;
43
44 int myPos = loop << 1;
45 int myPos2 = myPos + 1;
46 int brutSmypos = brutS[myPos];
47
48 int px = brutSmypos +
49 (((brutD[myPos] - brutSmypos)*buffratio) >> BUFFPOINTNB);
50
51 brutSmypos = brutS[myPos2];
52 int py = brutSmypos +
53 (((brutD[myPos2] - brutSmypos)*buffratio) >> BUFFPOINTNB);
54
55 px = std::max(px, 0);
56 py = std::max(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
135void zoom_filter_mmx ([[maybe_unused]] int prevX,
136 [[maybe_unused]] int prevY,
137 [[maybe_unused]] const unsigned int *expix1,
138 [[maybe_unused]] unsigned int *expix2,
139 [[maybe_unused]] const int *brutS,
140 [[maybe_unused]] const int *brutD,
141 [[maybe_unused]] int buffratio,
142 [[maybe_unused]] const GoomCoefficients &precalCoef)
143{
144}
145
146#endif
147
148/*
149 * vim:ts=4:sw=4:ai:et:si:sts=4
150 */
151
signed int * brutD
Definition: filters.cpp:101
guint32 * expix2
Definition: filters.cpp:106
guint32 * expix1
Definition: filters.cpp:105
unsigned int * coeffs
Definition: filters.cpp:98
unsigned int prevY
Definition: filters.cpp:111
unsigned int prevX
Definition: filters.cpp:111
GoomCoefficients precalCoef
modif d'optim by Jeko : precalcul des 4 coefs résultant des 2 pos
Definition: filters.cpp:146
int buffratio
modif by jeko : fixedpoint : buffration = (16:16) (donc 0<=buffration<=2^16)
Definition: filters.cpp:127
signed int * brutS
Definition: filters.cpp:100
static constexpr uint8_t BUFFPOINTNB
void zoom_filter_mmx(int prevX, int prevY, const unsigned int *expix1, unsigned int *expix2, const int *brutS, const int *brutD, int buffratio, const GoomCoefficients &precalCoef)
int zoom_filter_mmx_supported()
static constexpr uint8_t PERTEMASK
static constexpr uint8_t PERTEDEC
std::array< std::array< int, 16 >, 16 > GoomCoefficients
Definition: zoom_filters.h:3