public FileFormat GetFormat() { GpkByteProperty formatProp = objectExport.GetProperty("Format") as GpkByteProperty; if (formatProp == null) { return(FileFormat.Unknown); } string format = formatProp.nameValue; return(DdsPixelFormat.ParseFileFormat(format)); }
public void SaveFormat(GpkExport export) { GpkByteProperty formatProp = export.GetProperty("Format") as GpkByteProperty; if (formatProp == null) { parsedImageFormat = FileFormat.Unknown; } else { string format = formatProp.nameValue; parsedImageFormat = DdsPixelFormat.ParseFileFormat(format); } }
public static void importTexture(GpkExport export, string file) { try { var texture2d = export.Payload as Texture2D; var image = new DdsFile(); var config = new DdsSaveConfig(texture2d.parsedImageFormat, 0, 0, false, false); image.Load(file); if (image.MipMaps.Count == 0 || CoreSettings.Default.GenerateMipMaps) { image.GenerateMipMaps(); } texture2d.maps = new List <MipMap>(); foreach (DdsMipMap mipMap in image.MipMaps.OrderByDescending(mip => mip.Width)) { byte[] outputData = image.WriteMipMap(mipMap, config); var textureMipMap = new MipMap(); textureMipMap.flags = (int)CompressionTypes.LZO; //textureMipMap.flags = 0; textureMipMap.uncompressedData = outputData; textureMipMap.uncompressedSize = outputData.Length; textureMipMap.uncompressedSize_chunkheader = outputData.Length; textureMipMap.sizeX = mipMap.Width; textureMipMap.sizeY = mipMap.Height; if (textureMipMap.flags != 0) { textureMipMap.generateBlocks(); } texture2d.maps.Add(textureMipMap); } int mipTailBaseIdx = (int)Math.Log(image.Width > image.Height ? image.Width : image.Height, 2); ((GpkIntProperty)export.GetProperty("MipTailBaseIdx")).SetValue(mipTailBaseIdx.ToString()); logger.Info("Imported image from {0}, size {1}x{2}, target format {3}, mipTailBaseIdx {4}", file, image.Width, image.Height, config.FileFormat, mipTailBaseIdx); } catch (Exception ex) { logger.Error(ex, "Failed to import texture"); logger.Error(ex); } }