The two-dimensional travel encoding is similar to the one-dimensional travel encoding, but the length value with the same character represents the side length of the square containing the same character. That is, the number of symbols in the horizontal and vertical directions must be the same during encoding. The following is an example.
Example:
Figure 7-10 2D travel Encoding
Encoding Process: For 8x8 images on the left, scan and encode one line from left to right, from top to bottom.
If you encounter a character that has been encoded, you must skip it to the next character that has not been encoded.
Step 1: There are three symbols 05 in the X direction, but there are only two symbols 05 in the Y direction. Therefore, the square size can only be 2*2, that is, the side length is 2, and the code is: 05 02
Step 2: There is 1 Symbol 05 in the X direction, while there are 2 symbols 05 in the Y direction, but the square size can only be 1*1, that is, the side length is 1, encoding: 05 01
Step 3: The X direction has 1 Symbol 10, and the Y direction has 2 symbols 10. The square size can only be 1*1, that is, the side length is 1 and the code is 10 01.
Step 4: There are four symbols in the X direction, 21 in the Y direction, and 21 in the Y direction. The square size is 4*4, that is, the side length is 4 and the code is 21 04.
The encoding of the first line has been completed and transferred to the second line. Because the first two characters in the second line have been encoded, skip this step and start encoding for the third character.
Step 5: there is 1 Symbol 05 in the X direction and 1 Symbol 05 in the Y direction. The square size is 1*1, that is, the side length is 1 and the code is 05 01.
Step 6: there is 1 Symbol 10 in the X direction, 7 symbols 10 in the Y direction, and 1*1 in the square size, that is, the side length is 1 and the code is 10 01.
Because the last four characters 21 in the second line have been encoded, skip and go to the third line.
Step 7: The X direction has four symbols 10, and the Y direction has six symbols 10. The square size is 4*4, encoded as: 10 04.
Because the last four characters of the third line are 21 characters, and the first four characters of the fourth line are all encoded, skip this step, go to the last 4 characters of the fifth line.
Step 8: There are two symbols in the X direction, 21 in the Y direction, and 21 in the Y direction. The square size is 2*2, encoded as: 21 02.
Step 9: The X direction has two symbols 31, and the Y direction has four symbols 21. The square size is 2*2, encoded as 31 02.
Because the 8 characters in the sixth line have been encoded, skip and go to the seventh line.
Step 10: The X direction has four symbols 10, and the Y direction has two symbols 10. The square size is 2*2, encoded as: 10 02.
The following code is as follows: 10 02, 15 01,31 01, 31 02, 15 01, 31 01