BitmapConverter.hh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef BITMAPCONVERTER_HH
  2. #define BITMAPCONVERTER_HH
  3. #include "DisplayMode.hh"
  4. #include "openmsx.hh"
  5. #include <cstdint>
  6. namespace openmsx {
  7. template<int N> struct DoublePixel;
  8. template<> struct DoublePixel<2> { using type = uint32_t; };
  9. template<> struct DoublePixel<4> { using type = uint64_t; };
  10. /** Utility class for converting VRAM contents to host pixels.
  11. */
  12. template <class Pixel>
  13. class BitmapConverter
  14. {
  15. public:
  16. /** Create a new bitmap scanline converter.
  17. * @param palette16 Pointer to 2*16-entries array that specifies
  18. * VDP color index to host pixel mapping.
  19. * This is kept as a pointer, so any changes to the palette
  20. * are immediately picked up by convertLine. Though to allow
  21. * some internal optimizations, this class should be informed about
  22. * changes in this array (not needed for the next two), see
  23. * palette16Changed().
  24. * Used for display modes Graphic4, Graphic5 and Graphic6.
  25. * First 16 entries are for even pixels, next 16 are for odd pixels
  26. * @param palette256 Pointer to 256-entries array that specifies
  27. * VDP color index to host pixel mapping.
  28. * This is kept as a pointer, so any changes to the palette
  29. * are immediately picked up by convertLine.
  30. * Used for display mode Graphic7.
  31. * @param palette32768 Pointer to 32768-entries array that specifies
  32. * VDP color index to host pixel mapping.
  33. * This is kept as a pointer, so any changes to the palette
  34. * are immediately picked up by convertLine.
  35. * Used when YJK filter is active.
  36. */
  37. BitmapConverter(const Pixel* palette16,
  38. const Pixel* palette256,
  39. const Pixel* palette32768);
  40. /** Convert a line of V9938 VRAM to 512 host pixels.
  41. * Call this method in non-planar display modes (Graphic4 and Graphic5).
  42. * @param linePtr Pointer to array of host pixels.
  43. * @param vramPtr Pointer to VRAM contents.
  44. */
  45. void convertLine(Pixel* linePtr, const byte* vramPtr);
  46. /** Convert a line of V9938 VRAM to 512 host pixels.
  47. * Call this method in planar display modes (Graphic6 and Graphic7).
  48. * @param linePtr Pointer to array of host pixels.
  49. * @param vramPtr0 Pointer to VRAM contents, first plane.
  50. * @param vramPtr1 Pointer to VRAM contents, second plane.
  51. */
  52. void convertLinePlanar(Pixel* linePtr,
  53. const byte* vramPtr0, const byte* vramPtr1);
  54. /** Select the display mode to use for scanline conversion.
  55. * @param mode_ The new display mode.
  56. */
  57. inline void setDisplayMode(DisplayMode mode_)
  58. {
  59. mode = mode_;
  60. }
  61. /** Inform this class about changes in the palette16 array.
  62. */
  63. inline void palette16Changed()
  64. {
  65. dPaletteValid = false;
  66. }
  67. private:
  68. void calcDPalette();
  69. inline void renderGraphic4(Pixel* pixelPtr, const byte* vramPtr0);
  70. inline void renderGraphic5(Pixel* pixelPtr, const byte* vramPtr0);
  71. inline void renderGraphic6(
  72. Pixel* pixelPtr, const byte* vramPtr0, const byte* vramPtr1);
  73. inline void renderGraphic7(
  74. Pixel* pixelPtr, const byte* vramPtr0, const byte* vramPtr1);
  75. inline void renderYJK(
  76. Pixel* pixelPtr, const byte* vramPtr0, const byte* vramPtr1);
  77. inline void renderYAE(
  78. Pixel* pixelPtr, const byte* vramPtr0, const byte* vramPtr1);
  79. inline void renderBogus(Pixel* pixelPtr);
  80. const Pixel* const __restrict palette16;
  81. const Pixel* const __restrict palette256;
  82. const Pixel* const __restrict palette32768;
  83. using DPixel = typename DoublePixel<sizeof(Pixel)>::type;
  84. DPixel dPalette[16 * 16];
  85. DisplayMode mode;
  86. bool dPaletteValid;
  87. };
  88. } // namespace openmsx
  89. #endif