code: def build_colormap(palette, dtype, info):
          
          from trollimage.colormap import Colormap
          sqpalette = np.asanyarray(palette).squeeze() / 255.0
          if hasattr(palette, 'attrs') and 'palette_meanings' in palette.attrs:
              meanings = palette.attrs['palette_meanings']
              iterator = zip(meanings, sqpalette)
          else:
              iterator = enumerate(sqpalette[:-1])
  
          if dtype == np.dtype('uint8'):
              tups = [(val, tuple(tup))
                      for (val, tup) in iterator]
              colormap = Colormap(*tups)
  
          elif 'valid_range' in info:
              tups = [(val, tuple(tup))
                      for (val, tup) in iterator]
              colormap = Colormap(*tups)
  
              sf = info.get('scale_factor', np.array(1))
              colormap.set_range(
                  *info['valid_range'] * sf + info.get('add_offset', 0))
  
          return colormap, sqpalette
docs: Create the colormap from the `raw_palette` and the valid_range.