github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/zdct/block.go (about) 1 // Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package zdct 6 7 const blockSize = 64 // A DCT block is 8x8. 8 9 type block [blockSize]int32 10 11 const ( 12 w1 = 2841 // 2048*sqrt(2)*cos(1*pi/16) 13 w2 = 2676 // 2048*sqrt(2)*cos(2*pi/16) 14 w3 = 2408 // 2048*sqrt(2)*cos(3*pi/16) 15 w5 = 1609 // 2048*sqrt(2)*cos(5*pi/16) 16 w6 = 1108 // 2048*sqrt(2)*cos(6*pi/16) 17 w7 = 565 // 2048*sqrt(2)*cos(7*pi/16) 18 19 w1pw7 = w1 + w7 20 w1mw7 = w1 - w7 21 w2pw6 = w2 + w6 22 w2mw6 = w2 - w6 23 w3pw5 = w3 + w5 24 w3mw5 = w3 - w5 25 26 r2 = 181 // 256/sqrt(2) 27 ) 28 29 // unzig maps from the zig-zag ordering to the natural ordering. For example, 30 // unzig[3] is the column and row of the fourth element in zig-zag order. The 31 // value is 16, which means first column (16%8 == 0) and third row (16/8 == 2). 32 var unzig = [blockSize]int{ 33 0, 1, 8, 16, 9, 2, 3, 10, 34 17, 24, 32, 25, 18, 11, 4, 5, 35 12, 19, 26, 33, 40, 48, 41, 34, 36 27, 20, 13, 6, 7, 14, 21, 28, 37 35, 42, 49, 56, 57, 50, 43, 36, 38 29, 22, 15, 23, 30, 37, 44, 51, 39 58, 59, 52, 45, 38, 31, 39, 46, 40 53, 60, 61, 54, 47, 55, 62, 63, 41 } 42 43 type quantIndex int 44 45 const ( 46 quantIndexLuminance quantIndex = iota 47 quantIndexChrominance 48 nQuantIndex 49 ) 50 51 // unscaledQuant are the unscaled quantization tables in zig-zag order. Each 52 // encoder copies and scales the tables according to its quality parameter. 53 // The values are derived from section K.1 after converting from natural to 54 // zig-zag order. 55 var unscaledQuant = [nQuantIndex][blockSize]byte{ 56 // Luminance. 57 { 58 16, 11, 12, 14, 12, 10, 16, 14, 59 13, 14, 18, 17, 16, 19, 24, 40, 60 26, 24, 22, 22, 24, 49, 35, 37, 61 29, 40, 58, 51, 61, 60, 57, 51, 62 56, 55, 64, 72, 92, 78, 64, 68, 63 87, 69, 55, 56, 80, 109, 81, 87, 64 95, 98, 103, 104, 103, 62, 77, 113, 65 121, 112, 100, 120, 92, 101, 103, 99, 66 }, 67 // Chrominance. 68 { 69 17, 18, 18, 24, 21, 24, 47, 26, 70 26, 47, 99, 66, 56, 66, 99, 99, 71 99, 99, 99, 99, 99, 99, 99, 99, 72 99, 99, 99, 99, 99, 99, 99, 99, 73 99, 99, 99, 99, 99, 99, 99, 99, 74 99, 99, 99, 99, 99, 99, 99, 99, 75 99, 99, 99, 99, 99, 99, 99, 99, 76 99, 99, 99, 99, 99, 99, 99, 99, 77 }, 78 }