# Simplest bitmap graphic file format?

**URL:** <https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553>\
**Category:** Factual Questions\
**Created:** [January 24, 2012, 11:27pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553 "2012-01-24T23:27:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [January 24, 2012, 11:27pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/1 "2012-01-24T23:27:51Z")

</div>

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.

Thanks!!

---

<div class="post-metadata">

**Author:** ![Blakeyrat](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@Blakeyrat](https://boards.straightdope.com/u/Blakeyrat)\
**Post date:** [January 24, 2012, 11:33pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/2 "2012-01-24T23:33:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Francis\_Vaughan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/francis_vaughan/32/3093_2.png) [@Francis\_Vaughan](https://boards.straightdope.com/u/Francis_Vaughan)\
**Post date:** [January 25, 2012, 12:00am UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/3 "2012-01-25T00:00:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [January 25, 2012, 12:05am UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/4 "2012-01-25T00:05:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![thelurkinghorror](https://avatars.discourse-cdn.com/v4/letter/t/7c8e57/32.png) [@thelurkinghorror](https://boards.straightdope.com/u/thelurkinghorror)\
**Post date:** [January 25, 2012, 12:18am UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/5 "2012-01-25T00:18:53Z")

</div>

> [@Chronos](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![andrewm](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@andrewm](https://boards.straightdope.com/u/andrewm)\
**Post date:** [January 25, 2012, 12:24am UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/6 "2012-01-25T00:24:36Z")

</div>

XPM is worth considering. It’s plain text so it’s trivial to write from any language and it’s a straight palletized bitmap - no compression.

> **[X PixMap](https://en.wikipedia.org/wiki/X_PixMap)**
>
> X PixMap (XPM) is an image file format used by the X Window System, created in 1989 by Daniel Dardailler and Colas Nahaboo working at Bull Research Center at Sophia Antipolis, France, and later enhanced by Arnaud Le Hors.
> It is intended primarily for creating icon pixmaps, and supports transparent pixels. Derived from the earlier XBM syntax, it is a plain text file in the XPM2 format or of a C programming language syntax, which can be included in a C program file.
> The first (1989) XPM format is...

There are plenty of free tools for converting them to BMP, JPG, PNG, etc.

---

<div class="post-metadata">

**Author:** ![leahcim](https://avatars.discourse-cdn.com/v4/letter/l/b4bc9f/32.png) [@leahcim](https://boards.straightdope.com/u/leahcim)\
**Post date:** [January 25, 2012, 12:56am UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/7 "2012-01-25T00:56:19Z")

</div>

I recall [Truevision TGA](http://en.wikipedia.org/wiki/Truevision_TGA)from 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](http://www.irfanview.com/). It reads in a lot of formats and can convert to more modern formats easily.

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [January 25, 2012, 1:04am UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/8 "2012-01-25T01:04:58Z")

</div>

You can write raw RGB data into a file, and Photoshop can open it.

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [January 25, 2012, 4:29am UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/9 "2012-01-25T04:29:02Z")

</div>

> [@](#):
>
> You can write raw RGB data into a file, and Photoshop can open it.

In what format? You can’t just have raw data without any format, and what format it is could make a huge difference.

---

<div class="post-metadata">

**Author:** ![Hermitian](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/hermitian/32/470_2.png) [@Hermitian](https://boards.straightdope.com/u/Hermitian)\
**Post date:** [January 25, 2012, 1:29pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/10 "2012-01-25T13:29:33Z")

</div>

> **[Netpbm](https://en.wikipedia.org/wiki/Netpbm_format)**
>
> Netpbm (formerly Pbmplus) is an open-source package of graphics programs and a programming library. It is used mainly in the Unix world, where one can find it included in all major open-source operating system distributions, but also works on Microsoft Windows, macOS, and other operating systems.
> Several graphics formats are used and defined by the Netpbm project:
> are image file formats designed to be easily exchanged between platforms. They are also sometimes referred to collectively as the po...

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [January 25, 2012, 1:39pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/11 "2012-01-25T13:39:56Z")

</div>

> [@Chronos](#):
>
> In what format? You can’t just have raw data without any format, and what format it is could make a huge difference.

Just RGB samples written in order - RGB,RGB,RGB…  
Photoshop lets you specify rows \* columns and planar/chunky format when opening raw.

---

<div class="post-metadata">

**Author:** ![Ludovic](https://avatars.discourse-cdn.com/v4/letter/l/7ab992/32.png) [@Ludovic](https://boards.straightdope.com/u/Ludovic)\
**Post date:** [January 25, 2012, 1:47pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/12 "2012-01-25T13:47:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [January 25, 2012, 3:12pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/13 "2012-01-25T15:12:52Z")

</div>

> [@Hermitian](#):
>
> [Netpbm - Wikipedia](http://en.wikipedia.org/wiki/Netpbm_format)

I like this. It seems ideal! Thanks!

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [January 25, 2012, 3:17pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/14 "2012-01-25T15:17:26Z")

</div>

> [@beowulff](#):
>
> Just RGB samples written in order - RGB,RGB,RGB…  
> Photoshop lets you specify rows \* columns and planar/chunky format when opening raw.

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?

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [January 25, 2012, 3:21pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/15 "2012-01-25T15:21:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mangetout](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/mangetout/32/19_2.png) [@Mangetout](https://boards.straightdope.com/u/Mangetout)\
**Post date:** [January 25, 2012, 3:37pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/16 "2012-01-25T15:37:47Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [January 25, 2012, 3:44pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/17 "2012-01-25T15:44:05Z")

</div>

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.

Thanks!

---

<div class="post-metadata">

**Author:** ![beowulff](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/beowulff/32/542_2.png) [@beowulff](https://boards.straightdope.com/u/beowulff)\
**Post date:** [January 25, 2012, 4:32pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/18 "2012-01-25T16:32:05Z")

</div>

> [@Napier](#):
>
> 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?

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.

---

<div class="post-metadata">

**Author:** ![ftg](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ftg/32/2801_2.png) [@ftg](https://boards.straightdope.com/u/ftg)\
**Post date:** [January 25, 2012, 8:52pm UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/19 "2012-01-25T20:52:52Z")

</div>

I have also netpbm (and its variants). Several programs I use can read it and then I can use those to convert (if necessary) to a more popular format.

---

<div class="post-metadata">

**Author:** ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)\
**Post date:** [January 26, 2012, 9:27am UTC](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553/20 "2012-01-26T09:27:09Z")

</div>

Out of curiosity, why do you need to do graphics at such a low level instead of using a graphics or visualization library?

[Next page](https://boards.straightdope.com/t/simplest-bitmap-graphic-file-format/610553.md?page=2)
