Data Compression with Diagram Encoding and Pattern Substitution