-- © Copyright 2000 by John Halleck, All Rights Reserved.
-- PNG's CRC. It is defined by ISO 3309 [ISO-3309] or ITU-T V.42 [ITU-T-V42].
-- It uses the CRC polynomial:
-- x^32 + x^26 + x^23 + x^22 + x^16
-- + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
-- This implementation is more or less directly from the PNG standard.
-- The standard is found at: http://www.w3.org/TR/REC-png-multi.html
-- (Or was at the time I wrote this.)
with PNG_CRC_Table; use PNG_CRC_Table;
-- This code could just as well compute any other 32 bit CRC, just
-- by with'ing the table for the appropriate CRC.
-- See the PNG_CRC_Table_Generator code for the details.
package body PNG_CRC is
-- These are just implemented direct from the RFC. They are all so
-- simple that there is not much point in any commentary other
-- than pointing people at the RFC.
procedure Initialize (Given : out State) is
begin
Given := 16#FFFFFFFF#;
end Initialize;
procedure Process_Data (Given : in out State; Byte : Unsigned_8) is
begin
Given := Shift_Right (Given, 8) xor
State (Table (Unsigned_8 (Given and 16#FF#) xor Byte));
end Process_Data;
function Final_CRC (Given : in State) return CRC is
begin
return CRC (Given) xor 16#FFFFFFFF#;
end Final_CRC;
-- Just CRC a string.
function Process_String (Given : String) return CRC is
Status : State;
begin
Initialize (Status);
for I in Given'Range loop
Process_Data (Status, Unsigned_8 (Character'Pos (Given (I))));
end loop;
return Final_CRC (Status);
end Process_String;
end PNG_CRC;
This page is http://www.cc.utah.edu/~nahaj/ada/crc/png_crc.adb.html
© Copyright 2000 by John Halleck, All Rights Reserved.
This snapshot was last modified on August 11th, 2000
And the underlying file was last modified on August 5th, 2000