madb
madb copied to clipboard
Support for additional PixelFormats in RawImage.ToImage
In RawImage.ToImage (RawImage.cs:257), two pixel formats are hard coded. If the screen buffer is 32-bit, ARGB is always assumed; if the screen buffer is 16-bit, RGB565 is always assumed.
The Microsoft Visual Studio Android emulator uses a RGB format, so the colors are off.
The following code reads the ARGB offsets and determines the pixel format based on these values:
if(this.Bpp == 32) {
if(this.Alpha.Offset == 0 && this.Red.Offset == 8 && this.Green.Offset == 16 && this.Blue.Offset == 24) {
format = PixelFormat.Format32bppArgb;
} else if(this.Red.Offset == 0 && this.Green.Offset == 8 && this.Blue.Offset == 16 && this.Alpha.Offset == 24) {
format = PixelFormat.Format32bppRgb;
}
} else if(this.Bpp == 16) {
if (this.Red.Offset == 0 && Green.Offset == 5 && Red.Offset == 11) {
format = PixelFormat.Format16bppRgb565;
} else if(this.Red.Offset == 0 && Green.Offset == 5 && Red.Offset == 10) {
format = PixelFormat.Format16bppRgb555;
}
}
return ToImage ( format );