1 #ifndef __MDFN_SURFACE_H 2 #define __MDFN_SURFACE_H 3 4 #if defined(FRONTEND_SUPPORTS_RGB565) 5 /* 16bit color - RGB565 */ 6 #define RED_MASK 0xf800 7 #define GREEN_MASK 0x7e0 8 #define BLUE_MASK 0x1f 9 #define ALPHA_MASK 0x2000 10 #define RED_EXPAND 3 11 #define GREEN_EXPAND 2 12 #define BLUE_EXPAND 3 13 #define RED_SHIFT 11 14 #define GREEN_SHIFT 5 15 #define BLUE_SHIFT 0 16 #define MAKECOLOR(r, g, b, a) (((r >> RED_EXPAND) << RED_SHIFT) | ((g >> GREEN_EXPAND) << GREEN_SHIFT) | ((b >> BLUE_EXPAND) << BLUE_SHIFT)) 17 #else 18 /* 16bit color - RGB555 */ 19 #define RED_MASK 0x7c00 20 #define GREEN_MASK 0x3e0 21 #define BLUE_MASK 0x1f 22 #define RED_EXPAND 3 23 #define GREEN_EXPAND 3 24 #define BLUE_EXPAND 3 25 #define RED_SHIFT 10 26 #define GREEN_SHIFT 5 27 #define BLUE_SHIFT 0 28 #define MAKECOLOR(r, g, b, a) (((r >> RED_EXPAND) << RED_SHIFT) | ((g >> GREEN_EXPAND) << GREEN_SHIFT) | ((b >> BLUE_EXPAND) << BLUE_SHIFT)) 29 #endif 30 31 struct MDFN_PaletteEntry 32 { 33 uint8 r, g, b; 34 }; 35 36 typedef struct 37 { 38 int32 x, y, w, h; 39 } MDFN_Rect; 40 41 enum 42 { 43 MDFN_COLORSPACE_RGB = 0, 44 MDFN_COLORSPACE_YCbCr = 1, 45 MDFN_COLORSPACE_YUV = 2, // TODO, maybe. 46 }; 47 48 class MDFN_PixelFormat 49 { 50 public: 51 52 MDFN_PixelFormat(); 53 MDFN_PixelFormat(const unsigned int p_colorspace, const uint8 p_rs, const uint8 p_gs, const uint8 p_bs, const uint8 p_as); 54 55 unsigned int bpp; 56 unsigned int colorspace; 57 58 union 59 { 60 uint8 Rshift; // Bit position of the lowest bit of the red component 61 uint8 Yshift; 62 }; 63 64 union 65 { 66 uint8 Gshift; // [...] green component 67 uint8 Ushift; 68 uint8 Cbshift; 69 }; 70 71 union 72 { 73 uint8 Bshift; // [...] blue component 74 uint8 Vshift; 75 uint8 Crshift; 76 }; 77 78 uint8 Ashift; // [...] alpha component. 79 // Creates a color value for the surface corresponding to the 8-bit R/G/B/A color passed. 80 INLINE uint32 MakeColor(uint8 r, uint8 g, uint8 b, uint8 a = 0) const 81 { 82 return MAKECOLOR(r, g, b, a); 83 } 84 }; // MDFN_PixelFormat; 85 86 // Supports 32-bit RGBA 87 // 16-bit is WIP 88 class MDFN_Surface //typedef struct 89 { 90 public: 91 92 MDFN_Surface(); 93 MDFN_Surface(void *const p_pixels, const uint32 p_width, const uint32 p_height, const uint32 p_pitchinpix, const MDFN_PixelFormat &nf); 94 95 ~MDFN_Surface(); 96 97 uint16 *pixels16; 98 99 // w, h, and pitch32 should always be > 0 100 int32 w; 101 int32 h; 102 103 union 104 { 105 int32 pitch32; // In pixels, not in bytes. 106 int32 pitchinpix; // New name, new code should use this. 107 }; 108 109 MDFN_PaletteEntry *palette; 110 111 MDFN_PixelFormat format; 112 113 void SetFormat(const MDFN_PixelFormat &new_format, bool convert); 114 115 // Creates a value for the surface corresponding to the R/G/B/A color passed. 116 INLINE uint32 MakeColor(uint8 r, uint8 g, uint8 b, uint8 a = 0) const 117 { 118 return MAKECOLOR(r, g, b, a); 119 } 120 private: 121 void Init(void *const p_pixels, const uint32 p_width, const uint32 p_height, const uint32 p_pitchinpix, const MDFN_PixelFormat &nf); 122 }; 123 124 #endif 125