Screen Scanner - Psychlo

Post date: Jul 28, 2011 6:46:55 PM

"Just got inspired last night and decided to start a class to get the screen in "blocks" and check which one has changed to update only those."

(* ********************************
*  uScreenScanner.pas             *
*  version: 1.0                   *
*  by Psychlo                     *
*                                 *
*  15/07/2011                     *
*  ic0de.org                      *
*                                 *
*  Music: Breaking Benjamin       *
*                                 *
*  Add me into the credits of     *
*    your RAT ;)                  *
*                                 *
*  Thanks to:                     *
*    iC0de Community              *
*    Torry's Delphi Page          *
*    givex8                       *
*    Protocol                     *
*    dn5                          *
******************************** *)
unit uScreenScanner;
interface
uses
  Windows, SysUtils, Graphics;
const
  ERRORMSG_INCORRECT_WIDTH = 'Width must be multiple of 8!';
  ERRORMSG_INCORRECT_HEIGHT = 'Height must be multiple of 8!';
type
  TBmpPack = packed record
    Bmp: TBitmap;
    Modified: Boolean;
  end;
  TBmpArray = Array of TBmpPack;
  TScreenScanner = class
    private
      fDivScreen: Integer;
      fScreenWidth, fScreenHeight: Integer;
      fWatchRect: TRect;
      fScreenArray: Array of TBmpArray;
      function CompareBitmap(Bmp1, Bmp2 : TBitmap): Integer;
    published
      constructor Create(
        const DivScreen: Integer = 8;
        const X: Integer = 0;
        const Y: Integer = 0;
        const Width: Integer = 0;
        const Height: Integer = 0
      );
      destructor Destroy; override;
      procedure ScanScreen;
      function GetSnapshot(lpRect: TRect): TBitmap;
      function GetBitmapRect(lpRect: TRect; Bitmap: TBitmap): TBitmap;
      function GetBmpPack(i, j: Integer): TBmpPack;
      function IsBmpPackModified(i, j: Integer): Boolean;
      property ColumnCount: Integer read fDivScreen;
      property RowCount: Integer read fDivScreen;
      property ScreenWidth: Integer read fScreenWidth;
      property ScreenHeight: Integer read fScreenHeight;
  end;
implementation
//... to be continued in attachment ;) ...

Basically this project does this:

Gets a snapshot of the screen;

Saves it in a matrix 8x8;

Updates the blocks that changes;

Shows the blocks in a reduced size to fit the form (about 2/3 of your resolution, but that is just me playing around).

So far I have done few tests. In a 1920x1080 and 3 secs update rate resolution considering compression capacity of 15%, gives me about 2~8kb/s for "small changes" in the screen. Of course that if the entire screen changes there are peaks. I found peaks of 400kb/s.

Only Delphi source code is included in the archive.