Implement a fast version of the discrete cosine transform

The implementation is taken from libjpeg version 9a