All being chars ranging from 30 to 255, based in the rate of change of the last, it can predict the new sample.. but when it is growing and close to 255 it overflows, also when diminishing close to 0.
I am looking for a way to avoid overflows in this case and others.
You can use a longer data type (16 bits signed integers instead of chars). If you need to get 8-bit results (unsigned char), you should check it against the limits (0 and 255) and saturate before convert it to unsigned char.
Regards