#region License // Copyright 2015-2016 Kastellanos Nikolaos // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #endregion using System; using System.IO; using Microsoft.Xna.Framework.Content.Pipeline; using Microsoft.Xna.Framework.Content.Pipeline.Graphics; using Microsoft.Xna.Framework.Graphics; namespace nkast.Aether.Content.Pipeline { [ContentImporter(".dds", DisplayName = "DDS Importer - Aether", DefaultProcessor = "DDSProcessor")] public class DDSImporter : ContentImporter { public override TextureContent Import(string filename, ContentImporterContext context) { TextureContent output; using(Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { using(BinaryReader reader = new BinaryReader(stream)) { DDSHeader header = new DDSHeader(reader); if (header.PixelFormat.Flags == PF_Flags.FOURCC && header.PixelFormat.FourCC == PF_FourCC.DX10) { throw new NotImplementedException("DX10 Header not supported"); } if (header.PitchOrLinearSize != 0) throw new NotImplementedException(); if (header.Caps2.HasFlag(DDS_Caps2.CUBEMAP)) { TextureCubeContent cube = new TextureCubeContent(); SurfaceFormat format = GetFormat(header.PixelFormat); for (int f = 0; f < 6; f++) { int width = header.Width; int height = header.Height; BitmapContent bitmap = CreateBitmap(format, width, height); int size = GetBitmapSize(format, width, height); byte[] src = reader.ReadBytes(size); bitmap.SetPixelData(src); cube.Faces[f].Add(bitmap); if (header.Caps.HasFlag(DDS_Caps.MIPMAP)) { for(int m=0; m