@staticmethod
def _fix_crop_offset_size(offset, size, raster_size, allow_larger=False):
    """Check and correct default values of invalid offset or size"""
    if offset > raster_size or offset + size < 0:
        raise ValueError(
            'Cropping region is outside the image! offset: %f size: %f' % (
            float(offset), float(size)))
    if allow_larger:
        return offset, size
    if offset < 0:
        size += offset
        offset = 0
    if size + offset > raster_size:
        size = raster_size - offset
    return offset, size
