| e8555c89 Andy McCall |
1 |
#ifndef HQCOMMON_HH |
| 2 |
#define HQCOMMON_HH |
| 3 |
|
| 4 |
#include "endian.hh" |
| 5 |
#include "narrow.hh" |
| 6 |
#include "xrange.hh" |
| 7 |
#include <cassert> |
| 8 |
#include <cstdint> |
| 9 |
#include <span> |
| 10 |
|
| 11 |
namespace openmsx { |
| 12 |
|
| 13 |
struct EdgeHQ |
| 14 |
{ |
| 15 |
[[nodiscard]] bool operator()(uint32_t c1, uint32_t c2) const |
| 16 |
{ |
| 17 |
if (c1 == c2) return false; |
| 18 |
|
| 19 |
unsigned r1 = (c1 >> 0) & 0xFF; |
| 20 |
unsigned g1 = (c1 >> 8) & 0xFF; |
| 21 |
unsigned b1 = (c1 >> 16) & 0xFF; |
| 22 |
|
| 23 |
unsigned r2 = (c2 >> 0) & 0xFF; |
| 24 |
unsigned g2 = (c2 >> 8) & 0xFF; |
| 25 |
unsigned b2 = (c2 >> 16) & 0xFF; |
| 26 |
|
| 27 |
auto dr = narrow_cast<int>(r1 - r2); |
| 28 |
auto dg = narrow_cast<int>(g1 - g2); |
| 29 |
auto db = narrow_cast<int>(b1 - b2); |
| 30 |
|
| 31 |
int dy = dr + dg + db; |
| 32 |
if (dy < -0xC0 || dy > 0xC0) return true; |
| 33 |
|
| 34 |
if (int du = dr - db; |
| 35 |
du < -0x1C || du > 0x1C) return true; |
| 36 |
|
| 37 |
if (int dv = 3 * dg - dy; |
| 38 |
dv < -0x30 || dv > 0x30) return true; |
| 39 |
|
| 40 |
return false; |
| 41 |
} |
| 42 |
}; |
| 43 |
|
| 44 |
template<typename EdgeOp> |
| 45 |
void calcEdgesGL(std::span<const uint32_t> curr, std::span<const uint32_t> next, |
| 46 |
std::span<Endian::L32> edges2, EdgeOp edgeOp) |
| 47 |
{ |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
auto size = curr.size(); |
| 88 |
assert(next.size() == size); |
| 89 |
assert(2 * edges2.size() == size); |
| 90 |
|
| 91 |
using Pixel = uint32_t; |
| 92 |
|
| 93 |
uint32_t pattern = 0; |
| 94 |
Pixel c5 = curr[0]; |
| 95 |
Pixel c8 = next[0]; |
| 96 |
if (edgeOp(c5, c8)) pattern |= 0x1800'0000; |
| 97 |
|
| 98 |
auto size2 = size / 2; |
| 99 |
for (auto xx : xrange(size2 - 1)) { |
| 100 |
pattern = (pattern >> (16 + 9)) & 0x001C; |
| 101 |
pattern |= (edges2[xx] << 3) & 0xC460'C460; |
| 102 |
|
| 103 |
if (edgeOp(c5, c8)) pattern |= 0x0000'0080; |
| 104 |
Pixel c6 = curr[2 * xx + 1]; |
| 105 |
if (edgeOp(c6, c8)) pattern |= 0x0004'0800; |
| 106 |
if (edgeOp(c5, c6)) pattern |= 0x0010'2000; |
| 107 |
Pixel c9 = next[2 * xx + 1]; |
| 108 |
if (edgeOp(c5, c9)) pattern |= 0x0008'1000; |
| 109 |
|
| 110 |
if (edgeOp(c6, c9)) pattern |= 0x0080'0000; |
| 111 |
c5 = curr[2 * xx + 2]; |
| 112 |
if (edgeOp(c5, c9)) pattern |= 0x0800'0000; |
| 113 |
if (edgeOp(c6, c5)) pattern |= 0x2000'0000; |
| 114 |
c8 = next[2 * xx + 2]; |
| 115 |
if (edgeOp(c6, c8)) pattern |= 0x1000'0000; |
| 116 |
|
| 117 |
edges2[xx] = pattern; |
| 118 |
} |
| 119 |
|
| 120 |
pattern = (pattern >> (16 + 9)) & 0x001C; |
| 121 |
pattern |= (edges2[size2 - 1] << 3) & 0xC460'C460; |
| 122 |
|
| 123 |
if (edgeOp(c5, c8)) pattern |= 0x0000'0080; |
| 124 |
Pixel c6 = curr[size - 1]; |
| 125 |
if (edgeOp(c6, c8)) pattern |= 0x0004'0800; |
| 126 |
if (edgeOp(c5, c6)) pattern |= 0x0010'2000; |
| 127 |
Pixel c9 = next[size - 1]; |
| 128 |
if (edgeOp(c5, c9)) pattern |= 0x0008'1000; |
| 129 |
|
| 130 |
if (edgeOp(c6, c9)) pattern |= 0x1880'0000; |
| 131 |
|
| 132 |
edges2[size2 - 1] = pattern; |
| 133 |
} |
| 134 |
|
| 135 |
} |
| 136 |
|
| 137 |
#endif |