ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/OniSplit/Imaging/DdsReader.cs
Revision: 1114
Committed: Wed Jan 22 14:08:57 2020 UTC (5 years, 8 months ago) by iritscen
File size: 978 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
4 namespace Oni.Imaging
5 {
6 internal static class DdsReader
7 {
8 public static List<Surface> Read(string filePath, bool noMipMaps)
9 {
10 var surfaces = new List<Surface>();
11
12 using (var reader = new BinaryReader(filePath))
13 {
14 var header = DdsHeader.Read(reader);
15 var format = header.GetSurfaceFormat();
16
17 for (int i = 0; i < header.MipmapCount; i++)
18 {
19 int width = Math.Max(header.Width >> i, 1);
20 int height = Math.Max(header.Height >> i, 1);
21
22 if (format == SurfaceFormat.DXT1)
23 {
24 width = Math.Max(width, 4);
25 height = Math.Max(height, 4);
26 }
27
28 var surface = new Surface(width, height, format);
29 reader.Read(surface.Data, 0, surface.Data.Length);
30 surfaces.Add(surface);
31
32 if (noMipMaps)
33 break;
34 }
35 }
36
37 return surfaces;
38 }
39 }
40 }