From the manual:

bmap_lock(BMAP* bmap,var mode)
Preloads and locks a bitmap and returns its texture format. Mostly used for writing into or reading from a bitmap.
Parameters:
bmap name or pointer of a bmap
mode always 0

You can only access the base texture, not a mipmap. If your texture has mipmaps, call bmap_to_mipmap after manipulating it.