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