openMSX
SuperImposedFrame.cc
Go to the documentation of this file.
2#include "PixelOperations.hh"
3#include "LineScalers.hh"
4#include "unreachable.hh"
5#include "vla.hh"
6#include "build-info.hh"
7#include <algorithm>
8#include <concepts>
9#include <cstdint>
10#include <memory>
11
12namespace openmsx {
13
14template<std::unsigned_integral Pixel>
16{
17public:
19
20private:
21 [[nodiscard]] unsigned getLineWidth(unsigned line) const override;
22 [[nodiscard]] const void* getLineInfo(
23 unsigned line, unsigned& width,
24 void* buf, unsigned bufWidth) const override;
25
27};
28
29
30// class SuperImposedFrame
31
32std::unique_ptr<SuperImposedFrame> SuperImposedFrame::create(
33 const PixelFormat& format)
34{
35#if HAVE_16BPP
36 if (format.getBytesPerPixel() == 2) {
37 return std::make_unique<SuperImposedFrameImpl<uint16_t>>(format);
38 }
39#endif
40#if HAVE_32BPP
41 if (format.getBytesPerPixel() == 4) {
42 return std::make_unique<SuperImposedFrameImpl<uint32_t>>(format);
43 }
44#endif
45 UNREACHABLE; return nullptr; // avoid warning
46}
47
50{
51}
52
54 const FrameSource* top_, const FrameSource* bottom_)
55{
56 top = top_;
57 bottom = bottom_;
59}
60
61
62// class SuperImposedFrameImpl
63
64template<std::unsigned_integral Pixel>
66 const PixelFormat& format)
68 , pixelOps(format)
69{
70}
71
72template<std::unsigned_integral Pixel>
73unsigned SuperImposedFrameImpl<Pixel>::getLineWidth(unsigned line) const
74{
75 unsigned tNum = (getHeight() == top ->getHeight()) ? line : line / 2;
76 unsigned bNum = (getHeight() == bottom->getHeight()) ? line : line / 2;
77 unsigned tWidth = top ->getLineWidth(tNum);
78 unsigned bWidth = bottom->getLineWidth(bNum);
79 return std::max(tWidth, bWidth);
80}
81
82template<std::unsigned_integral Pixel>
83const void* SuperImposedFrameImpl<Pixel>::getLineInfo(
84 unsigned line, unsigned& width, void* buf, unsigned bufWidth) const
85{
86 unsigned tNum = (getHeight() == top ->getHeight()) ? line : line / 2;
87 unsigned bNum = (getHeight() == bottom->getHeight()) ? line : line / 2;
88 unsigned tWidth = top ->getLineWidth(tNum);
89 unsigned bWidth = bottom->getLineWidth(bNum);
90 width = std::max(tWidth, bWidth); // as wide as the widest source
91 width = std::min(width, bufWidth); // but no wider than the output buffer
92
93 auto* tBuf = static_cast<Pixel*>(buf);
94 VLA_SSE_ALIGNED(Pixel, bBuf, width);
95 auto* tLine = top ->getLinePtr(tNum, width, tBuf);
96 auto* bLine = bottom->getLinePtr(bNum, width, bBuf);
97
98 AlphaBlendLines<Pixel> blend(pixelOps);
99 blend(tLine, bLine, tBuf, width); // possibly tLine == tBuf
100 return tBuf;
101}
102
103} // namespace openmsx
Interface for getting lines from a video frame.
Definition: FrameSource.hh:17
void setHeight(unsigned height_)
Definition: FrameSource.hh:200
unsigned getHeight() const
Gets the number of lines in this frame.
Definition: FrameSource.hh:46
SuperImposedFrameImpl(const PixelFormat &format)
This class represents a frame that is the (per-pixel) alpha-blend of two other frames.
void init(const FrameSource *top, const FrameSource *bottom)
static std::unique_ptr< SuperImposedFrame > create(const PixelFormat &format)
const FrameSource * bottom
SuperImposedFrame(const PixelFormat &format)
constexpr vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:265
constexpr vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:283
void format(SectorAccessibleDisk &disk, bool dos1)
Format the given disk (= a single partition).
This file implemented 3 utility functions:
Definition: Autofire.cc:9
uint32_t Pixel
#define UNREACHABLE
Definition: unreachable.hh:38
#define VLA_SSE_ALIGNED(TYPE, NAME, LENGTH)
Definition: vla.hh:44