#BMP テスト
64ドット * 64ドットの灰色の四角形(test.bmp)を書き出します。
色々適当に試したメモ帳。
fun file_header nx ny =
{bfType = "BM", bfSize = 14 + 40 + nx * ny * 3, bfReserved1 = 0, bfReserved2 = 0, bfOffBits = 14 + 40}
fun info_header nx ny =
{biSize = 40, biWidth = nx , biHeight = ny, biPlanes = 1, biBitCount = 24, biCompression = 0, biSizeImage = nx * ny * 3, biXPelsPerMeter = 3780, biYpelsPerMeter = 3780, biClrUsed = 0, biClrImportant =0}
fun str_int2 i =
str (chr (i mod 256)) ^ str (chr (i div 256))
fun str_int4 i =
str (chr (i mod 256)) ^ str (chr (i div 256 mod 256)) ^ str (chr (i div (256 * 256) mod 256)) ^ str (chr (i div (256 * 256 * 256) mod 256))
fun bin_file_header fh =
#bfType fh ^ str_int4 (#bfSize fh) ^ str_int2 (#bfReserved1 fh) ^ str_int2 (#bfReserved2 fh) ^ str_int4 (#bfOffBits fh)
fun bin_info_header ih =
str_int4 (#biSize ih) ^ str_int4 (#biWidth ih) ^ str_int4 (#biHeight ih) ^ str_int2 (#biPlanes ih) ^ str_int2 (#biBitCount ih) ^ str_int4 (#biCompression ih) ^ str_int4 (#biSizeImage ih) ^ str_int4 (#biXPelsPerMeter ih) ^ str_int4 (#biYpelsPerMeter ih)
^ str_int4 (#biClrUsed ih) ^ str_int4 (#biClrImportant ih)
fun a_to_str' a n i res =
if i = n then res
else a_to_str' a n (i + 1) (res ^ (str (chr (Array.sub(a, i)))))
fun a_to_str a =
a_to_str' a (Array.length a) 0 ""
val a = Array.array(64 * 64 * 3, 127);
val f = TextIO.openOut("test.bmp");
val fh = file_header 64 64;
val ih = info_header 64 64;
val q1 = bin_file_header fh;
val q2 = bin_info_header ih;
val q3 = a_to_str a;
TextIO.output(f, q1 ^ q2 ^ q3);
TextIO.closeOut(f);