private BitmapSource DecodeTexture(RawTexture model)
{
BitmapSource bmp;
switch (model.Format)
{
default:
case RawTexture.DataFormat.Invalid:
{
return null;
}
case RawTexture.DataFormat.Bgr888:
case RawTexture.DataFormat.Bgr565:
{
var rgb888 = model.Decode();
bmp = BitmapSource.Create(model.Width,
model.Height,
96,
96,
PixelFormats.Bgr24,
null,
rgb888,
model.Width * 3);
break;
}
case RawTexture.DataFormat.A8:
{
var rgb888 = model.Decode();
var alpha = GscToAlpha(rgb888);
bmp = BitmapSource.Create(model.Width,
model.Height,
96,
96,
PixelFormats.Bgra32,
null,
alpha,
model.Width * 4);
break;
}
}
bmp.Freeze();
return bmp;
}