What is the simplest file format for writing bitmap graphics? I want to be able to write a file, byte by byte, from various programming environments, based on numerical data I already have.
Technically, “simplest” requires an opinion, but I hope that this could be answered pretty objectively, and suspect that General Questions would be the best place to ask.
Lossy compression algorithms like in typical JPEG files would be quite a lot of work for me to program. I’m not all that much of a programmer. If I had to do run length encoding, like many bitmap files use in a lossless way, I probably could, but if I hear anything about wavelets I’m not even going to try.
I’m hoping there is a format that is very simple, such as a header with row and column count, a palette with R and G and B values, and a long body of palette addresses that map like the sequencing of letters on a page or like progressive scan picture tubes.
I only want to be able to write, not read. That should simplify things, as I could choose just a particular subset of a graphic file format’s abilities. And I don’t care much what format it is, for my end use, as long as I can find utilities (Paint?) that can translate it into common ones like BMP and PNG.
What programming languages are we talking about? Do they not have libraries with image-drawing code in them?
EDIT: I guess .bmp would be the simplest format all-around, but IMO you’d be better off just using your programming language’s library to draw a PNG or other compressed format.
Programming language and platform would be useful to know.
There is a dichotomy between compressed formats and simple formats. You never ever have to write compressed formats directly.
There are a host of simple formats that are little more than a header that is the image dimensions, and then a stream of RGB values. Where it gets a bit messy is how you lay them out. Historically just about every way has been done. Column versus row major order, interleaved RGB versus non-interleaved, raw 8 bit values, 16 bit values, and so on.
But as above, for the most part almost any platform and language will have available libraries that allow you to simply create a 2D array (or three) of values, and then to write these out in any format you desire. There are tool chains that provide conversion and reformatting of image files as well. You really need not worry about any of the nitty gritty stuff. This is, after all, the point of proper programming environments. You should never have to re-invent anything.
So far as I know, BMP doesn’t even use a palette. It’s just a grid of pixels, with a value for the R, G and B in each one. And it’s certainly easy to find tools to support it.
And also sometimes a value for “A” for alpha or transparency, depending on what you can specify. Both trivial to generate in a programming language pixel-by-pixel (e.g. nested for loops), if not the more efficient way to do it.
I recall Truevision TGAfrom back in the day has being very simple (or at least having the option of being very simple).
If you’re looking for something free to do the conversion afterwords, I like Irfanview. It reads in a lot of formats and can convert to more modern formats easily.
Datapoint: I have created .BMP files byte by byte. It was pretty easy. I didn’t even need an example, just worked from the raw specs. Only took an hour or so.
Yes, but, what exactly do you mean? Is it one byte for red (00 = off and FF = full brightness), one byte for blue, one byte for green, then on to the next pixel, left to right across the image, then top to bottom down the image? And what does “planar” versus “chunky” mean?
As for programming environment, more often than anything else, I use SAS, which is a “Statistical Analysis System”. Well, it used to be, back when they sold software. Now they sell solutions. But the only have solutions for one problem, namely, that you need software.
I digress…
This package includes a programming language, but it doesn’t support generating graphics in the raw sense of writing pixels. There are various canned routines that create graphs and whatnot. I occasionally need pixel by pixel control, though, such as when generating a visual target to test an imaging method. And I have always toyed with the idea of trying to generate a random dot stereogram.
Thanks, all! I am very interested in the .ppm and similar text formats, and also feel encouraged to just try writing .bmp.
If you anticipate a lot of horizontal repeats of the same value, RLE might be worth investigating (basically, it’s BMP, but instead of explicitly coding each pixel in turn, you specify pairs of values consisting of the colour, and the number of pixels for which it is repeated)
Some success. Hermitian, I checked out the netpbm Wikipedia article, and it’s a cinch to solve my problem. Then I downloaded IrfanView, a right handy utility, and it opened the little graphic I wrote in a text editor, and saved it into a .bmp that Paint opened.
I can programmatically create the images I want this way, absolutely without any inconvenience or trouble. Perfect!
Though, beowulff, I am still curious per my previous post to you.
Photoshop will let you specify the bits-per-pxiel, although it’s generally 16bits for each color. So 0x0000 is 0% color and 0xFFFF is 100% color (i.e. R=0xFFFF, B = 0x0000 G = 0x0000 is a pixel that’s pure Red). These days, most people use “chunky” format where the color triads are written in order - RGB,RGB,RGB… from upper left to lower right, in row order. It’s also possible to specify the file as R,R,R… and then G,G,G…, and then B,B,B… so that each color is in it’s own plane.