Skip to content

Commit d323a20

Browse files
committed
feature: supports RGBA16 pixel format
Signed-off-by: leo <[email protected]>
1 parent 203c503 commit d323a20

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/ViewModels/ImageSource.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ private static ImageSource DecodeWithPfim(Stream stream, long size)
117117
case ImageFormat.Rgb24:
118118
pixelFormat = PixelFormats.Bgr24;
119119
break;
120+
case ImageFormat.Rgba16:
121+
var pixels2 = pfiImage.DataLen / 2;
122+
data = new byte[pixels2 * 4];
123+
stride = pfiImage.Width * 4;
124+
for (var i = 0; i < pixels2; i++)
125+
{
126+
var src = BitConverter.ToUInt16(pfiImage.Data, i * 2);
127+
data[i * 4 + 0] = (byte)Math.Round((src & 0x0F) / 15F * 255); // B
128+
data[i * 4 + 1] = (byte)Math.Round(((src >> 4) & 0x0F) / 15F * 255); // G
129+
data[i * 4 + 2] = (byte)Math.Round(((src >> 8) & 0x0F) / 15F * 255); // R
130+
data[i * 4 + 3] = (byte)Math.Round(((src >> 12) & 0x0F) / 15F * 255); // A
131+
}
132+
133+
alphaFormat = AlphaFormat.Premul;
134+
break;
120135
case ImageFormat.Rgba32:
121136
alphaFormat = AlphaFormat.Premul;
122137
break;
@@ -131,7 +146,7 @@ private static ImageSource DecodeWithPfim(Stream stream, long size)
131146
return new ImageSource(bitmap, size);
132147
}
133148
}
134-
catch (Exception e)
149+
catch
135150
{
136151
return new ImageSource(null, 0);
137152
}

0 commit comments

Comments
 (0)