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
mp3.zip
contains header files, testers, and a Makefile. You will add to the following files:
pngchunklist.c
extractuiucchunk.c
insertuiucchunk.c
pnglib.c
and pnglib.h
(optional, provided to allow sharing code between the other three 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.
what comes next?and do that.
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:
fopen
fseek
fread
ntohl
printf
or an alternative display function. Remember that if you are printing a string it needs to be null-terminated; for example a 4-byte string is stored in 5 bytes, with the last one being 0.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:
IHDR
or IEND
chunks or has them in the wrong position in the file, print an error message to stderr and exit with code 4width
or height
, a space, and then the corresponding value. Print these two lines in the same order they appear within the PNG file.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.
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:
memcmp
(or strncmp
or the like)fwrite
malloc
and free
– not strictly required, but several simple approaches to the task would need them.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.
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.
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.
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.