各位大虾,那位可以帮我把这段C的代码转成DELPHI的代码,谢谢了! ( 积分: 100 )

  • 主题发起人 主题发起人 freeskying_sy
  • 开始时间 开始时间
F

freeskying_sy

Unregistered / Unconfirmed
GUEST, unregistred user!
#define OFFSET 0x30
void encode(byte *Histogram, Byte *ASMTOutput, int HistSize)
{
int HistIdx, OutIdx;
long BitArray;
HistIdx = OutIdx = 0;
/*Convert the histogram 3 bytes at a time*/
while (HistIdx < HistSize - 2)
{
BitArray = Histogram[HistIdx];
BitArray = (BitArray << 8) + Histogram[HistIdx+1];
BitArray = (BitArray << 8) + Histogram[HistIdx+2];
ASTMOutput[OutIdx] = ((BitArray &amp;
0xFC0000) >> 18) + OFFSET;
ASTMOutput[OutIdx+1] = ((BitArray &amp;
0x03F0000) >> 12) + OFFSET;
ASTMOutput[OutIdx+2] = ((BitArray &amp;
0x000FC0) >> 6) + OFFSET;
ASTMOutput[OutIdx+3] (BitArray &amp;
0x00003F) + OFFSET;
HistIdx +=3;
OutIdx +=4;
}
if (HistIdx == HistSize - 2)
{
/* 2 bytes left in histogram */
BitArray = Histogram[HistIdx];
BitArray = (BitArray << 8) + Histogram[HistIdx+1];
ASTMOutput[OutIdx] = ((BitArray &amp;
0x03F0000 >> 12) + OFFSET;
ASTMOutput[OutIdx+1] = ((BitArray &amp;
0x000FC0) >> 6) + OFFSET;
ASTMOutput[OutIdx+2] = (BitArray &amp;
0x00003F) + OFFSET;
}
else
if (HistIdx == HistSize - 1)
{
/* 1 byte left in histogram */
BitArray = Histogram[HistIdx];
ASTMOutput[OutIdx] = ((BitArray &amp;
0x000FC0) >> 6) + OFFSET;
ASTMOutput[OutIdx+1] = (BitArray &amp;
0x00003F) + OFFSET;
}
}

void decode(byte *ASTMField, byte *Histogram, int FieldSize)
{
int FieldIdx, HistIdx:
long BitArray;
FieldIdx = HistIdx = 0;
/* Decode four characters at a time */
while (FieldIdx < FieldSize - 3)
{
BitArray = ASTMField[FieldIdx] - OFFSET;
BitArray = (BitArray << 6)+ (ASTMField[FieldIdx+1] - OFFSET);
BitArray = (BitArray << 6) + (ASTMField[FieldIdx+2] - OFFSET;
BitArray = (BitArray6 << 6) + (ASTMField[FieldIdx+3] - OFFSET;
Histogram[HistIdx] = (BitArray &amp;
0xFF0000) >> 16;
Histogram[HistIdx+1] = (BitArray &amp;
0x00FF00) >> 8;
Histogram[HistIdx+2] = (BitArray &amp;
0x0000FF);
FieldIdx +=4;
HistIdx +=3;
}
if (FieldIdx == FieldSize -3)
{
/* Three bytes left to convert */
BitArray = ASTMField[FieldIdx] - OFFSET;
BitArray = (BitArray << 6) + (ASTMField[FieldIdx+1] - OFFSET;
BitArray = (BitArray << 6) = ASTMField[FieldIdx+1] - OFFSET;
Histogram[HistIdx] = (BitArray &amp;
0x00FF00) >> 8;
Histogram[HistIdx+1] = (BitArray &amp;
0x0000FF0;
}
else
if (FieldIdx == FieldSize - 2)
{
/* Two bytes left to convert */
BitArray = ASTMField[FieldIdx] - OFFSET;
BitArray = (BitArray << 6) + (ASTMField[FieldIdx+1] - OFFSET;
Histogram[HistIdx] = (BitArray &amp;
0x0000FF);
}
}
 
#define OFFSET 0x30
void encode(byte *Histogram, Byte *ASMTOutput, int HistSize)
{
int HistIdx, OutIdx;
long BitArray;
HistIdx = OutIdx = 0;
/*Convert the histogram 3 bytes at a time*/
while (HistIdx < HistSize - 2)
{
BitArray = Histogram[HistIdx];
BitArray = (BitArray << 8) + Histogram[HistIdx+1];
BitArray = (BitArray << 8) + Histogram[HistIdx+2];
ASTMOutput[OutIdx] = ((BitArray &amp;
0xFC0000) >> 18) + OFFSET;
ASTMOutput[OutIdx+1] = ((BitArray &amp;
0x03F0000) >> 12) + OFFSET;
ASTMOutput[OutIdx+2] = ((BitArray &amp;
0x000FC0) >> 6) + OFFSET;
ASTMOutput[OutIdx+3] (BitArray &amp;
0x00003F) + OFFSET;
HistIdx +=3;
OutIdx +=4;
}
if (HistIdx == HistSize - 2)
{
/* 2 bytes left in histogram */
BitArray = Histogram[HistIdx];
BitArray = (BitArray << 8) + Histogram[HistIdx+1];
ASTMOutput[OutIdx] = ((BitArray &amp;
0x03F0000 >> 12) + OFFSET;
ASTMOutput[OutIdx+1] = ((BitArray &amp;
0x000FC0) >> 6) + OFFSET;
ASTMOutput[OutIdx+2] = (BitArray &amp;
0x00003F) + OFFSET;
}
else
if (HistIdx == HistSize - 1)
{
/* 1 byte left in histogram */
BitArray = Histogram[HistIdx];
ASTMOutput[OutIdx] = ((BitArray &amp;
0x000FC0) >> 6) + OFFSET;
ASTMOutput[OutIdx+1] = (BitArray &amp;
0x00003F) + OFFSET;
}
}

void decode(byte *ASTMField, byte *Histogram, int FieldSize)
{
int FieldIdx, HistIdx:
long BitArray;
FieldIdx = HistIdx = 0;
/* Decode four characters at a time */
while (FieldIdx < FieldSize - 3)
{
BitArray = ASTMField[FieldIdx] - OFFSET;
BitArray = (BitArray << 6)+ (ASTMField[FieldIdx+1] - OFFSET);
BitArray = (BitArray << 6) + (ASTMField[FieldIdx+2] - OFFSET;
BitArray = (BitArray6 << 6) + (ASTMField[FieldIdx+3] - OFFSET;
Histogram[HistIdx] = (BitArray &amp;
0xFF0000) >> 16;
Histogram[HistIdx+1] = (BitArray &amp;
0x00FF00) >> 8;
Histogram[HistIdx+2] = (BitArray &amp;
0x0000FF);
FieldIdx +=4;
HistIdx +=3;
}
if (FieldIdx == FieldSize -3)
{
/* Three bytes left to convert */
BitArray = ASTMField[FieldIdx] - OFFSET;
BitArray = (BitArray << 6) + (ASTMField[FieldIdx+1] - OFFSET;
BitArray = (BitArray << 6) = ASTMField[FieldIdx+1] - OFFSET;
Histogram[HistIdx] = (BitArray &amp;
0x00FF00) >> 8;
Histogram[HistIdx+1] = (BitArray &amp;
0x0000FF0;
}
else
if (FieldIdx == FieldSize - 2)
{
/* Two bytes left to convert */
BitArray = ASTMField[FieldIdx] - OFFSET;
BitArray = (BitArray << 6) + (ASTMField[FieldIdx+1] - OFFSET;
Histogram[HistIdx] = (BitArray &amp;
0x0000FF);
}
}
 
const
OFFSET = $30;
procedure encode(const Histogram;
var ASMTOutput;
HistSize: integer)
type
BArray = array [0..0] of Byte;
var
HistIdx, OutIdx: integer;
BitArray: longint;
begin
HistIdx := 0;
OutIdx := 0;
while (HistIdx < HistSize - 2)do
begin
BitArray := BArray(Histogram)[HistIdx];
BitArray := (BitArray shl 8) + BArray(Histogram)[HistIdx+1];
BitArray := (BitArray shl 8) + BArray(Histogram)[HistIdx+2];
BArray(ASTMOutput)[OutIdx] := ((BitArray and $FC0000) shr 18) + OFFSET;
BArray(ASTMOutput)[OutIdx+1] := ((BitArray and $03F0000) shr 12) + OFFSET;
BArray(ASTMOutput)[OutIdx+2] := ((BitArray and $000FC0) shr 6) + OFFSET;
BArray(ASTMOutput)[OutIdx+3] := (BitArray and $00003F) + OFFSET;
HistIdx := HistIdx + 3;
OutIdx := OutInd + 4;
end;
if (HistIdx = HistSize - 2) then
begin
BitArray := BArray(Histogram)[HistIdx];
BitArray := (BitArray shl 8) + BArray(Histogram)[HistIdx+1];
BArray(ASTMOutput)[OutIdx] := ((BitArray and $03F0000 shr 12) + OFFSET;
BArray(ASTMOutput)[OutIdx+1] := ((BitArray and $000FC0) shr 6) + OFFSET;
BArray(ASTMOutput)[OutIdx+2] := (BitArray and $00003F) + OFFSET;
end
else
if (HistIdx = HistSize - 1) then
begin
BitArray := BArray(Histogram)[HistIdx];
BArray(ASTMOutput)[OutIdx] := ((BitArray and $000FC0) shr 6) + OFFSET;
BArray(ASTMOutput)[OutIdx+1] := (BitArray and $00003F) + OFFSET;
end;
end;

procedure decode(const ASTMField;
var Histogram;
FieldSize: integer)
type
BArray = array [0..0] of Byte;
var
FieldIdx, HistIdx: integer;
BitArray: longint;
begin
FieldIdx := 0;
HistIdx := 0;
while (FieldIdx < FieldSize - 3)do
begin
BitArray := BArray(ASTMField)[FieldIdx] - OFFSET;
BitArray := (BitArray shl 6) + BArray(ASTMField)[FieldIdx+1] - OFFSET;
BitArray := (BitArray shl 6) + BArray(ASTMField)[FieldIdx+2] - OFFSET;
BitArray := (BitArray shl 6) + BArray(ASTMField)[FieldIdx+3] - OFFSET;
BArray(Histogram)[HistIdx] := (BitArray and $FF0000) shr 16;
BArray(Histogram)[HistIdx+1] := (BitArray and $00FF00) shr 8;
BArray(Histogram)[HistIdx+2] := (BitArray and $0000FF);
FieldIdx := FieldIdx + 4;
HistIdx := HistIdx + 3;
end;
if (FieldIdx = FieldSize -3) then
begin
BitArray := BArray(ASTMField)[FieldIdx] - OFFSET;
BitArray := (BitArray shl 6) + BArray(ASTMField)[FieldIdx+1] - OFFSET;
BitArray := (BitArray shl 6) + BArray(ASTMField)[FieldIdx+1] - OFFSET;
BArray(Histogram)[HistIdx] := BitArray and $00FF00) shr 8;
BArray(Histogram)[HistIdx+1] := BitArray and $0000FF0;
end
else
if (FieldIdx = FieldSize - 2) then
begin
BitArray := BArray(ASTMField)[FieldIdx] - OFFSET;
BitArray := (BitArray shl 6) + BArray(ASTMField)[FieldIdx+1] - OFFSET;
BArray(Histogram)[HistIdx] := (BitArray and $0000FF);
end;
end;


应该不会没什么遗漏处,自己再改改
用时代入引用而不是地址
encode(a^, b^, x);
 
const
OFFSET = $30
procedure encode(var Histogram,ASMTOutput:array of byte;HistSize:integer);
var
HistIdx, OutIdx : integer;
BitArray : cardinal;
begin
HistIdx := 0
OutIdx := 0
//Convert the histogram 3 bytes at a time
while (HistIdx < HistSize - 2)do
begin
BitArray := Histogram[HistIdx];
BitArray := BitArray shl 8 or Histogram[HistIdx+1];
BitArray := BitArray shl 8 or Histogram[HistIdx+2];
ASMTOutput[OutIdx ] := ((BitArray and $0FC0000) shr 18) + OFFSET;
ASMTOutput[OutIdx+1] := ((BitArray and $03F0000) shr 12) + OFFSET;
ASMTOutput[OutIdx+2] := ((BitArray and $0000FC0) shr 6) + OFFSET;
ASMTOutput[OutIdx+3] := (BitArray and $000003F) + OFFSET;
Inc(HistIdx,3)
Inc(OutIdx,4)
end
if (HistIdx = HistSize - 2)
then
begin
BitArray := Histogram[HistIdx];
BitArray := (BitArray shl 8) + Histogram[HistIdx+1];
ASMTOutput[OutIdx ] := (BitArray and $03F0000) shr 12 + OFFSET;
ASMTOutput[OutIdx+1] := (BitArray and $0000FC0) shr 6 + OFFSET;
ASMTOutput[OutIdx+2] := (BitArray and $000003F) + OFFSET;
end
else
if (HistIdx = HistSize - 1)
then
begin
BitArray := Histogram[HistIdx];
ASMTOutput[OutIdx ] := ((BitArray and $000FC0) shr 6) + OFFSET;
ASMTOutput[OutIdx+1] := (BitArray and $00003F) + OFFSET;
end
end;

procedure decode(var ASTMField,Histogram : array of byte;
FieldSize : integer);
var
FieldIdx,HistIdx : integer;
BitArray : cardinal;
begin
HistIdx := 0
FieldIdx := 0
while (FieldIdx < FieldSize - 3)do
begin
BitArray := ASTMField[FieldIdx] - OFFSET;
BitArray := (BitArray shl 6) + ASTMField[FieldIdx+1] - OFFSET;
BitArray := (BitArray shl 6) + ASTMField[FieldIdx+2] - OFFSET;
BitArray := (BitArray shl 6) + ASTMField[FieldIdx+3] - OFFSET;
Histogram[HistIdx ] := (BitArray and $FF0000) shr 16;
Histogram[HistIdx+1] := (BitArray and $00FF00) shr 8;
Histogram[HistIdx+2] := (BitArray and $0000FF);
Inc(FieldIdx,4);
Inc(HistIdx,3);
end;

if (FieldIdx = FieldSize -3)
then
begin
BitArray := ASTMField[FieldIdx] - OFFSET;
BitArray := (BitArray shl 6) + ASTMField[FieldIdx+1] - OFFSET;
BitArray := (BitArray shl 6) + ASTMField[FieldIdx+1] - OFFSET;
Histogram[HistIdx ] := (BitArray and $00FF00) shr 8;
Histogram[HistIdx+1] := BitArray and $0000FF0;
end
else
if (FieldIdx = FieldSize - 2)
then
begin
BitArray := ASTMField[FieldIdx] - OFFSET;
BitArray := (BitArray shl 6) + ASTMField[FieldIdx+1] - OFFSET;
Histogram[HistIdx] := BitArray and $0000FF;
end
end;
 
谢谢楼上的两位兄弟,给分!
 
刚才给someset兄的分自己感觉不好意思,另开一帖请someset过来领分!
 
真搞不明白你
还把这贴留着学术研究吗?
 
兄弟啊,答完了啊,给分结贴吧?
 
哈哈,光说给分却没有给;
 
后退
顶部