# JPEG

To my best knowledge, the patent on the *QM-coder used in JPEG has expired*. I've read this post recently and started to put some arithmetic decoding into C code. After some crunching days of development this is the result: sample image from that post is on one screen - the decoded on the other one.

Decoder code was based on my JPEG81 coefficient decoder.

## Arithmetic decoding

### Intro

The question is how to store 16-bit signed integers with less bits?

For example 13_{dec}:

0000000000001101 = 13

Dividing into parts:

SIGN 'unused' part significant part
0 00000000000 1101

The significant part is enough to store the number with an additional *length*. It always *starts* with 1 from the left, so it doesn't have to be coded either:

length=3 and 3 bits of 101 = 1101

Nomenclature:

- 3 is the
**magnitude category** (log_{2} for binary numbers)
- 101
_{bin} is the **low order magnitude bits**

Our number will be 2^{3} + 101_{bin}= 8 + 5 = 13.

OK, but lenght is also a number, how to save bits there?

Lenght could be Huffman-coded - thus saving bits. Or arithmetic coded based on probability.

20151012

More to come..