Re: Simple Graphics Coding



maud said:

I would like to produce a number of maps with customized pushpins. I
do not need to embedded this into an application, however I need to
produce many more than I can manually construct. I was hoping someone
could recommend a simple application or programming environment to
work in. I have been thinking that if I get a background map image,
and then create a table of the pixel locations corresponding to map
locations, I would just need a program that given some sort of input
text file, created an image by placing a designated image on top of
the world map image at a designated pixel location.

Any ideas?

Writing a very simple image processing library is actually not so hard. The
easiest file format to use is probably the BMP format. (If your images are
in some other format, any image editing package worth its salt (GIMP,
Photoshop, whatever) can convert to and from BMP easily). Writing load and
save shouldn't take you more than an hour or so.

Then read the pixel data into a buffer having a structure of your own
devising (make it easy to have many buffers).

I do it like this (well, almost - mine is actually a bit more complicated
than this, but I've streamlined it for the purpose of this explanation):

struct fbuf_
{
unsigned long **pixel; /* 0xRRGGBB */
size_t width;
size_t height;
};

The idea is that, given a pointer fb to a struct fbuf_, you do
fb->pixel=malloc(fb->height * sizeof *fb->pixel) and then loop round each
of the rows, mallocing fb->width * sizeof fb->pixel[i] bytes for each row.
At this point, you can actually set and get pixels using fb->pixel[y][x]
if you like, although you might want to wrap that up in a couple of
functions.

Then write some supporting routines, especially a little routine to "blit"
(copy an image rectangle of a given size) from a given location in one
buffer to a given location in another. Clone-and-modify it (or add a flag)
to take a particular colour and treat it as transparent (i.e. don't copy
pixels of that colour). Then you can do the pushpin-onto-map thing very
easily, specifying the background colour of the pushpin image as the
"don't copy this" colour - and it will actually look pretty neat if you
have a decent pin image.

Don't forget to save your resultant image. :-)

Yes, it takes some up-front time investment and maybe a little learning,
but it's really quite easy, help is available here, and when you're done
you should have something you can be reasonably proud of and that you can
re-use when the next little graphics job comes along.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.