Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

Bmp.c

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  Bmp.c                                                                               */
00003 /*                                                                                      */
00004 /*  Author: Eli Boling                                                                  */
00005 /*  Description: Converts data to bmp format.                                           */
00006 /*                                                                                      */
00007 /*  The contents of this file are subject to the Genesis3D Public License               */
00008 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00009 /*  compliance with the License. You may obtain a copy of the License at                */
00010 /*  http://www.genesis3d.com                                                            */
00011 /*                                                                                      */
00012 /*  Software distributed under the License is distributed on an "AS IS"                 */
00013 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00014 /*  the License for the specific language governing rights and limitations              */
00015 /*  under the License.                                                                  */
00016 /*                                                                                      */
00017 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00018 /*Genesis3D Version 1.1 released November 15, 1999                            */
00019 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
00020 /*                                                                                      */
00021 /****************************************************************************************/
00022 #define WIN32_LEAN_AND_MEAN
00023 #include        <windows.h>
00024 
00025 #include        <stdio.h>
00026 
00027 #define WIDTH                   640
00028 #define HEIGHT                  480
00029 
00030 BITMAPFILEHEADER        bfh = 
00031 {
00032         ((unsigned short)'B' | ((unsigned short)'M' << 8)),
00033         sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFO) + WIDTH * HEIGHT * 2,
00034         0,
00035         0,
00036         sizeof(BITMAPINFOHEADER)
00037 };
00038 
00039 BITMAPINFO              bi =
00040 {
00041         {
00042         sizeof(BITMAPINFOHEADER),
00043         WIDTH,
00044         HEIGHT,
00045         1,
00046         24,
00047         BI_RGB,
00048         0,
00049         0,
00050         0,
00051         0,
00052         0
00053         }
00054 };
00055 
00056 #ifdef BITS16
00057         #define RED(x)          ((unsigned short)((x>>11) & 0x1f))
00058         #define GREEN(x)        ((unsigned short)((x>>6 ) & 0x1f))
00059         #define BLUE(x)         ((unsigned short)((x>>0 ) & 0x1f))
00060 #else
00061         #define RED(x)          ((unsigned short)((x>>11) & 0x1f))
00062         #define GREEN(x)        ((unsigned short)((x>>5 ) & 63))
00063         #define BLUE(x)         ((unsigned short)((x>>0 ) & 0x1f))
00064 #endif
00065 
00066 int WriteBMP(unsigned short *ScreenBuffer, const char *Name)
00067 {
00068         FILE *  out;
00069         int     y;
00070 
00071         out = fopen(Name, "wb");
00072 
00073         if (!out)
00074                 return 0;
00075 
00076         if      (fwrite(&bfh, sizeof(bfh), 1, out) != 1)
00077                 return 0;
00078 
00079         if      (fwrite(&bi, sizeof(bi), 1, out) != 1)
00080                 return 0;
00081 
00082         for     (y = HEIGHT-1; y >= 0; y--)
00083         {
00084                 int                     i;
00085                 unsigned short *p;
00086                 unsigned char   Buff[WIDTH * 3];
00087                 unsigned char * BuffPtr;
00088 
00089                 BuffPtr = &Buff[0];
00090                 p = &ScreenBuffer[y*WIDTH];
00091                 for     (i = 0; i < WIDTH; i++)
00092                 {
00093                         #ifdef BIT16
00094                                 unsigned short  c;
00095                         
00096                                 c = p[i];
00097                                 c = (RED(c) << 10) + (GREEN(c) << 5) + BLUE(c);
00098                                 p[i] = c;
00099                         #else
00100                                 
00101                                 #ifdef VER1
00102                                 char c[3];
00103                                 c = (char)(GREEN(p[i]) << 2);
00104                                 fwrite(&c, 1, 1, out);
00105                                 c = (char)(RED(p[i]) << 3);
00106                                 fwrite(&c, 1, 1, out);
00107                                 c = (char)(BLUE(p[i]) << 3);
00108                                 fwrite(&c, 1, 1, out);
00109                                 #else
00110                                 #if 0
00111                                 char c[3];
00112                                 c = (char)(BLUE(p[i]) << 3);
00113                                 fwrite(&c, 1, 1, out);
00114                                 c = (char)(GREEN(p[i]) << 2);
00115                                 fwrite(&c, 1, 1, out);
00116                                 c = (char)(RED(p[i]) << 3);
00117                                 fwrite(&c, 1, 1, out);
00118                                 #else
00119                                 *BuffPtr++ = (char)(BLUE(p[i]) << 3);
00120                                 *BuffPtr++ = (char)(GREEN(p[i]) << 2);
00121                                 *BuffPtr++ = (char)(RED(p[i]) << 3);
00122 //                              fwrite(&c[0], 3, 1, out);
00123                                 #endif
00124                                 #endif
00125                         #endif
00126                 }
00127 
00128                 fwrite(&Buff[0], WIDTH * 3, 1, out);
00129                 #ifdef BIT16
00130                         p = &ScreenBuffer[y*WIDTH];
00131                         for     (i = 0; i < WIDTH; i++)
00132                                 fwrite(&p[(i+2)%WIDTH], 2, 1, out);
00133                 #endif
00134         }
00135 
00136         if      (fclose(out))
00137                 return 0;
00138 
00139         return 1;
00140 }
00141 

Generated on Tue Sep 30 12:35:19 2003 for GTestAndEngine by doxygen 1.3.2