module StumpyJPEG::Quantization

Defined in:

stumpy_jpeg/quantization.cr
stumpy_jpeg/standards.cr

Constant Summary

CHROMA = Matrix.rows([[17, 18, 24, 47, 99, 99, 99, 99], [18, 21, 26, 66, 99, 99, 99, 99], [24, 26, 56, 99, 99, 99, 99, 99], [47, 66, 99, 99, 99, 99, 99, 99], [99, 99, 99, 99, 99, 99, 99, 99], [99, 99, 99, 99, 99, 99, 99, 99], [99, 99, 99, 99, 99, 99, 99, 99], [99, 99, 99, 99, 99, 99, 99, 99]])
LUMA = Matrix.rows([[16, 11, 10, 16, 24, 40, 51, 61], [12, 12, 14, 19, 26, 58, 60, 55], [14, 13, 16, 24, 40, 57, 69, 56], [14, 17, 22, 29, 51, 87, 80, 62], [18, 22, 37, 56, 68, 109, 103, 77], [24, 35, 55, 64, 81, 104, 113, 92], [49, 64, 78, 87, 103, 121, 120, 101], [72, 92, 95, 98, 112, 100, 103, 99]])
SCALING_FACTORS = [0.125, 0.09011997775086848, 0.09567085809127245, 0.10630376184590705, 0.125, 0.1590948225716042, 0.23096988312782163, 0.4530637231764438, 0.09011997775086848, 0.06497288311853625, 0.06897484482073575, 0.07664074121909412, 0.09011997775086848, 0.11470097496345072, 0.16652000582879983, 0.326640741219094, 0.09567085809127245, 0.06897484482073575, 0.07322330470336312, 0.08136137691302557, 0.09567085809127245, 0.12176590554643292, 0.17677669529663684, 0.34675996133053677, 0.10630376184590705, 0.07664074121909412, 0.08136137691302557, 0.09040391826073059, 0.10630376184590705, 0.1352990250365492, 0.19642373959677548, 0.3852990250365491, 0.125, 0.09011997775086848, 0.09567085809127245, 0.10630376184590705, 0.125, 0.1590948225716042, 0.23096988312782163, 0.4530637231764438, 0.1590948225716042, 0.11470097496345072, 0.12176590554643292, 0.1352990250365492, 0.1590948225716042, 0.2024893005527218, 0.29396890060483954, 0.5766407412190938, 0.23096988312782163, 0.16652000582879983, 0.17677669529663684, 0.19642373959677548, 0.23096988312782163, 0.29396890060483954, 0.42677669529663664, 0.8371526015321517, 0.4530637231764438, 0.326640741219094, 0.34675996133053677, 0.3852990250365491, 0.4530637231764438, 0.5766407412190938, 0.8371526015321517, 1.6421338980680102]

Scaling factors for quantization From "Compressed Image File Formats: JPEG, PNG, GIF, XBM, BMP" (1999)

S(i, j) = 0.125 * F(i) * F(j)

F(0) = 1 F(x) = 1 / (Math.sqrt(2) * Math.cos(x * Math::PI / 16.0))