openMSX
HQ3xScaler.cc
Go to the documentation of this file.
1 /*
2 Original code: Copyright (C) 2003 MaxSt ( maxst@hiend3d.com )
3 openMSX adaptation by Wouter Vermaelen
4 
5 License: LGPL
6 
7 Visit the HiEnd3D site for info:
8  http://www.hiend3d.com/hq2x.html
9 */
10 
11 #include "HQ3xScaler.hh"
12 #include "HQCommon.hh"
13 #include "LineScalers.hh"
14 #include "unreachable.hh"
15 #include "build-info.hh"
16 #include <cstdint>
17 
18 namespace openmsx {
19 
20 template<typename Pixel> struct HQ_1x1on3x3
21 {
22  void operator()(const Pixel* in0, const Pixel* in1, const Pixel* in2,
23  Pixel* out0, Pixel* out1, Pixel* out2,
24  unsigned srcWidth, unsigned* edgeBuf, EdgeHQ edgeOp)
25  __restrict;
26 };
27 
28 template<typename Pixel>
30  const Pixel* __restrict in0, const Pixel* __restrict in1,
31  const Pixel* __restrict in2,
32  Pixel* __restrict out0, Pixel* __restrict out1,
33  Pixel* __restrict out2,
34  unsigned srcWidth, unsigned* __restrict edgeBuf,
35  EdgeHQ edgeOp) __restrict
36 {
37  unsigned c2 = readPixel(in0[0]); unsigned c3 = c2;
38  unsigned c5 = readPixel(in1[0]); unsigned c6 = c5;
39  unsigned c8 = readPixel(in2[0]); unsigned c9 = c8;
40 
41  unsigned pattern = 0;
42  if (edgeOp(c5, c8)) pattern |= 3 << 6;
43  if (edgeOp(c5, c2)) pattern |= 3 << 9;
44 
45  for (unsigned x = 0; x < srcWidth; ++x) {
46  unsigned c1 = c2;
47  unsigned c4 = c5;
48  unsigned c7 = c8;
49  c2 = c3;
50  c5 = c6;
51  c8 = c9;
52  if (x != srcWidth - 1) {
53  c3 = readPixel(in0[x + 1]);
54  c6 = readPixel(in1[x + 1]);
55  c9 = readPixel(in2[x + 1]);
56  }
57 
58  pattern = (pattern >> 6) & 0x001F; // left overlap
59  // overlaps with left
60  //if (edgeOp(c8, c4)) pattern |= 1 << 0; // B - l: c5-c9 6
61  //if (edgeOp(c5, c7)) pattern |= 1 << 1; // B - l: c6-c8 7
62  //if (edgeOp(c5, c4)) pattern |= 1 << 2; // l: c5-c6 8
63  // overlaps with top and left
64  //if (edgeOp(c5, c1)) pattern |= 1 << 3; // l: c2-c6 9, t: c4-c8 0
65  //if (edgeOp(c4, c2)) pattern |= 1 << 4; // l: c5-c3 10, t: c5-c7 1
66  // non-overlapping pixels
67  if (edgeOp(c5, c8)) pattern |= 1 << 5; // B
68  if (edgeOp(c5, c9)) pattern |= 1 << 6; // BR
69  if (edgeOp(c6, c8)) pattern |= 1 << 7; // BR
70  if (edgeOp(c5, c6)) pattern |= 1 << 8; // R
71  // overlaps with top
72  //if (edgeOp(c2, c6)) pattern |= 1 << 9; // R - t: c5-c9 6
73  //if (edgeOp(c5, c3)) pattern |= 1 << 10; // R - t: c6-c8 7
74  //if (edgeOp(c5, c2)) pattern |= 1 << 11; // t: c5-c8 5
75  pattern |= ((edgeBuf[x] & (1 << 5) ) << 6) |
76  ((edgeBuf[x] & ((1 << 6) | (1 << 7))) << 3);
77  edgeBuf[x] = pattern;
78 
79  unsigned pixel0, pixel1, pixel2, pixel3, pixel4,
80  pixel5, pixel6, pixel7, pixel8;
81 
82 #include "HQ3xScaler-1x1to3x3.nn"
83 
84  out0[3 * x + 0] = writePixel<Pixel>(pixel0);
85  out0[3 * x + 1] = writePixel<Pixel>(pixel1);
86  out0[3 * x + 2] = writePixel<Pixel>(pixel2);
87  out1[3 * x + 0] = writePixel<Pixel>(pixel3);
88  out1[3 * x + 1] = writePixel<Pixel>(pixel4);
89  out1[3 * x + 2] = writePixel<Pixel>(pixel5);
90  out2[3 * x + 0] = writePixel<Pixel>(pixel6);
91  out2[3 * x + 1] = writePixel<Pixel>(pixel7);
92  out2[3 * x + 2] = writePixel<Pixel>(pixel8);
93  }
94 }
95 
96 
97 
98 template<typename Pixel>
100  : Scaler3<Pixel>(pixelOps_)
101  , pixelOps(pixelOps_)
102 {
103 }
104 
105 template<typename Pixel>
107  unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
108  ScalerOutput<Pixel>& dst, unsigned dstStartY, unsigned dstEndY)
109 {
110  PolyScale<Pixel, Scale_2on3<Pixel>> postScale(pixelOps);
111  EdgeHQ edgeOp = createEdgeHQ(pixelOps);
112  doHQScale3<Pixel>(HQ_1x1on3x3<Pixel>(), edgeOp, postScale,
113  src, srcStartY, srcEndY, srcWidth,
114  dst, dstStartY, dstEndY, (srcWidth * 9) / 2);
115 }
116 
117 template<typename Pixel>
119  unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
120  ScalerOutput<Pixel>& dst, unsigned dstStartY, unsigned dstEndY)
121 {
123  EdgeHQ edgeOp = createEdgeHQ(pixelOps);
124  doHQScale3<Pixel>(HQ_1x1on3x3<Pixel>(), edgeOp, postScale,
125  src, srcStartY, srcEndY, srcWidth,
126  dst, dstStartY, dstEndY, srcWidth * 3);
127 }
128 
129 template<typename Pixel>
131  unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
132  ScalerOutput<Pixel>& dst, unsigned dstStartY, unsigned dstEndY)
133 {
134  PolyScale<Pixel, Scale_4on3<Pixel>> postScale(pixelOps);
135  EdgeHQ edgeOp = createEdgeHQ(pixelOps);
136  doHQScale3<Pixel>(HQ_1x1on3x3<Pixel>(), edgeOp, postScale,
137  src, srcStartY, srcEndY, srcWidth,
138  dst, dstStartY, dstEndY, (srcWidth * 9) / 4);
139 }
140 
141 template<typename Pixel>
143  unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
144  ScalerOutput<Pixel>& dst, unsigned dstStartY, unsigned dstEndY)
145 {
146  PolyScale<Pixel, Scale_2on1<Pixel>> postScale(pixelOps);
147  EdgeHQ edgeOp = createEdgeHQ(pixelOps);
148  doHQScale3<Pixel>(HQ_1x1on3x3<Pixel>(), edgeOp, postScale,
149  src, srcStartY, srcEndY, srcWidth,
150  dst, dstStartY, dstEndY, (srcWidth * 3) / 2);
151 }
152 
153 template<typename Pixel>
155  unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
156  ScalerOutput<Pixel>& dst, unsigned dstStartY, unsigned dstEndY)
157 {
158  PolyScale<Pixel, Scale_8on3<Pixel>> postScale(pixelOps);
159  EdgeHQ edgeOp = createEdgeHQ(pixelOps);
160  doHQScale3<Pixel>(HQ_1x1on3x3<Pixel>(), edgeOp, postScale,
161  src, srcStartY, srcEndY, srcWidth,
162  dst, dstStartY, dstEndY, (srcWidth * 9) / 8);
163 }
164 
165 template<typename Pixel>
167  unsigned srcStartY, unsigned srcEndY, unsigned srcWidth,
168  ScalerOutput<Pixel>& dst, unsigned dstStartY, unsigned dstEndY)
169 {
170  PolyScale<Pixel, Scale_4on1<Pixel>> postScale(pixelOps);
171  EdgeHQ edgeOp = createEdgeHQ(pixelOps);
172  doHQScale3<Pixel>(HQ_1x1on3x3<Pixel>(), edgeOp, postScale,
173  src, srcStartY, srcEndY, srcWidth,
174  dst, dstStartY, dstEndY, (srcWidth * 3) / 4);
175 }
176 
177 // Force template instantiation.
178 #if HAVE_16BPP
179 template class HQ3xScaler<uint16_t>;
180 #endif
181 #if HAVE_32BPP
182 template class HQ3xScaler<uint32_t>;
183 #endif
184 
185 } // namespace openmsx
openmsx::HQ3xScaler::scale8x1to9x3
void scale8x1to9x3(FrameSource &src, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, ScalerOutput< Pixel > &dst, unsigned dstStartY, unsigned dstEndY) override
Definition: HQ3xScaler.cc:154
openmsx::EdgeHQ
Definition: HQCommon.hh:44
openmsx::PixelOperations
Definition: PixelOperations.hh:144
openmsx::HQ3xScaler::scale4x1to9x3
void scale4x1to9x3(FrameSource &src, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, ScalerOutput< Pixel > &dst, unsigned dstStartY, unsigned dstEndY) override
Definition: HQ3xScaler.cc:130
openmsx::ScalerOutput
Definition: ScalerOutput.hh:7
openmsx::Pixel
uint32_t Pixel
Definition: GLHQLiteScaler.cc:98
openmsx::HQ3xScaler::scale2x1to3x3
void scale2x1to3x3(FrameSource &src, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, ScalerOutput< Pixel > &dst, unsigned dstStartY, unsigned dstEndY) override
Definition: HQ3xScaler.cc:142
openmsx::HQ3xScaler
Runs the hq3x scaler algorithm.
Definition: HQ3xScaler.hh:13
openmsx::PolyScale
Polymorphic wrapper around another line scaler.
Definition: LineScalers.hh:312
build-info.hh
HQ3xScaler.hh
LineScalers.hh
openmsx::createEdgeHQ
EdgeHQ createEdgeHQ(const PixelOperations< Pixel > &pixelOps)
Definition: HQCommon.hh:85
openmsx::x
constexpr KeyMatrixPosition x
Keyboard bindings.
Definition: Keyboard.cc:1416
openmsx::HQ3xScaler::scale2x1to9x3
void scale2x1to9x3(FrameSource &src, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, ScalerOutput< Pixel > &dst, unsigned dstStartY, unsigned dstEndY) override
Definition: HQ3xScaler.cc:106
openmsx::HQ3xScaler::scale1x1to3x3
void scale1x1to3x3(FrameSource &src, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, ScalerOutput< Pixel > &dst, unsigned dstStartY, unsigned dstEndY) override
Definition: HQ3xScaler.cc:118
openmsx::Scaler3
Base class for 3x scalers.
Definition: Scaler3.hh:12
openmsx::HQ3xScaler::HQ3xScaler
HQ3xScaler(const PixelOperations< Pixel > &pixelOps)
Definition: HQ3xScaler.cc:99
openmsx::FrameSource
Interface for getting lines from a video frame.
Definition: FrameSource.hh:14
openmsx::readPixel
uint32_t readPixel(Pixel p)
Definition: HQCommon.hh:18
openmsx::HQ_1x1on3x3
Definition: HQ3xScaler.cc:21
unreachable.hh
openmsx::HQ_1x1on3x3::operator()
void operator()(const Pixel *in0, const Pixel *in1, const Pixel *in2, Pixel *out0, Pixel *out1, Pixel *out2, unsigned srcWidth, unsigned *edgeBuf, EdgeHQ edgeOp)
Definition: HQ3xScaler.cc:29
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::HQ3xScaler::scale4x1to3x3
void scale4x1to3x3(FrameSource &src, unsigned srcStartY, unsigned srcEndY, unsigned srcWidth, ScalerOutput< Pixel > &dst, unsigned dstStartY, unsigned dstEndY) override
Definition: HQ3xScaler.cc:166
HQCommon.hh