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