22 #ifndef PSP_PIXEL_FORMAT_H 23 #define PSP_PIXEL_FORMAT_H 25 #include "graphics/pixelformat.h" 26 #include "backends/platform/psp/trace.h" 51 PSPPixelFormat() : format(Type_Unknown), bitsPerPixel(0), swapRB(false) {}
52 void set(Type type,
bool swap =
false);
54 PSPPixelFormat::Type &bufferType,
55 PSPPixelFormat::Type &paletteType,
58 uint32 convertTo32BitColor(uint32 color)
const;
60 inline uint32 rgbaToColor(uint32 r, uint32 g, uint32 b, uint32 a)
const {
65 color = (((b >> 4) << 8) | ((g >> 4) << 4) | ((r >> 4) << 0) | ((a >> 4) << 12));
68 color = (((b >> 3) << 10) | ((g >> 3) << 5) | ((r >> 3) << 0) | ((a >> 7) << 15));
71 color = (((b >> 3) << 11) | ((g >> 2) << 5) | ((r >> 3) << 0));
75 color = (((b >> 0) << 16) | ((g >> 0) << 8) | ((r >> 0) << 0) | ((a >> 0) << 24));
84 inline void colorToRgba(uint32 color, uint32 &r, uint32 &g, uint32 &b, uint32 &a)
const {
87 a = (color >> 12) & 0xF;
88 b = (color >> 8) & 0xF;
89 g = (color >> 4) & 0xF;
90 r = (color >> 0) & 0xF;
97 a = (color >> 15) ? 0xFF : 0;
98 b = (color >> 10) & 0x1F;
99 g = (color >> 5) & 0x1F;
100 r = (color >> 0) & 0x1F;
107 b = (color >> 11) & 0x1F;
108 g = (color >> 5) & 0x3F;
109 r = (color >> 0) & 0x1F;
116 a = (color >> 24) & 0xFF;
117 b = (color >> 16) & 0xFF;
118 g = (color >> 8) & 0xFF;
119 r = (color >> 0) & 0xFF;
127 inline uint32 setColorAlpha(uint32 color, byte alpha) {
130 color = (color & 0x0FFF) | (((uint32)alpha >> 4) << 12);
133 color = (color & 0x7FFF) | (((uint32)alpha >> 7) << 15);
137 color = (color & 0x00FFFFFF) | ((uint32)alpha << 24);
146 inline uint32 pixelsToBytes(uint32 pixels)
const {
147 switch (bitsPerPixel) {
160 PSP_ERROR(
"Incorrect bitsPerPixel value[%u]. pixels[%u]\n", bitsPerPixel, pixels);
166 inline uint16 swapRedBlue16(uint16 color)
const {
171 output = (color & 0xf0f0) | ((color & 0x000f) << 8) | ((color & 0x0f00) >> 8);
174 output = (color & 0x83e0) | ((color & 0x001f) << 10) | ((color & 0x7c00) >> 10);
177 output = (color & 0x07e0) | ((color & 0x001f) << 11) | ((color & 0xf800) >> 11);
180 PSP_ERROR(
"invalid format[%u] for swapping\n", format);
187 inline uint32 swapRedBlue32(uint32 color)
const {
192 output = (color & 0xf0f0f0f0) |
193 ((color & 0x000f000f) << 8) | ((color & 0x0f000f00) >> 8);
196 output = (color & 0x83e083e0) |
197 ((color & 0x001f001f) << 10) | ((color & 0x7c007c00) >> 10);
200 output = (color & 0x07e007e0) |
201 ((color & 0x001f001f) << 11) | ((color & 0xf800f800) >> 11);
204 output = (color & 0xff00ff00) |
205 ((color & 0x000000ff) << 16) | ((color & 0x00ff0000) >> 16);
208 output = ((color & 0x000000ff) << 24) | ((color & 0x0000ff00) << 8) |
209 ((color & 0x00ff0000) >> 8) | ((color & 0xff000000) >> 24);
212 PSP_ERROR(
"invalid format[%u] for swapping\n", format);
221 inline uint32 getColorValueAt(byte *pointer)
const {
224 switch (bitsPerPixel) {
230 result = *(uint16 *)pointer;
233 result = *(uint32 *)pointer;
237 PSP_ERROR(
"Incorrect bitsPerPixel value[%u].\n", bitsPerPixel);