ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/OniSplit/Imaging/SysReader.cs
Revision: 1114
Committed: Wed Jan 22 14:08:57 2020 UTC (5 years, 8 months ago) by iritscen
File size: 1080 byte(s)
Log Message:
Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.Drawing;
4 using System.Drawing.Imaging;
5 using System.Runtime.InteropServices;
6
7 namespace Oni.Imaging
8 {
9 internal static class SysReader
10 {
11 public static Surface Read(string filePath)
12 {
13 using (Bitmap bmp = new Bitmap(filePath, false))
14 {
15 SurfaceFormat surfaceFormat;
16 PixelFormat pixelFormat;
17
18 if (bmp.RawFormat == ImageFormat.Jpeg || bmp.RawFormat == ImageFormat.Bmp)
19 {
20 surfaceFormat = SurfaceFormat.BGRX;
21 pixelFormat = PixelFormat.Format32bppRgb;
22 }
23 else
24 {
25 surfaceFormat = SurfaceFormat.BGRA;
26 pixelFormat = PixelFormat.Format32bppArgb;
27 }
28
29 var surface = new Surface(bmp.Width, bmp.Height, surfaceFormat);
30 var rc = new Rectangle(0, 0, bmp.Width, bmp.Height);
31
32 var data = bmp.LockBits(rc, ImageLockMode.ReadOnly, pixelFormat);
33 Marshal.Copy(data.Scan0, surface.Data, 0, surface.Data.Length);
34 bmp.UnlockBits(data);
35
36 return surface;
37 }
38 }
39 }
40 }