OXYGENHUB
◆ main openmsx / src / video / BitmapConverter.hh
4.3 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#ifndef BITMAPCONVERTER_HH
2
#define BITMAPCONVERTER_HH
3
4
#include "DisplayMode.hh"
5
6
#include <array>
7
#include <cstdint>
8
#include <span>
9
10
namespace openmsx {
11
12
/** Utility class for converting VRAM contents to host pixels.
13
  */
14
class BitmapConverter
15
{
16
public:
17
	using Pixel = uint32_t;
18
	using DPixel = uint64_t;
19
20
	/** Create a new bitmap scanline converter.
21
	  * @param palette16 Pointer to 2*16-entries array that specifies
22
	  *   VDP color index to host pixel mapping.
23
	  *   This is kept as a pointer, so any changes to the palette
24
	  *   are immediately picked up by convertLine. Though to allow
25
	  *   some internal optimizations, this class should be informed about
26
	  *   changes in this array (not needed for the next two), see
27
	  *   palette16Changed().
28
	  *   Used for display modes Graphic4, Graphic5 and Graphic6.
29
	  *   First 16 entries are for even pixels, next 16 are for odd pixels
30
	  * @param palette256 Pointer to 256-entries array that specifies
31
	  *   VDP color index to host pixel mapping.
32
	  *   This is kept as a pointer, so any changes to the palette
33
	  *   are immediately picked up by convertLine.
34
	  *   Used for display mode Graphic7.
35
	  * @param palette32768 Pointer to 32768-entries array that specifies
36
	  *   VDP color index to host pixel mapping.
37
	  *   This is kept as a pointer, so any changes to the palette
38
	  *   are immediately picked up by convertLine.
39
	  *   Used when YJK filter is active.
40
	  */
41
	BitmapConverter(std::span<const Pixel, 16 * 2> palette16,
42
	                std::span<const Pixel, 256>    palette256,
43
	                std::span<const Pixel, 32768>  palette32768);
44
45
	/** Convert a line of V9938 VRAM to 256 or 512 host pixels.
46
	  * Call this method in non-planar display modes (Graphic4 and Graphic5).
47
	  * @param buf Buffer where host pixels will be written to.
48
	  *            Depending on the screen mode, the buffer must contain at
49
	  *            least 256 or 512 pixels, but more is allowed (the extra
50
	  *            pixels aren't touched).
51
	  * @param vramPtr Pointer to VRAM contents.
52
	  */
53
	void convertLine(std::span<Pixel> buf, std::span<const uint8_t, 128> vramPtr);
54
55
	/** Convert a line of V9938 VRAM to 256 or 512 host pixels.
56
	  * Call this method in planar display modes (Graphic6 and Graphic7).
57
	  * @param buf Buffer where host pixels will be written to.
58
	  *            Depending on the screen mode, the buffer must contain at
59
	  *            least 256 or 512 pixels, but more is allowed (the extra
60
	  *            pixels aren't touched).
61
	  * @param vramPtr0 Pointer to VRAM contents, first plane.
62
	  * @param vramPtr1 Pointer to VRAM contents, second plane.
63
	  */
64
	void convertLinePlanar(std::span<Pixel> buf,
65
	                       std::span<const uint8_t, 128> vramPtr0,
66
	                       std::span<const uint8_t, 128> vramPtr1);
67
68
	/** Select the display mode to use for scanline conversion.
69
	  * @param mode_ The new display mode.
70
	  */
71
	void setDisplayMode(DisplayMode mode_)
72
	{
73
		mode = mode_;
74
	}
75
76
	/** Inform this class about changes in the palette16 array.
77
	  */
78
	void palette16Changed()
79
	{
80
		dPaletteValid = false;
81
	}
82
83
private:
84
	void calcDPalette();
85
86
	void renderGraphic4(std::span<Pixel, 256> buf,
87
	                    std::span<const uint8_t, 128> vramPtr0);
88
	void renderGraphic5(std::span<Pixel, 512> buf,
89
	                    std::span<const uint8_t, 128> vramPtr0) const;
90
	void renderGraphic6(std::span<Pixel, 512> buf,
91
	                    std::span<const uint8_t, 128> vramPtr0,
92
	                    std::span<const uint8_t, 128> vramPtr1);
93
	void renderGraphic7(std::span<Pixel, 256> buf,
94
	                    std::span<const uint8_t, 128> vramPtr0,
95
	                    std::span<const uint8_t, 128> vramPtr1) const;
96
	void renderYJK(     std::span<Pixel, 256> buf,
97
	                    std::span<const uint8_t, 128> vramPtr0,
98
	                    std::span<const uint8_t, 128> vramPtr1) const;
99
	void renderYAE(     std::span<Pixel, 256> buf,
100
	                    std::span<const uint8_t, 128> vramPtr0,
101
	                    std::span<const uint8_t, 128> vramPtr1) const;
102
	void renderBogus(   std::span<Pixel, 256> buf) const;
103
104
private:
105
	std::span<const Pixel, 16 * 2> palette16;
106
	std::span<const Pixel, 256>    palette256;
107
	std::span<const Pixel, 32768>  palette32768;
108
109
	std::array<DPixel, 16 * 16> dPalette;
110
	DisplayMode mode;
111
	bool dPaletteValid = false;
112
};
113
114
} // namespace openmsx
115
116
#endif