/*---------------------------------------------------------------------------
 * BMPSAVER_Color BMPFILEユーティリティ
 * bscbmp_u.c (2000/07/19 - 2000/12/24)
 * 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 <sys/libwwc.h>

#include "bsbmp_d.h"

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

/*--------------------------------------------------------------------*/
/* BMPFILE ヘッダー情報初期化 */
void bsc_bmp_init_header(int width, int height)
{
	int bfhSize;
	int byte_per_line;

	RGBQUAD far *ct = colortable;
	int i, j;

	/* １ラインにつき何バイト？*/
	byte_per_line = (width+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<16;i++) {
		for(j=0;j<16;j++) {
			unsigned c = wwc_palette_get_color(i, j);
			ct->rgbBlue		= (((c&0x000f)   )+1)*16-1;
			ct->rgbGreen	= (((c&0x00f0)>>4)+1)*16-1;
			ct->rgbRed 		= (((c&0x0f00)>>8)+1)*16-1;
			ct->rgbReserved	= 0;
			ct++;
		}
	}
}

