wiki:rfc15_nodatabitmask

Version 5 (modified by warmerdam, 17 years ago) ( diff )

switch to mask flags.

RFC 14: Null Masks

Author: Frank Warmerdam
Contact: warmerdam@…
Status: Development

Summary

Some file formats support a concept of a bitmask to identify pixels that are not valid data. This can be particularly valuable with byte image formats where a nodata pixel value can not be used because all pixel values have a valid meaning. This RFC tries to formalize a way of recognising and accessing such nodata bitmasks through the GDAL API.

The basic approach is to treat such masks as raster bands, but not regular raster bands on the datasource. Instead they are freestanding raster bands in a manner similar to the overview raster band objects. The nodata masks are represented as GDT_Byte bands with a value of zero indicating nodata and 255 indicating valid data. Intermediate values do not normally occur but in they future they might be interpreted as a confidence value or alpha transparency values.

API

GDALRasterBand is extended with the following methods:

    GDALRasterBand *GetNullMask();
    int             GetNullMaskFlags();

Note that the GetNullMask() should always return a GDALRasterBand mask, even if it is only an all 255 mask with the type indicating "all valid".

The GetNullMaskFlags() method returns an ORed set of status flags with the following available definitions that may be extended in the future:

  • GNMF_ALL_VALID(0x01): There are no invalid pixels, all mask values will be 255. When used this will normally be the only flag set.
  • GNMF_PER_DATASET(0x02): The mask band is shared between all bands on the dataset.
  • GNMF_ALPHA(0x04): The mask band is actually an alpha band and may have values other than 0 and 255.

Note that the GetNullMask() should always return a GDALRasterBand mask, even if it is only an all 255 mask with the flag GNMF_ALL_VALID set.

Default Implementation

The GDALRasterBand class will include a default implementation of GetNullMask() that returns one of two default implementations. The first default implement is a GNMF_ALL_VALID band that returns all 255. The second default implementation would return a mask computed by reading the imagery data and comparing it to the nodata value. The nodata based one would be used when the base band has a nodata value set.

Drivers Updated

These drivers will be updated:

  • JPEG Driver: support the "zlib compressed mask appended to the file" approach used by a few data providers.
  • GRASS Driver: updated to support handling null values as masks.

Possibly updated:

  • HDF4 Driver: This driver might possibly be updated to return real mask if we can figure out a way.
  • SDE Driver: This driver might be updated if Howard has sufficient time and enthusiasm.

Implementation Plan

This change will be implemented by Frank Warmerdam in trunk in time for the 1.5.0 release.

SWIG Implications

The GetNullMask() and GetNullMaskFlags() methods (and corrsponding defines) will need to be added. The bitmask should work like a normal raster band for swig purposes so minimal special work should be required.

Testing

Issues

I'm tempted to change GetNullMaskType() into GetNullMaskFlags() and have the result be an or-ed set of flags. It would allow us to differentiate mask bands auto generated from nodata, and add special interpretations in the future, like is-alpha or is-confidence.

  • I haven't filled in how creation of masks works.
  • I haven't talked about bitmask-via-spill file possibilities for the PAM subsystem.
Note: See TracWiki for help on using the wiki.