CIS-3030 Homework #2: PNG Chunk Manipulation

Due: Wednesday, September 18, 2013

Read chapters 4, 5, and 6 in the text. This is quite a lot of material but it represents the core of Haskell. We'll spend time over the next couple of weeks working with some examples to help you practice with the concepts.

In this assignment you will be writing some functions that manipulate binary data in PNG graphics files. See chapter 8 of PNG: The Definitive Guide for details on the structure of a PNG file. Roughly, a PNG file consists of a signature of eight bytes followed by an open ended number of "chunks." Each chunk consists of a length, a chunk type descriptor, a block of image data (or other information depending on the chunk type), and finally a CRC checksum.

You will need to import Data.Word to access the fixed sized unsigned integer type Word8. This type can be used to represent a single byte of data. For this assignment the PNG data will be presented to your functions as a list of Word8 objects. You will also need to import Data.Bits to access the various bit manipulation functions. See the Haskell Report sections on Data.Bits and Data.Word for more details about these library modules.

Write the following functions

      -- Returns True if the given list starts with a valid PNG signature.
      hasPNGHeader :: [Word8] -> Bool

      -- Returns the number of PNG chunks in the list.
      chunkCount :: [Word8] -> Int

      -- Breaks the PNG file into a list of its chunks.
      splitPNG :: [Word8] -> [[Word8]]

      -- Computes the CRC checksum over the given list using the algorithm in the PNG spec.
      computeCRC :: [Word8] -> Word32

      -- Verifies the CRC checksum on each chunk in a list of chunks.
      verifyCRC :: [[Word8]] -> [Bool]
    

The PNG CRC computation is described in the official specification of the PNG format.


Last Revised: 2013-09-01
© Copyright 2013 by Peter C. Chapin <PChapin@vtc.vsc.edu>