# Path: gsdview/imgutils.py
# def linear_lut(vmin=0, vmax=None, dtype='uint8', fill=False, omin=0,
#                omax=None):
#     """Compute a linear LUT.
# 
#     The returned LUT maps the imput domain (vmin, vmax) onto the output
#     one (0, vout) using a linear low. The value of vout depends on
#     dtype: 2**8-1 if dtype='uint8', 2**16-1 dtype='uint16'
# 
#     The *fill* parameter can be used to control the length of returned
#     LUT (see below).
# 
#     :param vmin:
#         minimum value (positive or null). Default 0
#     :type vmin:
#         int or float
#     :param vmax:
#         maximum value (positive) Default 2**nbits depending on dtype
#     :type vmax:
#         int or float
#     :param dtype:
#         numpy data type of the output LUT (default uint8)
#     :type dtype:
#         np.dtype (uint8 or uint16)
#     :param fill:
#         the length of the returned lut is:
# 
#             * vmax + 1 if bool(fill) == False
#             * max(vmax + 1, 2**nbits) if fill == True
#             * max(vmax + 1, fill) if fill is an number
# 
#     :type fill:
#         bool or int
#     :param omin:
#         @TBW
#     :param omax:
#         @TBW
#     :returns:     the look up table (LUT)
# 
#     """
# 
#     dtype = np.dtype(dtype)
#     if dtype not in (np.uint8, np.uint16):
#         raise ValueError(
#             'invalid dtype "%s" (uint8 or uint16 expected)' % dtype)
#     nmax = 2**(8 * dtype.itemsize)
# 
#     if omax is None:
#         omax = nmax - 1
# 
#     if vmax is None:
#         vmax = nmax - 1
#         nout = nmax
#     else:
#         nout = int(vmax + 1)
# 
#     if vmin < 0:
#         vmin = 0
# 
#     if fill is True:
#         nout = max(nout, nmax)
#     elif fill:
#         nout = max(nout, fill)
# 
#     if nout > 2**32:
#         raise ValueError('requested LUT is too large: %d.' % nout)
# 
#     lut = np.arange(nout, dtype='float32')
#     if vmin:
#         lut -= float(vmin)
# 
#     scale = float(omax - omin) / (vmax - vmin)
#     if scale != 1.0:
#         lut = np.round(scale * lut)
#     if omin:
#         lut += omin
# 
#     return lut.clip(omin, omax).astype(dtype)


import numpy as np
import os
import sys
import unittest
import numpy as np
from gsdview.imgutils import linear_lut
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  US




# Fix sys path
GSDVIEWROOT = os.path.abspath(
    os.path.join(os.path.dirname(__file__), os.pardir))
sys.path.insert(0, GSDVIEWROOT)




class TestLinearLUT(unittest.TestCase):
    def test_all_defaults(self):
        lut = linear_lut()
        self.assertEqual(lut.dtype, np.uint8)
        self.assertTrue(np.all(lut == np.arange(2**8, dtype='uint8')))

    def test_dtype_uint8(self):
        lut = linear_lut(dtype='uint8')
        self.assertEqual(lut.dtype, np.uint8)
        self.assertTrue(np.all(lut == np.arange(2**8, dtype='uint8')))

    def test_dtype_uint16(self):
        lut = linear_lut(dtype='uint16')
        self.assertEqual(lut.dtype, np.uint16)
        self.assertTrue(np.all(lut == np.arange(2**16, dtype='uint16')))

    def test_dtype_invalid(self):

# Path: gsdview/imgutils.py
# def linear_lut(vmin=0, vmax=None, dtype='uint8', fill=False, omin=0,
#                omax=None):
#     """Compute a linear LUT.
# 
#     The returned LUT maps the imput domain (vmin, vmax) onto the output
#     one (0, vout) using a linear low. The value of vout depends on
#     dtype: 2**8-1 if dtype='uint8', 2**16-1 dtype='uint16'
# 
#     The *fill* parameter can be used to control the length of returned
#     LUT (see below).
# 
#     :param vmin:
#         minimum value (positive or null). Default 0
#     :type vmin:
#         int or float
#     :param vmax:
#         maximum value (positive) Default 2**nbits depending on dtype
#     :type vmax:
#         int or float
#     :param dtype:
#         numpy data type of the output LUT (default uint8)
#     :type dtype:
#         np.dtype (uint8 or uint16)
#     :param fill:
#         the length of the returned lut is:
# 
#             * vmax + 1 if bool(fill) == False
#             * max(vmax + 1, 2**nbits) if fill == True
#             * max(vmax + 1, fill) if fill is an number
# 
#     :type fill:
#         bool or int
#     :param omin:
#         @TBW
#     :param omax:
#         @TBW
#     :returns:     the look up table (LUT)
# 
#     """
# 
#     dtype = np.dtype(dtype)
#     if dtype not in (np.uint8, np.uint16):
#         raise ValueError(
#             'invalid dtype "%s" (uint8 or uint16 expected)' % dtype)
#     nmax = 2**(8 * dtype.itemsize)
# 
#     if omax is None:
#         omax = nmax - 1
# 
#     if vmax is None:
#         vmax = nmax - 1
#         nout = nmax
#     else:
#         nout = int(vmax + 1)
# 
#     if vmin < 0:
#         vmin = 0
# 
#     if fill is True:
#         nout = max(nout, nmax)
#     elif fill:
#         nout = max(nout, fill)
# 
#     if nout > 2**32:
#         raise ValueError('requested LUT is too large: %d.' % nout)
# 
#     lut = np.arange(nout, dtype='float32')
#     if vmin:
#         lut -= float(vmin)
# 
#     scale = float(omax - omin) / (vmax - vmin)
#     if scale != 1.0:
#         lut = np.round(scale * lut)
#     if omin:
#         lut += omin
# 
#     return lut.clip(omin, omax).astype(dtype)


# Path: tests/test_lut.py
import numpy as np
import os
import sys
import unittest
import numpy as np
from gsdview.imgutils import linear_lut

# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  US




# Fix sys path
GSDVIEWROOT = os.path.abspath(
    os.path.join(os.path.dirname(__file__), os.pardir))
sys.path.insert(0, GSDVIEWROOT)




class TestLinearLUT(unittest.TestCase):
    def test_all_defaults(self):
        lut = linear_lut()
        self.assertEqual(lut.dtype, np.uint8)
        self.assertTrue(np.all(lut == np.arange(2**8, dtype='uint8')))

    def test_dtype_uint8(self):
        lut = linear_lut(dtype='uint8')
        self.assertEqual(lut.dtype, np.uint8)
        self.assertTrue(np.all(lut == np.arange(2**8, dtype='uint8')))

    def test_dtype_uint16(self):
        lut = linear_lut(dtype='uint16')
        self.assertEqual(lut.dtype, np.uint16)
        self.assertTrue(np.all(lut == np.arange(2**16, dtype='uint16')))

    def test_dtype_invalid(self):

        self.assertRaises(TypeError, linear_lut, dtype=0)