# Path: crayimage/imgutils/utils.py
# def wrong_dtype_exception(dtype):
#   return Exception(
#     'Image type (%s) does not understood. '
#     'For RAW images use ndarrays of %s type, for RGB model use ndarrays of %s type' % \
#     (dtype, RAW_T, RGB_T)
#   )


import numpy as np
from .special import COUNT_T, RGB_T, RAW_T, BIN_T
from .special import binning_rgb
from .special import binning_raw
from .utils import wrong_dtype_exception
__all__ = [
  'binnig_update',
  'binning',
  'uniform_mapping',
  'greedy_max_entropy_mapping',
  'almost_uniform_mapping'
]





def binnig_update(img, out, mapping=None):
  bins = out.shape[-1]
  n_channels = img.shape[0]

  if img.dtype == RGB_T:
    binning_rgb(img.reshape(n_channels, -1), mapping, out.reshape(n_channels, -1, bins))
    return out
  elif img.dtype == RAW_T:
    binning_raw(img.reshape(1, -1), mapping, out.reshape(1, -1, bins))
    return out
  else:

# Path: crayimage/imgutils/utils.py
# def wrong_dtype_exception(dtype):
#   return Exception(
#     'Image type (%s) does not understood. '
#     'For RAW images use ndarrays of %s type, for RGB model use ndarrays of %s type' % \
#     (dtype, RAW_T, RGB_T)
#   )


# Path: crayimage/imgutils/binning.py
import numpy as np
from .special import COUNT_T, RGB_T, RAW_T, BIN_T
from .special import binning_rgb
from .special import binning_raw
from .utils import wrong_dtype_exception

__all__ = [
  'binnig_update',
  'binning',
  'uniform_mapping',
  'greedy_max_entropy_mapping',
  'almost_uniform_mapping'
]





def binnig_update(img, out, mapping=None):
  bins = out.shape[-1]
  n_channels = img.shape[0]

  if img.dtype == RGB_T:
    binning_rgb(img.reshape(n_channels, -1), mapping, out.reshape(n_channels, -1, bins))
    return out
  elif img.dtype == RAW_T:
    binning_raw(img.reshape(1, -1), mapping, out.reshape(1, -1, bins))
    return out
  else:

    raise wrong_dtype_exception(img.dtype)