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