After DCT, it is necessary to convert the array (two-dimensional array) into a one-dimensional array according to the Z-shaped scanning rule for compression.
Schematic diagram of Z scan:
It can be seen from the figure that the Z shape starts from the upper left side and ends at the lower right side.
Implementation idea: Convert a two-dimensional array (array) to a one-dimensional array, take out the input array data through a two-dimensional loop, and transfer it to the address position of the one-dimensional array pointed to by the Z array.
The source program is as follows:
const unsigned char Zigzag[8][8] = { 0, 1, 5, 6, 14, 15, 27, 28, 2, 4, 7, 13, 16, 26, 29, 42, 3, 8, 12, 17, 25, 30, 41, 43, 9, 11, 18, 24, 31, 40, 44, 53, 10, 19, 23, 32, 39, 45, 52, 54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47, 50, 56, 59, 61, 35, 36, 48, 49, 57, 58, 62, 63 }; void __fastcall ZigScan_8x8(int czOutPut[], int czInPut[][8])//Z变换 { for(int i = 0; i < 8; i++) for(int j = 0; j < 8; j++) { czOutPut[Zigzag[i][j]] = czInPut[i][j]; } }