I have a matrix
$$A= \begin{pmatrix} 2 & -1 & 4 \\ -3 & 8 & -5\\ 12 & -7 & 16 \end{pmatrix} $$
and I would like to create the matrix
$$B= \begin{pmatrix} 6 & 5 & 6 \\ 11 & 26 & 15\\ 10 & 21 & 12 \end{pmatrix} $$
where each entry of B is the sum of its surrounding cells in $A$. So the first entry of $B$ is $2-1-3+8=6$. The $3\times 3$ matrix and the summing "radius" are a simplification, the question aims at $m \times n$ matrices along with arbitrary rectangular areas to be measured.
Is there some mathematical property which could help avoid having to implement something along the lines of $$b_{kl}=\sum_{l-a}^{l+b}\sum_{k-c}^{k+d}a_{kl} ~~~\text{given that the entries exist}$$ ? Special case: would things be easier if the entries only consisted of a fixed amount of $0$ and $1$?