CrImage::JPEG::DCT
Forward Discrete Cosine Transform (DCT) implementation Uses a separable 8x8 transform with precomputed coefficients.
Constants
BASIS = [[0.3535533905932738, 0.3535533905932738, 0.3535533905932738, 0.3535533905932738, 0.3535533905932738, 0.3535533905932738, 0.3535533905932738, 0.3535533905932738], [0.4903926402016152, 0.4157348061512726, 0.27778511650980114, 0.09754516100806417, -0.0975451610080641, -0.277785116509801, -0.4157348061512727, -0.4903926402016152], [0.46193976625564337, 0.19134171618254492, -0.19134171618254486, -0.46193976625564337, -0.4619397662556434, -0.19134171618254517, 0.191341716182545, 0.46193976625564326], [0.4157348061512726, -0.0975451610080641, -0.4903926402016152, -0.2777851165098011, 0.2777851165098009, 0.4903926402016153, 0.0975451610080644, -0.41573480615127256], [0.35355339059327384, -0.35355339059327373, -0.35355339059327384, 0.3535533905932737, 0.35355339059327384, -0.35355339059327334, -0.3535533905932733, 0.35355339059327323], [0.27778511650980114, -0.4903926402016152, 0.09754516100806415, 0.41573480615127273, -0.41573480615127256, -0.09754516100806429, 0.49039264020161516, -0.27778511650980076], [0.19134171618254495, -0.4619397662556434, 0.46193976625564326, -0.19134171618254528, -0.19134171618254495, 0.46193976625564315, -0.4619397662556437, 0.19134171618254314], [0.09754516100806417, -0.2777851165098011, 0.41573480615127273, -0.4903926402016153, 0.4903926402016152, -0.415734806151272, 0.27778511650980076, -0.09754516100806251]]
SCALE = [1.0 / (::Math.sqrt(8.0)), ::Math.sqrt(2.0 / 8.0), ::Math.sqrt(2.0 / 8.0), ::Math.sqrt(2.0 / 8.0), ::Math.sqrt(2.0 / 8.0), ::Math.sqrt(2.0 / 8.0), ::Math.sqrt(2.0 / 8.0), ::Math.sqrt(2.0 / 8.0)]
Class methods
transform(block : Array(Int32)) : Array(Int32)
Perform 2D DCT on an 8x8 block Input: 64-element array of pixel values (0-255 range) Output: 64-element array of DCT coefficients
transform_into(block : Indexable(Int32), result : Array(Int32)) : Nil
Source