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

Parse a local file and get structure in memory:

HeroesOfMightAndMagicBmp data = HeroesOfMightAndMagicBmp.fromFile("path/to/local/file.bmp");

Or parse structure from a byte array:

byte[] someArray = new byte[] { ... };
HeroesOfMightAndMagicBmp data = new HeroesOfMightAndMagicBmp(new ByteBufferKaitaiStream(someArray));

After that, one can get various attributes from the structure by invoking getter methods like:

data.magic() // => get magic

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

HeroesOfMightAndMagicBmp.java

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

import io.kaitai.struct.ByteBufferKaitaiStream;
import io.kaitai.struct.KaitaiStruct;
import io.kaitai.struct.KaitaiStream;
import java.io.IOException;

public class HeroesOfMightAndMagicBmp extends KaitaiStruct {
    public static HeroesOfMightAndMagicBmp fromFile(String fileName) throws IOException {
        return new HeroesOfMightAndMagicBmp(new ByteBufferKaitaiStream(fileName));
    }

    public HeroesOfMightAndMagicBmp(KaitaiStream _io) {
        this(_io, null, null);
    }

    public HeroesOfMightAndMagicBmp(KaitaiStream _io, KaitaiStruct _parent) {
        this(_io, _parent, null);
    }

    public HeroesOfMightAndMagicBmp(KaitaiStream _io, KaitaiStruct _parent, HeroesOfMightAndMagicBmp _root) {
        super(_io);
        this._parent = _parent;
        this._root = _root == null ? this : _root;
        _read();
    }
    private void _read() {
        this.magic = this._io.readU2le();
        this.width = this._io.readU2le();
        this.height = this._io.readU2le();
        this.data = this._io.readBytes((width() * height()));
    }
    private int magic;
    private int width;
    private int height;
    private byte[] data;
    private HeroesOfMightAndMagicBmp _root;
    private KaitaiStruct _parent;
    public int magic() { return magic; }
    public int width() { return width; }
    public int height() { return height; }
    public byte[] data() { return data; }
    public HeroesOfMightAndMagicBmp _root() { return _root; }
    public KaitaiStruct _parent() { return _parent; }
}