@classmethod
def generate(cls, size, callback, channels=3, target_mode=None):
    """Generates new LUT using provided callback.

        :param size: Size of the table. Passed to the constructor.
        :param callback: Function with three parameters which correspond
                         three color channels. Will be called ``size**3``
                         times with values from 0.0 to 1.0 and should return
                         a tuple with ``channels`` elements.
        :param channels: The number of channels which should return callback.
        :param target_mode: Passed to the constructor of the resulting
                            lookup table.
        """
    size1D, size2D, size3D = cls._check_size(size)
    if channels not in (3, 4):
        raise ValueError('Only 3 or 4 output channels are supported')
    table = [0] * (size1D * size2D * size3D * channels)
    idx_out = 0
    for b in range(size3D):
        for g in range(size2D):
            for r in range(size1D):
                table[idx_out:idx_out + channels] = callback(r / (size1D - 
                    1), g / (size2D - 1), b / (size3D - 1))
                idx_out += channels
    return cls((size1D, size2D, size3D), table, channels=channels,
        target_mode=target_mode, _copy_table=False)
