Optimizing freeform lenses for extended sources with algorithmic differentiable ray tracing and truncated