Changeset 38


Ignore:
Timestamp:
Aug 17, 2010, 3:28:20 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Testovací aplikace pro BitStream přepracována do oknové.
  • Opraveno: Chyba čtení bitového proudu pomocí metody Read.
Location:
BitStream
Files:
6 added
4 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • BitStream/UBitStream.pas

    r31 r38  
    11unit UBitStream;
    22
    3 // Date: 2010-06-14
     3// Date: 2010-08-17
    44
    55{$mode delphi}
     
    110110end;
    111111
    112 function TBitStream.CopyFrom(Source:TBitStream;Count:LongInt):LongInt;
    113 var
    114   I: LongInt;
     112function TBitStream.CopyFrom(Source: TBitStream; Count: LongInt): LongInt;
     113var
     114  BlockSize: LongInt;
    115115  Buffer: array[0..1023] of Byte;
    116116begin
    117117  Result := 0;
    118118  while Count > 0 do begin
    119     if Count > (SizeOf(Buffer) * 8) then I := SizeOf(Buffer) * 8
    120       else I := Count;
    121     I := Source.Read(Buffer, I);
    122     I := Write(Buffer, I);
    123     if I = 0 then Break;
    124     Dec(Count, I);
    125     Result := Result + I;
     119    if Count > (SizeOf(Buffer) * 8) then BlockSize := SizeOf(Buffer) * 8
     120      else BlockSize := Count;
     121    BlockSize := Source.Read(Buffer, BlockSize);
     122    BlockSize := Write(Buffer, BlockSize);
     123    if BlockSize = 0 then Break;
     124    Dec(Count, BlockSize);
     125    Result := Result + BlockSize;
    126126  end;
    127127end;
     
    201201  ByteCount: LongInt;
    202202  I: LongInt;
    203   BytePos: Byte;
     203  PosInByte: Byte;
    204204  Data: Byte;
    205205begin
     
    208208    if (FPosition + Count) > FSize then Count := FSize - FPosition;
    209209    ByteCount := Ceil(Count / 8);
    210     BytePos := FPosition mod 8;
     210    PosInByte := FPosition mod 8;
    211211    Stream.Position := Trunc(FPosition / 8);
    212     Data := Stream.ReadByte;
     212    Data := Stream.ReadByte; // Read first byte
    213213    for I := 0 to ByteCount - 1 do begin
    214       TBytes(Buffer)[I] := (Data shr BytePos) and ((1 shl (8 - BytePos)) - 1);
    215       if I <> (ByteCount - 1) then
    216         Data := Stream.ReadByte;
    217       if BytePos > 0 then
    218         TBytes(Buffer)[I] := TBytes(Buffer)[I] or (Data and ((1 shl BytePos) - 1)) shl (8 - BytePos);
    219       if (I = (ByteCount - 1)) and (BytePos > 0) then
    220         TBytes(Buffer)[I] := TBytes(Buffer)[I] and ((1 shl (Count mod 8)) - 1);
     214      TBytes(Buffer)[I] := (Data shr PosInByte) and ((1 shl (8 - PosInByte)) - 1);
     215      if (I < ByteCount) and (Stream.Position < Stream.Size) then
     216        Data := Stream.ReadByte else Data := 0;
     217      if PosInByte > 0 then
     218        TBytes(Buffer)[I] := TBytes(Buffer)[I] or
     219          ((Integer(Data) and ((1 shl PosInByte) - 1)) shl (8 - PosInByte));
     220      //if (I = (ByteCount - 1)) and (PosInByte > 0) then
     221      //  TBytes(Buffer)[I] := TBytes(Buffer)[I] and ((1 shl (Count mod 8)) - 1);
    221222    end;
    222223    Inc(FPosition, Count);
     
    232233  BytePos: Byte;
    233234  Data: Byte;
     235
    234236function Min(Value1, Value2: Integer): Integer;
    235237begin
    236   if Value1 < Value2 then Result := Value1 else Result := Value2;
     238  if Value1 < Value2 then Result := Value1
     239    else Result := Value2;
    237240end;
    238241
     
    283286destructor TMemoryBitStream.Destroy;
    284287begin
    285   FStream.Destroy;
     288  FStream.Free;
    286289  inherited Destroy;
    287290end;
Note: See TracChangeset for help on using the changeset viewer.