/// <summary> /// Builds a DDS image from an existing mipmap. /// </summary> /// <param name="mip">Mip to base image on.</param> /// <param name="DDSFormat">Format of mipmap.</param> public ImageEngineImage(MipMap mip, ImageEngineFormat DDSFormat) { Format = new Format(DDSFormat); MipMaps = new List <MipMap>() { mip }; header = DDSGeneral.Build_DDS_Header(1, mip.Height, mip.Width, DDSFormat); }
internal static List <MipMap> LoadImage(byte[] rawDDSData, ImageEngineFormat surfaceFormat, int width, int height, out DDSGeneral.DDS_HEADER header) { header = DDSGeneral.Build_DDS_Header(1, height, width, surfaceFormat); List <MipMap> MipMaps = null; // Create new fully formatted DDS i.e. one with a header. MemoryStream stream = new MemoryStream(); BinaryWriter bw = new BinaryWriter(stream); DDSGeneral.Write_DDS_Header(header, bw); bw.Write(rawDDSData); switch (surfaceFormat) { case ImageEngineFormat.DDS_DXT1: case ImageEngineFormat.DDS_DXT2: case ImageEngineFormat.DDS_DXT3: case ImageEngineFormat.DDS_DXT4: case ImageEngineFormat.DDS_DXT5: if (WindowsWICCodecsAvailable) { MipMaps = WIC_Codecs.LoadWithCodecs(stream, 0, 0, true); } else { MipMaps = DDSGeneral.LoadDDS(stream, header, new Format(surfaceFormat), 0); } break; case ImageEngineFormat.DDS_ARGB: case ImageEngineFormat.DDS_A8L8: case ImageEngineFormat.DDS_RGB: case ImageEngineFormat.DDS_ATI1: case ImageEngineFormat.DDS_ATI2_3Dc: case ImageEngineFormat.DDS_G8_L8: case ImageEngineFormat.DDS_V8U8: MipMaps = DDSGeneral.LoadDDS(stream, header, new Format(surfaceFormat), 0); break; default: throw new InvalidDataException("Image format is unknown."); } bw.Dispose(); // Also disposes MemoryStream return(MipMaps); }
private MemoryStream buildDdsImage(int mipMapIndex, out ImageEngineFormat imageFormat) { DomainPropertyByteValue formatProp = PropertyHeader.GetProperty("Format").FirstOrDefault()?.Value as DomainPropertyByteValue; imageFormat = ImageEngineFormat.Unknown; if (formatProp == null) { return(null); } string format = formatProp.PropertyString.Replace("PF_", null); switch (format) { case "DXT1": { imageFormat = ImageEngineFormat.DDS_DXT1; break; } case "DXT5": { imageFormat = ImageEngineFormat.DDS_DXT5; break; } case "G8": { imageFormat = ImageEngineFormat.DDS_G8_L8; break; } case "A8R8G8B8": { imageFormat = ImageEngineFormat.DDS_ARGB; break; } default: { return(null); } } DomainMipMap mipMap = MipMaps[mipMapIndex]; DDSGeneral.DDS_HEADER header = DDSGeneral.Build_DDS_Header(0, mipMap.Height, mipMap.Width, imageFormat); MemoryStream stream = new MemoryStream(); BinaryWriter writer = new BinaryWriter(stream); DDSGeneral.Write_DDS_Header(header, writer); stream.Write(mipMap.ImageData, 0, mipMap.ImageData.Length); stream.Flush(); stream.Position = 0; return(stream); }