display-name: "Images/BMP"

file-format windows-bitmap
{
	struct file-header
	{
		fixed-string(2) signature == "BM"
		unsigned32 file-size-check == file.size
		unsigned16 x-hotspot
		unsigned16 y-hotspot
		unsigned32 image-offset
	}

	struct bitmap-header
	{
		unsigned32 header-size
		unsigned32 bitmap-width
		unsigned32 bitmap-height
		unsigned16 color-planes == 1
		unsigned16 bits-per-pixel

		if (bitmap-header.header-size == 16)
		{
			unsigned32 compression
		}
		else
		{
			compression: 0
		}
	}

	struct [file.remaining-bytes] at file-header.image-offset
	{
		image
		{
			row-size-bits: bitmap-header.bits-per-pixel * bitmap-header.bitmap-width
			row-size-bytes: row-size-bits / 8
			if ((row-size-bits % 8) != 0)
			{
				row-size-bytes: row-size-bytes + 1
			}

			if ((row-size-bytes % 4) != 0)
			{
				row-stride: ((row-size-bytes / 4) + 1) * 4
			}

			format: "R8G8B8"
			width: bitmap-header.bitmap-width
			height: bitmap-header.bitmap-height
			flip-y: true
		}
	}
}

if (file.name like "*.*")
{
	interpret-as "windows-bitmap"
}
