Bitmaps in Computing

In computing, a bitmap serves as a mapping from a specific domain, such as a range of integers, to bits. It is also known as a bit array or bitmap index.

The term "bitmap" is commonly used to denote a particular bitmapping application known as a pix-map. A pix-map represents a map of pixels, where each pixel can store more than two colors, utilizing more than one bit per pixel. In this context, the domain is the array of pixels forming a digital graphic output device, such as a screen or monitor. Sometimes, "bitmap" implies one bit per pixel, while "pixmap" is used for images with multiple bits per pixel.

Bitmaps are a form of memory organization and an image file format employed to store digital images. Originating from computer programming terminology, a bitmap is essentially a map of bits, a spatially mapped array of bits. Alongside "pixmap," it now commonly refers to the concept of a spatially mapped array of pixels. The term is applicable to raster images in general, whether synthetic or photographic, stored in files or memory.

Many graphical user interfaces incorporate bitmaps into their built-in graphics subsystems.

Pixel Storage in Bitmaps

In uncompressed bitmaps, pixels are stored with a variable number of bits per pixel, indicating their color depth. Pixels of 8 bits or fewer can represent grayscale or indexed color. An alpha channel for transparency may be stored separately, either as a grayscale bitmap or in a fourth channel, converting 24-bit images to 32 bits per pixel.

The bits representing bitmap pixels may be packed or unpacked, depending on the format or device requirements. Depending on the color depth, a pixel will occupy at least n/8 bytes, where n is the bit depth.

size = width ⋅ height ⋅ n/8

For an uncompressed, packed bitmap (e.g., Microsoft DIB or BMP file format), a lower bound on storage size for an n-bit-per-pixel bitmap can be calculated using the formula above. Row padding effects may require additional bytes.

Device-Independent Bitmaps and BMP File Format

Microsoft has defined device-independent bitmaps (DIBs) and the BMP file format to facilitate bitmap exchange between devices and applications. DIBs allow bitmaps to be moved between devices, and they are commonly transported in metafiles, BMP files, and the Clipboard (CF_DIB data format).

The term "device-independent" in this context refers to the format or storage arrangement, not device-independent color.

Other Bitmap File Formats

The X Window System utilizes the XBM format for black-and-white images and XPM (pixelmap) for color images. Several uncompressed bitmap file formats exist, but standardized compressed formats like GIF, PNG, TIFF, and JPEG are widely used. Lossless compression, found in TIFF and PNG, maintains information in a smaller file size. JPEG, often used for its lossy compression, and TIFF have various options.

Additionally, there are "raw" image files, storing bitmaps with no other information. These raw files are distinct from photographic raw image formats, which store unprocessed sensor data in a structured container like TIFF, accompanied by extensive image metadata.

Additional Resource

For more information on bitmap image files and their file extensions, you can explore the following resource: Bitmap Image Files - File Extensions.

Below is pseudocode-like explanations for concepts related to bitmaps: 1.

Bitmap Initialization:

       // Create an empty bitmap with width and height
       function createBitmap(width, height):
           bitmap = new Array[width][height]
           return bitmap
        
2.

Setting Pixel Color:

```pseudocode // Set color of a pixel at position (x, y) in bitmap function setPixelColor(bitmap, x, y, color): bitmap[x][y] = color ``` 3.

Accessing Pixel Color:

```pseudocode // Get color of a pixel at position (x, y) in bitmap function getPixelColor(bitmap, x, y): return bitmap[x][y] ``` 4.

Drawing a Line:

```pseudocode // Draw a line from (x1, y1) to (x2, y2) in bitmap function drawLine(bitmap, x1, y1, x2, y2, color): // Implementation of line-drawing algorithm // ... // Set the color of pixels along the line for each pixel (x, y) in line: setPixelColor(bitmap, x, y, color) ``` 5.

Filling a Region:

```pseudocode // Fill a region starting from seed point (x, y) with a color function fillRegion(bitmap, x, y, targetColor, fillColor): // Implementation of flood-fill algorithm // ... // Set the color of pixels in the filled region for each pixel (x, y) in filled region: setPixelColor(bitmap, x, y, fillColor) ``` 6.

Bitmap Copy:

```pseudocode // Create a copy of the original bitmap function copyBitmap(originalBitmap): newBitmap = createBitmap(width(originalBitmap), height(originalBitmap)) // Copy pixel colors from original to new bitmap for x from 0 to width(originalBitmap): for y from 0 to height(originalBitmap): setPixelColor(newBitmap, x, y, getPixelColor(originalBitmap, x, y)) return newBitmap ``` These pseudocode snippets provide a basic understanding of bitmap operations, from initialization to drawing lines and filling regions. Note that the actual implementation details may vary based on the programming language and specific requirements.