MP3
Inside a PNG
Due dates may be found on the schedule.
Background on Chunk-based Media Files In 1985 Electronic Arts introduced a concept for storing media files as a sequence of packets or chunks of binary data, each preceded by a short label stating what type of data the chunk contained. Their Interchange File Format was adopted with slight tweaks by Microsoft as the Resource Interchange File Format (RIFF) on top of which Windows 3.1’s video, audio, and user interface element file formats were built. Since then that model has come to dominate the media file formats: many formats have the general form of a sequence of chunks, each with a header that specifies its type and size, coupled with specific rules for interpreting the bytes of certain chunk types. One benefit of this design is that basic applications can skip chunks they don’t understand and still get partial functionality, and updates to the format can add new features in new chunk types without breaking any existing files or applications.

PNG is a chunk-based file format. It is an open format, completely specified in a public royalty-free document, https://www.w3.org/TR/png/. The goal of a specification like that is to leave no ambiguity in how to create a file or interpret one you receive, which can lead to them being rather dense and difficult to read. Various parties sometimes make less-complete but easier-to-read summaries, such as https://en.wikipedia.org/wiki/PNG, which can be an easier place for a someone new to the format to start.

In this assignment you will

  1. Show sufficient understanding of PNG to
    1. List the chunks in a provided PNG file and the types.
    2. Copy the contents of a single chunk identified by type to a separate file.
    3. Replace the contents of a given chunk with new data, or add that chunk if not present.
  2. Write an application that stores other files inside custom chunks of a PNG and extracts such chunks if present.

1 Initial Files

mp3.zip contains header files, testers, and a Makefile. You will add to the following files:

The first three of these will be command-line application; we provide the basic command-line argument count checking for you and you write the rest. The pnglib files will not be directly tested, but can be used to keep your code organized.

These initial files provide very little structure. We have a general guide on coding from blank files that might be helpful to some of you.

A learning goal of this MP is working without us giving you a design or guide to getting started on this MP specifically. Please don’t ask course staff to bypass that goal by telling you how to design your code.

The two most common student questions
Question
How do I get started?
Answer
What is one thing your code will need to do? Write code to do that, then once it’s working move on to the next thing it will need to do.

 

Question
I’m stuck, what do I do next?
Answer
Walk through each line in the debugger, step by step. Check that the variable values after each line makes sense. See where it is in the file when it gets to the end of your code, then ask what comes next? and do that.

2 Create application pngchunklist

This application lists the type and size of each chunk in the PNG file in the order that they appear in the file. The format of this should be one printed-out line per chunk, each with the type, a space, and the length.

You can implement it in whatever way you wish, provided that you write all the code yourself without copying from any AI system or third party. We recommend using the following libraries:

Coding this application shouldn’t require malloc and should fseek past most of the bytes in the file.

For extra credit, add the following features to this application:

Extra credit is graded all-or-nothing and is only awarded on an MP if all normal credit is, so focus on passing the regular tests first.

3 Create application extractuiucchunk

This application looks for a special chunk with type uiuc; if found, it copies its contents into a separate file. If there is more than one such chunk, it copies the first and then exits with code 0. If there is no such chunk, prints an error message to stderr and exists with code 4.

You can implement it in whatever way you wish, provided that you write all the code yourself without copying from any AI system or third party. We recommend sharing significant code from pngchunklist (ideally by putting the chared code in library functions in pnglib.c and pnglib.h), and additionally using the following libraries:

4 Create application insertuiucchunk

Makes a copy of a PNG file with a new uiuc chunk. If the input PNG file already has a uiuc chunk, replaces it. If not, adds it between two existing chunks.

You can implement it in whatever way you wish, provided that you write all the code yourself without copying from any AI system or third party. We recommend sharing significant code with the other two applications (ideally by putting the shared code in library functions in pnglib.c and pnglib.h).

You’ll also need to generate a crc32 checksum; this is a computation based in coding theory which most CS programs either don’t teach at all or only teach it in an elective course. Perhaps that is why the code you need is given in the PNG specification in Appendix D. Note there are three functions in that appendix: the first to be run just once, the second to be given bytes of a chunk (either all at once or a bit at a time, it makes no difference), and the third a reference showing how you’d use the second if you have the entire chunk in one array of unsigned characters. Also note that the appendix is somewhat old and assumes that long means a 32-bit integer; currently int (or int32_t from #include <stdint.h>) is the type with that size.

5 Use insertuiucchunk

Put a secret payload inside a PNG of your choice and share it on the CampusWire post MP3 Image Share. This is an opportunity to share a bit about yourself and your interests; please keep it (both the image and its hidden contents) inoffensive.

6 Submission and Grading

Submit on the submission site. Submit pngchunklist.c, extractuiucchunk.c, and insertuiucchunk.c; if you changed them, also submit pnglib.c and pnglib.h. Do not change or submit the Makefile, tests, or example images.

6.1 Grading

Automated tests are provided in the make test target. These use specific images in the provided img/ directory to run. On the testing server, a different set of images will be used; that should have no impact on your grading if you’ve parsed the PNG files, but will reduce your score if you’ve hard coded solutions to specific files or test cases.

The three programs are weighted as follows:

Valgrind will also be run, and if it gives errors other points will be reduced by 10–25%, depending on how many applications have memory errors.