openMSX
FrameSource.hh
Go to the documentation of this file.
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
15namespace openmsx {
16
20{
21public:
22 using Pixel = uint32_t;
23
26 enum class FieldType {
32 EVEN,
35 ODD,
36 };
37
41 void init(FieldType fieldType_) { fieldType = fieldType_; }
42
45 [[nodiscard]] FieldType getField() const {
46 return fieldType;
47 }
48
51 [[nodiscard]] unsigned getHeight() const {
52 return height;
53 }
54
58 [[nodiscard]] virtual unsigned getLineWidth(unsigned line) const = 0;
59
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
80 [[nodiscard]] inline Pixel getLineColor(unsigned line) const {
81 ALIGNAS_SSE std::array<Pixel, 1280> buf; // large enough for widest line
82 return getUnscaledLine(line, buf)[0];
83 }
84
94 [[nodiscard]] inline 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 // Already the correct width.
100 return unscaledLine;
101 } else {
102 // slow path, non-inlined
103 // internalData might be equal to buf
104 scaleLine(unscaledLine, buf);
105 return buf;
106 }
107 }
108
116 [[nodiscard]] virtual std::span<const Pixel> getUnscaledLine(
117 unsigned line, std::span<Pixel> helpBuf) const = 0;
118
124 [[nodiscard]] std::span<const Pixel, 320> getLinePtr320_240(unsigned line, std::span<Pixel, 320> buf) const;
125
130 [[nodiscard]] std::span<const Pixel, 640> getLinePtr640_480(unsigned line, std::span<Pixel, 640> buf) const;
131
136 [[nodiscard]] std::span<const Pixel, 960> getLinePtr960_720(unsigned line, std::span<Pixel, 960> buf) const;
137
138protected:
139 FrameSource() = default;
140 ~FrameSource() = default;
141
142 void setHeight(unsigned height_) { height = height_; }
143
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
153private:
156 unsigned height;
157
158 FieldType fieldType;
159};
160
161} // namespace openmsx
162
163#endif // FRAMESOURCE_HH
#define ALIGNAS_SSE
Definition aligned.hh:24
Interface for getting lines from a video frame.
virtual bool hasContiguousStorage() const
Returns true when two consecutive rows are also consecutive in memory.
std::span< const Pixel > getLine(int line, std::span< Pixel > buf) const
Gets a pointer to the pixels of the given line number.
virtual unsigned getLineWidth(unsigned line) const =0
Gets the number of display pixels on the given line.
FieldType getField() const
Gets the role this frame plays in interlacing.
std::span< const Pixel, 320 > getLinePtr320_240(unsigned line, std::span< Pixel, 320 > buf) const
Get a pointer to a given line in this frame, the frame is scaled to 320x240 pixels.
Pixel getLineColor(unsigned line) const
Get the (single) color of the given line.
std::span< const Pixel, 960 > getLinePtr960_720(unsigned line, std::span< Pixel, 960 > buf) const
Get a pointer to a given line in this frame, the frame is scaled to 960x720 pixels.
void scaleLine(std::span< const Pixel > in, std::span< Pixel > out) const
void setHeight(unsigned height_)
unsigned getWidth() const
Get the width of (all) lines in this frame.
virtual std::span< const Pixel > getUnscaledLine(unsigned line, std::span< Pixel > helpBuf) const =0
Get a specific line, with the 'native' line-width.
void init(FieldType fieldType_)
(Re)initialize an existing FrameSource.
std::span< const Pixel, 640 > getLinePtr640_480(unsigned line, std::span< Pixel, 640 > buf) const
Get a pointer to a given line in this frame, the frame is scaled to 640x480 pixels.
unsigned getHeight() const
Gets the number of lines in this frame.
FieldType
What role does this frame play in interlacing?
@ ODD
Interlacing is on and this is an odd frame.
@ EVEN
Interlacing is on and this is an even frame.
@ NONINTERLACED
Interlacing is off for this frame.
This file implemented 3 utility functions:
Definition Autofire.cc:11
constexpr auto xrange(T e)
Definition xrange.hh:132