TPNGImage help

PNG Delphi

Unit methods > Update_Crc


Method to allow calculating crc from data.

type TByteArray = array[word] of Byte;
type pByteArray = ^TByteArray;
procedure
update_crc(crc: Cardinal; buf: pByteArray; len: Integer): Cardinal;

Description
This method is used to calculte crc values from data. CRC is the value resulting for the previous calls for update_crc. Buf is a pointer to the data to calculate and len is the size for the data in Buf. When you haven't any previous crc to use with CRC parameter, set it as
$FFFFFFFF. When you finished calculating the value xor the resulting crc with $FFFFFFFF.

An example:

const
  DATA: ARRAY[0..3] of Char = ('C', 'R', 'C', 'C')
var
  crcvalue: Cardinal;
begin
  crcvalue := update_crc($FFFFFFFF, @Data[0], 1);
  crcvalue := update_crc(crcvalue, @Data[1], 1);
  crcvalue := update_crc(crcvalue, @Data[2], 1);
  crcvalue := update_crc(crcvalue, @Data[3], 1) xor $FFFFFFFF;
end;


is the same as:

const
  DATA: ARRAY[0..3] of Char = ('C', 'R', 'C', 'C')
var
  crcvalue: Cardinal;
begin
  crcvalue := update_crc($FFFFFFFF, @Data[0], 4) xor $FFFFFFFF;
end;