| 1 |
#ifndef FRAMESOURCE_HH |
| 2 |
#define FRAMESOURCE_HH |
| 3 |
|
| 4 |
#include "aligned.hh" |
| 5 |
#include "narrow.hh" |
| 6 |
#include "xrange.hh" |
| 7 |
|
| 8 |
#include <algorithm> |
| 9 |
#include <array> |
| 10 |
#include <bit> |
| 11 |
#include <cassert> |
| 12 |
#include <cstdint> |
| 13 |
#include <span> |
| 14 |
|
| 15 |
namespace openmsx { |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
class FrameSource |
| 20 |
{ |
| 21 |
public: |
| 22 |
using Pixel = uint32_t; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
enum class FieldType : uint8_t { |
| 27 |
|
| 28 |
|
| 29 |
NONINTERLACED, |
| 30 |
|
| 31 |
|
| 32 |
EVEN, |
| 33 |
|
| 34 |
|
| 35 |
ODD, |
| 36 |
}; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
void init(FieldType fieldType_) { fieldType = fieldType_; } |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
[[nodiscard]] FieldType getField() const { |
| 46 |
return fieldType; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
[[nodiscard]] unsigned getHeight() const { |
| 52 |
return height; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
[[nodiscard]] virtual unsigned getLineWidth(unsigned line) const = 0; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
[[nodiscard]] unsigned getWidth() const { |
| 67 |
assert(height > 0); |
| 68 |
unsigned result = getLineWidth(0); |
| 69 |
for (auto line : xrange(1u, height)) { |
| 70 |
assert(result == getLineWidth(line)); (void)line; |
| 71 |
} |
| 72 |
return result; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
[[nodiscard]] Pixel getLineColor(unsigned line) const { |
| 81 |
ALIGNAS_SSE std::array<Pixel, 1280> buf; |
| 82 |
return getUnscaledLine(line, buf)[0]; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
[[nodiscard]] std::span<const Pixel> getLine(int line, std::span<Pixel> buf) const |
| 95 |
{ |
| 96 |
line = std::clamp(line, 0, narrow<int>(getHeight() - 1)); |
| 97 |
auto unscaledLine = getUnscaledLine(line, buf); |
| 98 |
if (unscaledLine.size() == buf.size()) { |
| 99 |
|
| 100 |
return unscaledLine; |
| 101 |
} else { |
| 102 |
|
| 103 |
|
| 104 |
scaleLine(unscaledLine, buf); |
| 105 |
return buf; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
[[nodiscard]] virtual std::span<const Pixel> getUnscaledLine( |
| 117 |
unsigned line, std::span<Pixel> helpBuf) const = 0; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
[[nodiscard]] std::span<const Pixel, 320> getLinePtr320_240(unsigned line, std::span<Pixel, 320> buf) const; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
[[nodiscard]] std::span<const Pixel, 640> getLinePtr640_480(unsigned line, std::span<Pixel, 640> buf) const; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
[[nodiscard]] std::span<const Pixel, 960> getLinePtr960_720(unsigned line, std::span<Pixel, 960> buf) const; |
| 137 |
|
| 138 |
protected: |
| 139 |
FrameSource() = default; |
| 140 |
~FrameSource() = default; |
| 141 |
|
| 142 |
void setHeight(unsigned height_) { height = height_; } |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
[[nodiscard]] virtual bool hasContiguousStorage() const { |
| 148 |
return false; |
| 149 |
} |
| 150 |
|
| 151 |
void scaleLine(std::span<const Pixel> in, std::span<Pixel> out) const; |
| 152 |
|
| 153 |
private: |
| 154 |
|
| 155 |
|
| 156 |
unsigned height; |
| 157 |
|
| 158 |
FieldType fieldType; |
| 159 |
}; |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
#endif |