TMDS的编码和解码,从8bit编码为10bit,并解码。
在编码为10bit的过程中,使用的是最小化差分算法和直流平衡算法。当然,TMDS是比LVDS强多了,一分钱一分货。
TMDS是收费的,貌似有版权费用,亲们小心使用~不过TMDS真的是很强大~
编码示意图:
请参考代码TMDS_Encode;
http://blog.csdn.net/shanghaiqianlun/article/details/6954500
解码示意图:
请参考代码TMDS_Decode;
http://blog.csdn.net/shanghaiqianlun/article/details/6954500
程序运行结果,编码测试图:
(从0x55和0xaa可以看出来,编码从电平的7次跳变,编码为电平的3次跳变,抗干扰能力增强)
data: [0x0] dis(0) 0b00000000 Encode: [0x100] 0b0100000000 Decode: 0x0
data: [0x1] dis(-8) 0b00000001 Encode: [0x1ff] 0b0111111111 Decode: 0x1
data: [0x2] dis(0) 0b00000010 Encode: [0x1fe] 0b0111111110 Decode: 0x2
data: [0x3] dis(-6) 0b00000011 Encode: [0x3fe] 0b1111111110 Decode: 0x3
data: [0x4] dis(2) 0b00000100 Encode: [0x303] 0b1100000011 Decode: 0x4
data: [0x5] dis(0) 0b00000101 Encode: [0x103] 0b0100000011 Decode: 0x5
data: [0x6] dis(-4) 0b00000110 Encode: [0x3fd] 0b1111111101 Decode: 0x6
data: [0x7] dis(4) 0b00000111 Encode: [0x302] 0b1100000010 Decode: 0x7
data: [0x8] dis(0) 0b00001000 Encode: [0x1f8] 0b0111111000 Decode: 0x8
data: [0x9] dis(-6) 0b00001001 Encode: [0x3f8] 0b1111111000 Decode: 0x9
data: [0xa] dis(-2) 0b00001010 Encode: [0x3f9] 0b1111111001 Decode: 0xa
data: [0xb] dis(4) 0b00001011 Encode: [0x306] 0b1100000110 Decode: 0xb
data: [0xc] dis(2) 0b00001100 Encode: [0x104] 0b0100000100 Decode: 0xc
data: [0xd] dis(-4) 0b00001101 Encode: [0x1fb] 0b0111111011 Decode: 0xd
data: [0xe] dis(2) 0b00001110 Encode: [0x305] 0b1100000101 Decode: 0xe
data: [0xf] dis(0) 0b00001111 Encode: [0x105] 0b0100000101 Decode: 0xf
data: [0x10] dis(0) 0b00010000 Encode: [0x1f0] 0b0111110000 Decode: 0x10
data: [0x11] dis(-6) 0b00010001 Encode: [0x10f] 0b0100001111 Decode: 0x11
data: [0x12] dis(-10) 0b00010010 Encode: [0x3f1] 0b1111110001 Decode: 0x12
data: [0x13] dis(-6) 0b00010011 Encode: [0x1f1] 0b0111110001 Decode: 0x13
data: [0x14] dis(-4) 0b00010100 Encode: [0x3f3] 0b1111110011 Decode: 0x14
data: [0x15] dis(2) 0b00010101 Encode: [0x30c] 0b1100001100 Decode: 0x15
data: [0x16] dis(0) 0b00010110 Encode: [0x1f2] 0b0111110010 Decode: 0x16
data: [0x17] dis(-2) 0b00010111 Encode: [0x3f2] 0b1111110010 Decode: 0x17
data: [0x18] dis(2) 0b00011000 Encode: [0x108] 0b0100001000 Decode: 0x18
data: [0x19] dis(-4) 0b00011001 Encode: [0x1f7] 0b0111110111 Decode: 0x19
data: [0x1a] dis(2) 0b00011010 Encode: [0x309] 0b1100001001 Decode: 0x1a
data: [0x1b] dis(0) 0b00011011 Encode: [0x109] 0b0100001001 Decode: 0x1b
data: [0x1c] dis(0) 0b00011100 Encode: [0x1f4] 0b0111110100 Decode: 0x1c
data: [0x1d] dis(-2) 0b00011101 Encode: [0x3f4] 0b1111110100 Decode: 0x1d
data: [0x1e] dis(2) 0b00011110 Encode: [0xa0] 0b0010100000 Decode: 0x1e
data: [0x1f] dis(-4) 0b00011111 Encode: [0x5f] 0b0001011111 Decode: 0x1f
data: [0x20] dis(-2) 0b00100000 Encode: [0x31f] 0b1100011111 Decode: 0x20
data: [0x21] dis(2) 0b00100001 Encode: [0x3e0] 0b1111100000 Decode: 0x21
data: [0x22] dis(2) 0b00100010 Encode: [0x11e] 0b0100011110 Decode: 0x22
data: [0x23] dis(-2) 0b00100011 Encode: [0x1e1] 0b0111100001 Decode: 0x23
data: [0x24] dis(-4) 0b00100100 Encode: [0x3e3] 0b1111100011 Decode: 0x24
data: [0x25] dis(0) 0b00100101 Encode: [0x1e3] 0b0111100011 Decode: 0x25
data: [0x26] dis(-2) 0b00100110 Encode: [0x1e2] 0b0111100010 Decode: 0x26
data: [0x27] dis(-4) 0b00100111 Encode: [0x11d] 0b0100011101 Decode: 0x27
data: [0x28] dis(-4) 0b00101000 Encode: [0x3e7] 0b1111100111 Decode: 0x28
data: [0x29] dis(2) 0b00101001 Encode: [0x318] 0b1100011000 Decode: 0x29
data: [0x2a] dis(0) 0b00101010 Encode: [0x1e6] 0b0111100110 Decode: 0x2a
data: [0x2b] dis(-2) 0b00101011 Encode: [0x3e6] 0b1111100110 Decode: 0x2b
data: [0x2c] dis(2) 0b00101100 Encode: [0x1e4] 0b0111100100 Decode: 0x2c
data: [0x2d] dis(0) 0b00101101 Encode: [0x11b] 0b0100011011 Decode: 0x2d
data: [0x2e] dis(0) 0b00101110 Encode: [0x24f] 0b1001001111 Decode: 0x2e
data: [0x2f] dis(0) 0b00101111 Encode: [0x2b0] 0b1010110000 Decode: 0x2f
data: [0x30] dis(-2) 0b00110000 Encode: [0x3ef] 0b1111101111 Decode: 0x30
data: [0x31] dis(6) 0b00110001 Encode: [0x310] 0b1100010000 Decode: 0x31
data: [0x32] dis(2) 0b00110010 Encode: [0x311] 0b1100010001 Decode: 0x32
data: [0x33] dis(0) 0b00110011 Encode: [0x111] 0b0100010001 Decode: 0x33
data: [0x34] dis(0) 0b00110100 Encode: [0x1ec] 0b0111101100 Decode: 0x34
data: [0x35] dis(-2) 0b00110101 Encode: [0x3ec] 0b1111101100 Decode: 0x35
data: [0x36] dis(2) 0b00110110 Encode: [0x247] 0b1001000111 Decode: 0x36
data: [0x37] dis(2) 0b00110111 Encode: [0x2b8] 0b1010111000 Decode: 0x37
data: [0x38] dis(0) 0b00111000 Encode: [0x1e8] 0b0111101000 Decode: 0x38
data: [0x39] dis(-2) 0b00111001 Encode: [0x117] 0b0100010111 Decode: 0x39
data: [0x3a] dis(-2) 0b00111010 Encode: [0xbc] 0b0010111100 Decode: 0x3a
data: [0x3b] dis(-2) 0b00111011 Encode: [0x2bc] 0b1010111100 Decode: 0x3b
data: [0x3c] dis(0) 0b00111100 Encode: [0x241] 0b1001000001 Decode: 0x3c
data: [0x3d] dis(0) 0b00111101 Encode: [0x2be] 0b1010111110 Decode: 0x3d
data: [0x3e] dis(-2) 0b00111110 Encode: [0x2bf] 0b1010111111 Decode: 0x3e
data: [0x3f] dis(4) 0b00111111 Encode: [0x240] 0b1001000000 Decode: 0x3f
data: [0x40] dis(-2) 0b01000000 Encode: [0x33f] 0b1100111111 Decode: 0x40
data: [0x41] dis(4) 0b01000001 Encode: [0x3c0] 0b1111000000 Decode: 0x41
data: [0x42] dis(2) 0b01000010 Encode: [0x3c1] 0b1111000001 Decode: 0x42
data: [0x43] dis(2) 0b01000011 Encode: [0x1c1] 0b0111000001 Decode: 0x43
data: [0x44] dis(0) 0b01000100 Encode: [0x13c] 0b0100111100 Decode: 0x44
data: [0x45] dis(-4) 0b01000101 Encode: [0x1c3] 0b0111000011 Decode: 0x45
data: [0x46] dis(-6) 0b01000110 Encode: [0x33d] 0b1100111101 Decode: 0x46
data: [0x47] dis(-2) 0b01000111 Encode: [0x13d] 0b0100111101 Decode: 0x47
data: [0x48] dis(0) 0b01001000 Encode: [0x138] 0b0100111000 Decode: 0x48
data: [0x49] dis(-4) 0b01001001 Encode: [0x1c7] 0b0111000111 Decode: 0x49
data: [0x4a] dis(-2) 0b01001010 Encode: [0x1c6] 0b0111000110 Decode: 0x4a
data: [0x4b] dis(-4) 0b01001011 Encode: [0x139] 0b0100111001 Decode: 0x4b
data: [0x4c] dis(-4) 0b01001100 Encode: [0x33b] 0b1100111011 Decode: 0x4c
data: [0x4d] dis(0) 0b01001101 Encode: [0x13b] 0b0100111011 Decode: 0x4d
data: [0x4e] dis(0) 0b01001110 Encode: [0x26f] 0b1001101111 Decode: 0x4e
data: [0x4f] dis(0) 0b01001111 Encode: [0x290] 0b1010010000 Decode: 0x4f
data: [0x50] dis(-2) 0b01010000 Encode: [0x3cf] 0b1111001111 Decode: 0x50
data: [0x51] dis(4) 0b01010001 Encode: [0x330] 0b1100110000 Decode: 0x51
data: [0x52] dis(2) 0b01010010 Encode: [0x331] 0b1100110001 Decode: 0x52
data: [0x53] dis(2) 0b01010011 Encode: [0x131] 0b0100110001 Decode: 0x53
data: [0x54] dis(0) 0b01010100 Encode: [0x1cc] 0b0111001100 Decode: 0x54
data: [0x55] dis(-2) 0b01010101 Encode: [0x133]0b0100110011 Decode: 0x55
data: [0x56] dis(-2) 0b01010110 Encode: [0x267] 0b1001100111 Decode: 0x56
data: [0x57] dis(0) 0b01010111 Encode: [0x298] 0b1010011000 Decode: 0x57
data: [0x58] dis(-2) 0b01011000 Encode: [0x337] 0b1100110111 Decode: 0x58
data: [0x59] dis(2) 0b01011001 Encode: [0x3c8] 0b1111001000 Decode: 0x59
data: [0x5a] dis(2) 0b01011010 Encode: [0x263] 0b1001100011 Decode: 0x5a
data: [0x5b] dis(2) 0b01011011 Encode: [0x29c] 0b1010011100 Decode: 0x5b
data: [0x5c] dis(0) 0b01011100 Encode: [0x261] 0b1001100001 Decode: 0x5c
data: [0x5d] dis(0) 0b01011101 Encode: [0x29e] 0b1010011110 Decode: 0x5d
data: [0x5e] dis(-2) 0b01011110 Encode: [0x29f] 0b1010011111 Decode: 0x5e
data: [0x5f] dis(2) 0b01011111 Encode: [0x260] 0b1001100000 Decode: 0x5f
data: [0x60] dis(-2) 0b01100000 Encode: [0x3df] 0b1111011111 Decode: 0x60
data: [0x61] dis(6) 0b01100001 Encode: [0x320] 0b1100100000 Decode: 0x61
data: [0x62] dis(2) 0b01100010 Encode: [0x321] 0b1100100001 Decode: 0x62
data: [0x63] dis(0) 0b01100011 Encode: [0x121] 0b0100100001 Decode: 0x63
data: [0x64] dis(0) 0b01100100 Encode: [0x1dc] 0b0111011100 Decode: 0x64
data: [0x65] dis(-2) 0b01100101 Encode: [0x3dc] 0b1111011100 Decode: 0x65
data: [0x66] dis(2) 0b01100110 Encode: [0x88] 0b0010001000 Decode: 0x66
data: [0x67] dis(-4) 0b01100111 Encode: [0x77] 0b0001110111 Decode: 0x67
data: [0x68] dis(-2) 0b01101000 Encode: [0x1d8] 0b0111011000 Decode: 0x68
data: [0x69] dis(-4) 0b01101001 Encode: [0x127] 0b0100100111 Decode: 0x69
data: [0x6a] dis(-4) 0b01101010 Encode: [0x273] 0b1001110011 Decode: 0x6a
data: [0x6b] dis(-2) 0b01101011 Encode: [0x73] 0b0001110011 Decode: 0x6b
data: [0x6c] dis(-2) 0b01101100 Encode: [0x271] 0b1001110001 Decode: 0x6c
data: [0x6d] dis(-2) 0b01101101 Encode: [0x28e] 0b1010001110 Decode: 0x6d
data: [0x6e] dis(-4) 0b01101110 Encode: [0x28f] 0b1010001111 Decode: 0x6e
data: [0x6f] dis(-2) 0b01101111 Encode: [0x8f] 0b0010001111 Decode: 0x6f
data: [0x70] dis(-2) 0b01110000 Encode: [0x32f] 0b1100101111 Decode: 0x70
data: [0x71] dis(2) 0b01110001 Encode: [0x3d0] 0b1111010000 Decode: 0x71
data: [0x72] dis(2) 0b01110010 Encode: [0x84] 0b0010000100 Decode: 0x72
data: [0x73] dis(-4) 0b01110011 Encode: [0x7b] 0b0001111011 Decode: 0x73
data: [0x74] dis(-2) 0b01110100 Encode: [0x279] 0b1001111001 Decode: 0x74
data: [0x75] dis(0) 0b01110101 Encode: [0x286] 0b1010000110 Decode: 0x75
data: [0x76] dis(-2) 0b01110110 Encode: [0x287] 0b1010000111 Decode: 0x76
data: [0x77] dis(-4) 0b01110111 Encode: [0x278] 0b1001111000 Decode: 0x77
data: [0x78] dis(-8) 0b01111000 Encode: [0x27d] 0b1001111101 Decode: 0x78
data: [0x79] dis(-4) 0b01111001 Encode: [0x7d] 0b0001111101 Decode: 0x79
data: [0x7a] dis(-2) 0b01111010 Encode: [0x7c] 0b0001111100 Decode: 0x7a
data: [0x7b] dis(-2) 0b01111011 Encode: [0x27c] 0b1001111100 Decode: 0x7b
data: [0x7c] dis(0) 0b01111100 Encode: [0x281] 0b1010000001 Decode: 0x7c
data: [0x7d] dis(-2) 0b01111101 Encode: [0x27e] 0b1001111110 Decode: 0x7d
data: [0x7e] dis(2) 0b01111110 Encode: [0x80] 0b0010000000 Decode: 0x7e
data: [0x7f] dis(-6) 0b01111111 Encode: [0x7f] 0b0001111111 Decode: 0x7f
data: [0x80] dis(-2) 0b10000000 Encode: [0x37f] 0b1101111111 Decode: 0x80
data: [0x81] dis(6) 0b10000001 Encode: [0x380] 0b1110000000 Decode: 0x81
data: [0x82] dis(2) 0b10000010 Encode: [0x381] 0b1110000001 Decode: 0x82
data: [0x83] dis(0) 0b10000011 Encode: [0x181] 0b0110000001 Decode: 0x83
data: [0x84] dis(-2) 0b10000100 Encode: [0x17c] 0b0101111100 Decode: 0x84
data: [0x85] dis(0) 0b10000101 Encode: [0x183] 0b0110000011 Decode: 0x85
data: [0x86] dis(-2) 0b10000110 Encode: [0x37d] 0b1101111101 Decode: 0x86
data: [0x87] dis(4) 0b10000111 Encode: [0x382] 0b1110000010 Decode: 0x87
data: [0x88] dis(2) 0b10001000 Encode: [0x178] 0b0101111000 Decode: 0x88
data: [0x89] dis(-2) 0b10001001 Encode: [0x187] 0b0110000111 Decode: 0x89
data: [0x8a] dis(-4) 0b10001010 Encode: [0x379] 0b1101111001 Decode: 0x8a
data: [0x8b] dis(0) 0b10001011 Encode: [0x179] 0b0101111001 Decode: 0x8b
data: [0x8c] dis(0) 0b10001100 Encode: [0x184] 0b0110000100 Decode: 0x8c
data: [0x8d] dis(-2) 0b10001101 Encode: [0x17b] 0b0101111011 Decode: 0x8d
data: [0x8e] dis(2) 0b10001110 Encode: [0xd0] 0b0011010000 Decode: 0x8e
data: [0x8f] dis(-2) 0b10001111 Encode: [0x2f] 0b0000101111 Decode: 0x8f
data: [0x90] dis(-2) 0b10010000 Encode: [0x38f] 0b1110001111 Decode: 0x90
data: [0x91] dis(2) 0b10010001 Encode: [0x370] 0b1101110000 Decode: 0x91
data: [0x92] dis(2) 0b10010010 Encode: [0x18e] 0b0110001110 Decode: 0x92
data: [0x93] dis(0) 0b10010011 Encode: [0x171] 0b0101110001 Decode: 0x93
data: [0x94] dis(0) 0b10010100 Encode: [0x18c] 0b0110001100 Decode: 0x94
data: [0x95] dis(-2) 0b10010101 Encode: [0x173] 0b0101110011 Decode: 0x95
data: [0x96] dis(0) 0b10010110 Encode: [0x227] 0b1000100111 Decode: 0x96
data: [0x97] dis(0) 0b10010111 Encode: [0x2d8] 0b1011011000 Decode: 0x97
data: [0x98] dis(-2) 0b10011000 Encode: [0x377] 0b1101110111 Decode: 0x98
data: [0x99] dis(4) 0b10011001 Encode: [0x388] 0b1110001000 Decode: 0x99
data: [0x9a] dis(2) 0b10011010 Encode: [0x223] 0b1000100011 Decode: 0x9a
data: [0x9b] dis(0) 0b10011011 Encode: [0x2dc] 0b1011011100 Decode: 0x9b
data: [0x9c] dis(-2) 0b10011100 Encode: [0xde] 0b0011011110 Decode: 0x9c
data: [0x9d] dis(0) 0b10011101 Encode: [0x2de] 0b1011011110 Decode: 0x9d
data: [0x9e] dis(-2) 0b10011110 Encode: [0x2df] 0b1011011111 Decode: 0x9e
data: [0x9f] dis(4) 0b10011111 Encode: [0x220] 0b1000100000 Decode: 0x9f
data: [0xa0] dis(-2) 0b10100000 Encode: [0x39f] 0b1110011111 Decode: 0xa0
data: [0xa1] dis(4) 0b10100001 Encode: [0x360] 0b1101100000 Decode: 0xa1
data: [0xa2] dis(2) 0b10100010 Encode: [0x361] 0b1101100001 Decode: 0xa2
data: [0xa3] dis(2) 0b10100011 Encode: [0x161] 0b0101100001 Decode: 0xa3
data: [0xa4] dis(0) 0b10100100 Encode: [0x19c] 0b0110011100 Decode: 0xa4
data: [0xa5] dis(-2) 0b10100101 Encode: [0x163] 0b0101100011 Decode: 0xa5
data: [0xa6] dis(-2) 0b10100110 Encode: [0x237] 0b1000110111 Decode: 0xa6
data: [0xa7] dis(0) 0b10100111 Encode: [0x2c8] 0b1011001000 Decode: 0xa7
data: [0xa8] dis(-2) 0b10101000 Encode: [0x367] 0b1101100111 Decode: 0xa8
data: [0xa9] dis(2) 0b10101001 Encode: [0x398] 0b1110011000 Decode: 0xa9
data: [0xaa] dis(2) 0b10101010 Encode: [0x233]0b1000110011 Decode: 0xaa
data: [0xab] dis(2) 0b10101011 Encode: [0x2cc] 0b1011001100 Decode: 0xab
data: [0xac] dis(0) 0b10101100 Encode: [0x231] 0b1000110001 Decode: 0xac
data: [0xad] dis(0) 0b10101101 Encode: [0x2ce] 0b1011001110 Decode: 0xad
data: [0xae] dis(-2) 0b10101110 Encode: [0x2cf] 0b1011001111 Decode: 0xae
data: [0xaf] dis(2) 0b10101111 Encode: [0x230] 0b1000110000 Decode: 0xaf
data: [0xb0] dis(-2) 0b10110000 Encode: [0x36f] 0b1101101111 Decode: 0xb0
data: [0xb1] dis(4) 0b10110001 Encode: [0x390] 0b1110010000 Decode: 0xb1
data: [0xb2] dis(2) 0b10110010 Encode: [0xc4] 0b0011000100 Decode: 0xb2
data: [0xb3] dis(-2) 0b10110011 Encode: [0x3b] 0b0000111011 Decode: 0xb3
data: [0xb4] dis(-2) 0b10110100 Encode: [0x239] 0b1000111001 Decode: 0xb4
data: [0xb5] dis(-2) 0b10110101 Encode: [0x2c6] 0b1011000110 Decode: 0xb5
data: [0xb6] dis(-4) 0b10110110 Encode: [0x2c7] 0b1011000111 Decode: 0xb6
data: [0xb7] dis(-2) 0b10110111 Encode: [0xc7] 0b0011000111 Decode: 0xb7
data: [0xb8] dis(-2) 0b10111000 Encode: [0x23d] 0b1000111101 Decode: 0xb8
data: [0xb9] dis(0) 0b10111001 Encode: [0x2c2] 0b1011000010 Decode: 0xb9
data: [0xba] dis(-2) 0b10111010 Encode: [0x2c3] 0b1011000011 Decode: 0xba
data: [0xbb] dis(-4) 0b10111011 Encode: [0x23c] 0b1000111100 Decode: 0xbb
data: [0xbc] dis(-8) 0b10111100 Encode: [0x3e] 0b0000111110 Decode: 0xbc
data: [0xbd] dis(-8) 0b10111101 Encode: [0x23e] 0b1000111110 Decode: 0xbd
data: [0xbe] dis(-6) 0b10111110 Encode: [0x23f] 0b1000111111 Decode: 0xbe
data: [0xbf] dis(-2) 0b10111111 Encode: [0x3f] 0b0000111111 Decode: 0xbf
data: [0xc0] dis(0) 0b11000000 Encode: [0x140] 0b0101000000 Decode: 0xc0
data: [0xc1] dis(-4) 0b11000001 Encode: [0x1bf] 0b0110111111 Decode: 0xc1
data: [0xc2] dis(2) 0b11000010 Encode: [0x341] 0b1101000001 Decode: 0xc2
data: [0xc3] dis(0) 0b11000011 Encode: [0x141] 0b0101000001 Decode: 0xc3
data: [0xc4] dis(0) 0b11000100 Encode: [0x1bc] 0b0110111100 Decode: 0xc4
data: [0xc5] dis(-2) 0b11000101 Encode: [0x3bc] 0b1110111100 Decode: 0xc5
data: [0xc6] dis(2) 0b11000110 Encode: [0x217] 0b1000010111 Decode: 0xc6
data: [0xc7] dis(2) 0b11000111 Encode: [0x2e8] 0b1011101000 Decode: 0xc7
data: [0xc8] dis(0) 0b11001000 Encode: [0x1b8] 0b0110111000 Decode: 0xc8
data: [0xc9] dis(-2) 0b11001001 Encode: [0x147] 0b0101000111 Decode: 0xc9
data: [0xca] dis(-2) 0b11001010 Encode: [0xec] 0b0011101100 Decode: 0xca
data: [0xcb] dis(-2) 0b11001011 Encode: [0x2ec] 0b1011101100 Decode: 0xcb
data: [0xcc] dis(0) 0b11001100 Encode: [0x211] 0b1000010001 Decode: 0xcc
data: [0xcd] dis(0) 0b11001101 Encode: [0x2ee] 0b1011101110 Decode: 0xcd
data: [0xce] dis(-2) 0b11001110 Encode: [0x2ef] 0b1011101111 Decode: 0xce
data: [0xcf] dis(4) 0b11001111 Encode: [0x210] 0b1000010000 Decode: 0xcf
data: [0xd0] dis(-2) 0b11010000 Encode: [0x34f] 0b1101001111 Decode: 0xd0
data: [0xd1] dis(2) 0b11010001 Encode: [0x3b0] 0b1110110000 Decode: 0xd1
data: [0xd2] dis(2) 0b11010010 Encode: [0x21b] 0b1000011011 Decode: 0xd2
data: [0xd3] dis(2) 0b11010011 Encode: [0x2e4] 0b1011100100 Decode: 0xd3
data: [0xd4] dis(0) 0b11010100 Encode: [0x219] 0b1000011001 Decode: 0xd4
data: [0xd5] dis(0) 0b11010101 Encode: [0x2e6] 0b1011100110 Decode: 0xd5
data: [0xd6] dis(-2) 0b11010110 Encode: [0x2e7] 0b1011100111 Decode: 0xd6
data: [0xd7] dis(2) 0b11010111 Encode: [0x218] 0b1000011000 Decode: 0xd7
data: [0xd8] dis(-2) 0b11011000 Encode: [0x21d] 0b1000011101 Decode: 0xd8
data: [0xd9] dis(-2) 0b11011001 Encode: [0x2e2] 0b1011100010 Decode: 0xd9
data: [0xda] dis(-4) 0b11011010 Encode: [0x2e3] 0b1011100011 Decode: 0xda
data: [0xdb] dis(-2) 0b11011011 Encode: [0xe3] 0b0011100011 Decode: 0xdb
data: [0xdc] dis(-2) 0b11011100 Encode: [0x2e1] 0b1011100001 Decode: 0xdc
data: [0xdd] dis(-4) 0b11011101 Encode: [0x21e] 0b1000011110 Decode: 0xdd
data: [0xde] dis(-8) 0b11011110 Encode: [0x21f] 0b1000011111 Decode: 0xde
data: [0xdf] dis(-6) 0b11011111 Encode: [0x1f] 0b0000011111 Decode: 0xdf
data: [0xe0] dis(-6) 0b11100000 Encode: [0x35f] 0b1101011111 Decode: 0xe0
data: [0xe1] dis(0) 0b11100001 Encode: [0x15f] 0b0101011111 Decode: 0xe1
data: [0xe2] dis(0) 0b11100010 Encode: [0x20b] 0b1000001011 Decode: 0xe2
data: [0xe3] dis(0) 0b11100011 Encode: [0x2f4] 0b1011110100 Decode: 0xe3
data: [0xe4] dis(-2) 0b11100100 Encode: [0xf6] 0b0011110110 Decode: 0xe4
data: [0xe5] dis(0) 0b11100101 Encode: [0x2f6] 0b1011110110 Decode: 0xe5
data: [0xe6] dis(-2) 0b11100110 Encode: [0x2f7] 0b1011110111 Decode: 0xe6
data: [0xe7] dis(4) 0b11100111 Encode: [0x208] 0b1000001000 Decode: 0xe7
data: [0xe8] dis(-2) 0b11101000 Encode: [0xf2] 0b0011110010 Decode: 0xe8
data: [0xe9] dis(-2) 0b11101001 Encode: [0x2f2] 0b1011110010 Decode: 0xe9
data: [0xea] dis(0) 0b11101010 Encode: [0x2f3] 0b1011110011 Decode: 0xea
data: [0xeb] dis(-2) 0b11101011 Encode: [0xf3] 0b0011110011 Decode: 0xeb
data: [0xec] dis(0) 0b11101100 Encode: [0x2f1] 0b1011110001 Decode: 0xec
data: [0xed] dis(-2) 0b11101101 Encode: [0xf1] 0b0011110001 Decode: 0xed
data: [0xee] dis(-2) 0b11101110 Encode: [0x20f] 0b1000001111 Decode: 0xee
data: [0xef] dis(-6) 0b11101111 Encode: [0x2f0] 0b1011110000 Decode: 0xef
data: [0xf0] dis(-12) 0b11110000 Encode: [0xfa] 0b0011111010 Decode: 0xf0
data: [0xf1] dis(-10) 0b11110001 Encode: [0x2fa] 0b1011111010 Decode: 0xf1
data: [0xf2] dis(-6) 0b11110010 Encode: [0x2fb] 0b1011111011 Decode: 0xf2
data: [0xf3] dis(0) 0b11110011 Encode: [0x204] 0b1000000100 Decode: 0xf3
data: [0xf4] dis(-4) 0b11110100 Encode: [0x2f9] 0b1011111001 Decode: 0xf4
data: [0xf5] dis(0) 0b11110101 Encode: [0x206] 0b1000000110 Decode: 0xf5
data: [0xf6] dis(-4) 0b11110110 Encode: [0xf8] 0b0011111000 Decode: 0xf6
data: [0xf7] dis(-4) 0b11110111 Encode: [0x2f8] 0b1011111000 Decode: 0xf7
data: [0xf8] dis(-2) 0b11111000 Encode: [0x2fd] 0b1011111101 Decode: 0xf8
data: [0xf9] dis(4) 0b11111001 Encode: [0x202] 0b1000000010 Decode: 0xf9
data: [0xfa] dis(-2) 0b11111010 Encode: [0xfc] 0b0011111100 Decode: 0xfa
data: [0xfb] dis(0) 0b11111011 Encode: [0x2fc] 0b1011111100 Decode: 0xfb
data: [0xfc] dis(-6) 0b11111100 Encode: [0xfe] 0b0011111110 Decode: 0xfc
data: [0xfd] dis(-2) 0b11111101 Encode: [0x2fe] 0b1011111110 Decode: 0xfd
data: [0xfe] dis(4) 0b11111110 Encode: [0x0] 0b0000000000 Decode: 0xfe
data: [0xff] dis(-6) 0b11111111 Encode: [0xff] 0b0011111111 Decode: 0xff
代码测试:
// tmds_encod_win32.cpp : Defines the entry point for the console application. // #include "stdafx.h" #define BIT0(num) (((num)>>0) & 0x1) #define BIT1(num) (((num)>>1) & 0x1) #define BIT2(num) (((num)>>2) & 0x1) #define BIT3(num) (((num)>>3) & 0x1) #define BIT4(num) (((num)>>4) & 0x1) #define BIT5(num) (((num)>>5) & 0x1) #define BIT6(num) (((num)>>6) & 0x1) #define BIT7(num) (((num)>>7) & 0x1) #define BIT8(num) (((num)>>8) & 0x1) #define BIT9(num) (((num)>>9) & 0x1) #define SETBIT(num,offset,value) {(num) &= ~(0x1<<(offset)); (num) |= ((value)&0x1)<<(offset);} #define XOR(a,b) (((a)&0x1)!=((b)&0x1)) //异或 #define XNOR(a,b) (((a)&0x1)==((b)&0x1)) //异或,然后取非 typedef struct { unsigned int data; //only use bit0~9 int disparity; }TMDS_DATA, *PTMDA_DATA; //encode/decode TMDS data TMDS_DATA TmdsEncode(TMDS_DATA data); TMDS_DATA TmdsDecode(TMDS_DATA data); //printf 0bxxxxxxx void print_8bit(int value); void print_10bit(int value); //main function int _tmain(int argc, _TCHAR* argv[]) { TMDS_DATA data1,data2,data3; int i = 0; data1.disparity = data2.disparity = 0; for(i=0;i<256;i++) { data1.data = i; data1.disparity = data2.disparity; printf("data: [0x%x] ", data1.data); printf("dis(%d) ", data1.disparity); print_8bit(data1.data); data2 = TmdsEncode(data1); printf("Encode: [0x%x] ", data2.data); print_10bit(data2.data); data3 = TmdsDecode(data2); printf("Decode: 0x%x \n", data3.data); } getchar(); return 0; } //data中,bit位是1的个数,比如0b00000011,则个数为2 int N1(unsigned int data) { int num = 0; int i = 0; data = data & 0xFF; for(i=0; i<8 i="" if="" data="">>i) & 0x1) { num ++; } } return num; } //data中,bit位是0的个数,比如0b00000011,则个数为6 int N0(unsigned int data) { int num = 0; int i = 0; data = data & 0xFF; for(i=0; i<8 i="" if="" data="">>i) & 0x1) == 0 ) { num ++; } } return num; } TMDS_DATA TmdsEncode(TMDS_DATA tmds_data) { TMDS_DATA D_in; TMDS_DATA Q_temp; TMDS_DATA D_out; D_in.data = tmds_data.data; D_in.disparity = tmds_data.disparity; Q_temp.data = D_out.data = 0; Q_temp.disparity = D_out.disparity = 0; if((N1(D_in.data)>4) || ( (N1(D_in.data)==4) && (BIT0(D_in.data)==0) ) ) { SETBIT(Q_temp.data, 0, BIT0(D_in.data) ); SETBIT(Q_temp.data, 1, XNOR(BIT0(Q_temp.data),BIT1(D_in.data))); SETBIT(Q_temp.data, 2, XNOR(BIT1(Q_temp.data),BIT2(D_in.data))); SETBIT(Q_temp.data, 3, XNOR(BIT2(Q_temp.data),BIT3(D_in.data))); SETBIT(Q_temp.data, 4, XNOR(BIT3(Q_temp.data),BIT4(D_in.data))); SETBIT(Q_temp.data, 5, XNOR(BIT4(Q_temp.data),BIT5(D_in.data))); SETBIT(Q_temp.data, 6, XNOR(BIT5(Q_temp.data),BIT6(D_in.data))); SETBIT(Q_temp.data, 7, XNOR(BIT6(Q_temp.data),BIT7(D_in.data))); SETBIT(Q_temp.data, 8, 0x0); } else { SETBIT(Q_temp.data, 0, BIT0(D_in.data) ); SETBIT(Q_temp.data, 1, XOR(BIT0(Q_temp.data),BIT1(D_in.data))); SETBIT(Q_temp.data, 2, XOR(BIT1(Q_temp.data),BIT2(D_in.data))); SETBIT(Q_temp.data, 3, XOR(BIT2(Q_temp.data),BIT3(D_in.data))); SETBIT(Q_temp.data, 4, XOR(BIT3(Q_temp.data),BIT4(D_in.data))); SETBIT(Q_temp.data, 5, XOR(BIT4(Q_temp.data),BIT5(D_in.data))); SETBIT(Q_temp.data, 6, XOR(BIT5(Q_temp.data),BIT6(D_in.data))); SETBIT(Q_temp.data, 7, XOR(BIT6(Q_temp.data),BIT7(D_in.data))); SETBIT(Q_temp.data, 8, 0x1); } if((D_in.disparity==0) || (N1(Q_temp.data)==N0(Q_temp.data)) ) { if(BIT8(Q_temp.data) == 0x0) { SETBIT(D_out.data, 8, 0x0); SETBIT(D_out.data, 7, ~(BIT7(Q_temp.data))); SETBIT(D_out.data, 6, ~(BIT6(Q_temp.data))); SETBIT(D_out.data, 5, ~(BIT5(Q_temp.data))); SETBIT(D_out.data, 4, ~(BIT4(Q_temp.data))); SETBIT(D_out.data, 3, ~(BIT3(Q_temp.data))); SETBIT(D_out.data, 2, ~(BIT2(Q_temp.data))); SETBIT(D_out.data, 1, ~(BIT1(Q_temp.data))); SETBIT(D_out.data, 0, ~(BIT0(Q_temp.data))); SETBIT(D_out.data, 9, 0x1); D_out.disparity = D_in.disparity + N0(D_in.data) - N1(D_in.data); } else { SETBIT(D_out.data, 8, 0x1); SETBIT(D_out.data, 7, (BIT7(Q_temp.data))); SETBIT(D_out.data, 6, (BIT6(Q_temp.data))); SETBIT(D_out.data, 5, (BIT5(Q_temp.data))); SETBIT(D_out.data, 4, (BIT4(Q_temp.data))); SETBIT(D_out.data, 3, (BIT3(Q_temp.data))); SETBIT(D_out.data, 2, (BIT2(Q_temp.data))); SETBIT(D_out.data, 1, (BIT1(Q_temp.data))); SETBIT(D_out.data, 0, (BIT0(Q_temp.data))); SETBIT(D_out.data, 9, 0x0); D_out.disparity = D_in.disparity + N1(D_in.data) - N0(D_in.data); } } else { if( ((D_in.disparity>0) && (N1(Q_temp.data)>N0(Q_temp.data)) ) || ( D_in.disparity<0 n0="" q_temp="" data="">N1(Q_temp.data)) ) { SETBIT(D_out.data, 8, BIT8(Q_temp.data)); SETBIT(D_out.data, 7, ~BIT7(Q_temp.data)); SETBIT(D_out.data, 6, ~BIT6(Q_temp.data)); SETBIT(D_out.data, 5, ~BIT5(Q_temp.data)); SETBIT(D_out.data, 4, ~BIT4(Q_temp.data)); SETBIT(D_out.data, 3, ~BIT3(Q_temp.data)); SETBIT(D_out.data, 2, ~BIT2(Q_temp.data)); SETBIT(D_out.data, 1, ~BIT1(Q_temp.data)); SETBIT(D_out.data, 0, ~BIT0(Q_temp.data)); SETBIT(D_out.data, 9, 0x1); D_out.disparity = D_in.disparity + 2*((BIT8(Q_temp.data)) & 0x1 ) + N0(Q_temp.data) - N1(Q_temp.data); } else { SETBIT(D_out.data, 8, BIT8(Q_temp.data)); SETBIT(D_out.data, 7, BIT7(Q_temp.data)); SETBIT(D_out.data, 6, BIT6(Q_temp.data)); SETBIT(D_out.data, 5, BIT5(Q_temp.data)); SETBIT(D_out.data, 4, BIT4(Q_temp.data)); SETBIT(D_out.data, 3, BIT3(Q_temp.data)); SETBIT(D_out.data, 2, BIT2(Q_temp.data)); SETBIT(D_out.data, 1, BIT1(Q_temp.data)); SETBIT(D_out.data, 0, BIT0(Q_temp.data)); SETBIT(D_out.data, 9, 0x0); D_out.disparity = D_in.disparity - 2*((~BIT8(Q_temp.data)) & 0x1 ) + N1(Q_temp.data) - N0(Q_temp.data); } } return D_out; } TMDS_DATA TmdsDecode(TMDS_DATA tmds_data) { TMDS_DATA D_in; TMDS_DATA Q_temp; TMDS_DATA D_out; D_in.data = tmds_data.data; D_in.disparity = tmds_data.disparity; Q_temp.data = D_out.data = 0; Q_temp.disparity = D_out.disparity = 0; if(BIT9(D_in.data)) { SETBIT(Q_temp.data, 7, ~BIT7(D_in.data)); SETBIT(Q_temp.data, 6, ~BIT6(D_in.data)); SETBIT(Q_temp.data, 5, ~BIT5(D_in.data)); SETBIT(Q_temp.data, 4, ~BIT4(D_in.data)); SETBIT(Q_temp.data, 3, ~BIT3(D_in.data)); SETBIT(Q_temp.data, 2, ~BIT2(D_in.data)); SETBIT(Q_temp.data, 1, ~BIT1(D_in.data)); SETBIT(Q_temp.data, 0, ~BIT0(D_in.data)); } else { SETBIT(Q_temp.data, 7, BIT7(D_in.data)); SETBIT(Q_temp.data, 6, BIT6(D_in.data)); SETBIT(Q_temp.data, 5, BIT5(D_in.data)); SETBIT(Q_temp.data, 4, BIT4(D_in.data)); SETBIT(Q_temp.data, 3, BIT3(D_in.data)); SETBIT(Q_temp.data, 2, BIT2(D_in.data)); SETBIT(Q_temp.data, 1, BIT1(D_in.data)); SETBIT(Q_temp.data, 0, BIT0(D_in.data)); } if(BIT8(D_in.data)) { SETBIT(D_out.data, 0, BIT0(Q_temp.data)); SETBIT(D_out.data, 1, XOR( BIT1(Q_temp.data), BIT0(Q_temp.data) )); SETBIT(D_out.data, 2, XOR( BIT2(Q_temp.data), BIT1(Q_temp.data) )); SETBIT(D_out.data, 3, XOR( BIT3(Q_temp.data), BIT2(Q_temp.data) )); SETBIT(D_out.data, 4, XOR( BIT4(Q_temp.data), BIT3(Q_temp.data) )); SETBIT(D_out.data, 5, XOR( BIT5(Q_temp.data), BIT4(Q_temp.data) )); SETBIT(D_out.data, 6, XOR( BIT6(Q_temp.data), BIT5(Q_temp.data) )); SETBIT(D_out.data, 7, XOR( BIT7(Q_temp.data), BIT6(Q_temp.data) )); } else { SETBIT(D_out.data, 0, BIT0(Q_temp.data)); SETBIT(D_out.data, 1, XNOR( BIT1(Q_temp.data), BIT0(Q_temp.data) )); SETBIT(D_out.data, 2, XNOR( BIT2(Q_temp.data), BIT1(Q_temp.data) )); SETBIT(D_out.data, 3, XNOR( BIT3(Q_temp.data), BIT2(Q_temp.data) )); SETBIT(D_out.data, 4, XNOR( BIT4(Q_temp.data), BIT3(Q_temp.data) )); SETBIT(D_out.data, 5, XNOR( BIT5(Q_temp.data), BIT4(Q_temp.data) )); SETBIT(D_out.data, 6, XNOR( BIT6(Q_temp.data), BIT5(Q_temp.data) )); SETBIT(D_out.data, 7, XNOR( BIT7(Q_temp.data), BIT6(Q_temp.data) )); } return D_out; } void print_8bit(int value) { int byte = value & 0xFF; printf("0b"); for (int i = 7; i >= 0; i--) { if(byte & (1 << i)) printf("1"); else printf("0"); } printf(" "); } void print_10bit(int value) { int byte = value & 0x3FF; printf("0b"); for (int i = 9; i >= 0; i--) { if(byte & (1 << i)) printf("1"); else printf("0"); } printf(" "); } 0>8>8>