我该怎么用这个过程啊?
我在网上找到了这个,但我不知道我该怎么用啊?
该怎么引入一段数据流让它解压出来呢?解压以后的数据我怎么得到呢?
求大侠救救命,我DELPHI是赶鸭子上架啊
const // LZW encoding and decoding support
NoLZWCode = 4096;
type
PByte = ^Byte;
TByteStream = array[0..MaxInt - 1] of Byte;
PByteStream = ^TByteStream;
// abstract decoder class to define the base functionality of an encoder/decoder
TDecoder = class
public
procedure Decode(var Source: Pointer; Dest: Pointer; PackedSize, UnpackedSize: Integer); virtual; abstract;
procedure Encode(Source, Dest: Pointer; var FByteCounts: Cardinal); virtual; abstract;
end;
// Note: We need a different LZW decoder class for GIF because the bit order is reversed compared to that
// of TIFF and the code size increment is handled slightly different.
TGIFLZW = class(TDecoder)
private
FCodeSize: Cardinal;
FCodeMask: Cardinal;
FFreeCode: Cardinal;
FOldCode: Cardinal;
FPrefix: array[0..4095] of Cardinal; // LZW prefix
FSuffix, // LZW suffix
FStack: array [0..4095] of Byte; // stack
FStackPointer: PByte;
FTarget: PByte;
FFirstChar: Byte; // buffer for decoded byte
FClearCode,
FEOICode: Word;
function DecodeLZW(Code: Cardinal): Boolean;
public
InitialCodeSize: Byte; // must be set before decoding is started!
procedure Decode(var Source: Pointer; Dest: Pointer; PackedSize, UnpackedSize: Integer); override;
procedure Encode(Source, Dest: Pointer; var FByteCounts: Cardinal); override;
end;
implementation
function TGIFLZW.DecodeLZW(Code: Cardinal): Boolean;
var
InCode: Cardinal; // buffer for passed code
begin
// handling of clear codes
if Code = FClearCode then
begin
// reset of all variables
FCodeSize := InitialCodeSize + 1;
FCodeMask := (1 shl FCodeSize) - 1;
FFreeCode := FClearCode + 2;
FOldCode := NoLZWCode;
Result := True;
Exit;
end;
// check whether it is a valid, already registered code
if Code > FFreeCode then
raise Exception.Create('GIF LZW: invalid opcode.');
// handling for the first LZW code: print and keep it
if FOldCode = NoLZWCode then
begin
FFirstChar := FSuffix[Code];
FTarget^ := FFirstChar;
Inc(FTarget);
FOldCode := Code;
Result := True;
Exit;
end;
// keep the passed LZW code
InCode := Code;
// the first LZW code is always smaller than FFirstCode
if Code = FFreeCode then
begin
FStackPointer^ := FFirstChar;
Inc(FStackPointer);
Code := FOldCode;
end;
// loop to put decoded bytes onto the stack
while Code > FClearCode do
begin
FStackPointer^ := FSuffix[Code];
Inc(FStackPointer);
Code := FPrefix[Code];
end;
// place new code into code table
FFirstChar := FSuffix[Code];
FStackPointer^ := FFirstChar;
Inc(FStackPointer);
FPrefix[FFreeCode] := FOldCode;
FSuffix[FFreeCode] := FFirstChar;
// increase code size if necessary
if (FFreeCode = FCodeMask) and
(FCodeSize < 12) then
begin
Inc(FCodeSize);
FCodeMask := (1 shl FCodeSize) - 1;
end;
if FFreeCode < 4095 then Inc(FFreeCode);
// put decoded bytes (from the stack) into the target buffer
FOldCode := InCode;
repeat
Dec(FStackPointer);
FTarget^ := FStackPointer^;
Inc(FTarget);
until FStackPointer = @FStack;
Result := True;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TGIFLZW.Decode(var Source: Pointer; Dest: Pointer; PackedSize, UnpackedSize: Integer);
var
I: Integer;
Data, // current data
Bits, // counter for bit management
Code: Cardinal; // current code value
SourcePtr: PByte;
begin
FTarget := Dest;
SourcePtr := Source;
// initialize parameter
FCodeSize := InitialCodeSize + 1;
FClearCode := 1 shl InitialCodeSize;
FEOICode := FClearCode + 1;
FFreeCode := FClearCode + 2;
FOldCode := NoLZWCode;
FCodeMask := (1 shl FCodeSize) - 1;
// init code table
for I := 0 to FClearCode - 1 do
begin
FPrefix[I] := NoLZWCode;
FSuffix[I] := I;
end;
// initialize stack
FStackPointer := @FStack;
Data := 0;
Bits := 0;
while PackedSize > 0 do
begin
// read code from bit stream
Inc(Data, SourcePtr^ shl Bits);
Inc(Bits, 8);
while Bits >= FCodeSize do
begin
// current code
Code := Data and FCodeMask;
// prepare next run
Data := Data shr FCodeSize;
Dec(Bits, FCodeSize);
// EOICode -> decoding finished, check also for badly written codes and
// terminate the loop as soon as the target is filled up
if (Code = FEOICode) or
((PChar(FTarget) - PChar(Dest)) >= UnpackedSize) then Exit;
if not DecodeLZW(Code) then Break;
end;
Inc(SourcePtr);
Dec(PackedSize);
end;
end;
该怎么引入一段数据流让它解压出来呢?解压以后的数据我怎么得到呢?
求大侠救救命,我DELPHI是赶鸭子上架啊
const // LZW encoding and decoding support
NoLZWCode = 4096;
type
PByte = ^Byte;
TByteStream = array[0..MaxInt - 1] of Byte;
PByteStream = ^TByteStream;
// abstract decoder class to define the base functionality of an encoder/decoder
TDecoder = class
public
procedure Decode(var Source: Pointer; Dest: Pointer; PackedSize, UnpackedSize: Integer); virtual; abstract;
procedure Encode(Source, Dest: Pointer; var FByteCounts: Cardinal); virtual; abstract;
end;
// Note: We need a different LZW decoder class for GIF because the bit order is reversed compared to that
// of TIFF and the code size increment is handled slightly different.
TGIFLZW = class(TDecoder)
private
FCodeSize: Cardinal;
FCodeMask: Cardinal;
FFreeCode: Cardinal;
FOldCode: Cardinal;
FPrefix: array[0..4095] of Cardinal; // LZW prefix
FSuffix, // LZW suffix
FStack: array [0..4095] of Byte; // stack
FStackPointer: PByte;
FTarget: PByte;
FFirstChar: Byte; // buffer for decoded byte
FClearCode,
FEOICode: Word;
function DecodeLZW(Code: Cardinal): Boolean;
public
InitialCodeSize: Byte; // must be set before decoding is started!
procedure Decode(var Source: Pointer; Dest: Pointer; PackedSize, UnpackedSize: Integer); override;
procedure Encode(Source, Dest: Pointer; var FByteCounts: Cardinal); override;
end;
implementation
function TGIFLZW.DecodeLZW(Code: Cardinal): Boolean;
var
InCode: Cardinal; // buffer for passed code
begin
// handling of clear codes
if Code = FClearCode then
begin
// reset of all variables
FCodeSize := InitialCodeSize + 1;
FCodeMask := (1 shl FCodeSize) - 1;
FFreeCode := FClearCode + 2;
FOldCode := NoLZWCode;
Result := True;
Exit;
end;
// check whether it is a valid, already registered code
if Code > FFreeCode then
raise Exception.Create('GIF LZW: invalid opcode.');
// handling for the first LZW code: print and keep it
if FOldCode = NoLZWCode then
begin
FFirstChar := FSuffix[Code];
FTarget^ := FFirstChar;
Inc(FTarget);
FOldCode := Code;
Result := True;
Exit;
end;
// keep the passed LZW code
InCode := Code;
// the first LZW code is always smaller than FFirstCode
if Code = FFreeCode then
begin
FStackPointer^ := FFirstChar;
Inc(FStackPointer);
Code := FOldCode;
end;
// loop to put decoded bytes onto the stack
while Code > FClearCode do
begin
FStackPointer^ := FSuffix[Code];
Inc(FStackPointer);
Code := FPrefix[Code];
end;
// place new code into code table
FFirstChar := FSuffix[Code];
FStackPointer^ := FFirstChar;
Inc(FStackPointer);
FPrefix[FFreeCode] := FOldCode;
FSuffix[FFreeCode] := FFirstChar;
// increase code size if necessary
if (FFreeCode = FCodeMask) and
(FCodeSize < 12) then
begin
Inc(FCodeSize);
FCodeMask := (1 shl FCodeSize) - 1;
end;
if FFreeCode < 4095 then Inc(FFreeCode);
// put decoded bytes (from the stack) into the target buffer
FOldCode := InCode;
repeat
Dec(FStackPointer);
FTarget^ := FStackPointer^;
Inc(FTarget);
until FStackPointer = @FStack;
Result := True;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TGIFLZW.Decode(var Source: Pointer; Dest: Pointer; PackedSize, UnpackedSize: Integer);
var
I: Integer;
Data, // current data
Bits, // counter for bit management
Code: Cardinal; // current code value
SourcePtr: PByte;
begin
FTarget := Dest;
SourcePtr := Source;
// initialize parameter
FCodeSize := InitialCodeSize + 1;
FClearCode := 1 shl InitialCodeSize;
FEOICode := FClearCode + 1;
FFreeCode := FClearCode + 2;
FOldCode := NoLZWCode;
FCodeMask := (1 shl FCodeSize) - 1;
// init code table
for I := 0 to FClearCode - 1 do
begin
FPrefix[I] := NoLZWCode;
FSuffix[I] := I;
end;
// initialize stack
FStackPointer := @FStack;
Data := 0;
Bits := 0;
while PackedSize > 0 do
begin
// read code from bit stream
Inc(Data, SourcePtr^ shl Bits);
Inc(Bits, 8);
while Bits >= FCodeSize do
begin
// current code
Code := Data and FCodeMask;
// prepare next run
Data := Data shr FCodeSize;
Dec(Bits, FCodeSize);
// EOICode -> decoding finished, check also for badly written codes and
// terminate the loop as soon as the target is filled up
if (Code = FEOICode) or
((PChar(FTarget) - PChar(Dest)) >= UnpackedSize) then Exit;
if not DecodeLZW(Code) then Break;
end;
Inc(SourcePtr);
Dec(PackedSize);
end;
end;
...全文
相关推荐
比较器在转换过程中为何会有振荡?
因此,在转换的过程中为什么存在振荡? 当转换电平缓慢改变的时候,这个现象经常会发生。常常是由于输入信号存在噪声,因此在转换电平
Twitter新员工的入职过程是什么样的?
Twitter新员工的入职过程是什么样的?这是有人在quora上提出的一个问题,做回答的是Twitter公司的业务运营经理AlexMcCauley。我们的入职过程大概是这样的:—在你开始工作之前是被我
西门子之如何实现过程变量的平均值归档?.pdf
西门子之如何实现过程变量的平均值归档?pdf,西门子之如何实现过程变量的平均值归档?在变量的人:编辑器中,用户可以通过打开“过程变量属性”对话框,在“加工”的“参数”页面中选择“平均值”选项,来定义该
什么是面向对象?什么是面向过程?
这是对面向过程和面向对象的解释,个人参考一些文章后做的小总结。
过程重要吗?
一个定义团队规模与沟通过程范围以及目的过程的目的随着范围的变化而变化过程层次需要适当的接口必须支持微过程所有这些组合在一起会产生什么结果呢?本文来自于RationalEdge:遵循软件开发中一个协调一致的过程的价值是确定无疑的。但是究竟需要什么样的过程呢?究竟有多复杂呢?需要什么样规模的团队?GaryPollice教授考虑到企业中对多样化过程的需求情况,详细回答了这些问题。在我参加2006年敏捷年会,这个会议讨论关于方法和技术的问题,之前。我已经开始编写这个月的理论与实践专栏中的文章,这篇文章是关于测试过程中使用和创建模拟对象的问题的。哦,我听到你说“天啦,这是唯一关于敏捷的论文。”我可以向你


语言基础/算法/系统设计
