Data compression, encoding and decompression method, device, electronic equipment and storage medium
By encoding and compressing the compressed data, determining the encoding length based on the numerical size of the data, and compressing the encoding based on the length, the problem of low data compression rate in the prior art is solved, and efficient data compression effect is achieved.
Patent Information
- Application Number
- CN202110918085.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-11
- Publication Date
- 2025-03-25
- Estimated Expiration
- 2041-08-11
AI Technical Summary
The existing data compression method has low compression rate, making it difficult to effectively compress data under limited bandwidth and power supply.
By encoding the compressed data, the encoding length is determined based on the numerical size of the data, and the encoding is compressed based on the length to generate the result compression encoding. This method improves the efficiency of data compression by optimizing the encoding length and the representation of intermediate compression encoding in the storage space.
High compression rate data compression is achieved, reducing the actual number of bytes occupied, thereby improving the efficiency of data transmission and power utilization.
Smart Images

Figure CN113630125B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a data compression, encoding and decompression method, device, electronic device and storage medium. Background Art
[0002] In some measurement systems, especially when bandwidth and power are limited, in order to transmit more data while reducing power consumption, data compression can be performed to reduce the amount of data before transmission.
[0003] In the process of implementing the present invention, the inventors found that the prior art has the following technical problems: the compression rate of the existing data compression method is not high. Summary of the invention
[0004] The embodiments of the present invention provide a data compression, encoding and decompression method, device, electronic device and storage medium to achieve a data compression effect with a high compression rate.
[0005] In a first aspect, an embodiment of the present invention provides a data compression method, which may include:
[0006] Obtaining data to be compressed, encoding the data to be compressed to obtain a code to be compressed, and determining a code length of the data to be compressed according to a numerical value of the data to be compressed;
[0007] Compress the to-be-compressed code according to the code length to obtain an intermediate compressed code;
[0008] A result compression code is generated based on the code length and the intermediate compression code.
[0009] In a second aspect, an embodiment of the present invention provides a coding and decompression method, which may include:
[0010] Obtaining a code stream to be decompressed, and obtaining a code length from the code stream to be decompressed, wherein the code length is determined according to the numerical value of the data to be compressed when compressing the data to be compressed before compression corresponding to the code to be decompressed in the code stream to be decompressed;
[0011] Determine the code to be decompressed from the code stream to be decompressed according to the code length, and decompress the code to be decompressed according to the code length to obtain a result decompressed code;
[0012] The result decompression code is decompressed to obtain result decompressed data.
[0013] In a third aspect, an embodiment of the present invention further provides a data compression device, which may include:
[0014] The data encoding module is used to obtain the data to be compressed, encode the data to be compressed, obtain the code to be compressed, and determine the code length of the data to be compressed according to the value of the data to be compressed;
[0015] A coding compression module, used for compressing the to-be-compressed code according to the code length to obtain an intermediate compression code;
[0016] The data compression module is used to generate a result compression code according to the code length and the intermediate compression code.
[0017] In a fourth aspect, an embodiment of the present invention further provides a coding and decompression device, which may include:
[0018] A code length obtaining module is used to obtain a code stream to be decompressed, and obtain a code length from the code stream to be decompressed. The code length is determined according to the numerical value of the data to be compressed when compressing the data to be compressed before compression corresponding to the code to be decompressed in the code stream to be decompressed;
[0019] The coding and decompression module is used to determine the code to be decompressed from the code stream to be decompressed according to the code length, decompress the code to be decompressed according to the code length, and obtain the result decompression code;
[0020] The encoding and decoding module is used to decode the result decompression code to obtain the result decompressed data.
[0021] In a fifth aspect, an embodiment of the present invention further provides an electronic device, which may include:
[0022] one or more processors;
[0023] A memory for storing one or more programs;
[0024] When one or more programs are executed by one or more processors, the one or more processors implement the data compression method or encoding and decompression method provided by any embodiment of the present invention.
[0025] In a sixth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a data compression method or an encoding and decompression method provided by any embodiment of the present invention.
[0026] The technical solution of the embodiment of the present invention encodes the acquired data to be compressed to obtain the code to be compressed, and determines the code length of the data to be compressed according to the numerical value of the data to be compressed, wherein the code length can be the minimum number of bytes that can accurately store the code to be compressed and the code length in the storage space at the same time; compresses the code to be compressed according to the code length to obtain an intermediate compression code that can represent the code to be compressed based on the minimum number of bytes in the storage space; and then generates a result compression code according to the code length and the intermediate compression code, that is, the code length is recorded in the result compression code, thereby determining how many bytes (i.e. the minimum number of bytes) are based on which to store the result compression code according to the code length in the result compression code, which improves the compression rate in the data compression process by reducing the number of bytes actually occupied. The above technical solution achieves the effect of data compression with a high compression rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 is a flow chart of a data compression method in Embodiment 1 of the present invention;
[0028] Figure 2 is a schematic diagram of current error data in a data compression method in Embodiment 1 of the present invention;
[0029] Figure 3 is a flow chart of a data compression method in Embodiment 2 of the present invention;
[0030] Figure 4 is a flow chart of a data compression method in Embodiment 3 of the present invention;
[0031] Figure 5 is a flowchart of an optional example of a data compression method in Embodiment 3 of the present invention;
[0032] Figure 6 is a flow chart of a coding and decompression method in Embodiment 4 of the present invention;
[0033] Figure 7 is a structural block diagram of a data compression device in Embodiment 5 of the present invention;
[0034] Figure 8 It is a structural block diagram of a coding and decompression device in Embodiment 6 of the present invention;
[0035] Fig. 9 It is a structural schematic diagram of an electronic device in Embodiment 7 of the present invention. DETAILED DESCRIPTION
[0036] The present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It is also necessary to explain that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.
[0037] Embodiment 1
[0038] Figure 1 1 is a flow chart of a data compression method provided in Embodiment 1 of the present invention. This embodiment is applicable to the case where the compressed data is compressed, and is particularly applicable to the case where the compressed data is compressed based on the encoding length of the compressed data. The method can be executed by the data compression device provided in the embodiment of the present invention, and the device can be implemented by software and / or hardware, and the device can be integrated in an electronic device, and the electronic device can be various user terminals or servers.
[0039] See also Figure 1 The method of the embodiment of the present invention specifically includes the following steps:
[0040] S110, obtaining data to be compressed, encoding the data to be compressed to obtain a code to be compressed, and determining a code length of the data to be compressed according to a numerical value of the data to be compressed.
[0041] The data to be compressed may be data to be compressed, such as data intercepted from a data stream to be compressed or independent data directly obtained. In practical applications, optionally, the data stream to be compressed may be first divided into data blocks to be compressed, and then the data to be compressed may be obtained from the data blocks to be compressed, wherein the amount of data to be compressed in the data blocks to be compressed may be determined according to the real-time requirements and the data sampling rate. For example, assuming that the data sampling rate of the data stream to be compressed is 1000 Hz (Hz), a data block to be compressed is divided every 0.1 second (s), then each data block to be compressed may include sampling values of 100 points, that is, the amount of data is 100. Therefore, each subsequent step may be processed in units of data blocks to be compressed, that is, each data to be compressed in the data blocks to be compressed is processed in sequence. Optionally, since each data block to be compressed is independent of each other, the size of each data block to be compressed may be the same or different, which is not specifically limited here.
[0042] The data to be compressed is encoded to obtain the code to be compressed. The optional encoding schemes may be binary encoding, variable length encoding, non-return-to-zero encoding, Manchester encoding or differential Manchester encoding, etc., which are not specifically limited herein. For example, since the computer defaults to representing the encoding result (i.e., the code to be compressed) by N (such as N=1, 2 or 4, etc.) bytes, taking N=4 as an example, the code to be compressed obtained after binary encoding 72 (the data to be compressed) may be 00000000 00000000000000000 01001000.
[0043] The numerical value size may be the numerical size of the data to be compressed, such as the numerical value size of 72 (data to be compressed) is 72. The code length may be the minimum number of bytes that can store the code to be compressed. The reason for setting it is that, as mentioned above, the computer defaults to representing the encoding result by N bytes. In other words, even a very small encoding result of the data to be compressed, such as 0, needs to be stored by N bytes, which may result in the 0s on the first multiple bits of the encoding result being invalid numbers, and only the numbers on the following bits are valid numbers. For example, in the encoding result of 72, only the numbers on the following 8 bits are valid numbers, and the remaining invalid numbers occupy more storage space. Therefore, the proposal of the code length can reduce the storage space occupied while accurately representing the encoding result. Exemplarily, the code length of 72 is 2 (bytes), where 2 bytes equal 16 bits. It should be noted that, in the code to be compressed of 72, only the numbers on the last 8 bits are valid numbers. The reason why the code length is 2 instead of 1 is that the transmission of multiple data is mostly carried out in the form of data streams. If the default N bytes represent a coding result, then in the coding and decompression process, the codes to be decompressed can be directly split out one by one from the code stream to be decompressed according to N. However, if a coding result is represented by the code length, the code lengths of the codes to be decompressed may be different. At this time, it is necessary to split out each code to be decompressed from the code stream to be decompressed in turn according to the code length of each code to be decompressed, that is, first determine how many bytes the corresponding code to be decompressed occupies according to the code length, and then count these bytes of code from the code stream to be decompressed as the code to be decompressed. Therefore, the code length needs to be stored in the final coding result (that is, the result compression code in S130). To be precise, the code length can be the minimum number of bytes that can simultaneously store the code to be compressed and the code length.
[0044] It should be noted that the above-mentioned process of obtaining the to-be-compressed code and the process of determining the code length may be performed simultaneously, sequentially, or one after the other, which is not specifically limited here.
[0045] S120, compress the code to be compressed according to the code length to obtain an intermediate compressed code.
[0046] Among them, the compression code to be compressed is compressed according to the code length, and an intermediate compression code is obtained, the number of bytes occupied in the storage space is the code length. For example, the code length of 72 is 2, so the intermediate compression code of 72 can be 00 00000001001000. The process of obtaining the above intermediate compression code can have multiple implementation methods, such as obtaining the intermediate compression code after shifting the code to be compressed to the left according to the code length, that is, obtaining the intermediate compression code after shifting the code to be compressed to the left by the code length bytes, and then shifting the entire code to be compressed to the high position by the code length bytes, and then filling zeros in the low position; for example, determining the invalid bytes in the code to be compressed according to the code length, removing the invalid bytes from the code to be compressed, and obtaining the intermediate compression code, wherein the invalid bytes can be bytes that do not play a substantial role in the code to be compressed, such as the first 2 bytes in the code to be compressed of 72 are invalid bytes; of course, the intermediate compression code can also be obtained through other schemes, which are not specifically limited here. The process of obtaining the above intermediate compression code (ie the coding compression process) is mostly binary integer operations, which can be implemented based on bit operations, thereby improving the computational efficiency in the coding compression process by reducing the amount of calculation, and the central processing unit (CPU) overhead is relatively small.
[0047] S130, generating a result compression code according to the code length and the intermediate compression code.
[0048] Among them, the intermediate compression code can be an effective representation of the code to be compressed, so the result compression code generated according to the code length and the intermediate compression code can be an effective representation of the code length and the code to be compressed, which can effectively represent the code to be compressed while occupying the least storage space (i.e., the number of bytes), and the code length helps to accurately separate the code to be decompressed from the code stream to be decompressed during the code decompression process. In practical applications, optionally, the generation process of the above result compression code can have multiple implementation schemes, such as first encoding the code length to obtain the length code, and then adding the length code to the preset bit of the intermediate compression code to generate the result compression code, wherein the preset bit is the pre-set bit in the intermediate compression code, such as the first M bits in the intermediate compression code, M can be an integer greater than or equal to 1, and its specific value can be related to the maximum value of the code length; for example, first encoding the code length to obtain the length code, and then splicing the length code and the intermediate compression code to generate the result compression code; of course, the result compression code can also be generated by other schemes, which are not specifically limited here. The generation process of the above-mentioned result compression coding is mostly binary integer operation. For example, the process of adding the length code to the preset bit position can be understood as the process of moving the bit position where the length code is located to the preset bit position. This binary integer operation process can be implemented based on bit operations. Bit operations with smaller computational complexity improve the generation efficiency of the result compression coding and have smaller CPU overhead.
[0049] It should be noted that the above steps cooperate with each other. First, the compression code to be compressed is compressed based on the code length, thereby achieving the effect of lossless compression of the compression code to be compressed, and then ensuring that the data can be completely restored when the code is decompressed. Secondly, the intermediate compression code can be obtained based on bit operations and the result compression code can be generated, and the CPU overhead is small; moreover, the above steps can be completed based on streaming calculations, and the memory overhead is small. Thirdly, the application of the code length reduces the storage space occupied by the result compression code finally generated, that is, it improves the compression rate in the data compression process by reducing the number of bytes actually occupied. Finally, it has been verified by experiments that when the above data compression method is applied to the electroencephalography (EEG) data to be compressed, it can be compressed to 24-26%, and the compression rate is relatively high; moreover, the above data compression method can not only be used in narrowband wireless communication systems, but also has good data compression effects in communication systems, databases and storage systems that are not sensitive to bandwidth and power consumption.
[0050] The technical solution of the embodiment of the present invention encodes the acquired data to be compressed to obtain the code to be compressed, and determines the code length of the data to be compressed according to the numerical value of the data to be compressed, wherein the code length can be the minimum number of bytes that can accurately store the code to be compressed and the code length in the storage space at the same time; compresses the code to be compressed according to the code length to obtain an intermediate compression code that can represent the code to be compressed based on the minimum number of bytes in the storage space; and then generates a result compression code according to the code length and the intermediate compression code, that is, the code length is recorded in the result compression code, thereby determining how many bytes (i.e. the minimum number of bytes) are based on which to store the result compression code according to the code length in the result compression code, which improves the compression rate in the data compression process by reducing the number of bytes actually occupied. The above technical solution achieves the effect of data compression with a high compression rate.
[0051] An optional technical solution for obtaining data to be compressed may include: obtaining a data stream to be compressed, wherein the data stream to be compressed includes multiple data to be compressed; for each current compressed data in the data to be compressed, determining from the data stream to be compressed the previous compressed data of the current compressed data and the previous compressed data of the previous compressed data; determining current predicted data of the current compressed data based on the previous compressed data and the previous compressed data, and determining current error data of the current compressed data based on the current compressed data and the current predicted data; and using the current error data as the data to be compressed.
[0052] Among them, the current compressed data can be a certain data to be compressed among the third and subsequent data to be compressed in the data stream to be compressed, the previous compressed data can be the data to be compressed that is adjacent to the current compressed data and located in front of the current compressed data in the data stream to be compressed, and the previous compressed data can be the data to be compressed that is adjacent to the previous compressed data and located in front of the previous compressed data in the data stream to be compressed. The method of determining the current predicted data of the current compressed data based on the previous compressed data and the previous compressed data can be linear prediction or nonlinear prediction, which can be determined according to the data characteristics of the data stream to be compressed. Further, the current error data of the current compressed data is determined based on the current compressed data and the current predicted data, and then the current error data is used as the data to be compressed, that is, the subsequent steps are performed with the current error data as the main body. Of course, for the first two data to be compressed in the data stream to be compressed, they still perform the subsequent steps with themselves as the main body. In practical applications, optionally, the above data prediction process can be performed in units of data blocks to be compressed divided from the data stream to be compressed, that is, data prediction is performed on each data to be compressed in the data block to be compressed, thereby obtaining an error sequence consisting of the third data to be compressed in the data block to be compressed, that is, the error sequence can be a sequence including each current error data determined in sequence. It should be noted that, since each data to be compressed in the data stream to be compressed has local continuity, the dynamic range of the error sequence obtained based on each current error data will be greatly reduced compared to the data stream to be compressed, such as compressing the data stream to be compressed with a dynamic range of 0-100 to an error sequence with a dynamic range of less than 10, so that when the error sequence is subsequently compressed (that is, each current error data in the error sequence is compressed), the result encoding result of the error sequence with a smaller dynamic range occupies fewer bytes in the storage space, thereby further improving the compression rate in the data compression process.
[0053] To better understand the process of obtaining the above error sequence, see Figure 2 , where the curve is the data flow to be compressed, D n is the current compressed data (i.e., the nth data to be compressed in the data stream to be compressed), D n-1 is the last compressed data (i.e. the n-1th data to be compressed in the data stream to be compressed), D n-2 is the previous compressed data (i.e., the n-2th data to be compressed in the data stream to be compressed). If the prediction process of the current prediction data is linear prediction, then the current prediction data P linearly extended at this time is n =2×D n-1 -D n-2 , which is equivalent to drawing a line through D n-2 and D n-1 Straight line, then the straight line at D n The value at the position is P nIn practical applications, optional, P n It can be calculated by bit operation, that is, D n-1 Shift left by 1 bit and then subtract D n-2 , which speeds up P by avoiding multiplication operations n Compared with nonlinear prediction, the advantages of linear prediction are better versatility and less CPU overhead. Furthermore, the current error data R n =D n -P n .
[0054] Embodiment 2
[0055] Figure 3 It is a flow chart of a data compression method provided in the second embodiment of the present invention. This embodiment is optimized based on the above-mentioned technical solutions. In this embodiment, optionally, determining the coding length of the data to be compressed according to the numerical size of the data to be compressed may include: obtaining the correspondence between each candidate length and each candidate numerical range, the candidate numerical range includes determining according to the number of valid bits corresponding to the corresponding candidate length; determining the target numerical range from each candidate numerical range according to the numerical size of the data to be compressed, and determining the coding length corresponding to the target numerical range from each candidate length according to the corresponding relationship; or, determining the intermediate numerical range including the numerical size of the data to be compressed from each candidate numerical range, determining the intermediate length corresponding to the intermediate numerical range from each candidate length according to the corresponding relationship, and taking the intermediate length with the smallest length among the intermediate lengths as the coding length. Among them, the explanations of the terms that are the same or corresponding to the above-mentioned embodiments are not repeated here.
[0056] See also Figure 3 The method of this embodiment may specifically include the following steps:
[0057] S210, obtaining data to be compressed, encoding the data to be compressed, and obtaining the code to be compressed.
[0058] S220, obtaining a correspondence between each candidate length and each candidate numerical range, wherein the candidate numerical range is determined according to the number of valid bits corresponding to the corresponding candidate length.
[0059] Wherein, the candidate length may be a candidate encoding length; the candidate numerical range may be a candidate numerical range, which may be determined according to the valid bit number of the candidate length corresponding to itself, wherein the valid bit number may be the bit number of bits that can be used to store the encoding result of the data to be compressed, such as the number of bytes is the number of bits included in the byte of the candidate length minus the number of bits occupied by the candidate length in the byte. Exemplarily, assuming that a certain candidate length occupies 2 bits in a certain byte, then the valid bit number of the candidate length is 1 (byte) is 6 (i.e. 8-2), and its corresponding candidate numerical range may be [-32, 31], and the valid bit number of the candidate length is 2 (bytes) is 14 (i.e. 16-2), and its corresponding candidate numerical range may be [-8192, 8919], as shown in Table 1, wherein the minimum value is the minimum value in the candidate numerical range, and the maximum value is the maximum value in the candidate numerical range.
[0060] Table 1 Correspondence between candidate lengths and candidate value ranges
[0061] Candidate length (bytes) Number of effective bits (bits) Minimum Maximum 1 6 -32 31 2 14 -8192 8191 3 22 -2097152 2097151 4 30 -536870912 536870911
[0062] S230 , determining a target numerical range from each candidate numerical range according to the numerical value of the data to be compressed, and determining a coding length corresponding to the target numerical range from each candidate length according to a corresponding relationship.
[0063] The target numerical range can be determined in a variety of ways, such as determining an intermediate numerical range including the numerical value of the data to be compressed from each candidate numerical range, and taking the intermediate numerical range where the largest minimum value among the minimum values of each intermediate numerical range (or the smallest maximum value among the maximum values of each intermediate numerical range) is located as the target numerical range. By way of example, taking Table 1 as an example, the candidate numerical range including 72 (numerical value) includes [-8192, 8191], [-2097152, 2097151] and [-536870912, 536870911], wherein the minimum values of these three intermediate numerical ranges are -8192, -2097152 and -536870912 respectively, then the largest minimum value is -8192, and therefore the target numerical range is [-8192, 8191]. Compared with the remaining intermediate numerical ranges, the candidate length corresponding to the target numerical range is the smallest, thereby minimizing the storage space occupied while ensuring accurate representation of the code to be compressed. Furthermore, the corresponding relationship determines the coding length corresponding to the target numerical range from each candidate length.
[0064] S240, determine an intermediate numerical range including the numerical value of the data to be compressed from each candidate numerical range, and determine an intermediate length corresponding to the intermediate numerical range from each candidate length according to the corresponding relationship, and use the intermediate length with the smallest length among the intermediate lengths as the encoding length.
[0065] Among them, the intermediate length can be a candidate length corresponding to the intermediate value range including the numerical value size, and the number of lengths of the intermediate length can be one, two or more, which is related to the specific actual situation. In order to ensure accurate representation of the compressed code while minimizing the storage space occupied, the intermediate length with the smallest length among the intermediate lengths is used as the encoding length. Exemplarily, assuming that the intermediate value range is [-8192, 8191], [-2097152, 2097151] and [-536870912, 536870911], their corresponding intermediate lengths are 2 (bytes), 3 (bytes) and 4 (bytes), respectively, so 2 can be used as the encoding length.
[0066] It should be noted that S230 and S240 are two optional solutions in the process of determining the code length, and either one of them can be selected for execution in practical applications.
[0067] S250, compress the code to be compressed according to the code length to obtain an intermediate compressed code.
[0068] S260: Generate a result compression code according to the code length and the intermediate compression code.
[0069] Exemplarily, assuming that the binary encoding result of the encoding length (such as length encoding, where 1 corresponds to 00, 2 corresponds to 01, 3 corresponds to 10, and 4 corresponds to 11) is added to the highest 2 bits of the first byte of the intermediate compression code, then an example of the resulting compression code is shown in Table 2:
[0070] Table 2 Results compression coding
[0071] Data to be compressed Encoding length (bytes) Result compression encoding (binary) -17 1 00 101111 72 2 01 000000 01001000 1765937 3 10 011010 11110010 00110001 -478767369 4 11 100011 01110110 10010110 11110111
[0072] The technical solution of the embodiment of the present invention obtains the correspondence between each candidate length and each candidate numerical range, wherein the candidate numerical range corresponding to the candidate length can include the determination based on the number of valid bits corresponding to the candidate length, and determines the target numerical range from each candidate numerical range according to the numerical size of the data to be compressed, and determines the coding length corresponding to the target numerical range from each candidate length according to the correspondence; or, determines from each candidate numerical range an intermediate numerical range including the numerical size of the data to be compressed, determines from each candidate length an intermediate length corresponding to the intermediate numerical range according to the correspondence, and uses the intermediate length with the smallest length among the intermediate lengths as the coding length, thereby obtaining a coding length that can minimize the storage space occupied while ensuring accurate representation of the code to be compressed, which is an important means to reduce the compression rate.
[0073] Embodiment 3
[0074] Figure 4 It is a flow chart of a data compression method provided in the third embodiment of the present invention. This embodiment is optimized based on the above-mentioned technical solutions. In this embodiment, optionally, encoding the data to be compressed to obtain the code to be compressed may include: determining the shortest encoding parameter corresponding to the data to be compressed, and encoding the data to be compressed according to the shortest encoding parameter to obtain the compressed code; if the amount of compressed coded data is greater than or equal to the amount of data to be compressed, binary encoding the data to be compressed to obtain the code to be compressed. Among them, the explanations of the terms that are the same as or corresponding to the above-mentioned embodiments are not repeated here.
[0075] See also Figure 4 The method of this embodiment may specifically include the following steps:
[0076] S310: Obtain data to be compressed, determine the shortest encoding parameter corresponding to the data to be compressed, and encode the data to be compressed according to the shortest encoding parameter to obtain a compressed code.
[0077] Among them, the shortest coding parameter can indicate the minimum number of bits required to store the data to be compressed. In practical applications, the shortest coding parameter can optionally be a pre-set value, such as different data blocks to be compressed or each data to be compressed in a data stream to be compressed corresponds to the same shortest coding parameter. This is suitable for situations where data fluctuations are relatively small. At this time, the shortest coding parameter is relatively small, thereby better ensuring the compression rate, and reducing the amount of calculation in the encoding process because there is no need to calculate the shortest coding parameter. It can also be a value calculated in real time, such as each data to be compressed in the same data block to be compressed or each data to be compressed in a data stream to be compressed corresponds to the same shortest coding parameter. Taking the application error sequence as an example, the shortest coding parameter in each data block to be compressed where R is the error sequence, |R[..]| is the mean of the absolute values of the error sequence, log e 2 is a constant, and log2 x is equivalent to the number of times x becomes 0 after multiple arithmetic right shifts, that is, how many bits x occupies in the storage space (one right shift occupies 1 bit), so the number of bits occupied by the mean of the absolute value of the error sequence can be multiplied by log e 2 and then round down to an integer. This is suitable for situations where the data fluctuation is relatively large, or it is impossible to determine in advance whether the data fluctuation is large, and it is impossible to pre-set a suitable value for all the data blocks to be compressed. It should be noted that, on the one hand, the above is an example of the error sequence R, which can also be directly the data to be compressed in actual applications, that is, in this case |R[..]| can represent the mean of the absolute values of the data to be compressed; on the other hand, the above calculation process can be implemented through bit operations, thereby reducing the CPU overhead.
[0078] Furthermore, the compressed data may be encoded according to the shortest encoding parameter. An optional encoding method may be to continue taking the error sequence as an example, for each current error data in the error sequence, decompose the current error data into three parts: a sign, and divide the absolute value of the current error data by 2. m The remainder and quotient of the error data can be quickly calculated based on bit operations. Assuming that r represents the absolute value of the current error data, the remainder can be obtained by using r and 2 m -1 bitwise AND, where 2 m It can be obtained by shifting 1 left by m bits; the quotient can be obtained by shifting r right by m bits. The compressed code thus obtained can be composed of four parts as shown in Table 3, and a specific example of the compressed code is shown in Table 4 (assuming m=4):
[0079] Table 3: Components of compressed code
[0080] Components Length (bits) illustrate symbol 1 0: positive number, 1: negative number Remainder m Big-endian / little-endian binary encoding of remainder business ≥0 It consists of a series of 0s, the number of which is the same as the value of the quotient. End Sign 1 Fixed to 1, used to identify the end of a compressed code
[0081] Table 4 has been compressed and coded
[0082] Current error data symbol Remainder business Compressed encoding (binary) 0 0 0 0 0 0000 1 7 0 7 0 0 0111 1 -17 1 1 1 1 0001 0 1 110 0 14 6 0 1110 000000 1
[0083] S320: If the amount of compressed and coded data is greater than or equal to the amount of data to be compressed, binary code the data to be compressed to obtain the code to be compressed.
[0084] Among them, when the amount of compressed and encoded data is greater than or equal to the amount of data to be compressed, this means that the compressed code after compression is not less than the original data to be compressed. This may be because the compression rate of the encoding scheme (i.e., compression method) based on the shortest encoding parameters depends on the continuity of the data. When the data changes particularly drastically, especially when the error sequence is used as the basis for encoding, each current error data in the error sequence is very large, and thus the amount of compressed and encoded data obtained will also be very large, and may even reach thousands of bytes. Based on this, in order to ensure a better compression rate, a different compression method can be used at this time, such as binary encoding the data to be compressed to obtain the code to be compressed, and then cooperating with subsequent steps to compress the code to be compressed based on the code length.
[0085] Of course, when the amount of compressed encoded data is smaller than the amount of data to be compressed, this means that the compressed code after compression is smaller than the original data to be compressed, that is, a better compression rate can be obtained when encoding based on the shortest encoding parameters. At this time, the compressed code can be directly used as the result compression code and exited.
[0086] S330: Determine the encoding length of the data to be compressed according to the numerical value of the data to be compressed.
[0087] S340, compress the code to be compressed according to the code length to obtain an intermediate compressed code.
[0088] S350: Generate a result compression code according to the code length and the intermediate compression code.
[0089] The technical solution of the embodiment of the present invention takes into account that each to-be-compressed data in the to-be-compressed data stream may be data that changes steadily or may be data that changes suddenly. Therefore, in order to ensure the compression rate of the resulting compression code finally generated, the to-be-compressed data may be first encoded according to the shortest encoding parameter corresponding to the to-be-compressed data to obtain the compressed code, and then it is determined whether the amount of compressed encoded data is greater than or equal to the amount of data of the to-be-compressed data; if so, it means that the above-mentioned to-be-compressed data is not suitable for encoding according to the shortest encoding parameter to complete data compression, then the to-be-compressed code may be obtained by binary encoding the to-be-compressed data, and then the to-be-compressed code is compressed based on the code length to complete data compression, thereby achieving the effect of selecting a suitable compression method according to the actual situation of the data to be compressed to ensure a higher compression rate.
[0090] On this basis, optionally, after the result compression code is generated according to the code length and the intermediate compression code, the above-mentioned encoding compression method may also include: if the data volume of the result compression code is less than the data volume of the data to be compressed, then the compression method corresponding to the result compression code and the splicing result of the result compression code are used as the compression result of the data to be compressed, otherwise the compression method corresponding to the data to be compressed and the splicing result of the data to be compressed are used as the compression result of the data to be compressed. Among them, in order to ensure that the data to be compressed has a good compression rate, a suitable compression method may be used to compress it. On this basis, since different compression methods may correspond to different decompression methods in the encoding and decompression process, the compression method can also be stored in the storage space, so that it can be determined which decompression method to use for encoding and decompression in the encoding and decompression process. Therefore, when the amount of data in the result compression code is less than the amount of data to be compressed, this indicates that the data compression process based on the coding length is effective compression, and the compression method corresponding to the result compression code and the splicing result of the result compression code can be used as the compression result of the data to be compressed; similarly, when the amount of data in the result compression code is greater than or equal to the amount of data to be compressed, this indicates that the data compression process based on the coding length is invalid compression, and the compression method corresponding to the data to be compressed (i.e., uncompressed) and the splicing result of the data to be compressed can be used as the compression result of the data to be compressed. The above compression method can be understood as metadata (Metadata) in the compression result, where metadata can also be called intermediate data, relay data, etc., which is data (data aboutdata) describing data (i.e., compression result), mainly describing the property information of the data, used to support functions such as indicating storage location, historical data, resource search or file record, so that the receiver of the compression result can decode and restore the data to be compressed according to the metadata in the received compression result, as shown in Table 5 for example:
[0091] Table 5 Composition of the four fields in the compression result
[0092]
[0093]
[0094] In order to better understand the mutual cooperation process of the above-mentioned technical solutions, the following is an exemplary description of them in combination with specific examples. Figure 5 :
[0095] S301. Divide the data blocks to be compressed from the data stream to be compressed;
[0096] S302. Perform linear prediction on each data to be compressed starting from the third data to be compressed in the compressed data block to obtain an error sequence, wherein the error sequence includes a plurality of current error data;
[0097] S303. Encode the current error data based on the shortest encoding parameter to obtain a compressed code;
[0098] S304. If the amount of compressed data (ie, length) is less than the amount of data to be compressed, jump to S306, otherwise discard the compressed code generated in S303 and continue to execute S305;
[0099] S305. Binary encode the current error data based on the code length to obtain the result compression code, and jump to S307;
[0100] S306. Combine the metadata and the compressed code to form a data frame, and jump to S308;
[0101] S307. Combining the metadata and the result compression encoding together to form a data frame;
[0102] S308. End.
[0103] Embodiment 4
[0104] Figure 6 This is a flowchart of a coding and decompression method provided in Embodiment 4 of the present invention. This embodiment is applicable to the case where the result decompressed data is decompressed from the coded stream to be decompressed, and is particularly applicable to the case where the result decompressed data is decompressed from the coded stream to be decompressed according to the coding length of the result decompressed data. The method can be executed by the coding and decompression device provided in the embodiment of the present invention, and the device can be implemented by software and / or hardware, and the device can be integrated in an electronic device, and the electronic device can be various user terminals or servers.
[0105] See also Figure 6 The method of the embodiment of the present invention specifically includes the following steps:
[0106] S410, obtaining a code stream to be decompressed, and obtaining a code length from the code stream to be decompressed, wherein the code length is determined according to the numerical value of the data to be compressed when compressing the pre-compressed data to be compressed corresponding to the code to be decompressed in the code stream to be decompressed.
[0107] Among them, the code stream to be decompressed can be a code stream including at least one code to be decompressed, wherein the code to be decompressed can be a code obtained by compressing the data to be compressed corresponding to the code to be decompressed. Since the code length of the data to be compressed has been added to the code to be decompressed (i.e., the result compression code) when the data to be compressed is compressed, the code length can be obtained from the code stream to be decompressed. The code length is determined according to the numerical size of the data to be compressed during the data compression process.
[0108] S420, determining the code to be decompressed from the code stream to be decompressed according to the code length, and decompressing the code to be decompressed according to the code length to obtain a result decompressed code.
[0109] Among them, since the codes to be decompressed in the code stream to be decompressed are connected in sequence, when the codes to be decompressed are decompressed, the first premise is to cut out the complete codes to be decompressed from the code stream to be decompressed. On this basis, since the code length can indicate how many bytes the code to be decompressed occupies in the storage space, it is possible to determine how many bits are used to store the code to be decompressed after the bits used to store the code length according to the code length, and then take out the codes on these bits from the code stream to be decompressed as the codes to be decompressed, that is, the codes to be decompressed can be determined from the code stream to be decompressed according to the code length. Then, the codes to be decompressed are decompressed according to the code length to obtain the result decompressed code, wherein the code decompression process is the opposite of the code compression process described in the above embodiments, and will not be repeated here.
[0110] S430, decompress the result code to obtain result decompressed data.
[0111] The encoding and decoding process is the opposite of the data encoding process described in the above embodiments, which will not be described in detail here. The decompressed data is equivalent to the data to be compressed.
[0112] It should be noted that the encoding and decompression process may also involve processes such as the data stream segmentation to be compressed (i.e., the coded stream segmentation to be decompressed), data prediction (i.e., coding prediction) described above, which are not specifically limited here.
[0113] The technical solution of the embodiment of the present invention obtains the code length from the acquired code stream to be decompressed. The code length can be determined according to the numerical value of the data to be compressed when compressing the compressed data before compression corresponding to the code to be decompressed in the code stream to be decompressed; since the code length can be used to determine which bits of the code in the code stream to be decompressed belong to the same code to be decompressed, the code to be decompressed can be determined from the code stream to be decompressed according to the code length, and the code to be decompressed is decompressed according to the code length to obtain the result decompressed code; and then, the result decompressed code is decompressed to obtain the result decompressed data. The above technical solution effectively completes the coding decompression process by obtaining the code length from the code stream to be decompressed.
[0114] Embodiment 5
[0115] Figure 7 This is a structural block diagram of a data compression device provided in Embodiment 5 of the present invention. The device is used to execute the data compression method provided in any of the above embodiments. The device and the data compression method in the above embodiments belong to the same inventive concept. For details not described in detail in the embodiment of the data compression device, please refer to the embodiment of the above data compression method. Figure 7 The device may specifically include: a data encoding module 510, a coding compression module 520 and a data compression module 530.
[0116] The data encoding module 510 is used to obtain the data to be compressed, encode the data to be compressed, obtain the code to be compressed, and determine the code length of the data to be compressed according to the value of the data to be compressed;
[0117] A code compression module 520, used for compressing the code to be compressed according to the code length to obtain an intermediate compressed code;
[0118] The data compression module 530 is used to generate a result compression code according to the code length and the intermediate compression code.
[0119] Optionally, the encoding and compression module 520 may be specifically used for:
[0120] Shift the code to be compressed to the left according to the code length to obtain an intermediate compressed code; or
[0121] Invalid bytes in the code to be compressed are determined according to the code length, and the invalid bytes are removed from the code to be compressed to obtain an intermediate compressed code.
[0122] Optionally, the data compression module 530 may be specifically used for:
[0123] Encode the code length to obtain the length code;
[0124] The length code is added to the preset bit position of the intermediate compression code to generate the result compression code; or, the length code and the intermediate compression code are concatenated to generate the result compression code.
[0125] Optionally, the data encoding module 510 may include:
[0126] A corresponding relationship acquisition unit, used to acquire a corresponding relationship between each candidate length and each candidate value range, wherein the candidate value range is determined according to the number of valid bits corresponding to the corresponding candidate length;
[0127] A coding length determination unit is used to determine a target numerical range from each candidate numerical range according to the numerical size of the data to be compressed, and determine a coding length corresponding to the target numerical range from each candidate length according to the corresponding relationship; or, determine an intermediate numerical range including the numerical size of the data to be compressed from each candidate numerical range, and determine an intermediate length corresponding to the intermediate numerical range from each candidate length according to the corresponding relationship, and use the smallest intermediate length among the intermediate lengths as the coding length.
[0128] Optionally, the data encoding module 510 may include:
[0129] A data stream to be compressed acquiring unit, used for acquiring a data stream to be compressed, wherein the data stream to be compressed includes a plurality of data to be compressed;
[0130] A previous compressed data determining unit, for determining, for each current compressed data in the data to be compressed, the previous compressed data of the current compressed data and the previous compressed data of the previous compressed data from the data stream to be compressed;
[0131] The unit for determining data to be compressed is used to determine current prediction data of current compressed data according to last compressed data and previous compressed data, and to determine current error data of current compressed data according to current compressed data and current prediction data, and to use current error data as data to be compressed.
[0132] Optionally, the data encoding module 510 may include:
[0133] A first data encoding unit, used for determining the shortest encoding parameter corresponding to the data to be compressed, and encoding the data to be compressed according to the shortest encoding parameter to obtain a compressed code;
[0134] The second data encoding unit is used for, if the amount of compressed and encoded data is greater than or equal to the amount of data to be compressed, to perform binary encoding on the data to be compressed to obtain the code to be compressed.
[0135] On this basis, optionally, the data compression device may further include:
[0136] A compression method splicing module is used to use the compression method corresponding to the result compression code and the splicing result of the result compression code as the compression result of the data to be compressed if the data amount of the result compression code is less than the data amount of the data to be compressed; otherwise, the compression method corresponding to the data to be compressed and the splicing result of the data to be compressed are used as the compression result of the data to be compressed.
[0137] The data compression device provided by the fifth embodiment of the present invention encodes the acquired data to be compressed through the data encoding module to obtain the code to be compressed, and determines the code length of the data to be compressed according to the numerical value of the data to be compressed, wherein the code length can be the minimum number of bytes that can accurately store the code to be compressed and the code length in the storage space at the same time; the coding compression module compresses the code to be compressed according to the code length to obtain an intermediate compression code that can represent the code to be compressed based on the minimum number of bytes in the storage space; further, the data compression module generates a result compression code according to the code length and the intermediate compression code, that is, the code length is recorded in the result compression code, thereby determining how many bytes (i.e. the minimum number of bytes) are based on which the result compression code is stored according to the code length in the result compression code, and the compression rate in the data compression process is improved by reducing the number of bytes actually occupied. The above device achieves the effect of data compression with a high compression rate.
[0138] The data compression device provided in the embodiment of the present invention can execute the data compression method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0139] It is worth noting that in the embodiment of the above-mentioned data compression device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0140] Embodiment 6
[0141] Figure 8 This is a structural block diagram of a coding and decompression device provided in Embodiment 6 of the present invention. The device can be used to execute the coding and decompression method provided in any of the above embodiments. The device and the coding and decompression method of the above embodiments belong to the same inventive concept. For details not described in detail in the embodiments of the coding and decompression device, please refer to the embodiments of the above coding and decompression method. Figure 8 The device may specifically include: a coding length obtaining module 610, a coding decompression module 620, and a coding and decoding module 630.
[0142] The code length obtaining module 610 is used to obtain the code stream to be decompressed, and obtain the code length from the code stream to be decompressed. The code length is determined according to the numerical value of the data to be compressed when compressing the data to be compressed before compression corresponding to the code to be decompressed in the code stream to be decompressed.
[0143] The code decompression module 620 is used to determine the code to be decompressed from the code stream to be decompressed according to the code length, and decompress the code to be decompressed according to the code length to obtain a result decompressed code;
[0144] The encoding and decoding module 630 is used to decode the result decompression code to obtain result decompressed data.
[0145] The coding and decompression device provided in the sixth embodiment of the present invention obtains the coding length from the acquired code stream to be decompressed through the coding length obtaining module. The coding length can be determined according to the numerical value of the data to be compressed when compressing the data to be compressed before compression corresponding to the code to be decompressed in the code stream to be decompressed; because the coding length can be used to determine which bits of the codes in the code stream to be decompressed belong to the same code to be decompressed, the coding and decompression module determines the code to be decompressed from the code stream to be decompressed according to the coding length, and decompresses the code to be decompressed according to the coding length to obtain the result decompressed code; then, the coding and decompression module decompresses the result decompressed code to obtain the result decompressed data. The above device can effectively complete the coding and decompression process through the coding length obtained from the code stream to be decompressed.
[0146] The encoding and decompression device provided in the embodiment of the present invention can execute the encoding and decompression method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0147] It is worth noting that in the embodiment of the above-mentioned encoding and decompression device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0148] Embodiment 7
[0149] Fig. 9 A schematic diagram of the structure of an electronic device provided in Embodiment 7 of the present invention is shown in FIG. Fig. 9 As shown, the electronic device includes a memory 710, a processor 720, an input device 730, and an output device 740. The number of processors 720 in the electronic device can be one or more. Fig. 9A processor 720 is taken as an example; the memory 710, the processor 720, the input device 730 and the output device 740 in the electronic device can be connected via a bus or other means. Fig. 9 The connection via bus 750 is taken as an example.
[0150] The memory 710, as a computer-readable storage medium, can be used to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the data compression method in the embodiment of the present invention (for example, the data encoding module 510, the encoding compression module 520 and the data compression module 530 in the data compression device), or, program instructions / modules corresponding to the encoding and decompression method in the embodiment of the present invention (for example, the encoding length obtaining module 610, the encoding and decompression module 620 and the encoding and decoding module 630 in the encoding and decompression device). The processor 720 executes various functional applications and data processing of the electronic device by running the software programs, instructions and modules stored in the memory 710, that is, implements the above-mentioned data compression method or encoding and decompression method.
[0151] The memory 710 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 710 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some instances, the memory 710 may further include a memory remotely arranged relative to the processor 720, and these remote memories may be connected to the device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0152] The input device 730 may be used to receive input digital or character information and generate key signal input related to user settings and function control of the device. The output device 740 may include a display device such as a display screen.
[0153] Embodiment 8
[0154] Embodiment 8 of the present invention provides a storage medium including computer executable instructions, wherein the computer executable instructions are used to perform a data compression method when executed by a computer processor, the method comprising:
[0155] Obtaining data to be compressed, encoding the data to be compressed to obtain a code to be compressed, and determining a code length of the data to be compressed according to a numerical value of the data to be compressed;
[0156] Compress the to-be-compressed code according to the code length to obtain an intermediate compressed code;
[0157] A result compression code is generated based on the code length and the intermediate compression code.
[0158] Of course, the computer executable instructions of a storage medium including computer executable instructions provided by an embodiment of the present invention are not limited to the operations of the method described above, but can also execute related operations in the data compression method provided by any embodiment of the present invention.
[0159] Embodiment 9
[0160] Embodiment 9 of the present invention provides a storage medium including computer executable instructions, wherein the computer executable instructions are used to execute a coding and decompression method when executed by a computer processor. The method may include:
[0161] Obtaining a code stream to be decompressed, and obtaining a code length from the code stream to be decompressed, wherein the code length is determined according to the numerical value of the data to be compressed when compressing the data to be compressed before compression corresponding to the code to be decompressed in the code stream to be decompressed;
[0162] Determine the code to be decompressed from the code stream to be decompressed according to the code length, and decompress the code to be decompressed according to the code length to obtain a result decompressed code;
[0163] The result decompression code is decompressed to obtain result decompressed data.
[0164] Of course, the computer executable instructions of a storage medium including computer executable instructions provided by an embodiment of the present invention are not limited to the operations of the method described above, but can also execute related operations in the encoding and decompression method provided by any embodiment of the present invention.
[0165] Through the above description of the implementation methods, the technicians in the relevant field can clearly understand that the present invention can be implemented by means of software and necessary general hardware, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory (FLASH), hard disk or optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0166] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.
Claims
1. A data compression method, characterized in that: include: Acquire data to be compressed, encode the data to be compressed to obtain a code to be compressed, and determine the code length of the data to be compressed according to the value of the data to be compressed; Compressing the code to be compressed according to the code length to obtain an intermediate compressed code; Generate a result compression code according to the code length and the intermediate compression code; The step of generating a result compression code according to the code length and the intermediate compression code comprises: encoding the code length to obtain a length code; Adding the length code to the preset bit position of the intermediate compression code to generate a result compression code; or, The length code and the intermediate compression code are concatenated to generate a result compression code.
2. The method according to claim 1, characterized in that Compressing the code to be compressed according to the code length to obtain an intermediate compressed code includes: The to-be-compressed code is shifted to the left according to the code length to obtain an intermediate compressed code; or, Invalid bytes in the code to be compressed are determined according to the code length, and the invalid bytes are removed from the code to be compressed to obtain an intermediate compressed code.
3. The method according to claim 1, characterized in that The step of determining the encoding length of the data to be compressed according to the numerical value of the data to be compressed comprises: Obtaining a correspondence between each candidate length and each candidate value range; the candidate value range includes being determined according to the number of valid bits corresponding to the corresponding candidate length; Determine a target numerical range from each of the candidate numerical ranges according to the numerical value of the data to be compressed, and determine a coding length corresponding to the target numerical range from each of the candidate lengths according to the corresponding relationship; or, An intermediate numerical range including the numerical size of the data to be compressed is determined from each of the candidate numerical ranges, and an intermediate length corresponding to the intermediate numerical range is determined from each of the candidate lengths according to the corresponding relationship, and the intermediate length with the smallest length among the intermediate lengths is used as the encoding length.
4. The method according to claim 1, characterized in that: The step of obtaining the data to be compressed includes: Acquire a data stream to be compressed, wherein the data stream to be compressed includes a plurality of data to be compressed; For each of the currently compressed data in the data to be compressed, determining the last compressed data of the currently compressed data and the previous compressed data of the last compressed data from the data stream to be compressed; The current prediction data of the current compressed data is determined according to the last compressed data and the previous compressed data, and the current error data of the current compressed data is determined according to the current compressed data and the current prediction data, and the current error data is used as the data to be compressed.
5. The method according to claim 1, characterized in that The step of encoding the data to be compressed to obtain the code to be compressed includes: Determining the shortest encoding parameter corresponding to the data to be compressed, and encoding the data to be compressed according to the shortest encoding parameter to obtain a compressed code; If the amount of the compressed and coded data is greater than or equal to the amount of the data to be compressed, binary encoding is performed on the data to be compressed to obtain the code to be compressed.
6. The method according to claim 5, characterized in that After generating the result compression code according to the code length and the intermediate compression code, the method further includes: If the amount of data in the result compression coding is smaller than the amount of data in the data to be compressed, the compression method corresponding to the result compression coding and the concatenated result of the result compression coding will be used as the compression result of the data to be compressed; otherwise, the compression method corresponding to the data to be compressed and the concatenated result of the data to be compressed will be used as the compression result of the data to be compressed.
7. A coding and decompression method, characterized in that: include: Acquire a code stream to be decompressed, and obtain a code length from the code stream to be decompressed, wherein the code length is determined according to the numerical value of the data to be compressed when compressing the data to be compressed before compression corresponding to the code to be decompressed in the code stream to be decompressed; Determine the to-be-decompressed code from the to-be-decompressed code stream according to the code length, and decompress the to-be-decompressed code according to the code length to obtain a result decompressed code; The result decompression code is decompressed to obtain result decompressed data.
8. A data compression device, characterized in that: include: A data encoding module, used to obtain data to be compressed, encode the data to be compressed to obtain a code to be compressed, and determine the code length of the data to be compressed according to the value of the data to be compressed; A code compression module, used for compressing the code to be compressed according to the code length to obtain an intermediate compressed code; A data compression module, used for generating a result compression code according to the code length and the intermediate compression code; The data compression module is also used to: encode the code length to obtain a length code; Adding the length code to the preset bit position of the intermediate compression code to generate a result compression code; or, The length code and the intermediate compression code are concatenated to generate a result compression code.
9. A coding and decompression device, characterized in that: include: A code length obtaining module, used for obtaining a code stream to be decompressed, and obtaining a code length from the code stream to be decompressed, wherein the code length is determined according to the numerical value of the data to be compressed when compressing the data to be compressed before compression corresponding to the code to be decompressed in the code stream to be decompressed; A coding and decompression module, used for determining the to-be-decompressed code from the to-be-decompressed code stream according to the code length, decompressing the to-be-decompressed code according to the code length, and obtaining a result decompression code; The encoding and decoding module is used to decode the result decompression code to obtain result decompressed data.
10. An electronic device, characterized in that: include: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the data compression method as described in any one of claims 1 to 6, or the encoding and decompression method as described in claim 7.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data compression method according to any one of claims 1 to 6 or the encoding and decompression method according to claim 7 is implemented.
Citation Information
Patent Citations
Data compression method and device, computer readable storage medium and electronic equipment
CN112527752A