Changeset 38
- Timestamp:
- Aug 17, 2010, 3:28:20 PM (14 years ago)
- Location:
- BitStream
- Files:
-
- 6 added
- 4 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
BitStream/UBitStream.pas
r31 r38 1 1 unit UBitStream; 2 2 3 // Date: 2010-0 6-143 // Date: 2010-08-17 4 4 5 5 {$mode delphi} … … 110 110 end; 111 111 112 function TBitStream.CopyFrom(Source: TBitStream;Count:LongInt):LongInt;113 var 114 I: LongInt;112 function TBitStream.CopyFrom(Source: TBitStream; Count: LongInt): LongInt; 113 var 114 BlockSize: LongInt; 115 115 Buffer: array[0..1023] of Byte; 116 116 begin 117 117 Result := 0; 118 118 while Count > 0 do begin 119 if Count > (SizeOf(Buffer) * 8) then I:= SizeOf(Buffer) * 8120 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; 126 126 end; 127 127 end; … … 201 201 ByteCount: LongInt; 202 202 I: LongInt; 203 BytePos: Byte;203 PosInByte: Byte; 204 204 Data: Byte; 205 205 begin … … 208 208 if (FPosition + Count) > FSize then Count := FSize - FPosition; 209 209 ByteCount := Ceil(Count / 8); 210 BytePos:= FPosition mod 8;210 PosInByte := FPosition mod 8; 211 211 Stream.Position := Trunc(FPosition / 8); 212 Data := Stream.ReadByte; 212 Data := Stream.ReadByte; // Read first byte 213 213 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); 221 222 end; 222 223 Inc(FPosition, Count); … … 232 233 BytePos: Byte; 233 234 Data: Byte; 235 234 236 function Min(Value1, Value2: Integer): Integer; 235 237 begin 236 if Value1 < Value2 then Result := Value1 else Result := Value2; 238 if Value1 < Value2 then Result := Value1 239 else Result := Value2; 237 240 end; 238 241 … … 283 286 destructor TMemoryBitStream.Destroy; 284 287 begin 285 FStream. Destroy;288 FStream.Free; 286 289 inherited Destroy; 287 290 end;
Note:
See TracChangeset
for help on using the changeset viewer.