Main Page Data Structures File List Data Fields Globals Related Pages

# bitmap.cpp File Reference

`#include "bitmap.h"`
`#include <assert.h>`
`#include <stdlib.h>`
`#include <stdio.h>`
`#include <mem.h>`

Go to the source code of this file.

## Functions
Bitmap * | BM_Alloc (int w, int h)
| Allocate a Bitmap structure.
Bitmap * | BM_Copy (Bitmap *bm)
| Copy a Bitmap.
void | BM_Free (Bitmap *bm)
| Free a Bitmap structure.
void | BM_Clear (Bitmap *bm, char pattern)
| Clear a Bitmap's bmBits.
void | BM_Invert (Bitmap *bm)
| Invert all pixel of a Bitmap.
void | BM_Scroll (Bitmap *bm, int dx, int dy)
| Scroll bitmap contents.
Bitmap * | BM_Load (char *fn)
| Load a bitmap from a bmp file.
void | BM_Save (Bitmap *bm, char *fn)
| Save a bitmap into a bmp file.
void | BM_Blit (Bitmap *dst, int x, int y, Bitmap *src, int u, int v, int w, int h, int mode)
| Copy a region between two Bitmaps (with clipping).
void | BM_FastBlit (Bitmap *dst, int x, int y, Bitmap *src, int u, int v, int w, int h, int mode)
| Copy a region between two Bitmaps (without clipping).
## Variables
BM_BlitFunc * | blitFuncs []
| Function pointers to blitter functions.

## Function Documentation

Bitmap* BM_Alloc | ( | int | w,
|  | int | h
| ) |

  | Allocate a Bitmap structure. Parameters:
  w, h | width and height of bitmap
Returns: Pointer to bitmap structure or NULL if out of memory. Note: The bitmap is not cleared for performance reasons. Do this by using BM_Clear(). Definition at line 44 of file bitmap.cpp. References Bitmap::bmBitsSize, Bitmap::height, and Bitmap::width. Referenced by BM_Copy(), BM_Load(), and gfxTest().

void BM_Blit | ( | Bitmap * | dst,
|  | int | x,
|  | int | y,
|  | Bitmap * | src,
|  | int | u,
|  | int | v,
|  | int | w,
|  | int | h,
|  | int | mode
| ) |

  | Copy a region between two Bitmaps (with clipping). Note: This function does clipping, and is therefore quite inefficient for copying small regions. Don't use this to copy text, or other small bitmaps. Do the clipping yourself, and use the fastblt functions instead. Parameters:
  dst | pointer to destination Bitmap
  x,y | destination coordinates
  w,h | width and height in pixels
  u,v | source coordinates
  mode | blitmode (BLT_COPY, BLT_OR..)
Note: source width [height] is used, if w [h] is set to -1. implement overlapping region copies (by using a temporary bitmap). Definition at line 335 of file bitmap.cpp. References BM_FastBlit(), Bitmap::height, src, and Bitmap::width. Referenced by BM_Scroll(), GFX_Print(), and gfxTest().

void BM_Clear | ( | Bitmap * | bm,
|  | char | pattern
| ) |

  | Clear a Bitmap's bmBits. Parameters:
  bm | pointer to a Bitmap structure.
  pattern | byte pattern to use.
Definition at line 104 of file bitmap.cpp. References Bitmap::bmBits, and Bitmap::bmBitsSize. Referenced by BM_Load(), BM_Scroll(), and gfxTest().

Bitmap* BM_Copy | ( | Bitmap * | bm | ) |

  | Copy a Bitmap. Parameters:
  bm | pointer to bitmap to copy.
Returns: pointer to copied bitmap, or NULL if out of memory. Definition at line 66 of file bitmap.cpp. References BM_Alloc(), Bitmap::bmBits, Bitmap::bmBitsSize, Bitmap::height, and Bitmap::width. Referenced by BM_Scroll().

void BM_FastBlit | ( | Bitmap * | dst,
|  | int | x,
|  | int | y,
|  | Bitmap * | src,
|  | int | u,
|  | int | v,
|  | int | w,
|  | int | h,
|  | int | mode
| ) |

  | Copy a region between two Bitmaps (without clipping). Note: This function does not do clipping. You'll have to take care of that yourself. Parameters:
  dst | pointer to destination Bitmap
  x,y | destination coordinates
  w,h | width and height in pixels
  u,v | source coordinates
  op | one of the BLT_XXX blitmode constants
Note: source width [height] is used, if w [h] is set to -1. This function doesn't handle overlapping source and destination regions (the blit does always start at the top-left corner). Definition at line 398 of file bitmap.cpp. References blitFuncs, Bitmap::bmBits, fbm, Bitmap::height, lbm, pages, shift, src, and Bitmap::width. Referenced by BM_Blit(), and GFX_FillRect().

void BM_Free | ( | Bitmap * | bm | ) |

  | Free a Bitmap structure. BM_Free frees a Bitmap (and its bmBits) previously allocated by BM_Alloc. Parameters:
  bm | pointer to a Bitmap structure.
Note: bmBits are only freed, if the pointer is non-null. Definition at line 87 of file bitmap.cpp. References Bitmap::bmBitsSize, Bitmap::height, and Bitmap::width. Referenced by BM_Scroll(), and gfxTest().

void BM_Invert | ( | Bitmap * | bm | ) |

  | Invert all pixel of a Bitmap. Parameters:
  bm | pointer to a Bitmap structure.
Definition at line 115 of file bitmap.cpp. References Bitmap::bmBits, and Bitmap::bmBitsSize.

Bitmap* BM_Load | ( | char * | fn | ) |

  | Load a bitmap from a bmp file. This function allocates and loads a bitmap from a windows .bmp file. Only two color, uncompressed bitmaps are supported. Parameters:
  fn | filename to load.
Returns: pointer to a Bitmap structure or NULL if an error occured. Definition at line 183 of file bitmap.cpp. References BitmapFileHeader::bfOffBits, BitmapFileHeader::bfType, BitmapFileHeader::biBitCount, BitmapFileHeader::biCompression, BitmapFileHeader::biHeight, BitmapFileHeader::biPlanes, BitmapFileHeader::biWidth, BM_Alloc(), BM_Clear(), Bitmap::bmBits, Bitmap::bmBitsSize, Bitmap::height, src, and Bitmap::width. Referenced by gfxTest().

void BM_Save | ( | Bitmap * | bm,
|  | char * | fn
| ) |

  | Save a bitmap into a bmp file. This function saves a bitmap into a two-color, uncompressed windows .bmp file. Parameters:
  bm | Bitmap to save.
  fn | filename to save to.
Definition at line 252 of file bitmap.cpp. References BitmapFileHeader::bfOffBits, BitmapFileHeader::bfReserved1, BitmapFileHeader::bfReserved2, BitmapFileHeader::bfSize, BitmapFileHeader::bfType, BitmapFileHeader::biBitCount, BitmapFileHeader::biClrImportant, BitmapFileHeader::biClrUsed, BitmapFileHeader::biCompression, BitmapFileHeader::biHeight, BitmapFileHeader::biPlanes, BitmapFileHeader::biSize, BitmapFileHeader::biSizeImage, BitmapFileHeader::biWidth, BitmapFileHeader::biXPelsPerMeter, BitmapFileHeader::biYPelsPerMeter, Bitmap::bmBits, BMP_BGCOLOR, BMP_FGCOLOR, BitmapFileHeader::color0, BitmapFileHeader::color1, DPI2PPM, Bitmap::height, src, and Bitmap::width. Referenced by gfxTest().

void BM_Scroll | ( | Bitmap * | bm,
|  | int | dx,
|  | int | dy
| ) |

  | Scroll bitmap contents. Parameters:
  bm | pointer to a Bitmap structure.
  dx, dy | shift by (dx, dy) pixels.
Todo: re-implement this function as an in-place move! Definition at line 161 of file bitmap.cpp. References BM_Blit(), BM_Clear(), BM_Copy(), and BM_Free().

## Variable Documentation

BM_BlitFunc* blitFuncs[]`[static]`

| Initial value:
     {
      NULL,           BM_Blit_Nor,   BM_Blit_NotAnd,  BM_Blit_NotCopy,
      BM_Blit_AndNot, NULL,          BM_Blit_Xor,     BM_Blit_Nand,
      BM_Blit_And,    BM_Blit_Nexor, NULL,            BM_Blit_NotOr,
      BM_Blit_Copy,   BM_Blit_OrNot, BM_Blit_Or,      NULL
    }
Function pointers to blitter functions. Definition at line 26 of file bitmap.cpp. Referenced by BM_FastBlit().