uint GetPreferedWidth(List<Component> list, EFormat format) { uint resultWidth = 0; if (list.Count > 0) { if (format == EFormat.Horizontal) { foreach (Component ele in list) { Size perfectSize = ele.GetPreferedSize(); resultWidth += Spacer + perfectSize.width; } resultWidth -= Spacer; } else if (format == EFormat.Vertical) { foreach (Component ele in list) { Size perfectSize = ele.GetPreferedSize(); resultWidth = Math.Max(resultWidth, perfectSize.width); } } } return resultWidth; }
public static void SaveToFile <T>(T obj, string fileName, EFormat format = EFormat.Json) { if (format == EFormat.Json) { if (!Directory.Exists(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + _directoryName)) { Directory.CreateDirectory(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + _directoryName); } using (StreamWriter file = new StreamWriter(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + _directoryName + fileName)) { string json = JsonUtility.ToJson((T)obj, true); file.Write(json); } } else if (format == EFormat.Txt) { if (obj is ISaveable saveable) { using (StreamWriter file = new StreamWriter(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + _directoryName + fileName)) { saveable.WriteObjectToStream(file); } } } }
public DatabaseQuery() { ConnectionString = "Server=myServerAddress;Port=3306;Database=myDataBase;Uid=myUsername;Pwd = myPassword;"; Query = "Select 'X-Polit' as Framework "; ServerType = EDbType.MySql; QueryOutFormat = EFormat.Console; }
public static string Convert(string outDir, string filepath, EUncookExtension filetype, EFormat format = EFormat.R8G8B8A8_UNORM, int mipmaps = 0 ) { string textconvpath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Tools/DDS/texconv.exe"); var argsss = $" -o '{outDir}' -y -f {format} -ft {filetype} '{filepath}'"; var proc = new ProcessStartInfo(textconvpath) { WorkingDirectory = Path.GetDirectoryName(textconvpath), Arguments = $" -o \"{outDir}\" -y -f {format} -m {mipmaps} -l -ft {filetype} \"{filepath}\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, }; using (var p = Process.Start(proc)) { p.WaitForExit(); } var fi = new FileInfo(Path.Combine(outDir, $"{Path.GetFileNameWithoutExtension(filepath)}.{filetype}")); if (!fi.Exists) { throw new NotImplementedException(); } return(fi.FullName); }
public static int Convert(string outDir, string filepath, EUncookExtension convertFt, EFormat convertF = EFormat.R8G8B8A8_UNORM, bool overwrite = true ) { var fi = new FileInfo(textconvpath); if (!fi.Exists) { } var proc = new ProcessStartInfo(textconvpath) { WorkingDirectory = Path.GetDirectoryName(textconvpath), Arguments = $" -o {outDir} -y -f {convertF} -ft {convertFt} {filepath}", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, }; using (var p = Process.Start(proc)) { p.WaitForExit(); } return(1); }
public static bool Convert(string outDir, string filepath, EUncookExtension filetype, EFormat format = EFormat.R8G8B8A8_UNORM, int mipmaps = 0 ) { var logger = ServiceLocator.Default.ResolveType <ILoggerService>(); var proc = new ProcessStartInfo(textconvpath) { WorkingDirectory = Path.GetDirectoryName(textconvpath), Arguments = $" -o \"{outDir}\" -y -f {format} -m {mipmaps} -l -ft {filetype} \"{filepath}\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, }; using (var p = Process.Start(proc)) { p.WaitForExit(); } var fi = new FileInfo(Path.Combine(outDir, $"{Path.GetFileNameWithoutExtension(filepath)}.{filetype}")); if (!fi.Exists) { logger.LogString($"Could not convert {fi.FullName}.", Logtype.Error); return(false); } return(true); }
public static string Convert(string outDir, string filepath, EUncookExtension filetype, EFormat format = EFormat.R8G8B8A8_UNORM, int mipmaps = 0 ) { var proc = new ProcessStartInfo(textconvpath) { WorkingDirectory = Path.GetDirectoryName(textconvpath), Arguments = $" -o \"{outDir}\" -y -f {format} -m {mipmaps} -l -ft {filetype} \"{filepath}\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, }; using (var p = Process.Start(proc)) { p.WaitForExit(); } var fi = new FileInfo(Path.Combine(outDir, $"{Path.GetFileNameWithoutExtension(filepath)}.{filetype}")); if (!fi.Exists) { return(null); } return(fi.FullName); }
public static (byte, byte) GetREDEngineByteFromEFormat(EFormat fmt) { switch (fmt) { case EFormat.R8G8B8A8_UNORM: return(0xFD, 0x3); // Attention! this returns 0xFDx 0x3 //TODO: case EFormat.BC1_UNORM: return(0x7, 0x4); case EFormat.BC2_UNORM: return(0x0D, 0x4); case EFormat.BC3_UNORM: return(0x08, 0x4); case EFormat.BC4_UNORM: return(0x0E, 0x4); case EFormat.BC5_UNORM: return(0x0F, 0x4); case EFormat.BC7_UNORM: return(0x0A, 0x4); default: return(0x0, 0x0); // Attention! this returns 0x 0x } }
uint GetPreferedHeight(List<Component> list, EFormat format) { uint resultHeight = 0; if (list.Count > 0) { if (format == EFormat.Horizontal) { foreach (Component ele in list) { Size perfectSize = ele.GetPreferedSize(); resultHeight = Math.Max(resultHeight, perfectSize.height); } } else if (format == EFormat.Vertical) { foreach (Component ele in list) { Size perfectSize = ele.GetPreferedSize(); resultHeight += Spacer + perfectSize.height; } resultHeight -= Spacer; } } return resultHeight; }
public ChartDataSeries(Guid id, string name, EFormat format, OptionsData?options = null, int?capacity = null) : base(id, m4x4.Identity, name) { m_data = new List <Pt>(capacity ?? 100); m_range_x = RangeF.Invalid; Cache = new ChartGfxCache(CreatePiece); Format = format; Options = options ?? new OptionsData(); }
public static string GetMimeType(EFormat format) { switch (format) { case EFormat.Json: return("application/json"); case EFormat.ToString: return("text/html"); } return("text / html"); }
public DDSMetadata(uint width, uint height, uint mipscount = 0, EFormat format = EFormat.R8G8B8A8_UNORM, uint bpp = 16, bool iscubemap = false, uint slicecount = 0) { Width = width; Height = height; Mipscount = mipscount; Format = format; Bpp = bpp; Iscubemap = iscubemap; Slicecount = slicecount; }
/// <summary> /// 获取像素格式对应的纹理格式 /// </summary> /// /// <param name="format">像素格式</param> /// /// <returns>纹理格式</returns> /// <exception cref="InvalidOperationException">无纹理格式与指定的像素格式对应</exception> /// <seealso cref="EFormat"/> /// <author>Nianchen Deng</author> public static TextureFormat GetTextureFormat(this EFormat format) { switch (format) { case EFormat.BGR32: return(TextureFormat.BGRA32); case EFormat.RGB: return(TextureFormat.RGB24); case EFormat.RGB32: return(TextureFormat.RGBA32); default: throw new InvalidOperationException( "Pixel format is not supported by texture"); } }
public static void VFlip(string outDir, string filepath, EFormat format = EFormat.R8G8B8A8_UNORM) { var proc = new ProcessStartInfo(textconvpath) { WorkingDirectory = Path.GetDirectoryName(textconvpath), Arguments = $" -o \"{outDir}\" -y -f {format} -vflip \"{filepath}\"", UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, }; using (var p = Process.Start(proc)) { p.WaitForExit(); } }
/// <summary> /// Serializa un objeto al tipo especificado /// </summary> /// <param name="o">Objeto</param> /// <param name="format">Formato</param> public static string Serialize(object o, EFormat format) { if (o == null) { return(""); } switch (format) { case EFormat.Json: return(SerializationHelper.SerializeToJson(o)); case EFormat.JsonIndented: return(SerializationHelper.SerializeToJson(o, false, true)); case EFormat.ToString: return(o.ToString()); default: return(""); } }
public static bool LoadFromFile <T>(ref T obj, string fileName, EFormat format = EFormat.Json) where T : new() { try { string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + _directoryName + fileName; if (File.Exists(path)) { if (format == EFormat.Json) { using (StreamReader file = new StreamReader(path)) { obj = JsonUtility.FromJson <T>(file.ReadToEnd()); } return(true); } else if (format == EFormat.Txt) { obj = new T(); if (obj is ILoadable loadable) { using (StreamReader file = new StreamReader(path)) { loadable.LoadFromStream(file); } return(true); } return(false); } else { return(false); } } else { return(false); //file not found } } catch { return(false); } }
/// <summary> /// 获取像素格式对应的像素字节数 /// </summary> /// /// <param name="format">像素格式</param> /// /// <returns>每个像素所占字节数</returns> /// <exception cref="ArgumentOutOfRangeException"></exception> /// <seealso cref="EFormat"/> /// <author>Nianchen Deng</author> public static int GetSizePerPixel(this EFormat format) { switch (format) { case EFormat.Unknown: return(0); case EFormat.Mono8: return(1); case EFormat.BGR: case EFormat.RGB: return(3); case EFormat.BGR32: case EFormat.RGB32: return(4); case EFormat.HSV: return(3 * sizeof(float)); default: throw new ArgumentOutOfRangeException(nameof(format), format, null); } }
public H2BitmapCollection(Stream stream, int offset, int magic) { BinaryReader binReader = new BinaryReader(stream); stream.Position = offset; Type = (EType)binReader.ReadInt16(); Format = (EFormat)binReader.ReadInt16(); Usage = (EUsage)binReader.ReadInt16(); Flags = (EFlags)binReader.ReadInt16(); DetailFadeFactor = binReader.ReadSingle(); SharpenAmount = binReader.ReadSingle(); BumpHeight = binReader.ReadSingle(); SpriteBudgetSize = (ESpriteBudgetSize)binReader.ReadInt16(); SpriteBudgetCount = binReader.ReadInt16(); ColourPlateWidth = binReader.ReadInt16(); ColourPlateHeight = binReader.ReadInt16(); CompressedColourPlateDataCount = binReader.ReadInt32(); CompressedColourPlateDataPointer = binReader.ReadInt32(); ProcessedPixelDataCount = binReader.ReadInt32(); ProcessedPixelDataPointer = binReader.ReadInt32(); BlueFilterSize = binReader.ReadSingle(); AlphaBias = binReader.ReadSingle(); MipmapCount = binReader.ReadInt16(); SpriteUsage = (ESpriteUsage)binReader.ReadInt16(); SpriteSpacing = binReader.ReadInt16(); ForceFormat = binReader.ReadInt16(); int sequenceCount = binReader.ReadInt32(); int sequencePointer = binReader.ReadInt32(); int bitmapCount = binReader.ReadInt32(); int bitmapPointer = binReader.ReadInt32(); Sequences = new Sequence[sequenceCount]; for (int i = 0; i < sequenceCount; i++) Sequences[i] = new Sequence(stream, (sequencePointer - magic) + (i * Sequence.SizeOf), magic); Bitmaps = new BitmapData[bitmapCount]; for (int i = 0; i < bitmapCount; i++) Bitmaps[i] = new BitmapData(stream, (bitmapPointer - magic) + (i * BitmapData.SizeOf)); }
public static uint CalculateMipMapSize(uint width, uint height, EFormat format) { //TODO: dword align, check if sizes are not pow2 switch (format) { case EFormat.R8G8B8A8_UNORM: return(width * height * 4); //(width * bpp + 7) / 8; case EFormat.BC1_UNORM: case EFormat.BC4_UNORM: return(width * height / 2); //max(1,width ?4)x max(1,height ?4)x 8 (DXT1) case EFormat.BC2_UNORM: case EFormat.BC3_UNORM: case EFormat.BC5_UNORM: case EFormat.BC7_UNORM: return(width * height); //max(1,width ?4)x max(1,height ?4)x 16 (DXT2-5) default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Deprecated /// </summary> /// <param name="DXGIFormat"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static (ETextureCompression, ETextureRawFormat, ETexGroupFlags) GetRedFormatsFromDxgiFormat(EFormat DXGIFormat) { switch (DXGIFormat) { case EFormat.R32G32B32A32_FLOAT: return(ETextureCompression.TCM_None, ETextureRawFormat.TRF_HDRFloat, ETexGroupFlags.RawFormatOnly); case EFormat.R16G16B16A16_FLOAT: return(ETextureCompression.TCM_None, ETextureRawFormat.TRF_HDRHalf, ETexGroupFlags.RawFormatOnly); case EFormat.R10G10B10A2_UNORM: return(ETextureCompression.TCM_None, ETextureRawFormat.TRF_DeepColor, ETexGroupFlags.RawFormatOnly); case EFormat.R8G8B8A8_UNORM: throw new NotImplementedException(); case EFormat.R32_UINT: throw new NotImplementedException(); case EFormat.R8G8_UNORM: return(ETextureCompression.TCM_None, ETextureRawFormat.TRF_R8G8, ETexGroupFlags.RawFormatOnly); case EFormat.R16_FLOAT: return(ETextureCompression.TCM_None, ETextureRawFormat.TRF_HDRFloatGrayscale, ETexGroupFlags.RawFormatOnly); case EFormat.R8_UINT: return(ETextureCompression.TCM_None, ETextureRawFormat.TRF_Grayscale, ETexGroupFlags.RawFormatOnly); case EFormat.A8_UNORM: return(ETextureCompression.TCM_None, ETextureRawFormat.TRF_AlphaGrayscale, ETexGroupFlags.RawFormatOnly); case EFormat.BC1_UNORM: return(ETextureCompression.TCM_DXTNoAlpha, ETextureRawFormat.TRF_Invalid, ETexGroupFlags.CompressionOnly); case EFormat.BC2_UNORM: throw new NotImplementedException(); case EFormat.BC3_UNORM: return(ETextureCompression.TCM_DXTAlpha, ETextureRawFormat.TRF_Invalid, ETexGroupFlags.CompressionOnly); case EFormat.BC4_UNORM: return(ETextureCompression.TCM_QualityR, ETextureRawFormat.TRF_Invalid, ETexGroupFlags.CompressionOnly); case EFormat.BC5_UNORM: return(ETextureCompression.TCM_Normalmap, ETextureRawFormat.TRF_Invalid, ETexGroupFlags.CompressionOnly); case EFormat.BC7_UNORM: return(ETextureCompression.TCM_QualityColor, ETextureRawFormat.TRF_Invalid, ETexGroupFlags.CompressionOnly); default: throw new ArgumentOutOfRangeException(nameof(DXGIFormat), DXGIFormat, null); } }
public FileFormat(EFileExtension FileExtension, EFormat Format, String Version) { this.FileExtension = FileExtension; this.Format = Format; this.Version = Version; }
public extern void SetIndexStream(EFormat format, Span <Byte> stream);
public void SetIndexStream(EFormat format, Span <Byte> stream) { _indexStream = stream.ToArray(); IndexFormat = format; }
public BitmapData(Stream stream, int offset) { BinaryReader binReader = new BinaryReader(stream); stream.Position = offset; Tag = binReader.ReadChars(4); Width = binReader.ReadInt16(); Height = binReader.ReadInt16(); Depth = binReader.ReadInt16(); Type = (EType)binReader.ReadInt16(); Format = (EFormat)binReader.ReadInt16(); Flags = (EFlags)binReader.ReadUInt16(); RegistrationPointX = binReader.ReadInt16(); RegistrationPointY = binReader.ReadInt16(); MIPMapCount = binReader.ReadInt16(); PixelOffset = binReader.ReadInt32(); unused00 = binReader.ReadInt16(); LOD1Offset = binReader.ReadInt32(); LOD2Offset = binReader.ReadInt32(); LOD3Offset = binReader.ReadInt32(); unused0 = binReader.ReadInt32(); unused1 = binReader.ReadInt32(); unused2 = binReader.ReadInt32(); LOD1Size = binReader.ReadInt32(); LOD2Size = binReader.ReadInt32(); LOD3Size = binReader.ReadInt32(); unused3 = binReader.ReadInt32(); unused4 = binReader.ReadInt32(); unused5 = binReader.ReadInt32(); ID = binReader.ReadInt32(); unused6 = binReader.ReadBytes(32); }
void OrderComponents(List<Component> list, EHorizontalAlignment HAlignment, EVerticalAlignment VAlignment, EFormat format, Position origin, Size area) { if (list.Count > 0) { if (format == EFormat.Horizontal) { switch (HAlignment) { case EHorizontalAlignment.HLeft: { int strechSegment = 0; uint widthTakenUp = 0; foreach (Component ele in list) { if (((IElement)ele).HorizontalStyle == EElementStyle.Stretch) { ++strechSegment; } else { Size perfectSize = ele.GetPreferedSize(); widthTakenUp += perfectSize.width; } } uint widthAvailable = (uint)(area.width - Spacer * (list.Count - 1) - widthTakenUp); uint averageWidth = 0; if (strechSegment > 0) { averageWidth = (uint)(widthAvailable / strechSegment); } int tempX = origin.X; foreach (Component comp in list) { Size perfectSize = comp.GetPreferedSize(); if (((IElement)comp).HorizontalStyle == EElementStyle.Fit) { comp.Position.X = tempX; comp.Size.width = perfectSize.width; tempX += (int)(Spacer + perfectSize.width); } else if (((IElement)comp).HorizontalStyle == EElementStyle.Stretch) { comp.Position.X = tempX; comp.Size.width = averageWidth; tempX += (int)(Spacer + averageWidth); } } break; } case EHorizontalAlignment.HRight: { int strechSegment = 0; uint widthTakenUp = 0; foreach (Component ele in list) { if (((IElement)ele).HorizontalStyle == EElementStyle.Stretch) { ++strechSegment; } else { Size perfectSize = ele.GetPreferedSize(); widthTakenUp += perfectSize.width; } } uint widthAvailable = (uint)(area.width - Spacer * (list.Count - 1) - widthTakenUp); uint averageWidth = 0; if (strechSegment > 0) { averageWidth = (uint)(widthAvailable / strechSegment); } int tempX = (int)(origin.X + area.width); for (int i = list.Count - 1; i >= 0; --i) { Component iter = list[i]; Size perfectSize = iter.GetPreferedSize(); if (((IElement)iter).HorizontalStyle == EElementStyle.Fit) { tempX -= (int)perfectSize.width; iter.Position.X = tempX; iter.Size.width = perfectSize.width; tempX -= (int)Spacer; } else if (((IElement)iter).HorizontalStyle == EElementStyle.Stretch) { tempX -= (int)averageWidth; iter.Position.X = tempX; iter.Size.width = averageWidth; tempX -= (int)Spacer; } } break; } case EHorizontalAlignment.HCenter: { bool isStretch = false; int strechSegment = 0; uint widthTakenUp = 0; foreach (Component ele in list) { if (((IElement)ele).HorizontalStyle == EElementStyle.Stretch) { ++strechSegment; isStretch = true; } else { Size perfectSize = ele.GetPreferedSize(); widthTakenUp += perfectSize.width; } } if (isStretch) { uint widthAvailable = (uint)(area.width - Spacer * (list.Count - 1) - widthTakenUp); uint averageWidth = (uint)(widthAvailable / strechSegment); int tempX = origin.X; for (int iter = 0; iter < list.Count - 1; ++iter) { Component comp = list[iter]; Size perfectSize = comp.GetPreferedSize(); if (((IElement)comp).HorizontalStyle == EElementStyle.Fit) { comp.Position.X = tempX; comp.Size.width = perfectSize.width; tempX += (int)(Spacer + perfectSize.width); } else if (((IElement)comp).HorizontalStyle == EElementStyle.Stretch) { comp.Position.X = tempX; comp.Size.width = averageWidth; tempX += (int)(Spacer + averageWidth); } } } else { widthTakenUp += (uint)(Spacer * (list.Count - 1)); int tempX = (int)(origin.X + area.width * 0.5f - widthTakenUp * 0.5f); foreach (Component comp in list) { Size perfectSize = comp.GetPreferedSize(); comp.Position.X = tempX; comp.Size.width = perfectSize.width; tempX += (int)(Spacer + perfectSize.width); } } break; } } switch (VAlignment) { case EVerticalAlignment.VTop: { int tempY = origin.Y; foreach (Component comp in list) { Size perfectSize = comp.GetPreferedSize(); if (((IElement)comp).VerticalStyle == EElementStyle.Stretch) { comp.Position.Y = tempY; comp.Size.height = area.height; } else if (((IElement)comp).VerticalStyle == EElementStyle.Fit) { comp.Position.Y = tempY; comp.Size.height = perfectSize.height; } } break; } case EVerticalAlignment.VBottom: { int tempY = origin.Y; foreach (Component comp in list) { Size perfectSize = comp.GetPreferedSize(); if (((IElement)comp).VerticalStyle == EElementStyle.Stretch) { comp.Position.Y = tempY; comp.Size.height = area.height; } else if (((IElement)comp).VerticalStyle == EElementStyle.Fit) { comp.Position.Y = (int)(tempY + area.height - perfectSize.height); comp.Size.height = perfectSize.height; } } break; } case EVerticalAlignment.VCenter: { int tempY = origin.Y; foreach (Component comp in list) { Size perfectSize = comp.GetPreferedSize(); if (((IElement)comp).VerticalStyle == EElementStyle.Stretch) { comp.Position.Y = tempY; comp.Size.height = area.height; } else if (((IElement)comp).VerticalStyle == EElementStyle.Fit) { comp.Position.Y = (int)(tempY + area.height * 0.5 - perfectSize.height * 0.5); comp.Size.height = perfectSize.height; } } break; } } } else if (format == EFormat.Vertical) { } foreach (Component ele in list) { ele.Pack(); } } }
public ChartDataSeries(string name, EFormat format, OptionsData?options = null, int?capacity = null) : this(Guid.NewGuid(), name, format, options, capacity) { }
public EFormat GetFormat() { EFormat ret = (EFormat)ITexturePINVOKE.Texture_GetFormat(swigCPtr); return(ret); }
public void SetFormat(EFormat pFormat) { throw new NotImplementedException(); }