code: def get_shape_view(self, shape_obj, avoid_oob=True):
          
          x1, y1, x2, y2 = [int(np.round(n)) for n in shape_obj.get_llur()]
  
          if avoid_oob:
              # avoid out of bounds indexes
              wd, ht = self.get_size()
              x1, x2 = max(0, x1), min(x2, wd - 1)
              y1, y2 = max(0, y1), min(y2, ht - 1)
  
          # calculate pixel containment mask in bbox
          yi = np.mgrid[y1:y2 + 1].reshape(-1, 1)
          xi = np.mgrid[x1:x2 + 1].reshape(1, -1)
          pts = np.asarray((xi, yi)).T
          contains = shape_obj.contains_pts(pts)
  
          view = np.s_[y1:y2 + 1, x1:x2 + 1]
          return (view, contains)
docs: Calculate a bounding box in the data enclosing `shape_obj` and
          return a view that accesses it and a mask that is True only for
          pixels enclosed in the region.
  
          If `avoid_oob` is True (default) then the bounding box is clipped
          to avoid coordinates outside of the actual data.