I'm not sure your supposition is right... I believe the compression is considerably more complex than that - your method is a lossless compression, that isn't particularly efficient: jpg uses a Human vision system based around 8x8 blocks
image of process[
^]
wiki description[
^]
I suspect that if you want to do this, you are going to have to convert your jpeg to a bitmap, play with it, then convert it back - which will lose you image quality.