.bmp file format of Heroes of Might and Magic: JavaScript 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.

Usage

See the usage examples in the JavaScript notes.

Parse structure from an ArrayBuffer:

var arrayBuffer = ...;
var data = new HeroesOfMightAndMagicBmp(new KaitaiStream(arrayBuffer));

After that, one can get various attributes from the structure by accessing fields or properties like:

data.magic // => get magic

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

HeroesOfMightAndMagicBmp.js

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['kaitai-struct/KaitaiStream'], factory);
  } else if (typeof module === 'object' && module.exports) {
    module.exports = factory(require('kaitai-struct/KaitaiStream'));
  } else {
    root.HeroesOfMightAndMagicBmp = factory(root.KaitaiStream);
  }
}(this, function (KaitaiStream) {
var HeroesOfMightAndMagicBmp = (function() {
  function HeroesOfMightAndMagicBmp(_io, _parent, _root) {
    this._io = _io;
    this._parent = _parent;
    this._root = _root || this;

    this._read();
  }
  HeroesOfMightAndMagicBmp.prototype._read = function() {
    this.magic = this._io.readU2le();
    this.width = this._io.readU2le();
    this.height = this._io.readU2le();
    this.data = this._io.readBytes((this.width * this.height));
  }

  return HeroesOfMightAndMagicBmp;
})();
return HeroesOfMightAndMagicBmp;
}));