ozf2: format specification

This page hosts a formal specification of ozf2 using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Block diagram

Format specification in Kaitai Struct YAML

meta:
  id: ozf2
  endian: le
seq:
  - id: header1
    type: header1
  - id: header2
    type: header2
  - id: zoom_levels
    type: zoom_levels_header
  - id: images
    type: images
instances:
  zoom_levels_footer:
    pos: _io.size - 4 * zoom_levels.num_zoom_levels
    type: zlf
types:
  header1:
    seq:
      - id: magic
        contents: "xw"
      - id: locked
        type: u4
      - id: tile_width
        type: u2
      - id: version
        type: u2
      - id: old_header_size
        type: u4
  header2:
    seq:
      - id: header_size
        type: u4
        doc: Always 40
      - id: image_width
        type: u4
        doc: Width of the image, px
      - id: image_height
        type: u4
        doc: Height of the image, px
      - id: image_depth
        type: u2
        doc: Must be 1
      - id: image_bpp
        type: u2
        doc: Must be 8
      - id: reserved1
        contents: [0, 0, 0, 0]
      - id: memory_size
        type: u4
        doc: height * width; probably not used and contains junk if it exceeds 0xFFFFFFFF (which is perfectly ok)
      - id: reserved2
        contents: [0, 0, 0, 0, 0, 0, 0, 0]
      - type: u4
      - type: u4
  zoom_levels_header:
    seq:
      - id: magic
        contents: "wwww"
      - id: num_zoom_levels
        type: u2
      - id: zoom_levels
        type: f4
        repeat: expr
        repeat-expr: num_zoom_levels
  images:
    seq:
      - id: magic
        contents: "wwww"
      - id: body
        size: 1000
        process: zlib
  zlf:
    seq:
      - id: tiles
        type: tile_by_offset
        repeat: eos
  tile_by_offset:
    seq:
      - id: offset
        type: u4
    instances: