static void DataOn(byte[] data, SocketAsyncEventArgs e) { Console.WriteLine("ThreadId:" + System.Threading.Thread.CurrentThread.ManagedThreadId); try { //建立一个读取数据包的类 参数是数据包 //这个类的功能很强大,可以读取数据包的数据,并可以把你发送过来的对象数据,转换对象引用 ReadBytes read = new ReadBytes(data); int lengt; //数据包长度,用于验证数据包的完整性 int cmd; //数据包命令类型 //注意这里一定要这样子写,这样子可以保证所有你要度的数据是完整的,如果读不出来 Raed方法会返回FALSE,从而避免了错误的数据导致崩溃 if (read.ReadInt32(out lengt) && read.Length == lengt && read.ReadInt32(out cmd)) { //read.Read系列函数是不会产生异常的 //根据命令读取数据包 switch (cmd) { case 1000: { int version = read.ReadInt32(); long data1 = read.ReadInt64(); float data2 = read.ReadFloat(); double db1 = read.ReadDouble(); bool b1 = read.ReadBoolean(); bool b2 = read.ReadBoolean(); short s1 = read.ReadInt16(); byte sb1 = read.ReadByte(); string str1 = read.ReadString(); string str2 = read.ReadString(); byte[] datax = read.ReadByteArray(); TestData tm2 = read.ReadObject <TestData>(); Console.WriteLine("int:" + version); Console.WriteLine("long:" + data1); Console.WriteLine("float:" + data2); Console.WriteLine("double:" + db1); Console.WriteLine("bool TRUE:" + b1); Console.WriteLine("bool False:" + b2); Console.WriteLine("short:" + s1); Console.WriteLine("byte:" + sb1); Console.WriteLine("string:" + str1); Console.WriteLine("string:" + str2); Console.WriteLine("bytes lengt:" + datax.Length); BufferFormat buffer = new BufferFormat(1000); buffer.AddItem(version); buffer.AddItem(data1); buffer.AddItem(data2); buffer.AddItem(db1); buffer.AddItem(b1); buffer.AddItem(b2); buffer.AddItem(s1); buffer.AddItem(sb1); buffer.AddItem(str1); buffer.AddItem(str2); buffer.AddItem(datax); TestData tmx = new TestData() { Id = 1, Data = new List <string>() { "123123", "32123123" }, Data2 = new List <Test2>() { new Test2 { A = 1, B = 2 }, new Test2 { A = 3, B = 4 } } }; buffer.AddItem(tmx); server.SendData(e.AcceptSocket, buffer.Finish()); } break; } } } catch (Exception er) { Console.WriteLine(er.ToString()); } }
/// <summary> /// Function to decode an uncompressed run of pixel data. /// </summary> /// <param name="reader">The reader used to read the data in the stream.</param> /// <param name="dest">The destination buffer pointer.</param> /// <param name="x">The current horizontal position in the scanline.</param> /// <param name="runLength">The size of the run, in pixels.</param> /// <param name="width">The total width of the run.</param> /// <param name="expand"><b>true</b> to expand a 24bpp scanline to 32bpp, or <b>false</b> if no expansion is needed.</param> /// <param name="flipHorizontal"><b>true</b> to decode the pixels from right to left, or <b>false</b> to decode from left to right.</param> /// <param name="format">The pixel format.</param> /// <returns><b>true</b> if the run contains entirely transparent pixels, or <b>false</b> if not.</returns> private unsafe bool DecodeRleEncodedRun(GorgonBinaryReader reader, ref byte *dest, ref int x, int runLength, int width, bool expand, bool flipHorizontal, BufferFormat format) { bool result = true; switch (format) { case BufferFormat.R8_UNorm: for (; runLength > 0; --runLength, ++x) { if (x >= width) { throw new IOException(string.Format(Resources.GORIMG_ERR_FILE_FORMAT_NOT_CORRECT, Codec)); } if (!flipHorizontal) { *(dest++) = reader.ReadByte(); } else { *(dest--) = reader.ReadByte(); } } break; case BufferFormat.B5G5R5A1_UNorm: { ushort *destPtr = (ushort *)dest; ushort pixel = reader.ReadUInt16(); if ((pixel & 0x8000) != 0) { result = false; } for (; runLength > 0; runLength--, ++x) { if (x >= width) { throw new IOException(string.Format(Resources.GORIMG_ERR_FILE_FORMAT_NOT_CORRECT, Codec)); } if (!flipHorizontal) { *(destPtr++) = pixel; } else { *(destPtr--) = pixel; } } dest = (byte *)destPtr; } return(result); case BufferFormat.R8G8B8A8_UNorm: { uint pixel; // Do expansion. if (expand) { pixel = (uint)((reader.ReadByte() << 16) | (reader.ReadByte() << 8) | reader.ReadByte() | 0xFF000000); result = false; } else { pixel = reader.ReadUInt32(); if ((pixel & 0xFF000000) != 0) { result = false; } } uint *destPtr = (uint *)dest; for (; runLength > 0; --runLength, ++x) { if (x >= width) { throw new IOException(string.Format(Resources.GORIMG_ERR_FILE_FORMAT_NOT_CORRECT, Codec)); } if (!flipHorizontal) { *(destPtr++) = pixel; } else { *(destPtr--) = pixel; } } dest = (byte *)destPtr; } return(result); } return(false); }
/// <summary> /// Function to read uncompressed TGA scanline data. /// </summary> /// <param name="reader">The reader used to read in the data from the source stream.</param> /// <param name="width">Image width.</param> /// <param name="dest">Destination buffer pointner</param> /// <param name="format">Format of the destination buffer.</param> /// <param name="conversionFlags">Flags used for conversion.</param> private unsafe bool ReadCompressed(GorgonBinaryReader reader, int width, byte *dest, BufferFormat format, TGAConversionFlags conversionFlags) { bool setOpaque = true; bool flipHorizontal = (conversionFlags & TGAConversionFlags.InvertX) == TGAConversionFlags.InvertX; bool expand = (conversionFlags & TGAConversionFlags.Expand) == TGAConversionFlags.Expand; for (int x = 0; x < width;) { if (reader.BaseStream.Position >= reader.BaseStream.Length) { throw new IOException(string.Format(Resources.GORIMG_ERR_FILE_FORMAT_NOT_CORRECT, Codec)); } byte rleBlock = reader.ReadByte(); int size = (rleBlock & 0x7F) + 1; if ((rleBlock & 0x80) != 0) { if (!DecodeRleEncodedRun(reader, ref dest, ref x, size, width, expand, flipHorizontal, format)) { setOpaque = false; } continue; } if (!DecodeUncompressedRun(reader, ref dest, ref x, size, width, expand, flipHorizontal, format)) { setOpaque = false; } } return(setOpaque); }
public ResultAwatier CR(int cmdTag, params object[] args) { CallPack buffer = new CallPack() { Id = Common.MakeID, CmdTag = cmdTag, Arguments = new List <byte[]>(args.Length) }; foreach (var item in args) { Type type = item.GetType(); buffer.Arguments.Add(Serialization.PackSingleObject(type, item)); } using (MemoryStream stream = new MemoryStream()) { BinaryWriter bufflist = new BinaryWriter(stream); if (AsyncUser.dataExtra != null) { bufflist.Write(CmdDef.CallCmd); byte[] classdata = BufferFormat.SerializeObject(buffer); bufflist.Write(classdata.Length); bufflist.Write(classdata); byte[] fdata = AsyncUser.dataExtra(stream.ToArray()); stream.Position = 0; stream.SetLength(0); bufflist.Write(0); bufflist.Write(fdata); } else { bufflist.Write(0); bufflist.Write(CmdDef.CallCmd); byte[] classdata = BufferFormat.SerializeObject(buffer); bufflist.Write(classdata.Length); bufflist.Write(classdata); } int l = (int)(stream.Length); byte[] data = BufferFormat.GetSocketBytes(l); stream.Position = 0; bufflist.Write(data); byte[] pdata = stream.ToArray(); #if !COREFX stream.Close(); #endif stream.Dispose(); AsyncUser.AddAsyncCallBack(this, buffer.Id); if (CallSend != null) { CallSend(pdata); } } return(fiber.Read()); }
/// <summary> /// Function to retrieve the total number of elements in a buffer. /// </summary> /// <param name="format">The desired format for the view.</param> /// <returns>The total number of elements.</returns> /// <remarks> /// <para> /// Use this to retrieve the number of elements based on the <paramref name="format"/> that will be passed to a shader resource view. /// </para> /// </remarks> public int GetTotalElementCount(BufferFormat format) => format == BufferFormat.Unknown ? 0 : GetTotalElementCount(new GorgonFormatInfo(format));
public HttpsException(string message, PacketReader reader) : base($"{message}{Environment.NewLine}{BufferFormat.AsHexString(reader)}") { }
public Result CallMethod <Result>(string module, string MethodName, List <RPCArgument> arglist, out object[] args) { args = null; RPCCallPack call = new RPCCallPack() { Id = MakeID.GetID(), CallTime = DateTime.Now, CallModule = module, Method = MethodName, Arguments = arglist, IsNeedReturn = true, }; WaitReturnValue var = new WaitReturnValue(); using (var.waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset)) { ReturnValueDiy.TryAdd(call.Id, var); byte[] data = BufferFormat.FormatFCA(call); if (CallBufferOutSend != null) { CallBufferOutSend(data); } if (var.waitHandle.WaitOne(OutTime)) { ZYClient_Result_Return returnx = var.returnvalue; Type type = returnx.ReturnType; if (returnx.Arguments != null && returnx.Arguments.Count > 0 && arglist.Count == returnx.Arguments.Count) { args = new object[returnx.Arguments.Count]; for (int i = 0; i < returnx.Arguments.Count; i++) { args[i] = Serialization.UnpackSingleObject(returnx.Arguments[i].type, returnx.Arguments[i].Value); } } if (type != null) { object returnobj = Serialization.UnpackSingleObject(type, returnx.Return); return((Result)returnobj); } else { return(default(Result)); } } else { ReturnValueDiy.TryRemove(call.Id, out var); throw new TimeoutException("out time,Please set the timeout time."); } } }
/// <inheritdoc /> public abstract unsafe Device *CaptureOpenDevice(string deviceName, uint frequency, BufferFormat format, int size);
/// <summary> /// Function to update the settings for the render target. /// </summary> /// <param name="mode">New video mode to use.</param> /// <param name="depthStencilFormat">The format of the internal depth/stencil buffer.</param> /// <exception cref="GorgonLibrary.GorgonException"> /// Thrown when the <see cref="GorgonLibrary.Graphics.GorgonVideoMode.Format">GorgonSwapChainSettings.VideoMode.Format</see> property cannot be used by the video device for displaying data. /// <para>-or-</para> /// <para>The width and height are not valid for the render target.</para> /// </exception> public void UpdateSettings(GorgonVideoMode mode, BufferFormat depthStencilFormat) { UpdateSettings(mode, Settings.IsWindowed, depthStencilFormat, Settings.BufferCount); }
/// <summary> /// Copy the provided unmanaged audio buffer to managed memory and convert the samples to float. /// </summary> /// <param name="size">Number of bytes allocated for the unmanaged buffer</param> /// <param name="bufferPtr">Pointer to the unmanaged buffer</param> /// <param name="format">Audio format for the unmanaged buffer</param> /// <returns>Array of managed memory containing float samples</returns> public static float[] ConvertToManagedFloatSamples(uint size, IntPtr bufferPtr, BufferFormat format) { uint bytesPerSample = format.BitsPerSample / 8; uint numSamples = size / bytesPerSample; float[] samples = new float[numSamples]; if (format.SampleFormat == SampleFormatType.Float) { Marshal.Copy(bufferPtr, samples, 0, (int)numSamples); } else if (format.SampleFormat == SampleFormatType.Int) { var toFloat = UnmanagedToFloat[format.BitsPerSample]; for (uint i = 0; i < numSamples; ++i) { samples[i] = toFloat(bufferPtr); bufferPtr = IntPtr.Add(bufferPtr, (int)bytesPerSample); } } return(samples); }
/// <summary> /// Function to clip the sprite region from the texture. /// </summary> /// <param name="texture">Texture containing the image data to clip.</param> /// <returns>A rectangle for the sprite. Or an empty rectangle if no sprite was selected.</returns> public unsafe Rectangle Clip(GorgonTexture2D texture) { GorgonImageData imageData = null; try { // Constrain our mouse to the texture. _startPoint.X = _startPoint.X.Max(0).Min(texture.Settings.Width - 1); _startPoint.Y = _startPoint.Y.Max(0).Min(texture.Settings.Height - 1); imageData = GorgonImageData.CreateFromTexture(texture); _stride = imageData.Buffers[0].PitchInformation.RowPitch; _format = imageData.Settings.Format; _bytesPerPixel = GorgonBufferFormatInfo.GetInfo(_format).SizeInBytes; _textureWidth = imageData.Settings.Width; // Get a pointer to the buffer. byte *bytePtr = (byte *)imageData.UnsafePointer; if (IsMaskValue(bytePtr, _startPoint.X, _startPoint.Y)) { return(Rectangle.Empty); } Queue <ClipSpan> clipSpans = new Queue <ClipSpan>(); _pixels = new bool[imageData.Settings.Width * imageData.Settings.Height]; int left = _startPoint.X; int top = _startPoint.Y; int right = left; int bottom = top; // Get the initial span from our starting point and add it to our queue. ClipSpan span = GetSpan(bytePtr, left, top); clipSpans.Enqueue(span); while (clipSpans.Count > 0) { // Take the span off the queue. span = clipSpans.Dequeue(); // Find the next vertical span above and below the current span. int west = span.Start; int east = span.End; int north = span.Y - 1; int south = span.Y + 1; // Check each pixel between the start and end of the upper and lower spans. for (int x = west; x <= east; ++x) { int pixelindex = _textureWidth * north + x; if ((span.Y > 0) && (!IsMaskValue(bytePtr, x, north)) && (!_pixels[pixelindex])) { clipSpans.Enqueue(GetSpan(bytePtr, x, north)); } pixelindex = _textureWidth * south + x; if ((span.Y >= imageData.Settings.Height - 1) || (IsMaskValue(bytePtr, x, south)) || (_pixels[pixelindex])) { continue; } clipSpans.Enqueue(GetSpan(bytePtr, x, south)); } // Update the boundaries. left = west.Min(left); right = (east + 1).Max(right); top = (north + 1).Min(top); bottom = south.Max(bottom); } return(Rectangle.FromLTRB(left, top, right, bottom)); } finally { if (imageData != null) { imageData.Dispose(); } } }
public Result Func(int cmdTag, params object[] args) { CallPack buffer = new CallPack() { Id = Common.MakeID, CmdTag = cmdTag, Arguments = new List <byte[]>(args.Length) }; foreach (var item in args) { Type type = item.GetType(); buffer.Arguments.Add(Serialization.PackSingleObject(type, item)); } using (MemoryStream stream = new MemoryStream()) { BinaryWriter bufflist = new BinaryWriter(stream); if (DataExtra != null) { bufflist.Write(CmdDef.CallCmd); bufflist.Write(buffer.Id); bufflist.Write(buffer.CmdTag); bufflist.Write(buffer.Arguments.Count); foreach (var arg in buffer.Arguments) { bufflist.Write(arg.Length); bufflist.Write(arg); } byte[] fdata = DataExtra(stream.ToArray()); stream.Position = 0; stream.SetLength(0); bufflist.Write(0); bufflist.Write(fdata); } else { bufflist.Write(0); bufflist.Write(CmdDef.CallCmd); bufflist.Write(buffer.Id); bufflist.Write(buffer.CmdTag); bufflist.Write(buffer.Arguments.Count); foreach (var arg in buffer.Arguments) { bufflist.Write(arg.Length); bufflist.Write(arg); } } int l = (int)(stream.Length); byte[] data = BufferFormat.GetSocketBytes(l); stream.Position = 0; bufflist.Write(data); byte[] pdata = stream.ToArray(); return(SendDataAsWait(buffer.Id, pdata)); } }
/// <summary> /// Function to retrieve a render target view. /// </summary> /// <param name="format">Format of the new render target view.</param> /// <param name="firstElement">The first element in the buffer to map to the view.</param> /// <param name="elementCount">The number of elements in the buffer to map to the view.</param> /// <returns>A render target view.</returns> /// <remarks>Use this to create/retrieve a render target view that can bind a portion of the target to the pipeline as a render target. /// <para>The <paramref name="format"/> for the render target view does not have to be the same as the render target backing buffer, and if the format is set to Unknown, then it will /// use the format from the buffer.</para> /// </remarks> /// <exception cref="GorgonLibrary.GorgonException">Thrown when the view could not created or retrieved from the internal cache.</exception> public GorgonRenderTargetBufferView GetRenderTargetView(BufferFormat format, int firstElement, int elementCount) { return(OnGetRenderTargetView(format, Settings.Format, firstElement, elementCount)); }
/// <summary> /// Initializes a new instance of the <see cref="BufferShaderViewKey"/> struct. /// </summary> /// <param name="start">The start.</param> /// <param name="count">The count.</param> /// <param name="format">The format.</param> public BufferShaderViewKey(int start, int count, BufferFormat format) : this(start, count, (int)format) { }
/// <summary> /// Function to retrieve an unordered access view for this texture. /// </summary> /// <param name="format">Format of the buffer.</param> /// <param name="mipStart">[Optional] First mip map level to map to the view.</param> /// <param name="arrayStart">[Optional] The first array index to map to the view.</param> /// <param name="arrayCount">[Optional] The number of array indices to map to the view.</param> /// <returns>A new unordered access view for the texture.</returns> /// <remarks>Use this to retrieve an unordered access view that will allow shaders to access the view using multiple threads at the same time. Unlike a shader view, only one /// unordered access view can be bound to the pipeline at any given time. /// <para>Unordered access views require a video device feature level of SM_5 or better.</para> /// <para>Textures that have a usage of staging cannot create unordered views.</para> /// </remarks> /// <exception cref="GorgonLibrary.GorgonException">Thrown when the usage for this texture is set to Staging. /// <para>-or-</para> /// <para>Thrown when the video device feature level is not SM_5 or better.</para> /// <para>-or-</para> /// <para>Thrown when the resource settings do not allow unordered access views.</para> /// <para>-or-</para> /// <para>Thrown when the view could not be created.</para> /// </exception> /// <exception cref="System.ArgumentException">Thrown when the <paramref name="mipStart"/>, <paramref name="arrayStart"/> or <paramref name="arrayCount"/> parameters are less than 0 or greater than or equal to the /// number of mip levels and/or array levels in the texture. /// <para>-or-</para> /// <para>Thrown if the bit count of the <paramref name="format"/> and the texture format are different, or if format is not in the R32 group and is not in the same group as the texture format.</para> /// </exception> public GorgonTextureUnorderedAccessView GetUnorderedAccessView(BufferFormat format, int mipStart = 0, int arrayStart = 0, int arrayCount = 1) { return(OnGetUnorderedAccessView(format, mipStart, arrayStart, arrayCount)); }
/// <summary> /// 数据包处理 /// </summary> /// <param name="data"></param> private void BufferIn(byte[] data) { ReadBytesV2 read = new ReadBytesV2(data); int length; if (read.ReadInt32(out length) && length == read.Length) { int cmd; if (read.ReadInt32(out cmd)) { PCMD pcmd = (PCMD)cmd; switch (pcmd) { case PCMD.SET: //准备就绪 BufferFormatV2 tmp = new BufferFormatV2((int)PCMD.GETALLMASK); Mainclient.Send(tmp.Finish()); break; case PCMD.ALLUSER: //获取全部用户列表 try { int count; if (read.ReadInt32(out count)) { for (int i = 0; i < count; i++) { string usermask; if (read.ReadString(out usermask)) { UserMaskList.Enqueue(usermask); } } RunQueueList(); } } catch (ArgumentOutOfRangeException) { } break; case PCMD.NOWCONN: //立刻连接到指定IP端口 string host; string key; if (read.ReadString(out host) && read.ReadString(out key)) { host = host + ":" + key; SocketClient client = new SocketClient(); Tp: IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, BindPort++); //绑定端口 if (BindPort >= 60000) { BindPort = 1000; } try { client.Sock.Bind(endpoint); //如果无法绑定那么重新选个端口 } catch { goto Tp; } if (client.Connect(this.Host, RegIpPort)) //连接到注册端口 { BufferFormat tmpX = new BufferFormat(100); tmpX.AddItem(Key); tmpX.AddItem(BindPort); client.Send(tmpX.Finish()); System.Threading.Thread.Sleep(50); BufferFormatV2 tmpX2 = new BufferFormatV2((int)PCMD.LEFTCONN); tmpX2.AddItem(key); Mainclient.Send(tmpX2.Finish()); client.Close(); System.Threading.Thread.Sleep(50); System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(RunConnToMe), host); } } break; case PCMD.LEFTCONN: string host2; string key2; if (read.ReadString(out host2) && read.ReadString(out key2)) { host2 = host2 + ":" + key2; System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(RunConnToMe), host2); } break; case PCMD.GETALLUSER: { int count; if (read.ReadInt32(out count)) { AllUser = new List <string>(); for (int i = 0; i < count; i++) { string var; if (read.ReadString(out var)) { AllUser.Add(var); } else { break; } } if (GetAllUserList != null) { GetAllUserList(AllUser); } } } break; case PCMD.ProxyData: { string keys; byte[] buff; if (read.ReadString(out keys) && read.ReadByteArray(out buff)) { if (ProxyList.ContainsKey(keys)) { client_DataOutPut(keys, ProxyList[keys], buff); } else { ConClient client = new ConClient(keys); if (ProxyList.TryAdd(client.Key, client)) { client_DataOutPut(keys, client, buff); } } } } break; } } } }
/// <summary> /// Function to retrieve a shader resource view object. /// </summary> /// <param name="format">The format of the resource view.</param> /// <param name="mipStart">[Optional] Starting mip map for the view.</param> /// <param name="mipCount">[Optional] Mip map count for the view.</param> /// <param name="arrayIndex">[Optional] Starting array index for the view.</param> /// <param name="arrayCount">[Optional] Array index count for the view.</param> /// <remarks>Use a shader view to access a texture from a shader. A shader view can view a select portion of the texture, and the view <paramref name="format"/> can be used to /// cast the format of the texture into another type (as long as the view format is in the same group as the texture format). For example, a texture with a format of R8G8B8A8 could be cast /// to R8G8B8A8_UInt_Normal, or R8G8B8A8_UInt or any of the other R8G8B8A8 formats. /// <para>Multiple views of the texture can be bound to different parts of the shader pipeline.</para> /// <para>Textures that have a usage of staging cannot create shader views.</para> /// </remarks> /// <exception cref="GorgonLibrary.GorgonException">Thrown when the view could not created or retrieved from the internal cache.</exception> /// <returns>A texture shader view object.</returns> public GorgonTextureShaderView GetShaderView(BufferFormat format, int mipStart = 0, int mipCount = 1, int arrayIndex = 0, int arrayCount = 1) { return(OnGetShaderView(format, mipStart, mipCount, arrayIndex, arrayCount)); }
/// <summary> /// 调用模块 /// </summary> /// <param name="data"></param> /// <returns>true 属于次模块,false 不属于此模块数据</returns> public bool CallModule(byte[] data, RPCUserInfo e, out ReadBytes read, out int cmd) { cmd = -1; read = new ReadBytes(data); int lengt; if (read.ReadInt32(out lengt) && read.Length == lengt && read.ReadInt32(out cmd)) { switch (cmd) { case 1001000: { RPCCallPack tmp; if (read.ReadObject <RPCCallPack>(out tmp)) { System.Threading.Tasks.Task.Factory.StartNew(() => { object returnValue; CallContext.SetData("Current", e); if (e.RPC_Call.RunModule(tmp, out returnValue)) { if (tmp.IsNeedReturn) { ZYClient_Result_Return var = new ZYClient_Result_Return() { Id = tmp.Id, CallTime = tmp.CallTime, Arguments = tmp.Arguments }; if (returnValue != null) { var.Return = Serialization.PackSingleObject(returnValue.GetType(), returnValue); var.ReturnType = returnValue.GetType(); } e.EnsureSend(BufferFormat.FormatFCA(var)); } } }, CancellationToken.None, TaskCreationOptions.None, e.QueueScheduler).ContinueWith(p => { try { p.Wait(); } catch (Exception er) { if (MsgOut != null) { MsgOut(er.ToString()); } } }); return(true); } } break; case 1001001: { ZYClient_Result_Return val; if (read.ReadObject <ZYClient_Result_Return>(out val)) { e.RPC_Call.SetReturnValue(val); return(true); } } break; } } return(false); }
public HttpsException(string message, byte[] buffer) : base($"{message}{Environment.NewLine}{BufferFormat.AsHexString(buffer, buffer.Length)}") { }
/// <summary> /// Initializes a new instance of the <see cref="DdsLegacyConversion" /> struct. /// </summary> /// <param name="format">The format.</param> /// <param name="flags">The flags.</param> /// <param name="pixelFormat">The pixel format.</param> public DdsLegacyConversion(BufferFormat format, DdsConversionFlags flags, DdsPixelFormat pixelFormat) { Format = format; Flags = flags; PixelFormat = pixelFormat; }
private void ReceiveWfc29901(NetState ns, byte[] buffer, int length) { Console.WriteLine($"{TypeName}: {ns} sent unhandled Wfc29901 message"); Console.WriteLine(BufferFormat.AsString(buffer, length)); }
/// <summary> /// Initializes a new instance of the <see cref="GorgonRenderTarget2DView"/> class. /// </summary> /// <param name="resource">The resource to bind.</param> /// <param name="format">The format of the render target view.</param> /// <param name="formatInfo">Information about the format.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="resource"/>, or the <paramref name="formatInfo"/> parameter is <b>null</b>.</exception> protected GorgonRenderTargetView(GorgonGraphicsResource resource, BufferFormat format, GorgonFormatInfo formatInfo) : base(resource) { FormatInformation = formatInfo ?? throw new ArgumentNullException(nameof(formatInfo)); Format = format; }
/// <inheritdoc /> public unsafe partial Device *CaptureOpenDevice(string deviceName, uint frequency, BufferFormat format, int size);
/// <summary> /// Initializes a new instance of the <see cref="GorgonRenderTargetBufferSettings"/> class. /// </summary> public GorgonRenderTargetBufferSettings() { SizeInBytes = 0; Format = BufferFormat.Unknown; }
/// <summary> /// Function to read in the TGA header from a stream. /// </summary> /// <param name="reader">The reader used to read the stream containing the data.</param> /// <param name="conversionFlags">Flags for conversion.</param> /// <returns>New image settings.</returns> private static IGorgonImageInfo ReadHeader(GorgonBinaryReader reader, out TGAConversionFlags conversionFlags) { conversionFlags = TGAConversionFlags.None; // Get the header for the file. TgaHeader header = reader.ReadValue <TgaHeader>(); if ((header.ColorMapType != 0) || (header.ColorMapLength != 0) || (header.Width <= 0) || (header.Height <= 0) || ((header.Descriptor & TgaDescriptor.Interleaved2Way) == TgaDescriptor.Interleaved2Way) || ((header.Descriptor & TgaDescriptor.Interleaved4Way) == TgaDescriptor.Interleaved4Way)) { throw new NotSupportedException(Resources.GORIMG_ERR_TGA_TYPE_NOT_SUPPORTED); } BufferFormat pixelFormat = BufferFormat.Unknown; switch (header.ImageType) { case TgaImageType.TrueColor: case TgaImageType.TrueColorRLE: switch (header.BPP) { case 16: pixelFormat = BufferFormat.B5G5R5A1_UNorm; break; case 24: case 32: pixelFormat = BufferFormat.R8G8B8A8_UNorm; if (header.BPP == 24) { conversionFlags |= TGAConversionFlags.Expand; } break; } if (header.ImageType == TgaImageType.TrueColorRLE) { conversionFlags |= TGAConversionFlags.RLE; } break; case TgaImageType.BlackAndWhite: case TgaImageType.BlackAndWhiteRLE: if (header.BPP == 8) { pixelFormat = BufferFormat.R8_UNorm; } else { throw new IOException(string.Format(Resources.GORIMG_ERR_FORMAT_NOT_SUPPORTED, header.ImageType)); } if (header.ImageType == TgaImageType.BlackAndWhiteRLE) { conversionFlags |= TGAConversionFlags.RLE; } break; default: throw new IOException(string.Format(Resources.GORIMG_ERR_FORMAT_NOT_SUPPORTED, header.ImageType)); } var settings = new GorgonImageInfo(ImageType.Image2D, pixelFormat) { MipCount = 1, ArrayCount = 1, Width = header.Width, Height = header.Height }; if ((header.Descriptor & TgaDescriptor.InvertX) == TgaDescriptor.InvertX) { conversionFlags |= TGAConversionFlags.InvertX; } if ((header.Descriptor & TgaDescriptor.InvertY) == TgaDescriptor.InvertY) { conversionFlags |= TGAConversionFlags.InvertY; } if (header.IDLength <= 0) { return(settings); } // Skip these bytes. for (int i = 0; i < header.IDLength; i++) { reader.ReadByte(); } return(settings); }
/// <inheritdoc /> public abstract unsafe void BufferData(uint buffer, BufferFormat format, void *data, int size, int frequency);
/// <summary> /// Function to decode an uncompressed run of pixel data. /// </summary> /// <param name="reader">The reader used to read the data from the stream.</param> /// <param name="dest">The destination buffer pointer.</param> /// <param name="x">The current horizontal position in the scanline.</param> /// <param name="runLength">The size of the run, in pixels.</param> /// <param name="width">The total width of the run.</param> /// <param name="expand"><b>true</b> to expand a 24bpp scanline to 32bpp, or <b>false</b> if no expansion is needed.</param> /// <param name="flipHorizontal"><b>true</b> to decode the pixels from right to left, or <b>false</b> to decode from left to right.</param> /// <param name="format">The pixel format.</param> /// <returns><b>true</b> if the run contains entirely transparent pixels, or <b>false</b> if not.</returns> private unsafe bool DecodeUncompressedRun(GorgonBinaryReader reader, ref byte *dest, ref int x, int runLength, int width, bool expand, bool flipHorizontal, BufferFormat format) { bool result = true; switch (format) { case BufferFormat.R8_UNorm: for (; runLength > 0; --runLength, ++x) { if (x >= width) { throw new IOException(string.Format(Resources.GORIMG_ERR_FILE_FORMAT_NOT_CORRECT, Codec)); } if (!flipHorizontal) { *(dest++) = reader.ReadByte(); } else { *(dest--) = reader.ReadByte(); } } break; case BufferFormat.B5G5R5A1_UNorm: { ushort *destPtr = (ushort *)dest; for (; runLength > 0; runLength--, ++x) { if (x >= width) { throw new IOException(string.Format(Resources.GORIMG_ERR_FILE_FORMAT_NOT_CORRECT, Codec)); } ushort pixel = reader.ReadUInt16(); if ((pixel & 0x8000) != 0) { result = false; } if (!flipHorizontal) { *(destPtr++) = pixel; } else { *(destPtr--) = pixel; } } // Send the updated destination address back to the calling function. // This is kind of ugly, but too lazy to make it nice. dest = (byte *)destPtr; } return(result); case BufferFormat.R8G8B8A8_UNorm: { uint *destPtr = (uint *)dest; for (; runLength > 0; --runLength, ++x) { if (x >= width) { throw new IOException(string.Format(Resources.GORIMG_ERR_FILE_FORMAT_NOT_CORRECT, Codec)); } uint pixel; if (expand) { pixel = (uint)((reader.ReadByte() << 16) | (reader.ReadByte() << 8) | reader.ReadByte() | 0xFF000000); result = false; } else { pixel = reader.ReadUInt32(); if ((pixel & 0xFF000000) != 0) { result = false; } } if (!flipHorizontal) { *(destPtr++) = pixel; } else { *(destPtr--) = pixel; } } // Send the updated destination address back to the calling function. // This is kind of ugly, but too lazy to make it nice. dest = (byte *)destPtr; } return(result); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="GorgonVideoMode"/> struct. /// </summary> /// <param name="width">The width of the video mode.</param> /// <param name="height">The height of the video mode.</param> /// <param name="format">The format for the video mode.</param> public GorgonVideoMode(int width, int height, BufferFormat format) : this(width, height, format, 0, 0) { }
/// <summary> /// Function to read uncompressed TGA scanline data. /// </summary> /// <param name="src">The pointer to the buffer containing the source data.</param> /// <param name="srcPitch">Pitch of the source scan line.</param> /// <param name="dest">Destination buffer pointner</param> /// <param name="format">Format of the destination buffer.</param> /// <param name="conversionFlags">Flags used for conversion.</param> private static unsafe bool ReadUncompressed(byte *src, int srcPitch, byte *dest, BufferFormat format, TGAConversionFlags conversionFlags) { bool flipHorizontal = (conversionFlags & TGAConversionFlags.InvertX) == TGAConversionFlags.InvertX; switch (format) { case BufferFormat.R8_UNorm: case BufferFormat.B5G5R5A1_UNorm: return(ImageUtilities.CopyScanline(src, srcPitch, dest, format, flipHorizontal)); case BufferFormat.R8G8B8A8_UNorm: if ((conversionFlags & TGAConversionFlags.Expand) != TGAConversionFlags.Expand) { return(ImageUtilities.CopyScanline(src, srcPitch, dest, format, flipHorizontal)); } ImageUtilities.Expand24BPPScanLine(src, srcPitch, dest, flipHorizontal); // We're already opaque by virtue of being 24 bit. return(false); } return(false); }
private void ResrunResultData(Result result) { using (MemoryStream stream = new MemoryStream()) { BinaryWriter bufflist = new BinaryWriter(stream); if (DataExtra != null) { bufflist.Write(CmdDef.ReturnResult); bufflist.Write(result.Id); bufflist.Write(result.ErrorId); if (string.IsNullOrEmpty(result.ErrorMsg)) { bufflist.Write(0); } else { byte[] strdata = Encoding.UTF8.GetBytes(result.ErrorMsg); bufflist.Write(strdata.Length); bufflist.Write(strdata); } bufflist.Write(result.Arguments.Count); foreach (var arg in result.Arguments) { bufflist.Write(arg.Length); bufflist.Write(arg); } byte[] fdata = DataExtra(stream.ToArray()); stream.Position = 0; stream.SetLength(0); bufflist.Write(0); bufflist.Write(fdata); } else { bufflist.Write(0); bufflist.Write(CmdDef.ReturnResult); bufflist.Write(result.Id); bufflist.Write(result.ErrorId); if (string.IsNullOrEmpty(result.ErrorMsg)) { bufflist.Write(0); } else { byte[] strdata = Encoding.UTF8.GetBytes(result.ErrorMsg); bufflist.Write(strdata.Length); bufflist.Write(strdata); } bufflist.Write(result.Arguments.Count); foreach (var arg in result.Arguments) { bufflist.Write(arg.Length); bufflist.Write(arg); } } int l = (int)(stream.Length); byte[] data = BufferFormat.GetSocketBytes(l); stream.Position = 0; bufflist.Write(data); byte[] pdata = stream.ToArray(); SendData(pdata); } }