class_docstr: Three-dimensional color lookup table.
  
  Transforms 3-channel pixels using the values of the channels as coordinates
  in the 3D lookup table and interpolating the nearest elements.
  
  This method allows you to apply almost any color transformation
  in constant time by using pre-calculated decimated tables.
  
  .. versionadded:: 5.2.0
  
  :param size: Size of the table. One int or tuple of (int, int, int).
               Minimal size in any dimension is 2, maximum is 65.
  :param table: Flat lookup table. A list of ``channels * size**3``
                float elements or a list of ``size**3`` channels-sized
                tuples with floats. Channels are changed first,
                then first dimension, then second, then third.
                Value 0.0 corresponds lowest value of output, 1.0 highest.
  :param channels: Number of channels in the table. Could be 3 or 4.
                   Default is 3.
  :param target_mode: A mode for the result image. Should have not less
                      than ``channels`` channels. Default is ``None``,
                      which means that mode wouldn't be changed.
class_docstr_tok: ["Three-dimensional","color","lookup","table",".","Transforms","3-channel","pixels","using","the","values","of","the","channels","as","coordinates","in","the","3D","lookup","table","and","interpolating","the","nearest","elements",".","This","method","allows","you","to","apply","almost","any","color","transformation","in","constant","time","by","using","pre-calculated","decimated","tables",".","..","versionadded",":",":","5.2.0",":","param","size",":","Size","of","the","table",".","One","int","or","tuple","of","(","int",",","int",",","int",")",".","Minimal","size","in","any","dimension","is","2",",","maximum","is","65.",":","param","table",":","Flat","lookup","table",".","A","list","of","``","channels","*","size","*","*","3","``","float","elements","or","a","list","of","``","size","*","*","3","``","channels-sized","tuples","with","floats",".","Channels","are","changed","first",",","then","first","dimension",",","then","second",",","then","third",".","Value","0.0","corresponds","lowest","value","of","output",",","1.0","highest",".",":","param","channels",":","Number","of","channels","in","the","table",".","Could","be","3","or","4",".","Default","is","3.",":","param","target_mode",":","A","mode","for","the","result","image",".","Should","have","not","less","than","``","channels","``","channels",".","Default","is","``","None","``",",","which","means","that","mode","would","n't","be","changed","."]
docstr: Transforms the table values using provided callback and returns
  a new LUT with altered values.
  
  :param callback: A function which takes old lookup table values
                   and returns a new set of values. The number
                   of arguments which function should take is
                   ``self.channels`` or ``3 + self.channels``
                   if ``with_normals`` flag is set.
                   Should return a tuple of ``self.channels`` or
                   ``channels`` elements if it is set.
  :param with_normals: If true, ``callback`` will be called with
                       coordinates in the color cube as the first
                       three arguments. Otherwise, ``callback``
                       will be called only with actual color values.
  :param channels: The number of channels in the resulting lookup table.
  :param target_mode: Passed to the constructor of the resulting
                      lookup table.
docstr_tok: ["Transforms","the","table","values","using","provided","callback","and","returns","a","new","LUT","with","altered","values",".",":","param","callback",":","A","function","which","takes","old","lookup","table","values","and","returns","a","new","set","of","values",".","The","number","of","arguments","which","function","should","take","is","``","self.channels","``","or","``","3","+","self.channels","``","if","``","with_normals","``","flag","is","set",".","Should","return","a","tuple","of","``","self.channels","``","or","``","channels","``","elements","if","it","is","set",".",":","param","with_normals",":","If","true",",","``","callback","``","will","be","called","with","coordinates","in","the","color","cube","as","the","first","three","arguments",".","Otherwise",",","``","callback","``","will","be","called","only","with","actual","color","values",".",":","param","channels",":","The","number","of","channels","in","the","resulting","lookup","table",".",":","param","target_mode",":","Passed","to","the","constructor","of","the","resulting","lookup","table","."]
code: def transform(
      self,
      callback,
      with_normals=False,
      channels=None,
      target_mode=None,
  ):
      """Transforms the table values using provided callback and returns
      a new LUT with altered values.
  
      :param callback: A function which takes old lookup table values
                       and returns a new set of values. The number
                       of arguments which function should take is
                       ``self.channels`` or ``3 + self.channels``
                       if ``with_normals`` flag is set.
                       Should return a tuple of ``self.channels`` or
                       ``channels`` elements if it is set.
      :param with_normals: If true, ``callback`` will be called with
                           coordinates in the color cube as the first
                           three arguments. Otherwise, ``callback``
                           will be called only with actual color values.
      :param channels: The number of channels in the resulting lookup table.
      :param target_mode: Passed to the constructor of the resulting
                          lookup table.
      """
      if channels not in (None, 3, 4):
          raise ValueError("Only 3 or 4 output channels are supported")
      ch_in = self.channels
      ch_out = channels or ch_in
      size1D, size2D, size3D = self.size
  
      table = [0] * (size1D * size2D * size3D * ch_out)
      idx_in = 0
      idx_out = 0
      for b in range(size3D):
          for g in range(size2D):
              for r in range(size1D):
                  values = self.table[idx_in : idx_in + ch_in]
                  if with_normals:
                      values = callback(
                          r / (size1D - 1),
                          g / (size2D - 1),
                          b / (size3D - 1),
                          *values,
                      )
                  else:
                      values = callback(*values)
                  table[idx_out : idx_out + ch_out] = values
                  idx_in += ch_in
                  idx_out += ch_out
  
      return type(self)(
          self.size,
          table,
          channels=ch_out,
          target_mode=target_mode or self.mode,
          _copy_table=False,
      )
  
imports: import functools
label_desc: Use image node_id 4 for calling the Color3DLUT obj's underlying member method code with example usage: obj.transform(callback, with_normals, channels, target_mode) and returns: type