/*---------------------------------------------------------------------------
 * BMPSAVER BMPFILEユーティリティ
 * bsbmp_u.c (2000/07/19 - 2000/12/13)
 * Copyright (c) 2000, Kazuhide Hatsuyama, All rights reserved.
 *   mail    : hat@lares.dti.ne.jp
 *   HomePage: http://www.lares.dti.ne.jp/~hat/
 *---------------------------------------------------------------------------*/

#define BIOS_INLINE

#include "bsbmp_d.h"

#define BPP			4
#define NCOLOR		(1<<BPP)

/*--------------------------------------------------------------------*/
/* BMPFILE ヘッダー情報初期化 */
void bs_bmp_init_header(int width, int height)
{
	int bfhSize;
	int byte_per_line;
	RGBQUAD far *ct = colortable;
	int c = 0xff;
	int i;

	/* １ラインにつき何バイト？*/
	byte_per_line = ((width+1)/2+3)&(~3);

	/* BMPファイルヘッダーサイズ */
	bfhSize = sizeof(BITMAPFILEHEADER)
			+ sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*NCOLOR;

	/* BMPファイルヘッダー作成 */
	bitMapFileHeader.bfType					= ('M'<<8)+'B';
	bitMapFileHeader.bfSize 				= bfhSize + byte_per_line*height;
	bitMapFileHeader.bfReserved1			= 0;
	bitMapFileHeader.bfReserved2			= 0;
	bitMapFileHeader.bfOffBits				= bfhSize;
	bitMapInfoHeader.biSize					= sizeof(BITMAPINFOHEADER);
	bitMapInfoHeader.biWidth				= width;
	bitMapInfoHeader.biHeight				= height;
	bitMapInfoHeader.biPlanes				= 1;
	bitMapInfoHeader.biBitCount 			= BPP;
	bitMapInfoHeader.biCompression			= 0;
	bitMapInfoHeader.biSizeImage			= 0;
	bitMapInfoHeader.biXPelsPerMeter		= 0;
	bitMapInfoHeader.biYPelsPerMeter		= 0;
	bitMapInfoHeader.biClrUsed				= 0;
	bitMapInfoHeader.biClrImportant			= 0;

	/* カラーテーブル */
	for(i=0;i<NCOLOR;i++) {
		ct->rgbBlue		= c;
		ct->rgbGreen	= c;
		ct->rgbRed 		= c;
		ct->rgbReserved	= 0;
		ct++;
		c -= 0x11;
	}
}

