How can you make a C++ program to generate and manipulate PNG images?

I have some experience programming but haven't really worked with images before. I have no idea where to start. The program has to run on Unix. This is the assignment:

Develop a program for image manipulation using object-oriented programming in C++.

The program does not need to have a graphical user interface or be able to display images: images should be created using a sequence of calls to the class member functions. The results can ultimately be displayed using widely available image viewers.

The project should implement the following classes

* GeometricObject
o Circle
o Rectangle
o Polygon
* Image

Your image class should have a member function createPngFile which will create a valid PNG format image file corresponding to the image object.

You can start your geometric objects classes using the texts' definitions, but you will need to extend them to handle position among other things.
This must be a pretty advanced class if your professor wants you to write a PNG file?

You might want to google "png file format". It is possible to write a very simple, uncompressed PNG.

Good luck.
closed account (z05DSL3A)
@fuze365

“I have some experience programming but haven't really worked with images before. I have no idea where to start.”

I would have to make some assumptions as to what you require. The first assumption being that this is a one off assignment that is not going to be developed over time in your course.

When you say you have no idea where to start, do you mean in general or with regards to images? In general start with the Image class, with images start with the data structure.

I will assume that you will want a simple colour space [cs], so something like RGB.
1
2
3
4
5
6
7
typedef unsigned char UBYTE1 ;
struct Color
{
    UBYTE1 blue ;
    UBYTE1 green ;
    UBYTE1 red ;
}; 


Logically your image data will be a 2D array of Colors, but the physical representation will depend on things like will you have a fixed size image, Do you want to keep it simple and index with [x][y] or have a big chunk of memory and play with pointer?

Anyway, your image class will need methods for getting and setting colours at x,y coordinates for your GeometricObjects to call to ‘draw’ on your image.

For info on PNG, try the following two resources (they may scare you a bit, but I’m assuming you will not need to do a full implementation).
http://www.faqs.org/ftp/rfc/pdf/rfc2083.txt.pdf
http://www.w3.org/TR/PNG/

[cs] http://en.wikipedia.org/wiki/Color_space

Hope that helps.
Thank you guys I am working on it right now...
Topic archived. No new replies allowed.