.bmp file format of Heroes of Might and Magic: Lua parsing library

Application

Heroes of Might and Magic

File extension

bmp

KS implementation details

License: CC0-1.0

This page hosts a formal specification of .bmp file format of Heroes of Might and Magic using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Lua source code to parse .bmp file format of Heroes of Might and Magic

heroes_of_might_and_magic_bmp.lua

-- This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
--
-- This file is compatible with Lua 5.3

local class = require("class")
require("kaitaistruct")

HeroesOfMightAndMagicBmp = class.class(KaitaiStruct)

function HeroesOfMightAndMagicBmp:_init(io, parent, root)
  KaitaiStruct._init(self, io)
  self._parent = parent
  self._root = root or self
  self:_read()
end

function HeroesOfMightAndMagicBmp:_read()
  self.magic = self._io:read_u2le()
  self.width = self._io:read_u2le()
  self.height = self._io:read_u2le()
  self.data = self._io:read_bytes((self.width * self.height))
end