00001 #ifndef BITMAP_H
00002 #define BITMAP_H
00003
00004
00005
00006
00007 #define BLT_CLEAR 0 // 0
00008 #define BLT_NOR 1 // ~(src | dst)
00009 #define BLT_NOTAND 2 // ~src & dst
00010 #define BLT_NOTCOPY 3 // ~src
00011 #define BLT_ANDNOT 4 // src & ~dst
00012 #define BLT_NOT 5 // ~dst
00013 #define BLT_XOR 6 // src ^ dst
00014 #define BLT_NAND 7 // ~(src & dst)
00015 #define BLT_AND 8 // src & dst
00016 #define BLT_NEXOR 9 // ~(src ^ dst)
00017 #define BLT_NOP 10 // dst
00018 #define BLT_NOTOR 11 // ~src | dst
00019 #define BLT_COPY 12 // src
00020 #define BLT_ORNOT 13 // src | ~dst
00021 #define BLT_OR 14 // (src | dst)
00022 #define BLT_SET 15 // 1
00023
00024
00025
00026 #define DPI2PPM(dpi) ((100.0/2.54)*dpi)
00027 #define PPM2DPI(ppm) ((ppm/(100.0/2.54))
00028
00029
00030
00031 #define BMP_BGCOLOR 0x96ff00
00032 #define BMP_FGCOLOR 0x182800
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00053 typedef struct
00054 {
00055
00056 short bfType;
00057 long bfSize;
00058 short bfReserved1;
00059 short bfReserved2;
00060 long bfOffBits;
00061
00062
00063 long biSize;
00064 long biWidth, biHeight;
00065 short biPlanes, biBitCount;
00066 long biCompression;
00067 long biSizeImage;
00068 long biXPelsPerMeter;
00069 long biYPelsPerMeter;
00070 long biClrUsed;
00071 long biClrImportant;
00072
00073
00074 unsigned long color0, color1;
00075
00076 } BitmapFileHeader;
00077
00078
00093 typedef struct Bitmap {
00094 int width, height;
00095 unsigned bmBitsSize;
00096 char bmBits[];
00097 } Bitmap;
00098
00099
00100 typedef (BM_BlitFunc)(
00101 char *dst, int dstwidth,
00102 char *src, int srcwidth,
00103 int width, int pages,
00104 char shift, char fbm, char lbm
00105 );
00106
00107
00108 extern "C" {
00109 BM_BlitFunc BM_Blit_Copy, BM_Blit_NotCopy;
00110 BM_BlitFunc BM_Blit_And, BM_Blit_Nand;
00111 BM_BlitFunc BM_Blit_NotAnd, BM_Blit_AndNot;
00112 BM_BlitFunc BM_Blit_Or, BM_Blit_Nor;
00113 BM_BlitFunc BM_Blit_NotOr, BM_Blit_OrNot;
00114 BM_BlitFunc BM_Blit_Xor, BM_Blit_Nexor;
00115 }
00116
00117
00127 inline char BM_GetPixel(Bitmap *bm, int x, int y)
00128 {
00129 if (x<0 || x>=bm->width || y<0 || y>=bm->height)
00130 return 0;
00131 if (bm->bmBits[x+(y>>3)*bm->width] & (1<<(y&7)))
00132 return 1;
00133 else
00134 return 0;
00135 }
00136
00137
00147 inline void BM_PutPixel(Bitmap *bm, int x, int y, char color)
00148 {
00149 if (x<0 || x>=bm->width || y<0 || y>=bm->height)
00150 return;
00151 if (color)
00152 bm->bmBits[x+(y>>3)*bm->width] |= 1<<(y&7);
00153 else
00154 bm->bmBits[x+(y>>3)*bm->width] &= ~(1<<(y&7));
00155 }
00156
00157
00164 extern Bitmap *BM_Alloc( int w, int h );
00165 extern void BM_Free( Bitmap *bm );
00166 extern Bitmap *BM_Copy( Bitmap *bm );
00167
00168 extern void BM_Clear( Bitmap *bm, char pattern=0x00 );
00169 extern void BM_Invert( Bitmap *bm );
00170 extern void BM_Scroll( Bitmap *bm, int dx, int dy );
00171
00172 extern Bitmap *BM_Load( char *fn );
00173 extern void BM_Save( Bitmap *bm, char *fn );
00174
00175 extern void BM_Blit( Bitmap *dst, int x, int y,
00176 Bitmap *src, int u=0, int v=0,
00177 int w=-1, int h=-1, int mode=BLT_COPY );
00178
00179 extern void BM_FastBlit( Bitmap *dst, int x, int y,
00180 Bitmap *src, int u=0, int v=0,
00181 int w=-1, int h=-1, int mode=BLT_COPY );
00182
00183 #endif