code: def fill_array(dstarr, order, r, g, b, a):
      
      # TODO: can we make this more efficient?
      dtype = dstarr.dtype
      maxv = np.iinfo(dtype).max
      bgval = dict(A=int(maxv * a), R=int(maxv * r), G=int(maxv * g),
                   B=int(maxv * b))
      bgtup = tuple([bgval[order[i]] for i in range(len(order))])
      if dtype is np.uint8 and len(bgtup) == 4:
          # optimiztion
          bgtup = np.array(bgtup, dtype=dtype).view(np.uint32)[0]
          dstarr = dstarr.view(np.uint32)
  
      dstarr[..., :] = bgtup
docs: Fill array dstarr with a color value. order defines the color planes
      in the array.  (r, g, b, a) are expected to be in the range 0..1 and
      are scaled to the appropriate values.
  
      dstarr can be a 2D or 3D array.