<s>
hqx	B-Algorithm
(	O
"	O
high	O
quality	O
scale	O
"	O
)	O
is	O
a	O
set	O
of	O
3	O
image	B-Algorithm
upscaling	I-Algorithm
algorithms	O
developed	O
by	O
Maxim	O
Stepin	O
.	O
</s>
<s>
The	O
algorithms	O
are	O
hq2x	B-Algorithm
,	O
hq3x	B-Algorithm
,	O
and	O
hq4x	B-Algorithm
,	O
which	O
magnify	O
by	O
a	O
factor	O
of	O
2	O
,	O
3	O
,	O
and	O
4	O
respectively	O
.	O
</s>
<s>
It	O
was	O
initially	O
created	O
in	O
2003	O
for	O
the	O
Super	O
NES	O
emulator	B-Application
ZSNES	B-Language
,	O
and	O
is	O
used	O
in	O
emulators	B-Application
such	O
as	O
Nestopia	B-Application
,	O
FCEUX	B-Application
,	O
higan	B-Language
,	O
and	O
Snes9x	B-Operating_System
.	O
</s>
<s>
The	O
source	O
image	O
's	O
pixels	B-Algorithm
are	O
iterated	O
through	O
from	O
top-left	O
to	O
bottom-right	O
.	O
</s>
<s>
For	O
each	O
pixel	B-Algorithm
,	O
the	O
surrounding	O
8	O
pixels	B-Algorithm
are	O
compared	O
to	O
the	O
color	O
of	O
the	O
source	O
pixel	B-Algorithm
.	O
</s>
<s>
Shapes	O
are	O
detected	O
by	O
checking	O
for	O
pixels	B-Algorithm
of	O
similar	O
color	O
according	O
to	O
a	O
YUV	O
threshold	O
.	O
</s>
<s>
hqx	B-Algorithm
uses	O
the	O
YUV	O
color	O
space	O
to	O
calculate	O
color	O
differences	O
,	O
so	O
that	O
differences	O
in	O
brightness	O
are	O
weighted	O
higher	O
to	O
order	O
to	O
mimic	O
human	O
perception	O
.	O
</s>
<s>
To	O
expand	O
the	O
single	O
pixel	B-Algorithm
into	O
a	O
2×2	O
,	O
3×3	O
,	O
or	O
4×4	O
block	O
of	O
pixels	B-Algorithm
,	O
the	O
arrangement	O
of	O
neighbors	O
is	O
looked	O
up	O
in	O
a	O
predefined	O
table	O
which	O
contains	O
the	O
necessary	O
interpolation	O
patterns	O
.	O
</s>
<s>
Generating	O
these	O
256-filter	O
lookup	O
tables	O
is	O
relatively	O
slow	O
,	O
and	O
is	O
the	O
major	O
source	O
of	O
complexity	O
in	O
the	O
algorithm	O
:	O
the	O
render	O
stage	O
is	O
very	O
simple	O
and	O
fast	O
,	O
and	O
designed	O
to	O
be	O
capable	O
of	O
being	O
performed	O
in	O
real	O
time	O
on	O
a	O
MMX-capable	O
CPU	O
.	O
</s>
<s>
A	O
C++	B-Language
port	O
by	O
byuu	O
,	O
the	O
author	O
of	O
bsnes	B-Language
,	O
which	O
encodes	O
the	O
LUT	O
in	O
a	O
space-efficient	O
way	O
.	O
</s>
<s>
libretro	B-Application
implements	O
two	O
families	O
of	O
shaders	O
in	O
Slang/HLSL	O
,	O
GLSL	B-Language
,	O
and	O
Cg	B-Language
:	O
</s>
<s>
The	O
hqx	B-Algorithm
family	O
,	O
which	O
is	O
true	O
hqx	B-Algorithm
.	O
</s>
<s>
As	O
it	O
runs	O
on	O
modern	O
GPUs	B-Architecture
,	O
lookup	O
tables	O
are	O
substituted	O
by	O
textures	O
.	O
</s>
<s>
The	O
textures	O
were	O
generated	O
by	O
interrogating	O
a	O
modified	O
version	O
of	O
hqx	B-Algorithm
for	O
its	O
switch/case	O
.	O
</s>
<s>
The	O
scalehq	B-Algorithm
family	O
,	O
which	O
is	O
frequently	O
confused	O
with	O
hqx	B-Algorithm
.	O
</s>
<s>
It	O
is	O
not	O
related	O
to	O
hqx	B-Algorithm
,	O
but	O
is	O
rather	O
a	O
generic	O
upscaling-smoothing	O
algorithm	O
.	O
</s>
<s>
hqx	B-Algorithm
has	O
also	O
been	O
implemented	O
in	O
ffmpeg	B-Library
for	O
upscaling	O
images	O
and	O
videos	O
2x	O
,	O
3x	O
,	O
or	O
4x	O
.	O
</s>
<s>
An	O
account	O
of	O
the	O
production	O
of	O
the	O
translation	O
for	O
ffmpeg	B-Library
is	O
and	O
usage	O
may	O
be	O
something	O
like	O
:	O
ffmpeg	B-Library
-i	O
%1	O
-filter_complex	O
hqx	B-Algorithm
=	O
2	O
hqx2-	O
%1	O
to	O
produce	O
a	O
2x	O
image	O
or	O
video	O
.	O
</s>
