mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 18:45:23 -04:00
Fix issue with non 32bpp skins crashing the client.
This commit is contained in:
parent
ee16d19678
commit
c756094023
@ -19,10 +19,24 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
public int CreateTexture( Bitmap bmp ) {
|
||||
Rectangle rec = new Rectangle( 0, 0, bmp.Width, bmp.Height );
|
||||
BitmapData data = bmp.LockBits( rec, ImageLockMode.ReadOnly, bmp.PixelFormat );
|
||||
int texId = CreateTexture( data.Width, data.Height, data.Scan0 );
|
||||
bmp.UnlockBits( data );
|
||||
return texId;
|
||||
// Convert other pixel formats into 32bpp formats.
|
||||
if( !FastBitmap.CheckFormat( bmp.PixelFormat ) ) {
|
||||
Utils.LogDebug( "Converting " + bmp.PixelFormat + " into 32bpp image" );
|
||||
using( Bitmap _32bmp = new Bitmap( bmp.Width, bmp.Height ) ) {
|
||||
using( Graphics g = Graphics.FromImage( _32bmp ) )
|
||||
g.DrawImage( bmp, 0, 0, bmp.Width, bmp.Height );
|
||||
|
||||
BitmapData data = _32bmp.LockBits( rec, ImageLockMode.ReadOnly, _32bmp.PixelFormat );
|
||||
int texId = CreateTexture( data.Width, data.Height, data.Scan0 );
|
||||
_32bmp.UnlockBits( data );
|
||||
return texId;
|
||||
}
|
||||
} else {
|
||||
BitmapData data = bmp.LockBits( rec, ImageLockMode.ReadOnly, bmp.PixelFormat );
|
||||
int texId = CreateTexture( data.Width, data.Height, data.Scan0 );
|
||||
bmp.UnlockBits( data );
|
||||
return texId;
|
||||
}
|
||||
}
|
||||
|
||||
public int CreateTexture( FastBitmap bmp ) {
|
||||
|
@ -34,14 +34,17 @@ namespace ClassicalSharp {
|
||||
public int Stride;
|
||||
public int Width, Height;
|
||||
|
||||
public static bool CheckFormat( PixelFormat format ) {
|
||||
return format == PixelFormat.Format32bppRgb || format == PixelFormat.Format32bppArgb;
|
||||
}
|
||||
|
||||
public void LockBits() {
|
||||
if( Bitmap == null ) throw new InvalidOperationException( "Underlying bitmap is null." );
|
||||
if( data != null ) return;
|
||||
|
||||
PixelFormat format = Bitmap.PixelFormat;
|
||||
if( !( format == PixelFormat.Format32bppArgb || format == PixelFormat.Format32bppRgb ) ) {
|
||||
if( !CheckFormat( format ) )
|
||||
throw new NotSupportedException( "Unsupported bitmap pixel format: " + format );
|
||||
}
|
||||
|
||||
Rectangle rec = new Rectangle( 0, 0, Bitmap.Width, Bitmap.Height );
|
||||
data = Bitmap.LockBits( rec, ImageLockMode.ReadWrite, format );
|
||||
|
Loading…
x
Reference in New Issue
Block a user