| 1093 | // for monochrome graphics, or four bits per pixel for 16 color bitmaps. |
| 1094 | |
| 1095 | void WriteBmp(FILE *file) |
| 1096 | { |
| 1097 | int x, y; |
| 1098 | dword value; |
| 1099 | |
| 1100 | // BitmapFileHeader |
| 1101 | PutByte('B'); PutByte('M'); |
| 1102 | PutLong(14+40 + (gs.fColor ? 64 : 8) + |
| 1103 | (long)4*gs.yWin*(((gs.xWin-1) >> (gs.fColor ? 3 : 5))+1)); |
| 1104 | PutWord(0); PutWord(0); |
| 1105 | PutLong(14+40 + (gs.fColor ? 64 : 8)); |
| 1106 | // BitmapInfo / BitmapInfoHeader |
| 1107 | PutLong(40); |
| 1108 | PutLong(gs.xWin); PutLong(gs.yWin); |
| 1109 | PutWord(1); PutWord(gs.fColor ? 4 : 1); |
| 1110 | PutLong(0 /*BI_RGB*/); PutLong(0); |
| 1111 | PutLong(0); PutLong(0); |
| 1112 | PutLong(0); PutLong(0); |
| 1113 | // RgbQuad |
| 1114 | if (gs.fColor) |
| 1115 | for (x = 0; x < 16; x++) { |
| 1116 | PutByte(RgbB(rgbbmp[x])); PutByte(RgbG(rgbbmp[x])); |
| 1117 | PutByte(RgbR(rgbbmp[x])); PutByte(0); |
| 1118 | } |
| 1119 | else { |
| 1120 | PutLong(0); |
| 1121 | PutByte(255); PutByte(255); PutByte(255); PutByte(0); |
| 1122 | } |
| 1123 | // Data |
| 1124 | for (y = gs.yWin-1; y >= 0; y--) { |
| 1125 | value = 0; |
| 1126 | for (x = 0; x < gs.xWin; x++) { |
| 1127 | if ((x & (gs.fColor ? 7 : 31)) == 0 && x > 0) { |
| 1128 | PutLong(value); |
| 1129 | value = 0; |
| 1130 | } |
| 1131 | if (gs.fColor) |
| 1132 | value |= (dword)FBmGet(gi.bm, x, y) << ((x & 7 ^ 1) << 2); |
| 1133 | else |
| 1134 | if (FBmGet(gi.bm, x, y)) |
| 1135 | value |= (dword)1 << (x & 31 ^ 7); |
| 1136 | } |
| 1137 | PutLong(value); |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | #define LFlipB(l) ((((l) & 0xff) << 24) | (((l) & 0xff00) << 8) | \ |