PNGwriter is a C++ library for creating PNG images.
Latest News:
Summary PNGwriter is a very easy to use open source graphics library that uses PNG as its output format. The interface has been designed to be as simple and intuitive as possible. It supports plotting and reading in the RGB (red, green, blue), HSV (hue, saturation, value/brightness) and CMYK (cyan, magenta, yellow, black) colour spaces, basic shapes, scaling, bilinear interpolation, full TrueType antialiased and rotated text support, bezier curves, opening existing PNG images and more. Documentation in English and Spanish. Runs under Linux, Unix, Mac OS X and Windows. Requires libpng and optionally FreeType2 for the text support.
Frequently Asked Questions: If your questions are not answered here, then post on the PNGwriter Forums, or send me an email. Why use the PNGwriter library? Because it is a fast and easy way of plotting directly from your C++ program.
PNGwriter lets you focus on your program, and saves you the trouble of learning how to create, use and read PNG images from scratch. You just need to specify what size you want your image, and then you go plotting pixel by pixel in a given colour with the plot function.
PNGwriter was originally written with scientists in mind. The need to create an image from the result of a scientific computer simulation arises as a natural part of scientific programming. Getting the data out of the program and into a high quality image in an efficient way can sometimes be hard, especially if the user is not a very experienced programmer. The methods used can often be highly inefficient or too complex to be feasible. If the data is in (x, y) form, then one can use any of the many plotting programs out there, like gnuplot, R. Brühl's excellent Abscissa and so on. If, on the other hand, the data is in (x, y, z) form, one must choose how to represent the third variable. Software such as Mathematica offers many alternatives in this respect, but if the amount of data points is considerable, rendering an image using Mathematica as an array of pixels using text-based data is many, many times slower than rendering the image to disk from the C++ program itself. Consider the bottlenecks involved: the program must produce a file, writing the data in ASCII mode. This is about two orders of magnitude slower than outputting the data in binary mode. It must then be rendered by Mathematica, using vector graphics (one object per pixel, though newer versions of Mathematica have better graphics handling capabilities). It is only at this stage that one can convert the image to a lossless bitmap image format such as PNG or TIFF. Another possibility is to use ImageMagick or Netpbm to process the data, but again, one is limited by the fact that the data must be written in ASCII format first, and support for 24-bit colour in the PPM file format is not standardized (i.e., mostly non-existent) and is endian-dependent. PNGwriter was written as a possible solution to this issue. Its interface is extremely intuitive, there is only one new object to learn about (the PNGwriter class), in other words, no classes and subclasses for pixels, colours, bitmaps, filenames, etc. As long as you know what colour you want the pixel at position (x, y) to be, you can implement any algorithm you want. Want to play with cellular automata but are tired of seeing you results as an array of 1s and 0s in text? Want to have a go at exploring fractals yourself? Need a quick way to implement that image-recognition algorithm you are working on for your autonomous rover, driverless vehicle or robot arm? Want to simulate gravitational lensing but haven't yet been able to create an actual image from your algorithm? Need to simulate an object moving on an energy surface, using interpolation between the available data points? PNGwriter can help!
What can I do with PNGwriter? PNGwriter enables you to do the following with an image:
Since one can generate an arbitrary number of PNG images with only one run of your program, and given that PNGwriter provides an easy way of renaming files given just an index number, creating movies of sequential images is now extremely easy. For this, one would just use MEncoder, or Apple's Quicktime Player. What *can't* I do with PNGwriter? There are certain things that PNGwriter will not do. For example, though PNGwriter (as of version 0.5.4) can read a very wide variety of PNG images, there are some variants that it has problems with. In summary:
Despite these limitations, PNGwriter will most likely read the vast majority of PNGs that you throw at it. Please see the Examples section for a detailed list of test images and how PNGwriter deals with them. Why use PNG images?
Because they are widely known and they use lossless compression.
They share some characteristics with GIF images, but unlike this format, PNG images are not tied by the copyright of the LZW compression that GIFs use. The PNG format is open, free, and good. They offer the possibility of using Alpha Channels (better than simple transparency, though please note that PNGwriter supports neither) and a whole lot of other useful and interesting things. You don't even have to convert the PNG images your program can make with PNGwriter if you want to use them on a web page, for example: as a matter of fact, PNG stands for Portable Network Graphics-- they were designed for internet use and any decent browser can view them. Most of the graphics on this site are PNG images. For more information, please visit www.libpng.org. Who might benefit from using this C++ library?
I wrote PPMWriter (see below) because I wanted something that would allow me to plot pixel by pixel to an image, giving the coordinates and colour coefficients. It was useful (though PNGwriter has come far, far further than PPMWriter) yet limited and not entirely bug-free :-), but there werent many programs that could open PPM images properly. So I wrote PNGwriter.
In principle it could be useful to anyone that needs to plot images of high quality generated by their C++ programs (simulations, calculations, etc.), and not diagrams or (x, y) line plots.
What do I need to be able to use PNGwriter? A C++ compiler, and libpng. libpng works on Unix, DOS, OS/2, Windows, Mac OS, BeOS, Amiga, etc. If your compiler is old, my personal recommendation is to get GCC. See www.cplusplus.com/info/compilers/#free for some information on free compilers. Also, if you wish to compile PNGwriter with text support, you will need FreeType2. If you're on Windows, check the How can I use PNGwriter under Windows? section.
Sounds interesting, how is it used?
If you want to see an example of the simplest possible use of PNGwriter, go to Quickstart. That is the bare minimum that you need to know to be able to use PNGwriter (and all you need to know, in most cases).
If you want to see more examples of PNGwriter in use, go to Examples.
If you want to have a look at the PNGwriter manual go to Manual. The PNGwriter package available in Downloads contains two complete examples and a PDF Manual. The header file for the library is also extensively commented.
If you want to ask a question, you can send an email to the email you'll find in Contacts, or you can post a messasge on the forum.
Can PNGwriter draw text and graph axes? Yes, PNGwriter now has full text support capabilities (including UTF-8 support), but it does not do axes. Here is the official reason: PNGwriter is aimed at the fast and intuitive creation of high quality images in scientific and image processing contexts. Any bitmap image requiring axes and that must be published at publication-quality should be using vector graphics for the axes (and maybe the text), not bitmap, and combine both in an EPS.
So, is all lost? Is there nothing that can be done? Of course not! Here's a solution: Create PNG images of the graph axes you want to add using your method of choice (The Gimp, Photoshop, etc.). Make it black on white, for example. From your program, open this file with PNGwriter. Write a simple routine that takes all black pixels, and plots them onto your image, at the position you specify, and in whatever colour you want. This can be automated so that it is done after every image has been completed. How do I use PNGwriter under Windows?
Please note: Though there are guides on this site for compiling PNGwriter under Windows using some popular compilers, I cannot offer support for this task.
You should get hold of a Windows implementation of GCC, the free GNU C/C++ compiler (two possible ways to do this are www.mingw.org and www.cygwin.com). You can also use the Borland C++ Builder or Microsoft Visual C++ .NET on Windows XP. Here are two clear, step-by-step HowTos: " Setting Up PNGWriter for Borland C++ Builder Version 6 on Windows XP" and "Setting Up PNGWriter for Microsoft Visual C++ .NET on Windows XP".
Also, using PNGwriter with Bloodshed Dev C++ is quite easy, as pointed out by Siva Chandra: "You can download the pre-compiled libraries for freetype from the GnuWin32 web-site: gnuwin32.sf.net. To build PNGwriter itself, create a new C++ library project called libpngwriter. Include the PNGwriter header file and the implementation file into this new project. Then compile. And thats it. You will have a libpngwriter.a file ready for use. Note that this will by default assume availability of freetype. To remove such assumption, you will have to compile with this option: -DNO_FREETYPE".
Please note: pngwriter.cc has to be renamed to pngwiter.cpp for MSVC7. If the extension is not changed then the C/C++ folder for the project property does not become visible and hence the MSVC7's default of using compiled headers in its project build will always return an error about being unable to find some precompiled header. It is necessary to change that feature in the project property in order to successfully build the PNGwriter library using this compiler.
What's in the PNGwriter package? The source tarball/zip file contains the following items:
What can I do if I don't want to/can't install libpng? In principle, everyone should be able to use PNGwriter, even Windows users (see "How do I use PNGwriter under Windows?").
If they don't wish to, then there is always PPMWriter. It's a C++ class to make PPM images. They are simpler than PNG images, and less programs will correctly display them, but you can use this class on ANY computer and it is entirely self-contained. More information can be found at ket.dyndns.org/ppmwriter. Please Note: Development of PPMWriter ceased quite a while ago, and has only a fraction of the functions that PNGwriter has. I cannot offer support for PPMWriter. How can I link to the PNGwriter project from my page?
Did you find PNGwriter useful? If so, spread the word, and tell others about it, by placing the following button on you project page. You never know, it might be just what someone was looking for!
If you want, you can link directly to the image on the PNGwriter site. In that case, the code to add to your page would be: <a href="http://pngwriter.sourceforge.net/"><img src="http://pngwriter.sourceforge.net/site_images/madewith.png" width="88" height="31" alt="Made With PNGwriter" BORDER="0" target="_blank"></a>
What is PNGwriter's current development status?
Though I consider PNGwriter to be in active development, versions are not rushed out the door just to increase the version number. In fact, you can expect quite some time to elapse between releases. This is due partly to my own time constraints but also because I do not want to turn PNGwriter into a do-it-all library. There are already enough libraries that offer full PNG support.
I do, however, pledge to not let so much time pass between releases when I have been notified of bugs (as happened with the 0.5.3 -> 0.5.4 update).
About the Author I live in Santiago, Chile and Albuquerque, New Mexico. You might want to take a look at my blog, if you're into photography (or just nice photographs) or motorcycling. There's an English edition (The Flight of the Platypus) and a Spanish edition (El Cantar De La Lluvia), the latter of which is far larger.
|
||
© 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Paul Blackburn |