public static void Pack(BufferChunk aChunk, int left, int top, int right, int bottom) { aChunk += left; aChunk += top; aChunk += right; aChunk += bottom; }
public virtual void CopyPixels(int x, int y, int width, int height, PixelBuffer24 pixBuff) { // Create a buffer // It has to be big enough for the bitmap data, as well as the x,y, and command int dataSize = (width) * (height) * pixBuff.Pixels.BytesPerPixel; BufferChunk chunk = new BufferChunk(dataSize + 128); // now put the basic command and simple components in chunk += SpaceControlChannel.SC_CopyPixels; CodecUtils.Pack(chunk, x, y, width, height); chunk += dataSize; // Finally, copy in the data int numBytesPerRow = pixBuff.Pixels.BytesPerPixel * width; IntPtr rowPtr = pixBuff.Pixels.Data; int offset = 0; int row = 0; for (row = y; row < (y + height); row++) { offset = pixBuff.Pixels.Data.ToInt32() + row * pixBuff.Pixels.Stride + x * pixBuff.Pixels.BytesPerPixel; rowPtr = (IntPtr)offset; chunk.CopyFrom(rowPtr, numBytesPerRow); } PackCommand(chunk); }
/// Some GraphPort control things /// public override void SaveState() { BufferChunk chunk = new BufferChunk(128); chunk += GDI32.EMR_SAVEDC; SendCommand(chunk); }
public override void PixBltPixelBuffer24(GDIDIBSection fPixMap, int x, int y) { MemoryStream ms = new MemoryStream(); PixelAccessorBGRb accessor = new PixelAccessorBGRb(fPixMap.Width, fPixMap.Height, fPixMap.Orientation, fPixMap.Pixels); // 2. Run length encode the image to a memory stream NewTOAPIA.Imaging.TargaRunLengthCodec rlc = new NewTOAPIA.Imaging.TargaRunLengthCodec(); rlc.Encode(accessor, ms); // 3. Get the bytes from the stream byte[] imageBytes = ms.GetBuffer(); int dataLength = (int)imageBytes.Length; // 4. Allocate a buffer chunk to accomodate the bytes, plus some more BufferChunk chunk = new BufferChunk(dataLength + 128); // 5. Put the command, destination, and data size into the buffer first chunk += (int)UICommands.PixBltRLE; ChunkUtils.Pack(chunk, x, y); ChunkUtils.Pack(chunk, accessor.Width, accessor.Height); chunk += dataLength; // 6. Put the image bytes into the chunk chunk += imageBytes; // 6. Finally, send the packet SendCommand(chunk); }
public override void PixBltPixelArray(IPixelArray pixBuff, int x, int y) { //NewTOAPIA.Kernel.PrecisionTimer timer = new NewTOAPIA.Kernel.PrecisionTimer(); // 1. convert the pixel array to a Bitmap object Bitmap bm = PixelBufferHelper.CreateBitmapFromPixelArray(pixBuff); // 2. Write this bitmap to a memory stream as a compressed JPEG image MemoryStream ms = new MemoryStream(); bm.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); // 3. Get the bytes from the stream byte[] imageBytes = ms.GetBuffer(); // 4. Allocate a buffer chunk to accomodate the bytes, plus some more BufferChunk chunk = new BufferChunk(imageBytes.Length + 128); // 5. Put the command, destination, and data size into the buffer first chunk += (int)UICommands.PixBltJPG; ChunkUtils.Pack(chunk, x, y); chunk += (int)imageBytes.Length; // 6. Put the image bytes into the chunk chunk += imageBytes; //double duration = timer.GetElapsedSeconds(); //Console.WriteLine("Encoder - Time to pack image: {0}", duration); // Finally, send the packet SendCommand(chunk); }
// Modes and attributes public override void SetTextColor(uint colorref) { BufferChunk chunk = new BufferChunk(128); chunk += GDI32.EMR_SETTEXTCOLOR; chunk += colorref; SendCommand(chunk); }
Guid UnpackGuid(BufferChunk chunk) { int bufferLength = chunk.NextInt32(); // How many bytes did we pack byte[] bytes = (byte[])chunk.NextBufferChunk(bufferLength); Guid aGuid = new Guid(bytes); return aGuid; }
void SetupBufferChunks() { fChunks = new Queue<BufferChunk>(); for (int i = 0; i < NumberOfPackets; i++) { BufferChunk newChunk = new BufferChunk(UDP.MTU); fChunks.Enqueue(newChunk); } }
public static void Pack(BufferChunk chunk, XFORM aTrans) { chunk += aTrans.eDx; chunk += aTrans.eDy; chunk += aTrans.eM11; chunk += aTrans.eM12; chunk += aTrans.eM21; chunk += aTrans.eM22; }
public virtual void ReceiveChunk(BufferChunk aRecord) { // First read out the record type int recordType = aRecord.NextInt32(); // Then deserialize the rest from there switch ((UserIOCommand)recordType) { case UserIOCommand.HideCursor: HideCursor(); break; case UserIOCommand.Showcursor: ShowCursor(); break; case UserIOCommand.MoveCursor: { int x = aRecord.NextInt32(); int y = aRecord.NextInt32(); MoveCursor(x, y); } break; case UserIOCommand.KeyboardActivity: { KeyActivityType kEvent = (KeyActivityType)aRecord.NextInt32(); VirtualKeyCodes vk = (VirtualKeyCodes)aRecord.NextInt32(); KeyboardActivityArgs kbda = new KeyboardActivityArgs(kEvent, vk); KeyboardActivity(this, kbda); } break; case UserIOCommand.MouseActivity: { MouseActivityType maType = MouseActivityType.None; MouseButtonActivity mbActivity = (MouseButtonActivity)aRecord.NextInt32(); int x = aRecord.NextInt32(); int y = aRecord.NextInt32(); int clicks = aRecord.NextInt32(); short delta = aRecord.NextInt16(); int keyflags = 0; MouseActivityArgs ma = new MouseActivityArgs(null, maType, mbActivity, MouseCoordinateSpace.Desktop, MouseMovementType.Absolute, IntPtr.Zero, x, y, delta, clicks, keyflags); MouseActivity(this, ma); } break; default: break; } }
// Drawing Primitives /// Our first pass will be to implement everything as /// taking explicit int parameters. /// We'll assume that drawing with a different pen will /// be accomplished by setting the Pen property on the /// port before drawing. This will keep our API count /// low and alleviate the need to pass the same /// parameter every time. We can add more later. /// public override void SetPixel(int x, int y, Color colorref) { BufferChunk chunk = new BufferChunk(128); chunk += GDI32.EMR_SETTEXTCOLOR; ChunkUtils.Pack(chunk, x, y); chunk += colorref.ToArgb(); SendCommand(chunk); }
public override void SelectUniqueObject(Guid objectID) { BufferChunk chunk = new BufferChunk(128); chunk += GDI32.EMR_SELECTUNIQUEOBJECT; chunk += (int)16; // The following byte array is 16 elements long chunk += objectID.ToByteArray(); SendCommand(chunk); }
public virtual void CreateSurface(string title, RECT frame, Guid uniqueID) { BufferChunk chunk = new BufferChunk(1024); chunk += SpaceControlChannel.SC_CreateSurface; CodecUtils.Pack(chunk,uniqueID); CodecUtils.Pack(chunk,frame.Left, frame.Top, frame.Width, frame.Height); PackCommand(chunk); }
public virtual void InvalidateSurfaceRect(Guid surfaceID, RECT frame) { BufferChunk chunk = new BufferChunk(1024); chunk += SpaceControlChannel.SC_InvalidateSurfaceRect; CodecUtils.Pack(chunk, surfaceID); CodecUtils.Pack(chunk, frame.Left, frame.Top, frame.Width, frame.Height); PackCommand(chunk); }
public static void Pack(BufferChunk chunk, Point[] points) { // Need to know how many points so that space can be allocated for them on the receiving end chunk += points.Length; // Encode each of the points for (int i = 0; i < points.Length; i++) { Pack(chunk, points[i].X, points[i].Y); } }
public static void Pack(BufferChunk chunk, GRADIENT_RECT[] gRect) { int nRects = gRect.Length; chunk += nRects; for (int i = 0; i < nRects; i++) { chunk += gRect[i].UpperLeft; chunk += gRect[i].LowerRight; } }
public static void Pack(BufferChunk chunk, Point3D[] points) { // Need to know how many points so that space can be allocated for them on the receiving end chunk += points.Length; // Encode each of the points foreach(Point3D aPoint in points) { Pack(chunk, (int)aPoint.X, (int)aPoint.Y); } }
GRADIENT_RECT[] UnpackGRADIENT_RECT(BufferChunk chunk) { int nRects = chunk.NextInt32(); GRADIENT_RECT[] pMesh = new GRADIENT_RECT[nRects]; for (int i = 0; i < nRects; i++) { pMesh[i].UpperLeft = chunk.NextUInt32(); pMesh[i].LowerRight = chunk.NextUInt32(); } return pMesh; }
void PackCommand(EMR aCommand) { BinaryFormatter fFormatter = new BinaryFormatter(); MemoryStream fMemoryStream = new MemoryStream(2048); fMemoryStream.Seek(0, SeekOrigin.Begin); fFormatter.Serialize(fMemoryStream, aCommand); byte[] sendBytes = fMemoryStream.GetBuffer(); BufferChunk chunk = new BufferChunk(sendBytes); //PackCommand(chunk); }
public virtual void Send(BufferChunk aChunk) { if (fSender == null) return; // Packetize the chunk fPacketizer.Packetize(aChunk, fSenderPacketPool); // Send out the smaller packets until done for (int i = 0; i < fSenderPacketPool.PacketsInFramePool; i++) { PacketBase packetWrapper = fSenderPacketPool.Packets[i]; fSender.Send(packetWrapper.Buffer); } }
public static BufferChunk Pack(EMR aCommand) { BinaryFormatter fFormatter = new BinaryFormatter(); MemoryStream fMemoryStream = new MemoryStream(2048); fMemoryStream.Seek(0, SeekOrigin.Begin); fFormatter.Serialize(fMemoryStream, aCommand); byte[] sendBytes = fMemoryStream.GetBuffer(); BufferChunk chunk = new BufferChunk(sendBytes); return chunk; }
public static void Pack(BufferChunk chunk, TRIVERTEX[] vertices) { int nVertices = vertices.Length; // Pack the vertices, starting with the length chunk += nVertices; for (int i = 0; i < nVertices; i++) { chunk += vertices[i].x; chunk += vertices[i].y; chunk += vertices[i].Alpha; chunk += vertices[i].Blue; chunk += vertices[i].Green; chunk += vertices[i].Red; } }
public override void MouseActivity(object sender, NewTOAPIA.UI.MouseEventArgs mevent) { BufferChunk chunk = new BufferChunk(1024); chunk += SpaceControlChannel.SC_MouseEvent; CodecUtils.Pack(chunk, mevent.Source); chunk += mevent.MouseID; chunk += (int)mevent.EventType; chunk += (int)mevent.Button; chunk += mevent.X; chunk += mevent.Y; chunk += mevent.Clicks; chunk += mevent.Delta; PackCommand(chunk); }
Point[] UnpackPoints(BufferChunk chunk) { // Need to know how many points so that space can be allocated for them on the receiving end int numPoints = chunk.NextInt32(); // Allocate a points array of the right size Point[] points = new Point[numPoints]; // Encode each of the points for (int i = 0; i < numPoints; i++) { points[i].x = chunk.NextInt32(); points[i].y = chunk.NextInt32(); } return points; }
public override void BitBlt(int x, int y, PixelBuffer pixBuff) { // Create a buffer // It has to be big enough for the bitmap data, as well as the x,y, and command int dataSize = pixBuff.Pixels.Stride * pixBuff.Pixels.Height; BufferChunk chunk = new BufferChunk(dataSize + 128); // now put the basic command and simple components in chunk += SpaceControlChannel.SC_BitBlt; CodecUtils.Pack(chunk, x, y); CodecUtils.Pack(chunk, pixBuff.Pixels.Width, pixBuff.Pixels.Height); chunk += dataSize; // Finally, copy in the data chunk.CopyFrom(pixBuff.Pixels.Data, dataSize); PackCommand(chunk); }
TRIVERTEX[] UnpackTRIVERTEX(BufferChunk chunk) { int nVertices = chunk.NextInt32(); TRIVERTEX[] pVertex = new TRIVERTEX[nVertices]; // Pack the vertices, starting with the length for (int i = 0; i < nVertices; i++) { pVertex[i].x = chunk.NextInt32(); pVertex[i].y = chunk.NextInt32(); pVertex[i].Alpha = chunk.NextUInt16(); pVertex[i].Blue = chunk.NextUInt16(); pVertex[i].Green = chunk.NextUInt16(); pVertex[i].Red = chunk.NextUInt16(); } return pVertex; }
void SendAudioEvent(AudioEvent anEvent) { BufferChunk chunk = new BufferChunk(anEvent.DataLength + 100); //public ushort cbSize; //public ushort wBitsPerSample; //public int nAvgBytesPerSec; //public short nBlockAlign; //public short nChannels; //public int nSamplesPerSec; //public short wFormatTag; chunk += (int)anEvent.WaveFormat.nChannels; chunk += (int)anEvent.WaveFormat.nSamplesPerSec; chunk += (int)anEvent.WaveFormat.wBitsPerSample; chunk += (int)anEvent.DataLength; chunk += anEvent.DataBuffer; fAudioChannel.Send(chunk); }
public virtual void ReceiveChunk(BufferChunk aRecord) { // First read out the record type int recordType = aRecord.NextInt32(); // Then deserialize the rest from there switch (recordType) { //case (int)UICommands.PixBlt: // { // // Get the X, Y // int x = aRecord.NextInt32(); // int y = aRecord.NextInt32(); // // get the length of the image bytes buffer // int dataSize = aRecord.NextInt32(); // byte[] imageBytes = (byte[])aRecord; // // Create a memory stream from the imageBytes // MemoryStream ms = new MemoryStream(imageBytes, false); // // Create a pixelArray from the stream // Bitmap bm = (Bitmap)Bitmap.FromStream(ms); // PixelArray<BGRAb> pixMap = PixelBufferHelper.CreatePixelArrayFromBitmap(bm); // // And finally, call the PixBlt function // PixBltBGRAb(pixMap, x, y); // } // break; case (int)UICommands.PixBltRLE: { // Get the X, Y int x = aRecord.NextInt32(); int y = aRecord.NextInt32(); int width = aRecord.NextInt32(); int height = aRecord.NextInt32(); // get the length of the image bytes buffer int dataSize = aRecord.NextInt32(); byte[] imageBytes = (byte[])aRecord; // Create a memory stream from the imageBytes MemoryStream ms = new MemoryStream(imageBytes, false); // Create a pixelArray from the stream if ((width != fPixMap.Width) || (height != fPixMap.Height)) fPixMap = new GDIDIBSection(width, height); TargaRunLengthCodec rlc = new TargaRunLengthCodec(); PixelAccessorBGRb accessor = new PixelAccessorBGRb(fPixMap.Width, fPixMap.Height, fPixMap.Orientation, fPixMap.Pixels, fPixMap.BytesPerRow); rlc.Decode(ms, accessor); // And finally, call the local PixBlt function PixBltPixelBuffer24(fPixMap, x, y); } break; case (int)UICommands.PixBltLuminance: { // Get the X, Y int x = aRecord.NextInt32(); int y = aRecord.NextInt32(); int width = aRecord.NextInt32(); int height = aRecord.NextInt32(); // get the length of the image bytes buffer int dataSize = aRecord.NextInt32(); byte[] imageBytes = (byte[])aRecord; // Create a memory stream from the imageBytes MemoryStream ms = new MemoryStream(imageBytes, false); // Create a pixelArray from the stream if ((width != fGrayImage.Width) || (height != fGrayImage.Height)) fGrayImage = new PixelArray<Lumb>(width, height); TargaLuminanceRLE rlc = new TargaLuminanceRLE(); rlc.Decode(ms, fGrayImage); // And finally, call the local PixBlt function PixBltLumb(fGrayImage, x, y); } break; case (int)UICommands.Showcursor: { ShowCursor(); } break; case (int)UICommands.HideCursor: { HideCursor(); } break; case (int)UICommands.MoveCursor: { int x = aRecord.NextInt32(); int y = aRecord.NextInt32(); MoveCursor(x, y); } break; default: //if (CommandReceived != null) // CommandReceived(aRecord); break; } }
public CommPacket(BufferChunk aChunk) :base(aChunk) { }
public void SendAudioFrame(BufferChunk chunk) { if (null != AudioChannel) { AudioChannel.Send(chunk); } }