## The BSB file format

A BSB image file has a .KAP extension and can be optionally accompanied by a .BSB file which stores further cartographic data and relates multiple .KAPs together. It is unusual in that it contains both ASCII text and binary data concatenated together and structured as follows:

- Text header in DOS text format (CR-LF line-endings) terminated by <Control-Z><NUL>
- Binary section consisting of:
  - One or more rows of run-length compressed raster data
  - An index table consisting of 32-bit integers storing file offsets to each image row

#### Text Header

Although described as proprietary by NOAA, much of the information in the ASCII text header is self explanatory. Each line begins with a 3 character token followed by a slash "/". The remainder of the line depends upon the token, but in general consists of a list of comma separated values. If the list of values is too long for 80 columns, the values for the token are continued on the next line by prefixing the new line with 4 spaces. Comments are indicated with a leading "!".

        ! An example BSB text header
        VER/3.0
        BSB/NA=Australia 3000000
            NU=,RA=625,480,DU=50
        KNP/SC=3000000,GD=,PR=LAMBERT CONFORMAL CONIC,PP=145.0
            PI=0.0,SP=Unknown,0,SK=0.0
            UN=METRES,SD=,DX=6000.0,DY=6000.0
        OST/1
        IFM/3
        RGB/1,199,231,252
        RGB/2,174,234,84
        RGB/3,255,254,206
        RGB/4,226,65,6
        DTM/0.0,0.0

The text header is terminated with a <Control-Z><NUL> sequence (ASCII characters 26 and 0). I have derived the following meanings for tokens:

- VER - Version number of BSB format e.g. 1, 2.0, 3.0, 3.07, 4.0
- BSB (or NOS for older GEO/NOS or GEO/NO1 files)
  - RA=width,height - width and height of raster image data in pixels
  - NA=Name given to the BSB chart (can represent more than one .KAP)
  - NU=Number of chart (especially when more than one chart is grouped or tiled together)
  - DU=Drawing Units in pixels/inch (same as DPI resolution) e.g. 50, 150, 175, 254, 300
- OST - Offset STrip image lines (number of image rows per entry in the index table) e.g. 1
- IFM - Depth of the colormap (bits per pixel). BSB supports 1 through 7 (2 through 127 max colors).
- RGB - Entries in the raster colormap of the form index,red,green,blue (index 0 is not used in BSB)
- KNP
  - SC=Scale e.g. 25000
  - GD=Geodetic Datum e.g. NAD83, WGS84
  - PR=Projection e.g. LAMBERT CONFORMAL CONIC, MERCATOR
  - PP=Projection Parameter (value depends upon Projection) e.g. 135.0
  - PI=? e.g. 0.0, 0.033333, 0.083333, 2.0
  - SP=?
  - SK=Skew angle? e.g. 0.0
  - TA=? e.g. 90
  - UN=Units (for DX, DY and others) e.g. METRES, FATHOMS
  - SD=Sounding Datum e.g. MEAN LOWER LOW WATER, HHWLT
  - DX=distance (approx.) covered by one pixel in X direction
  - DY=distance (approx.) covered by one pixel in Y direction
- KNQ
  - P1=...,P2=...
  - P3=...,P4=...
  - P5=...,P6=...
- CED - ? (appears to be optional for many applications)
- REF - Registration reference points (at least 3 points)
- PLY - ?
- DTM - ? (appears to be optional for many applications)

#### Binary Section

The first byte after the <Control-Z><NUL> sequence is a single byte storing the depth of the image, duplicating the information from the IFM token.

Next are one or more rows of run-length encoded raster data terminated by <NUL> characters. Each row, when decompressed, represents one horizontal line of the image.

Rows start with one or more bytes representing the row number. The storage of the row number finishes when the byte is less than 128. Row numbering starts at 1 rather than 0.

The next byte will indicate the color of a pixel using a colormap index. The nature of the bitstream packing limits the color depth to 7 bits. Therefore bytes of value greater than 127 as used to indicate that the next byte stores the 'run' length in addition to storing the colormap index.

### Author

The libbsb library and this web page was written by Stuart Cunningham with GIS related advice from Anuradha Suraparaju. Feedback is welcome.

Copyright (©) 2000, 2004, Stuart Cunningham.