/** * Returns a rotated version of the image * The image is rotated counter-clockwise. */ public RawImage GetRotated( ) { RawImage rotated = new RawImage ( ); rotated.Version = this.Version; rotated.Bpp = this.Bpp; rotated.Size = this.Size; rotated.Red.Offset = this.Red.Offset; rotated.Red.Length = this.Red.Length; rotated.Green.Offset = this.Green.Offset; rotated.Green.Length = this.Green.Length; rotated.Blue.Offset = this.Blue.Offset; rotated.Blue.Length = this.Blue.Length; rotated.Alpha.Offset = this.Alpha.Offset; rotated.Alpha.Length = this.Alpha.Length; rotated.Width = this.Height; rotated.Height = this.Width; int count = this.Data.Length; rotated.Data = new byte[count]; int byteCount = this.Bpp >> 3; // bpp is in bits, we want bytes to match our array int w = this.Width; int h = this.Height; for ( int y = 0; y < h; y++ ) { for ( int x = 0; x < w; x++ ) { Array.Copy ( this.Data, ( y * w + x ) * byteCount, rotated.Data, ( ( w - x - 1 ) * h + y ) * byteCount, byteCount ); } } return rotated; }
public RawImage GetFrameBuffer(IPEndPoint adbSockAddr, Device device) { RawImage imageParams = new RawImage(); byte[] request = FormAdbRequest("framebuffer:"); //$NON-NLS-1$ byte[] nudge = { 0 }; byte[] reply; Socket adbChan = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { adbChan.Connect(adbSockAddr); adbChan.Blocking = true; // if the device is not -1, then we first tell adb we're looking to talk // to a specific device SetDevice(adbChan, device?.SerialNumber); Write(adbChan, request); AdbResponse resp = ReadAdbResponse(adbChan); if (!resp.IOSuccess || !resp.Okay) { Log.v(LOGGING_TAG, "Got timeout or unhappy response from ADB fb req: " + resp.Message); adbChan.Close(); return null; } // first the protocol version. reply = new byte[4]; Read(adbChan, reply); BinaryReader buf; int version = 0; using (MemoryStream ms = new MemoryStream(reply)) { buf = new BinaryReader(ms); version = buf.ReadInt16(); } // get the header size (this is a count of int) int headerSize = RawImage.GetHeaderSize(version); // read the header reply = new byte[headerSize*4]; Read(adbChan, reply); using (MemoryStream ms = new MemoryStream(reply)) { buf = new BinaryReader(ms); // fill the RawImage with the header if (imageParams.ReadHeader(version, buf) == false) { Log.v(LOGGING_TAG, "Unsupported protocol: " + version); return null; } } Log.d(LOGGING_TAG, "image params: bpp=" + imageParams.Bpp + ", size=" + imageParams.Size + ", width=" + imageParams.Width + ", height=" + imageParams.Height); Write(adbChan, nudge); reply = new byte[imageParams.Size]; Read(adbChan, reply); imageParams.Data = reply; } finally { adbChan?.Close(); } return imageParams; }