Escolar Documentos
Profissional Documentos
Cultura Documentos
c
/
*******************************************************************
*******
* bitmap.c
*
* This is a 16-bit program.
*
* Tab stops are set to 2.
*
* Remember to compile in the LARGE memory model!
*
* To compile in Borland C: bcc -ml bitmap.c
*
* This program will only work on DOS- or Windows-based systems
with a
*
* VGA, SuperVGA or compatible video adapter.
*
* Please feel free to copy this source code.
* DESCRIPTION: This program demostrates drawing bitmaps, including
*
* transparent bitmaps.
*
******************************************************************
********/
#include
#include
#include
#include
<stdio.h>
<stdlib.h>
<dos.h>
<mem.h>
#define VIDEO_INT
#define SET_MODE
mode. */
#define VGA_256_COLOR_MODE
*/
#define TEXT_MODE
mode. */
0x10
0x00
0x13
0x03
#define SCREEN_WIDTH
0x13 */
#define SCREEN_HEIGHT
0x13 */
#define NUM_COLORS
0x13 */
320
200
256
/
*******************************************************************
*******
* fskip
*
*
Skips bytes in a file.
*
******************************************************************
********/
void fskip(FILE *fp, int num_bytes)
{
int i;
for (i=0; i<num_bytes; i++)
fgetc(fp);
}
/
*******************************************************************
*******
* set_mode
*
*
Sets the video mode.
*
******************************************************************
********/
void set_mode(byte mode)
{
union REGS regs;
regs.h.ah = SET_MODE;
regs.h.al = mode;
int86(VIDEO_INT, ®s, ®s);
}
/
*******************************************************************
*******
* load_bmp
*
*
Loads a bitmap file into memory.
*
******************************************************************
********/
void load_bmp(char *file,BITMAP *b)
{
FILE *fp;
long index;
word num_colors;
int x;
/* open the file */
if ((fp = fopen(file,"rb")) == NULL)
{
printf("Error opening file %s.\n",file);
exit(1);
}
/* check to see if it is a valid bitmap file */
if (fgetc(fp)!='B' || fgetc(fp)!='M')
{
fclose(fp);
printf("%s is not a bitmap file.\n",file);
exit(1);
}
/* read in the width and height of the image, and the
number of colors used; ignore the rest */
fskip(fp,16);
fread(&b->width, sizeof(word), 1, fp);
fskip(fp,2);
fread(&b->height,sizeof(word), 1, fp);
fskip(fp,22);
fread(&num_colors,sizeof(word), 1, fp);
fskip(fp,6);
/* assume we are working with an 8-bit file */
if (num_colors==0) num_colors=256;
/* try to allocate memory */
if ((b->data = (byte *) malloc((word)(b->width*b->height))) ==
NULL)
{
fclose(fp);
ignore this
loop */
}
}
/
*******************************************************************
*******
* Main
*
*
******************************************************************
********/
void main()
{
int i,x,y;
BITMAP bmp;
load_bmp("rocket.bmp",&bmp);
set_mode(VGA_256_COLOR_MODE);
set_mode(TEXT_MODE);
return;
}