def get_nodata_value(max_value):
    """
    Calculate the appropriate nodata value based on max of value range for the
    output image type

    Parameters
    ----------
    max_value : number
        max encoded value

    Returns
    -------
    int, nodata value
    """

    if max_value < 255:  # uint8 / grayscale
        return 255
    if max_value < 65535:  # uint16 / RGB
        return 65535
    if max_value < 16777215:  # uint32 / RGB
        return 16777215
    if max_value < 4294967295:  # uint32 / RGBA
        return 4294967295

    raise Exception("value is too large for uint32 / rgba")