@requires_application()
@pytest.mark.parametrize('data_on_init', [False, True])
@pytest.mark.parametrize('clim_on_init', [False, True])
@pytest.mark.parametrize('num_channels', [0, 1, 3, 4])
@pytest.mark.parametrize('texture_format', [None, '__dtype__', 'auto'])
@pytest.mark.parametrize('input_dtype', [np.uint8, np.uint16, np.float32, np.float64])
def test_image_clims_and_gamma(input_dtype, texture_format, num_channels, clim_on_init, data_on_init):
    'Test image visual with clims and gamma on shader.'
    size = (40, 40)
    if (texture_format == '__dtype__'):
        texture_format = input_dtype
    shape = ((size + (num_channels,)) if (num_channels > 0) else size)
    np.random.seed(0)
    data = _make_test_data(shape, input_dtype)
    (orig_clim, new_clim) = _get_orig_and_new_clims(input_dtype)
    is_16int_cpu_scaled = ((np.dtype(input_dtype).itemsize >= 2) and np.issubdtype(input_dtype, np.integer) and (texture_format is None))
    clim_atol = (2 if is_16int_cpu_scaled else 1)
    gamma_atol = (3 if is_16int_cpu_scaled else 2)
    kwargs = {}
    if clim_on_init:
        kwargs['clim'] = orig_clim
    if data_on_init:
        kwargs['data'] = data
    set_data_fails = ((num_channels != 4) and (texture_format is not None) and (texture_format != 'auto'))
    with TestingCanvas(size=size[::(- 1)], bgcolor='w') as c:
        image = Image(cmap='grays', texture_format=texture_format, parent=c.scene, **kwargs)
        if (not data_on_init):
            _set_image_data(image, data, set_data_fails)
            if set_data_fails:
                return
        rendered = c.render()
        _dtype = rendered.dtype
        shape_ratio = (rendered.shape[0] // data.shape[0])
        rendered1 = downsample(rendered, shape_ratio, axis=(0, 1)).astype(_dtype)
        _compare_render(data, rendered1)
        image.clim = new_clim
        rendered2 = downsample(c.render(), shape_ratio, axis=(0, 1)).astype(_dtype)
        scaled_data = ((np.clip(data, new_clim[0], new_clim[1]) - new_clim[0]) / (new_clim[1] - new_clim[0]))
        _compare_render(scaled_data, rendered2, rendered1, atol=clim_atol)
        image.gamma = 2
        rendered3 = downsample(c.render(), shape_ratio, axis=(0, 1)).astype(_dtype)
        _compare_render((scaled_data ** 2), rendered3, rendered2, atol=gamma_atol)
Test image visual with clims and gamma on shader.
@requires_application()
@pytest.mark.parametrize('data_on_init', [False, True])
@pytest.mark.parametrize('clim_on_init', [False, True])
@pytest.mark.parametrize('num_channels', [0, 1, 3, 4])
@pytest.mark.parametrize('texture_format', [None, '__dtype__', 'auto'])
@pytest.mark.parametrize('input_dtype', [np.uint8, np.uint16, np.float32, np.float64])
def test_image_clims_and_gamma(input_dtype, texture_format, num_channels, clim_on_init, data_on_init):
    
    size = (40, 40)
    if (texture_format == '__dtype__'):
        texture_format = input_dtype
    shape = ((size + (num_channels,)) if (num_channels > 0) else size)
    np.random.seed(0)
    data = _make_test_data(shape, input_dtype)
    (orig_clim, new_clim) = _get_orig_and_new_clims(input_dtype)
    is_16int_cpu_scaled = ((np.dtype(input_dtype).itemsize >= 2) and np.issubdtype(input_dtype, np.integer) and (texture_format is None))
    clim_atol = (2 if is_16int_cpu_scaled else 1)
    gamma_atol = (3 if is_16int_cpu_scaled else 2)
    kwargs = {}
    if clim_on_init:
        kwargs['clim'] = orig_clim
    if data_on_init:
        kwargs['data'] = data
    set_data_fails = ((num_channels != 4) and (texture_format is not None) and (texture_format != 'auto'))
    with TestingCanvas(size=size[::(- 1)], bgcolor='w') as c:
        image = Image(cmap='grays', texture_format=texture_format, parent=c.scene, **kwargs)
        if (not data_on_init):
            _set_image_data(image, data, set_data_fails)
            if set_data_fails:
                return
        rendered = c.render()
        _dtype = rendered.dtype
        shape_ratio = (rendered.shape[0] // data.shape[0])
        rendered1 = downsample(rendered, shape_ratio, axis=(0, 1)).astype(_dtype)
        _compare_render(data, rendered1)
        image.clim = new_clim
        rendered2 = downsample(c.render(), shape_ratio, axis=(0, 1)).astype(_dtype)
        scaled_data = ((np.clip(data, new_clim[0], new_clim[1]) - new_clim[0]) / (new_clim[1] - new_clim[0]))
        _compare_render(scaled_data, rendered2, rendered1, atol=clim_atol)
        image.gamma = 2
        rendered3 = downsample(c.render(), shape_ratio, axis=(0, 1)).astype(_dtype)
        _compare_render((scaled_data ** 2), rendered3, rendered2, atol=gamma_atol)