Image Viewer (From Scratch)

Started by
5 comments, last by mameman 16 years, 10 months ago
Basically I am attempting to learn how to implement various image formats in to an image viewer. I know its an EXTREMELY easy task to do using almost any language using some simple api but I want to learn how to display the images from scratch. The reason I want to do this is to get into practice of implementing features (other image formats) that might not be supported by default. For example using VB6 (i know i could of used vb.net) PNG wasn't supported and I had no idea how to implement it. So I figured by doing a viewer from scratch I can get alot of practically knowledge and learn how to implement this myself. My main goal really is to work on a PIC micro controller and create a simple MP3 player for fun. Although it is easy to create on on a computer using an OS it is alot more difficult on a micro controller since API for those are up to the programmer to create. So right now i just want to make an Image viewer then an audio player using the same principle. My main problem is I don't know where at all to start or how to go about this kind of thing. Anyone has any kind of suggestions. I don't even know what to type in Google since all i get is Slide show/Image Viewer/Audio Player with only 10 LINES OF CODE. So can anyone help get me pointed in the right direction?
Advertisement
Not an easy task - many image formats are very complex. PNG, for example, uses the deflate algorithm for compression. Basically this means you have to implement your own zip compression just in order to even begin reading PNG files.

JPEGS are a another difficult beast. It uses the discrete cosine transform for lossy compression - and there are many variants; progressive, non-progressive, etc. On top of that it uses a couple of lossless compression algorithms.

Not many people have implemented PNG libs and JPEG libs from scratch. Actually, Ken Silverman is the only one i can think of off the top of my head that has implemented both.

If you want example code - I guess you're going to have to download libpng and libjpeg to see how it's done. For alternative implementations I guess you could check out Silverman's code.

And then there are of course plenty of other image formats that might be just as complex...
Wack has the right idea, but personally, I would have used more emphatic formatting and superlatives [rolleyes].

The image formats you describe are very very involved. I'd imagine that there are tens of thousands of lines in libjpeg, and even more in libpng. The mathematics involved is nothing short of terrifying. Throw into the mix the lack of documentation and the wide variety of encoding options, and you have a virtually impossible task on your hands.

That's not to say it can't be done, but unless you have a deep understanding of predictive deflation and DCTs, you should find a new goal. I'm afraid that this all applies to MP3 too.

If you still haven't been put off the idea, I suggest you take a look at the official PNG specification and JPEG standard. They'll be sure to bring back your lunch [wink].

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
It's already been said, but it bears repeating. JPEG and PNG, while defined well enough (wotsit, hosted by GameDev.net, is a premiere online source for file format information), are not easy to impliment. They practically require a math degree and you'll write tens of thousands of lines to decode them.

Worse is GIF. It doesn't involve heavy math, but it's filled with extensions and interpretations (animated GIFs are even worse). Unless you have years and a wide audience to test with, you can be sure your GIF decoder will fail to load some files.

Overall MP3 is probably the easiest to implement. It does require a decent knowledge of math, but it's fairly well documented, and the more difficult files to decode (variable bitrate) are easy to seperate and mark as "unsupported". With the power of todays PCs, it also won't be as much of a problem if your first version is not well optimized (by comparison, a non-optimized JPEG decoder could result in full screen images having a noticable delay in loading)
So how would I start that process to make an MP3 decoder. Is their any kind of tutorial that shows one or a good book? I figured if I start with one format I can then use that knowledge and move on to another one.
As Michalson said, your first port of call should be Wotsit. Here is the section containing the MP3 documentation. It looks like there are a few separate source implementations available, as well as a format specification.

Good luck.
You'll need it [wink]

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
You might want to take a look at the free image libraries that are already out there and possibly dynamically link into them (you should be able to do this in VB6 or C++ and is quite trivial). These are all pre-built and ready to use. You will be able to see from these libraries just how complex this sort of thing is!. I ATTEMPTED to write a TIFF viewer many years ago and it was pretty much impossible with all of the different variations of TIFF that you can have. However if you do want to go down that route you may want to start with a bitmap viewer (this is simplest if image formats) and work your way up for there.

Good luck, you'll need it!.

MAMEman.

EDIT: Try these also ;)

GIF87a Spec
GIF89a Spec

This topic is closed to new replies.

Advertisement