def session_ps_14bit(max_h, max_w):
    """Trim size to 14-bit limitation
    """
    # why 16383 instead of 16384 for 14-bit?
    max_h = max(max_h, 24)
    max_w = max(max_w, 80)
    max_h = min(max_h, 204)  # 16383 // 80
    max_w = min(max_w, 682)  # 16383 // 24

    if max_h >= 127 and max_w >= 129:
        return 127, 129  # 127*129=16383

    if max_h >= 129 and max_w >= 127:
        return 129, 127  # 129*127=16383

    if max_h * max_w <= 16383:
        return max_h, max_w

    return 16383 // max_w, max_w