JPEG compression is based on truncated 2D cosine transforms. It's probably not worth to invent your own if there is a highly optimized industry standart format that does the same thing.
You can read and write JPEG files using the "graphics&Sound...graphics Formats" palette.