def shade(renderbuffer, bufferbbox, img3d, bbox):
  """Shade a renderbuffer with a downloaded chunk. 
    The buffer will only be painted in the overlapping
    region of the content."""

  if not Bbox.intersects(bufferbbox, bbox):
    return

  spt = max2(bbox.minpt, bufferbbox.minpt)
  ept = min2(bbox.maxpt, bufferbbox.maxpt)

  ZERO3 = Vec(0,0,0)

  istart = max2(spt - bbox.minpt, ZERO3)
  iend = min2(ept - bbox.maxpt, ZERO3) + img3d.shape[:3]

  rbox = Bbox(spt, ept) - bufferbbox.minpt
  if len(img3d.shape) == 3:
    img3d = img3d[ :, :, :, np.newaxis]
  
  renderbuffer[ rbox.to_slices() ] = img3d[ istart.x:iend.x, istart.y:iend.y, istart.z:iend.z, : ]
def shade ( renderbuffer , bufferbbox , img3d , bbox ) : if not Bbox . intersects ( bufferbbox , bbox ) : return spt = max2 ( bbox . minpt , bufferbbox . minpt ) ept = min2 ( bbox . maxpt , bufferbbox . maxpt ) ZERO3 = Vec ( 0 , 0 , 0 ) istart = max2 ( spt - bbox . minpt , ZERO3 ) iend = min2 ( ept - bbox . maxpt , ZERO3 ) + img3d . shape [ : 3 ] rbox = Bbox ( spt , ept ) - bufferbbox . minpt if len ( img3d . shape ) == 3 : img3d = img3d [ : , : , : , np . newaxis ] renderbuffer [ rbox . to_slices ( ) ] = img3d [ istart . x : iend . x , istart . y : iend . y , istart . z : iend . z , : ]
Shade a renderbuffer with a downloaded chunk. 
    The buffer will only be painted in the overlapping
    region of the content.