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 SDL_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 SDL_PixelFormat& format)
33 {
34 #if HAVE_16BPP
35  if (format.BitsPerPixel == 15 || format.BitsPerPixel == 16) {
36  return std::make_unique<SuperImposedFrameImpl<uint16_t>>(format);
37  }
38 #endif
39 #if HAVE_32BPP
40  if (format.BitsPerPixel == 32) {
41  return std::make_unique<SuperImposedFrameImpl<uint32_t>>(format);
42  }
43 #endif
44  UNREACHABLE; return nullptr; // avoid warning
45 }
46 
47 SuperImposedFrame::SuperImposedFrame(const SDL_PixelFormat& format)
48  : FrameSource(format)
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 SDL_PixelFormat& format)
66  : SuperImposedFrame(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>
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
vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:269
uint32_t Pixel
vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:287
Interface for getting lines from a video frame.
Definition: FrameSource.hh:14
SuperImposedFrameImpl(const SDL_PixelFormat &format)
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
const FrameSource * bottom
SuperImposedFrame(const SDL_PixelFormat &format)
const Pixel * getLinePtr(int line, unsigned width, Pixel *buf) const
Gets a pointer to the pixels of the given line number.
Definition: FrameSource.hh:91
void format(SectorAccessibleDisk &disk, bool dos1)
Format the given disk (= a single partition).
void setHeight(unsigned height_)
Definition: FrameSource.hh:198
virtual unsigned getLineWidth(unsigned line) const =0
Gets the number of display pixels on the given line.
static std::unique_ptr< SuperImposedFrame > create(const SDL_PixelFormat &format)
AlphaBlendLines functor Generate an output line that is a per-pixel-alpha-blend of the two input line...
Definition: LineScalers.hh:256
This class represents a frame that is the (per-pixel) alpha-blend of two other frames.
unsigned getHeight() const
Gets the number of lines in this frame.
Definition: FrameSource.hh:44
#define VLA_SSE_ALIGNED(TYPE, NAME, LENGTH)
Definition: vla.hh:44
void init(const FrameSource *top, const FrameSource *bottom)
#define UNREACHABLE
Definition: unreachable.hh:38