I'm a Computer Science student who's been getting into bitmaps & pixmaps recently. I clearly understand what pixmaps do. A pixmap, as I understand, defines each pixel individually. So, maybe I could write a pixmap filelike this: 255,0,0 0,255,0 0,0,255 which would give me a red pixel, a green pixel, and a blue pixel. Seems pretty straightforward. However, I fail to understand exactly how bitmaps work. I mean, I understand that a bitmap simply maps a bit to some color at some point on the screen. I watched a YouTube video on how to create a bitmap file, but the guy's explanation of what a bitmap file is went over my head. Edit: I feel I now have a better conceptual grasp of what a bitmap is. Well, maybe not. Each bit in a bitmap corresponds to a certain color that is defined somewhere in the file. But how does the computer know which bit corresponds to which color?
moonman239 asked Jan 29, 2016 at 1:04 moonman239 moonman239 141 1 1 silver badge 4 4 bronze badges$\begingroup$ Do you understand how frame buffers work? en.wikipedia.org/wiki/Framebuffer (Caveat, it's got alot of history.) Is that some of what you are looking for? $\endgroup$
Commented Jan 29, 2016 at 14:11In addition to the pixel values, the width and height of the image are also required, and the colour depth (how many colours are available per pixel). Some formats also specify an alpha value, for transparency, which may be defined per pixel in addition to the red, green and blue components.
There are many different image file formats but a simple one to experiment with to gain understanding is ppm, one of the Netpbm formats.
Netpbm defines the following file types:
These have the advantages of being simple to understand, and easy to generate in a text editor for working with simple examples.
For example, a PPM file is simply the characters "P3" to identify it as PPM, followed by the width, height, maximum colour value and the pixel values in English reading order (left to right then top to bottom). Each pixel colour is a red value, a green value, and a blue value. All these values are space separated and human readable.
P3 # Indicates an ASCII PPM file 2 2 # Width and height of the image 255 # Maximum colour value 255 0 0 0 255 0 # A red pixel (255 0 0) followed by a green pixel 0 0 255 255 255 255 # A blue pixel followed by a white pixel
While this makes the format very easy to work with for small examples, it will also make the file size much larger than other formats which use bytes to represent colour components instead of writing out the human readable numbers. Many formats also include compression (either lossless or lossy).
Once you are accustomed to writing PPM files in ASCII characters, indicated by the file starting with "P3", you can move on to PPM files using bytes, indicated by the file starting with "P6". This is a similar format to what many programs use internally, but is no longer human readable in a text editor as not every byte will correspond to a printable ASCII character.
You also mention that a pixmap can have pixel values that refer to colours stored elsewhere in the file. I have avoided this format as it is not necessary for understanding how a pixmap works. This is known as using a palette (a list of predefined colours so each pixel is represented by an index of a colour in the palette). This is necessary for formats that only allow a small number of distinct colours, but for full colour images there is no need for a palette - each pixel is defined as red, green and blue components without having to refer to anything else.