Recent

Author Topic: [SOLVED] Scanning raw buffered data for blocks of zero  (Read 8060 times)

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: [SOLVED] Scanning raw buffered data for blocks of zero
« Reply #15 on: April 09, 2015, 11:49:43 am »
I think you want something like this:

Code: [Select]
procedure TForm1.ViewIgnoreZone(aList: TList);
var
  i : integer;
  sl : TStringList;
begin
  Assert(aList<>nil,'List parameter is nil');
  sl := TStringList.Create;
  try
    for i := 0 to aList.Count-1 do
      sl.Add(IntToStr(integer(aList.Items[i])));
    ShowMessage(sl.Text);
  finally
    sl.free;
  end;
end;

rasberryrabbit

  • Full Member
  • ***
  • Posts: 150
Re: [SOLVED] Scanning raw buffered data for blocks of zero
« Reply #16 on: April 09, 2015, 12:47:20 pm »
My useless function  :-[

It may help you.

Code: [Select]
function ScanZeroBlock(buf : Pchar; startpos, len:Integer; var FindPos:Integer):Integer;
var
  i : Integer;
  d4 : longword;
  d2 : word;
begin
  Result:=0;
  FindPos:=-1;
  Inc(buf,startpos);
  Dec(len,startpos);
  while len>0 do begin
    if len>3 then begin
      d4 := PLongword(buf)^;
      {$ifndef ENDIAN_LITTLE}
      d4:=Swap(d4);
      {$endif}
      if d4=0 then begin
        if FindPos=-1 then
           FindPos:=startpos;
        Inc(Result,4);
        Inc(StartPos,4);
      end else begin
        for i:=0 to 3 do begin
          if d4 and $ff=0 then begin
            if FindPos=-1 then
               FindPos:=startpos;
            Inc(Result);
          end else begin
            if FindPos>-1 then
               exit;
          end;
          d4:=d4 shr 8;
          Inc(startpos);
        end;
      end;
      Dec(len,4);
      Inc(buf,4);
    end else if len>1 then begin
      d2 := PWord(buf)^;
      {$ifndef ENDIAN_LITTLE}
      d2:=Swap(d2);
      {$endif}
      if d2=0 then begin
        if FindPos=-1 then
           FindPos:=startpos;
        Inc(Result,2);
        Inc(StartPos,2);
      end else begin
        for i:=0 to 1 do begin
          if d2 and $ff=0 then begin
            if FindPos=-1 then
               FindPos:=startpos;
            Inc(Result);
          end else begin
            if FindPos>-1 then
               exit;
          end;
          d2:=d2 shr 8;
          Inc(startpos);
        end;
      end;
      Dec(len,2);
      Inc(buf,2);
    end else if len>0 then begin
      if byte(buf^) and $ff=0 then begin
        if FindPos=-1 then
           FindPos:=startpos;
        Inc(Result);
      end else begin
        if FindPos>-1 then
           exit;
      end;
      Dec(len);
    end;
  end;

end;
Code is long, Life is short, AI is not your enemy.

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: [SOLVED] Scanning raw buffered data for blocks of zero
« Reply #17 on: April 09, 2015, 06:59:11 pm »
Thanks Howard - that works! First time I ever seen that step necessary so you live and learn.

Parcel - many thanks for taking the effort to write what you've done. It is appreciated. Nothing is useless.

 

TinyPortal © 2005-2018