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

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:

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.

SourceForge.net Logo Valid HTML 4.01! Valid CSS!