Data representing an image taken from a device frame buffer.
示例#1
0
        public RawImage GetFrameBuffer( IPEndPoint adbSockAddr, IDevice 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 );
                if ( !Write ( adbChan, request ) )
                    throw new IOException ( "failed asking for frame buffer" );

                AdbResponse resp = ReadAdbResponse ( adbChan, false /* readDiagString */);
                if ( !resp.IOSuccess || !resp.Okay ) {
                    this.LogError ( "Got timeout or unhappy response from ADB fb req: " + resp.Message );
                    adbChan.Close ( );
                    return null;
                }

                // first the protocol version.
                reply = new byte[4];
                if ( !Read ( adbChan, reply ) ) {
                    this.LogError ( "got partial reply from ADB fb:" );

                    adbChan.Close ( );
                    return null;
                }
                BinaryReader buf;
                int version = 0;
                using ( MemoryStream ms = new MemoryStream ( reply ) ) {
                    buf = new BinaryReader ( ms );

                    version = buf.ReadInt32 ( );
                }

                // get the header size (this is a count of int)
                int headerSize = RawImage.GetHeaderSize ( version );
                // read the header
                reply = new byte[headerSize * 4];
                if ( !Read ( adbChan, reply ) ) {
                    this.LogWarn ( "got partial reply from ADB fb:" );

                    adbChan.Close ( );
                    return null;
                }
                using ( MemoryStream ms = new MemoryStream ( reply ) ) {
                    buf = new BinaryReader ( ms );

                    // fill the RawImage with the header
                    if ( imageParams.ReadHeader ( version, buf ) == false ) {
                        this.LogWarn ( "Unsupported protocol: " + version );
                        return null;
                    }
                }

                this.LogDebug ( "image params: bpp=" + imageParams.Bpp + ", size="
                                + imageParams.Size + ", width=" + imageParams.Width
                                + ", height=" + imageParams.Height );

                if ( !Write ( adbChan, nudge ) )
                    throw new IOException ( "failed nudging" );

                reply = new byte[imageParams.Size];
                if ( !Read ( adbChan, reply ) ) {
                    this.LogWarn ( "got truncated reply from ADB fb data" );
                    adbChan.Close ( );
                    return null;
                }

                imageParams.Data = reply;
            } finally {
                if ( adbChan != null ) {
                    adbChan.Close ( );
                }
            }

            return imageParams;
        }
示例#2
0
        /**
         * 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;
        }
示例#3
0
 /// <summary>
 /// Gets the image from raw image.
 /// </summary>
 /// <param name="ri">The ri.</param>
 /// <returns></returns>
 private Image GetImageFromRawImage( RawImage ri )
 {
     try {
         this.LogDebug ( "Image Size: {0}", ri.Size.ToString ( ) );
         if ( ri.Bpp == 16 ) {
             return ri.ToImage ( PixelFormat.Format16bppRgb565 );
         } else if ( ri.Bpp == 32 ) {
             return ri.ToImage ( PixelFormat.Format32bppArgb );
         } else {
             return Rgb565.ToImage ( ri.Data );
         }
     } catch ( Exception ex ) {
         //Console.WriteLine ( ex );
         return null;
     }
 }