You will easily find algorithms in the literature.
In general, these filters involve adding/subtracting (always), multiplication (often) and division (sometimes).
The scanning sequence tends to be 1st in x, then in y. But this is not mandatory, just convenience, as the images tend to be available as arrays[x[[y].