Decoding method and related device
By tuning the Huffman encoding and decoding algorithms of the zlib library, parallel decoding of duplicate data and independent data is realized, solving the problem of slow loading pictures of SKIA, and improving the smoothness of image refresh and hardware resource utilization efficiency of electronic devices.
Patent Information
- Application Number
- CN202410214678.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-27
- Publication Date
- 2025-08-29
AI Technical Summary
Skia is slow to load pictures, resulting in poor fluency in refreshing pictures by electronic devices, mainly because the DEFLATE algorithm used by the zlib library is slow.
The Huffman encoding and decoding algorithm is used to tune the zlib library. By using the same decompression algorithm to decode duplicate data and independent data in parallel, the encoding mapping table is optimized, the encoding and decoding process is merged, and the redundant instruction execution is reduced.
It improves image loading speed, improves the fluency of refreshing images by electronic devices, reduces decoding time and saves the running cycle of hardware resources.
Smart Images

Figure CN120568136A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a decoding method and related devices. Background Art
[0002] Skia is a two-dimensional (2D) graphics processing library. As a graphics engine, Skia is widely used for image loading on electronic devices across various software systems, such as Android, Google Chrome OS (ChromeOS), the mobile application development framework (Flutter), and OpenHarmony. Skia uses the open-source zlib library to compress (also known as encode) and decompress (also known as decode) images, such as those in the portable network graphics (PNG) format. However, the DEFLATE algorithm used by the zlib library is slow, resulting in slower image decoding. Consequently, Skia loads images more slowly, and image refreshes on electronic devices are less smooth. Summary of the Invention
[0003] The present application discloses a decoding method and related devices, which can optimize the DEFLATE algorithm of the zlib library to reduce the decoding time of the image, thereby allowing skia to load images faster and improving the smoothness of image refresh on electronic devices.
[0004] In a first aspect, the present application provides a decoding method, which is applied to an electronic device, the method comprising: obtaining a compressed file of a first image, wherein the first image comprises first data and second data, the first data appears multiple times in the first image, and the second data appears once in the first image, the compressed file comprises a first codeword and a second codeword, the compressed file is obtained by encoding the first image using a first compression algorithm, the first codeword is obtained by encoding the first data using the first compression algorithm, and the second codeword is obtained by encoding the second data using the first compression algorithm, and the first compression algorithm comprises Huffman coding; decoding the compressed file using a first decompression algorithm and obtaining the first image, wherein the first data in the first image is obtained by decoding the first codeword in the compressed file using the first decompression algorithm, and the second data in the first image is obtained by decoding the second codeword in the compressed file using the first decompression algorithm, the first decompression algorithm corresponds to the first compression algorithm, and the first decompression algorithm comprises Huffman decoding; and displaying the first image.
[0005] For example, the first image is a picture in the portable network graphics (PNG) format.
[0006] In the above method, for the first data that appears multiple times and the second data that appears once in the first image, the electronic device will use the same compression algorithm and the same decompression algorithm for encoding and decoding, rather than using different compression algorithms and different decompression algorithms for encoding and decoding. Therefore, the first data and the second data in the above method can be decoded in parallel, rather than serially, reducing the decoding time of the first image, thereby making the loading and display of the first image faster and improving the smoothness of the electronic device refreshing the image. It can be understood that in order to ensure a better compression effect for the second data, a different compression algorithm and decompression algorithm from the first data are generally used for encoding and decoding to save storage space. In this application, the first data and the second data use the same compression algorithm and decompression algorithm. Although the compression effect is poor, parallel decoding can be achieved, which greatly reduces the decoding time. Therefore, this application can be considered as "trading storage space for decoding time."
[0007] In one possible implementation, when the compressed file is decoded using the first decompression algorithm and the first image is obtained, the electronic device can read the encoding mapping table corresponding to the compressed file, and obtain the data (including the first data and the second data) corresponding to each codeword in the compressed file from the encoding mapping table to obtain the first image, wherein the encoding mapping table is determined based on Huffman coding, and the encoding mapping table includes the correspondence between each data (including the first data and the second data) in the first image and each codeword in the compressed file, the first data in the encoding mapping table corresponds to the first codeword, and the second data in the encoding mapping table corresponds to the second codeword.
[0008] In the above method, the coding mapping table can be constructed based on the first data that appears multiple times and the second data that appears once in the first image, rather than being constructed only based on the first data. Therefore, the decoding of the first data and the second data can be completed simultaneously based on the coding mapping table, rather than first completing the decoding of the first data based on the coding mapping table and then decoding the second data, effectively reducing the decoding time of the first image and improving the fluency of refreshing the image of the electronic device.
[0009] In one possible implementation, the encoding mapping table corresponds to a Huffman tree, and the encoding mapping table includes the third data and the fourth data in the first image, as well as the third codeword and the fourth codeword in the compressed file, the third data corresponds to the third codeword, the fourth data corresponds to the fourth codeword, the number of times the third data appears in the first image is less than the number of times the fourth data appears in the first image, and the length of the third codeword is greater than the length of the fourth codeword. For example, because the number of times the first data appears is greater than the number of times the second data appears (i.e., 1), the length of the first codeword is less than the length of the second codeword.
[0010] In the above method, the coding mapping table corresponds to the Huffman tree. Based on the construction principle of the Huffman tree, the data that appear less frequently in the coding mapping table has a longer codeword length, and the data that appear more frequently has a shorter codeword length. This can achieve the effect of shortening the length of data that appear more frequently. Therefore, while ensuring a short decoding time, effective compression can be performed to save storage space.
[0011] In one possible implementation, the above-mentioned obtaining of the compressed file of the first image includes: when a first event is detected, loading the compressed file of the first application, and the first event is used to trigger the display of the first interface of the first application; the above-mentioned use of the first decompression algorithm to decode the compressed file and obtain the first image includes: calling the first decompression algorithm in the zlib library to decode the compressed file and obtain the first image; the above-mentioned display of the first image includes: rendering the first image through skia, and displaying the first image in the first interface.
[0012] In one possible implementation, the first compression algorithm and the first decompression algorithm are a DEFLATE algorithm, the DEFLATE algorithm includes an LZ77 algorithm and a Huffman algorithm, the LZ77 algorithm is used to search for the first data and the second data in the first image, and the Huffman algorithm is used to encode and decode the first data and the second data in the first image.
[0013] In the above method, the first compression algorithm and the first decompression algorithm (such as the DEFLATE algorithm) involved in the currently commonly used zlib library on skia can be optimized: the compression algorithm and decompression algorithm of the first data that appears multiple times and the second data that appears once are merged, so that the existing commonly used algorithms do not need to be changed, and the usability is higher.
[0014] In one possible implementation, the above-mentioned decoding of the compressed file using the first decompression algorithm and obtaining the first image is implemented by calling a first function, wherein the assembly instructions obtained by disassembling the first function include a first instruction and a second instruction, the first instruction is a memory read instruction (i.e., an ldr instruction), the first instruction and the second instruction use different registers, and the first instruction and the second instruction are executed in parallel in the first function.
[0015] In the above method, the first function that implements the decoding process can be disassembled, and the first instruction and the second instruction can be executed in parallel instead of serially. Therefore, the processor's operating cycle can be effectively saved, and the effective utilization of hardware resources is achieved. It can be understood that this application implements assembly optimization, effectively improves decoding efficiency, and thus makes the loading and display of the first image faster.
[0016] In one possible implementation, the above-mentioned use of the first decompression algorithm to decode the compressed file and obtain the first image includes: using the first decompression algorithm to decode the compressed file and obtain a second image; calling a second function to verify whether the decoded second image is identical to the original first image, and when the second image is identical to the first image, the electronic device obtains the correct second image (i.e., the first image), the second function includes a first macro definition (modified), and the first macro definition is used by the second function to execute single instruction stream multiple data stream SIMD; the above-mentioned display of the first image includes: when the second image is identical to the first image, displaying the second image.
[0017] In the above method, by modifying the macro definition of the second function, the SIMD assembly compilation option can be forced to execute, that is, an assembly instruction can process multiple data in the same way at the same time, thereby increasing the data parallel processing capability, thereby making the loading and display of the first image faster and improving the smoothness of the electronic device refreshing the image.
[0018] In a second aspect, the present application provides an electronic device comprising a transceiver (including an NFC module), a processor, and a memory; the memory is used to store a computer program, and the processor calls the computer program so that the electronic device executes the display method provided in the first aspect and any one of the embodiments of the first aspect.
[0019] In a third aspect, the present application provides a computer storage medium storing a computer program. When the computer program is executed by a processor, it is used to execute the display method provided in the first aspect and any one of the embodiments of the first aspect.
[0020] In a fourth aspect, the present application provides a computer program product, which, when executed on a device, enables the device to execute the display method provided in the first aspect and any one of the embodiments of the first aspect.
[0021] In a fifth aspect, the present application provides an electronic device, the electronic device including a method or apparatus for executing any aspect or embodiment of the present application. The electronic device is, for example, a chip.
[0022] It should be understood that the description of technical features, technical solutions, beneficial effects or similar language in this application does not imply that all features and advantages can be realized in any single implementation. On the contrary, it is understood that the description of a feature or beneficial effect means that a specific technical feature, technical solution or beneficial effect is included in at least one implementation. Therefore, the description of a technical feature, technical solution or beneficial effect in this application does not necessarily refer to the same implementation. Furthermore, the technical features, technical solutions and beneficial effects described in this application can also be combined in any appropriate manner. Those skilled in the art will understand that this application can be implemented without one or more specific technical features, technical solutions or beneficial effects of a specific implementation. In other implementations, additional technical features and beneficial effects can also be identified in specific implementations that do not embody all implementations. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] The following is an introduction to the drawings used in this application.
[0024] Figure 1 is a schematic diagram of a user interface provided by this application;
[0025] Figure 2 This is a flowchart of the process of loading an image using Skia provided by this application;
[0026] Figure 3 This is a schematic diagram of the processing process of the LZ77 algorithm provided by this application;
[0027] Figure 4 This is a schematic diagram of a Huffman tree and coding mapping table provided by this application;
[0028] Figure 5 This is a flowchart of the process of decoding a compressed file using the zlib library provided by this application;
[0029] Figure 6 This is a schematic diagram of an optimization idea provided by this application;
[0030] Figure 7 This is a schematic diagram of the processing process of another LZ77 algorithm provided by this application;
[0031] Figure 8 This is a schematic diagram of another Huffman tree and coding mapping table provided by this application;
[0032] Figure 9 This is a flowchart of another process of decoding a compressed file using the zlib library provided by this application;
[0033] Figure 10 This is a flowchart of a decoding method provided by this application;
[0034] Figure 11 This is a schematic diagram of the hardware structure of an electronic device provided by this application;
[0035] Figure 12 This is a schematic diagram of the software architecture of an electronic device provided in this application. DETAILED DESCRIPTION
[0036] The technical solutions in the embodiments of the present application will be described below in conjunction with the accompanying drawings. The terms used in the implementation methods of the embodiments of the present application are only used to explain the specific embodiments of the present application and are not intended to limit the present application.
[0037] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or, for example, A / B can mean A or B; “and / or” in the text is merely a description of the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, “multiple” refers to two or more than two.
[0038] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood to imply or suggest relative importance or implicitly indicate the number of the technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of this application, unless otherwise specified, "plurality" means two or more.
[0039] Skia is a two-dimensional (2D) graphics processing library. As a graphics engine, skia is widely used for loading images on electronic devices across various software systems, such as Android, Google Chrome OS (ChromeOS), the mobile application development framework Flutter, and OpenHarmony. Skia uses the open-source zlib library to compress (also known as encode) and decompress (also known as decode) images.
[0040] For example, when the electronic device 100 (taking a mobile phone as an example) runs the first application, it can load the image of the first application through skia and display the loaded image on the user interface of the first application, for example Figure 1 As shown, after the electronic device 100 starts the video application, it can display Figure 1The user interface 10 shown in (A) (i.e., the homepage of the video application) includes multiple controls for displaying pictures, such as control 11, control 12, control 13, control 14, and control 15. Since the electronic device 100 will load the pictures of the video application through skia, before the loading is successful, the controls for displaying pictures in the user interface 10 cannot display the corresponding pictures, such as controls 11 to 15 are displayed in gray. Assuming that the time it takes for skia to load the pictures in the user interface 10 is time 1, the electronic device 100 will display the successfully loaded picture only after the time 1 has passed since the user interface 10 was displayed. Figure 1 The user interface 20 shown in (B) is similar to the user interface 10, except that the controls for displaying pictures in the user interface 20 (such as controls 11 to 15) all include corresponding pictures.
[0041] Figure 2 This is a flowchart of the process of skia loading an image provided by an embodiment of the present application.
[0042] like Figure 2 As shown, when the electronic device 100 runs the first application, for example, when the electronic device 100 starts the first application, the electronic device 100 can load the compressed file of the image of the first application in the memory. Then, the electronic device 100 can call the zlib library to decode the compressed file and obtain the original image of the compressed file when the decoding is completed. Finally, the electronic device 100 can render the decoded original image through skia to display the original image in the interface of the first application. For example, Figure 2 The process shown corresponds to Figure 1 The process shown, Figure 2 The execution time of the process shown is Figure 1 The duration shown is 1.
[0043] The zlib library generally uses the DEFLATE algorithm, a lossless data compression and decompression algorithm that uses both the LZ77 and Huffman algorithms. The Huffman algorithm's encoding principle is to divide data into recurring characters (repeated data) and characters that appear only once (independent data). The repeated data is then encoded using variable-length encoding, using shorter symbols (such as bits) to represent more frequently occurring characters and longer symbols to represent less frequently occurring characters, thereby shortening the string and effectively saving space. The LZ77 algorithm can be understood as the Huffman root algorithm, which divides larger data into smaller blocks and identifies repeated data. This reduces the computational effort required to find repeated data and mitigates the situation where the Huffman algorithm requires longer symbols to represent more frequently occurring characters due to excessive spacing between repeated data (i.e., the distance between two adjacent repeated data). The DEFLATE algorithm used by the zlib library is a relatively slow algorithm. The zlib / DEFLATE algorithm can be optimized to increase the encoding and decoding speed of images (such as, but not limited to, portable network graphics (PNG)). Currently, there are optimized zlib forks: zlib-madler, zlib-ng, zlib-cloudflare, and Chromium's zlib.
[0044] In an embodiment of the present application, the original image of the compressed file may contain data that appears multiple times (i.e., repeated data) and data that appears only once (i.e., independent data). It can also be understood that the original image includes multiple data with the same content (i.e., repeated data) and data with a content that is different from the content of other data (i.e., independent data). Specific examples can be found in Table 1 below.
[0045] Table 1
[0046] character a b c d e f Frequency 45 13 9 5 1 1
[0047] Among them, the original picture shown in Table 1 includes character a that appears 45 times, character b that appears 13 times, character c that appears 9 times, character d that appears 5 times, character e that appears 1 time, and character f that appears 1 time. It can also be said that the original picture shown in Table 1 includes 45 characters a, 13 characters b, 9 characters c, 5 characters d, 1 character e, and 1 character f.
[0048] In conjunction with the above description of the DEFLATE algorithm, it can be understood that if repeated data appears multiple times in the original image, while independent data appears only once (generally not very long), the DEFLATE algorithm generally has a good compression effect on repeated data, but has almost no compression effect on independent data. For example, the compression effect is represented by the ratio of the compressed data size to the uncompressed data size; the smaller the ratio, the better the compression effect. Therefore, to achieve effective compression and save storage space, repeated data in the original image is currently encoded using the DEFLATE algorithm, while independent data is encoded using other algorithms (e.g., encoding and decoding algorithms that have a good compression effect on independent data). Not limited to this, considering the characteristics of the DEFLATE algorithm, the DEFLATE algorithm has a good compression effect on repeated data with long lengths and / or long spacing (hereinafter referred to as long repeated data), but has a very poor compression effect on repeated data with short lengths and short spacing (hereinafter referred to as short repeated data). Therefore, currently, long repeated data in the original image can also be encoded using the DEFLATE algorithm, while short repeated data and independent data are encoded using other algorithms.
[0049] For the convenience of description, the following embodiments are described by taking as an example that repeated data in the original image is encoded using the DEFLATE algorithm and independent data is encoded using other algorithms.
[0050] Next, the process of encoding repeated data in the original image using the DEFLATE algorithm is exemplified. Figure 3 The following example shows how to find duplicate data in the original image using the LZ77 algorithm. Figure 4 The following exemplifies the binary tree (which may be referred to as the Huffman tree) and the coding mapping table constructed when encoding repeated data in the original image using the Huffman algorithm.
[0051] Figure 3 A schematic diagram illustrating an exemplary processing process of the LZ77 algorithm.
[0052] like Figure 3 As shown in Figure 1, the LZ77 algorithm can use a sliding window to search for duplicate data in the original image. The sliding window can move in a certain direction, starting from the starting position of the original image and moving in a fixed direction until it reaches the end position of the original image. The length of the sliding window used when processing an original image can be fixed to limit the range of duplicate data search. The data in the original image that the sliding window passes through is the searched data (the data that has been searched during the encoding / decoding process is the encoded / decoded data), and the data that the sliding window does not pass through is the unsearched data (the data that has not been searched during the encoding / decoding process is the uncoded / decoded data). Figure 3Only string 1 (repeated data) that appears three times in the original image is shown. Figure 3 The first two occurrences of string 1 belong to searched data, and the last occurrence of string 1 belongs to unsearched data.
[0053] Figure 4 A schematic diagram illustrating a Huffman tree and a coding mapping table is shown as an example. Figure 4 The Huffman tree and coding mapping table shown are obtained by processing the repeated data in the original picture shown in Table 1.
[0054] Figure 4 The Huffman tree shown includes leaf nodes and intermediate nodes, wherein each leaf node represents a character to be encoded and the frequency of occurrence of the character. The corresponding leaf node can be referred to by the character in the following. For example, Figure 4 As shown, the leaf node a represents the character a and the frequency of occurrence of the character a. The parent node of each leaf node is an intermediate node, and the child nodes of each intermediate node are leaf nodes or other intermediate nodes. The number included in each intermediate node is the sum of the frequency of occurrence of the characters represented by the corresponding child nodes. The corresponding intermediate node can be referred to by the number included, for example Figure 4 As shown, the number included in the intermediate node 14 is 14, and the child nodes corresponding to the intermediate node 14 are leaf nodes c and leaf nodes d. The sum of the occurrence frequencies of characters c and d is 14. Based on the repeated data shown in Table 1 (i.e., character a, character b, character c, and character d), Figure 4 The Huffman tree shown includes 4 leaf nodes: leaf node a representing character a that appears 45 times, leaf node b representing character b that appears 13 times, leaf node c representing character c that appears 9 times, and leaf node d representing character d that appears 5 times. Figure 4 The Huffman tree shown includes three intermediate nodes: intermediate node 14, intermediate node 27 (child nodes are intermediate node 14 and leaf node b), and intermediate node 72 (child nodes are intermediate node 27 and leaf node a). Figure 4 The root node of the Huffman tree is shown as an intermediate node 72 .
[0055] Figure 4 In the Huffman tree shown, the edge of each intermediate node pointing to a child node (for example, the child node on the left) is marked as 0, and the edge pointing to another child node (for example, the child node on the right) is marked as 1. 0 and 1 can also be called labels. The codeword of each character obtained based on the Huffman tree is: the label sequence of the edges on the path from the root node to the leaf node representing the current character. Therefore, based on Figure 4 The code words of the characters obtained by the Huffman tree shown in FIG. 1 (ie, the code words of the repeated data shown in Table 1) can be found in FIG. Figure 4 The encoding mapping table shown in Figure 4In the Huffman tree and coding mapping table shown, the codeword of character a is the label of the edge on the path from the root node (i.e., intermediate node 72) to leaf node a: 1, the codeword of character b is the label of the edge on the path from the root node to leaf node b (passing through intermediate node 27): 01, the codeword of character c is the label of the edge on the path from the root node to leaf node c (passing through intermediate node 27 and intermediate node 14): 000, and the codeword of character d is the label of the edge on the path from the root node to leaf node d (passing through intermediate node 27 and intermediate node 14): 001.
[0056] From Table 1 and Figure 4 It can be seen that the repeated data are arranged from high to low in order of frequency of occurrence as a, b, c, d, and the repeated data are arranged from small to large in order of codeword length as a, b, c, d, that is, the codeword length of the character with higher frequency of occurrence is shorter, and the codeword length of the character with lower frequency of occurrence is longer.
[0057] The following is an example introduction Figure 2 The specific process of calling the zlib library to decode the compressed file of the picture.
[0058] Figure 5 This is a flowchart of the process of decoding a compressed file using the zlib library provided in an embodiment of the present application.
[0059] like Figure 5 As shown, when the compressed file to be decoded is loaded into the memory, the electronic device 100 can call the zlib library to decode the compressed file to obtain the original image of the compressed file. The repeated data in the original image corresponding to the compressed file is encoded by the DEFLATE algorithm (see above). Figure 3 and Figure 4 When the electronic device 100 decodes the compressed file, it can first decode the repeated data in the original image using the DEFLATE algorithm, and then decode the independent data in the original image using other algorithms.
[0060] like Figure 5 As shown, the electronic device 100 decodes the repeated data in the original image through the DEFLATE algorithm, which may include: when the electronic device 100 searches for the codeword of the repeated data through the LZ77 algorithm (for example, including reading the length and spacing of the codeword), it reads the encoding mapping table of the Huffman algorithm to obtain the repeated data in the original image. For example, the electronic device 100 can search for the codeword of each repeated data through the LZ77 algorithm. For each codeword found, the electronic device 100 can read the character corresponding to the codeword in the encoding mapping table (i.e., repeated data). An example of searching for the codeword of repeated data through the LZ77 algorithm can be seen above. Figure 3, the examples of Huffman tree and encoding mapping table constructed based on Huffman algorithm can be found in the above Figure 4 , for example, Figure 3 The string 1 shown is Figure 4 The code word of the character d shown is 001. When the electronic device 100 finds the character string 1 through the LZ77 algorithm, it can read the character d corresponding to the character string 1 (ie, 001) in the encoding mapping table.
[0061] like Figure 5 As shown, after the electronic device 100 obtains the repeated data in the original picture, it can decode the independent data in the original picture through other algorithms. Specifically, the electronic device 100 can decode the codewords corresponding to the independent data in the compressed file and obtain the independent data in the original picture.
[0062] from Figure 5 It can be seen that due to different encoding algorithms, the repeated data and independent data in the original picture will use different decoding algorithms for decoding, respectively. It can be understood that the repeated data and independent data will be decoded serially. Therefore, the encoding process of the original picture has two branches: the encoding branch of repeated data and the encoding branch of independent data. The encoding process of the original picture also has two branches: the decoding branch of repeated data and the decoding branch of independent data.
[0063] The following describes the analysis ideas of the above-mentioned skia loading image process in the embodiment of the present application.
[0064] Figure 6 This is a schematic diagram of an optimization idea provided in an embodiment of the present application.
[0065] like Figure 6 As shown, the embodiment of the present application found that the process of skia loading pictures is slow, for example Figure 1 and Figure 2 The duration 1 shown is long, and the smoothness of the electronic device 100 refreshing the picture is poor, resulting in a poor user experience, so it needs to be optimized. Further, the embodiment of the present application analyzes the process of skia loading pictures (for example Figure 2 The process shown in FIG5 is used to find the first hot function that is frequently called. The hot function refers to a function that is frequently called in the complete program call stack. The first hot function can be a loop execution function. Figure 2 The functions (used for decoding) that are called frequently in the process shown, for example, the first hotspot function is called each time to decode a type of data, and the first hotspot function is, for example, the hotspot function Cr_z_inflate.
[0066] like Figure 6As shown, the embodiment of the present application disassembles the first hotspot function found (disassembly can represent the operation of the central processing unit (CPU) during the specific execution of the function) and finds redundancy. An example of the disassembly of the first hotspot function is shown below:
[0067] ldr x9,[x27,#112] / / 3c
[0068] mov w10,#0xffffffff
[0069] lsl w11,w10,w8
[0070] bic w10,w24,w11
[0071] add x8,x9,w10,uxtw#2 / / 1c
[0072] ldrb w8,[x8,#1] / / 1c
[0073] The ldr instruction is a memory read instruction. The ldr instruction in the disassembly above is used to load data (e.g., 4-byte data) stored at address 1 (i.e., the address stored in the x27 register plus 112) in memory into the x9 register, using the x27 and x9 registers. The mov instruction is an assignment instruction. The mov instruction in the disassembly above is used to store the value 0xffffffff into the w10 register, using the w10 register. The lsl instruction is a data left shift instruction. The lsl instruction in the disassembly above uses the w8, w10, and w11 registers. The bic instruction represents a bitwise clear operation. The bic instruction in the disassembly above is used to invert the data in the w11 register, perform a bitwise AND operation on the inverted value with the data in the w24 register, and store the result in the w10 register, using the w11, w24, and w10 registers. The add instruction is an addition instruction. The add instruction in the disassembly above uses the x8, x9, and w10 registers. The "ldrb" instruction reads memory. The "ldrb" instruction in the disassembly above uses the x8 and w8 registers. It's understandable that the "add" instruction has a logical relationship with the "mov," "lsl," "bic," and "ldrb" instructions, meaning they must be executed in that order. However, the "ldr" instruction has no logical relationship with the other instructions.
[0074] In the disassembly of the above example, the ldr instruction and the add instruction use the same register: the x9 register. Therefore, the ldr instruction and the add instruction cannot be executed in parallel. The first hot function will execute the assembly instructions serially, resulting in more CPU operating cycles (abbreviated as CPU cycles) for execution. For example, the ldr instruction takes 3 CPU cycles to execute, and the add instruction takes 1 CPU cycle to execute. When the ldr instruction and the add instruction cannot be executed in parallel, 4 CPU cycles are required, but if they can be executed in parallel, only 3 CPU cycles are required. There is redundancy in the execution process, and more CPU cycles are occupied.
[0075] It is understandable that the registers allocated to instructions during execution are random. Therefore, the registers in the disassembly of the above example can also be other registers. For example, the same register used by the ldr instruction and the add instruction is the x8 register.
[0076] like Figure 6 As shown, after the embodiment of the present application finds that the first hotspot function has redundancy during execution through disassembly, the process of decoding the compressed file by the zlib library can be analyzed (for example Figure 5 ), optionally, the process of encoding the original image using the zlib library (DEFLATE algorithm) (e.g. Figure 3 and Figure 4 ), it is speculated that the redundancy is caused by the separate decoding of duplicate data and independent data (which can also be understood as serial decoding). It can be understood that separate decoding will also be encoded separately. Therefore, the redundancy also includes the separate encoding of duplicate data and independent data. Further analysis shows that although encoding and decoding independent data and duplicate data separately can achieve the effect of effective compression and saving storage space, after discovering that the process of skia loading pictures is slow and there is redundancy in disassembly, this application carefully analyzed and found that the computational complexity of encoding and decoding independent data and duplicate data separately is large, and the decoding process is executed by a single thread of the CPU (corresponding to the above-mentioned serial decoding), it is difficult to achieve effective utilization of hardware resources, resulting in a long decoding time, which affects picture loading.
[0077] like Figure 6As shown, based on the speculated redundancy reasons, the embodiment of the present application can modify the process of the zlib library decoding compressed files: use the same decoding algorithm (i.e., DEFLATE algorithm) to decode duplicate data and independent data together. The modification logic of the decoding method is also the idea of decoding optimization. It can be understood that modifying the decoding method will also correspond to modifying the encoding method. The modification logic of the encoding method is: use the same encoding algorithm (i.e., DEFLATE algorithm) to encode duplicate data and independent data together, so the encoding mapping table constructed based on the Huffman algorithm will be modified. The modified encoding mapping table includes codewords for duplicate data and independent data. The above modification logic can be understood as merging the encoding algorithm and decoding algorithm of duplicate data and independent data. The above modification logic can also be understood as deleting the encoding branch and decoding branch of independent data. The modified encoding method and decoding method can be found below. Figure 7 、 Figure 8 and Figure 9 The description is not detailed for now.
[0078] like Figure 6 As shown, after the embodiment of the present application determines the above-mentioned modification logic, it can be verified that the above-mentioned modification logic implements decoding optimization: run the modified decoding process, and disassemble the current first hotspot function. In some examples, the chip platform used for verification can be a kirin chip (such as kirin9000, kirin9000s), and the verification tool can include Xcode, instrument, terminal command window of the Mac platform, or simpleperf of the Android platform, or interactive disassembler (IDA) of the Windows platform. In some examples, for the shared object (so) file generated by skia compilation, a verification tool (such as IDA of the Windows platform) can be used to capture the disassembly instructions.
[0079] The embodiment of the present application runs the modified decoding process and finds that the time required for the decoding process is reduced, and the execution time of the skia loading picture process (including the decoding process) is also reduced, thus verifying that the above-mentioned modified logic can achieve decoding optimization. In some examples, the skia loading picture process after the modified decoding process is verified on a variety of mobile phones equipped with intelligent operating systems (assuming that they include Class A and Class B). The execution time of Class A mobile phones is reduced from 63 milliseconds (ms) to 57.9ms, and the execution time of Class B mobile phones is reduced from 59.3ms to 56.2ms. In some examples, the decoding method before modification and the decoding method after modification can be used to perform a large number of decoding processes (for example, 1,000 times) on the same picture, respectively. The shortest execution time, average execution time, median execution time, and longest execution time of the decoding process implemented using the decoding method before modification are 62ms, 63.5ms, 63.5ms, and 67ms, respectively; the shortest execution time, average execution time, median execution time, and longest execution time of the decoding process implemented using the modified decoding method are 57.1ms, 60.7ms, 60.6ms, and 64ms, respectively. It can be seen that after modifying the decoding method, the execution time of the decoding process counted in various ways has been reduced, for example, the median execution time is reduced from 63.5ms to 60.6ms.
[0080] The first hotspot function mentioned above is to modify the decoding process and then execute it in a loop Figure 2 The function that is called frequently in the process shown can be called the new first hotspot function, which is executed in a loop before modifying the decoding process. Figure 2 The first hotspot function that is called frequently in the process shown can be referred to as the old first hotspot function. An example of the disassembly of the new first hotspot function is shown below:
[0081] ldr x9,[x27,#112] / / 3c
[0082] mov w10,#0xffffffff
[0083] lsl w11,w10,w8
[0084] bic w10,w24,w11
[0085] lsl x8,w10,#2
[0086] ldrb w8,[x9,x8] / / 1c
[0087] Among them, the second lsl instruction in the disassembly of the new first hotspot function of the above example corresponds to the add instruction in the disassembly of the old first hotspot function of the above example. The second lsl instruction uses the x8 register and the w10 register, and does not use the x9 register. Other instructions are similar and will not be repeated. In the disassembly of the old first hotspot function of the above example, the ldr instruction and the add instruction use the same register (i.e., the x9 register). In the disassembly of the new first hotspot function of the above example, the ldr instruction and the second lsl instruction do not use the same register. Therefore, the ldr instruction and the second lsl instruction can be executed in parallel. For example, the ldr instruction takes 3 CPU cycles to execute, and the second lsl instruction takes 1 CPU cycle to execute. During the execution of the ldr instruction, the second lsl instruction can be executed in parallel, so a total of 3 CPU cycles are required, rather than 4 CPU cycles, saving one CPU cycle. Therefore, it can be obtained that there is no redundancy in the execution process of the new first hotspot function, and the decoding process is executed concurrently by CPU multi-threading, which reduces the operating cycle when the CPU executes the first hotspot function, and realizes the effective utilization of hardware resources. It can be understood that the embodiment of the present application realizes assembly optimization. Furthermore, the computational complexity of encoding and decoding independent data and repeated data together is also small, making implementation simpler. In other words, the embodiments of the present application can perform parallel operations in the decoding process, effectively improving decoding efficiency and saving image loading time.
[0088] It can be understood that the embodiments of the present application are optimized for the currently commonly used decompression algorithms (i.e., the decompression algorithm of the third-party library zlib called on skia, such as the DEFLATE algorithm). This can reduce the CPU running cycle without changing the existing algorithm, save the market for decoding pictures, and increase usability.
[0089] from Figure 6 It can be seen that the embodiment of the present application guesses the cause of redundancy through disassembly and analysis, and modifies the decoding method and encoding method accordingly. Finally, decoding optimization is achieved through specific operation tests and disassembly verification, thereby ensuring the reliability of the decoding method and encoding method provided by the embodiment of the present application.
[0090] Next, we will introduce the process of encoding the original image through the modified DEFLATE algorithm (based on Figure 6 (implemented by the modification logic of the encoding method).
[0091] Figure 7 It is a schematic diagram of another processing process of the LZ77 algorithm provided in an embodiment of the present application (which may be referred to as the processing process of the modified LZ77 algorithm).
[0092] Figure 7 and Figure 3The difference is that the sliding window used by the modified LZ77 algorithm not only finds duplicate data, but also finds independent data. Figure 7 Only string 1 (repeated data) that appears three times in the original image and string 2 (independent data) that appears once are shown. Figure 3 The first two occurrences of string 1 and string 2 belong to the searched data, and the last occurrence of string 1 belongs to the unsearched data.
[0093] Figure 8 This is a schematic diagram of another Huffman tree (which may be referred to as a modified Huffman tree) and a coding mapping table (which may be referred to as a modified coding mapping table) provided in an embodiment of the present application.
[0094] Figure 8 The Huffman tree shown and Figure 4 The Huffman tree shown is similar, except that Figure 4 The Huffman tree and coding mapping table shown are obtained by processing the repeated data in the original picture shown in Table 1. Figure 8 The Huffman tree and coding mapping table shown are obtained by processing the original picture shown in Table 1 (including repeated data and independent data).
[0095] Figure 8 The Huffman tree shown includes 6 leaf nodes, 4 of which are Figure 4 The Huffman tree shown includes 4 leaf nodes, that is, leaf nodes representing repeated data. The other 2 leaf nodes among these 6 leaf nodes are leaf node e representing the character e that has appeared once, and leaf node f representing the character f that has appeared once, that is, coconut chicken nodes representing independent data. Figure 8 The Huffman tree shown includes 5 intermediate nodes: intermediate node 2 (child nodes are leaf node e and leaf node f), intermediate node 7 (child nodes are intermediate node 2 and leaf node d), intermediate node 16 (child nodes are intermediate node 7 and leaf node c), intermediate node 29 (child nodes are intermediate node 16 and leaf node b), and intermediate node 74 (child nodes are intermediate node 29 and leaf node a). Figure 8 The root node of the Huffman tree is shown as an intermediate node 74 .
[0096] based on Figure 8 The code words of the characters obtained by the Huffman tree shown in Table 1 (i.e., the code words of the repeated data and independent data shown in Table 1) can be found in Figure 8 The encoding mapping table shown in Figure 8In the Huffman tree and coding mapping table shown, the codeword of character a is the label of the edge on the path from the root node (i.e., intermediate node 74) to leaf node a: 1, the codeword of character b is the label of the edge on the path from the root node to leaf node b (passing through intermediate node 29): 01, the codeword of character c is the label of the edge on the path from the root node to leaf node c (passing through intermediate node 29 and intermediate node 16): 001, the codeword of character d is the label of the edge on the path from the root node to leaf node d (passing through intermediate node 29, intermediate node 16, and intermediate node 7): 0001, the codeword of character e is the label of the edge on the path from the root node to leaf node e (passing through intermediate node 29, intermediate node 16, intermediate node 7, and intermediate node 2): 00000, and the codeword of character f is the label of the edge on the path from the root node to leaf node f (passing through intermediate node 29, intermediate node 16, intermediate node 7, and intermediate node 2): 00001.
[0097] Next, we will introduce the modified process of calling the zlib library to decode the compressed file of the picture (based on Figure 6 (implemented by modifying the logic of the decoding method).
[0098] Figure 9 This is a flowchart of another process of decoding a compressed file using the zlib library provided in an embodiment of the present application.
[0099] like Figure 9 As shown, when the compressed file to be decoded is loaded into the memory, the electronic device 100 can be based on Figure 6 The modified logic of the decoding method calls the zlib library to decode the compressed file to obtain the original image of the compressed file. Figure 6 The modification logic of the encoding method can be obtained. The repeated data and independent data in the original image corresponding to the compressed file are encoded by the DEFLATE algorithm. For details, please refer to the above Figure 7 and Figure 8 .
[0100] like Figure 9As shown, when the electronic device 100 decodes the compressed file, the repeated data and independent data in the original picture can be decoded by the DEFLATE algorithm. Specifically, when the electronic device 100 reads the codewords of the repeated data and independent data (for example, including the length and spacing of the read codewords) by the LZ77 algorithm, it reads the encoding mapping table of the Huffman algorithm to obtain the original picture (including repeated data and independent data). Exemplarily, the electronic device 100 can use the LZ77 algorithm to find the codewords of each repeated data and each independent data. For each codeword found, the electronic device 100 can read the character corresponding to the codeword in the encoding mapping table (i.e., the character in the original picture). For an example of using the LZ77 algorithm to find the codeword of repeated data, please refer to the above Figure 7 , the examples of Huffman tree and encoding mapping table constructed based on Huffman algorithm can be found in the above Figure 8 , for example, Figure 7 The string 1 shown is Figure 8 The code word of the character d shown is 0001. Figure 7 The string 2 shown is Figure 8 The code word of the character e shown is 00000. When the electronic device 100 finds the character string 1 through the LZ77 algorithm, it can read the character d corresponding to the character string 1 (i.e., 0001) in the encoding mapping table. When the electronic device 100 finds the character string 2 through the LZ77 algorithm, it can read the character e corresponding to the character string 2 (i.e., 00000) in the encoding mapping table.
[0101] Understandably, a large amount of code in skia is a compromise solution selected for compatibility with different operating system platforms. Many codes have not been deeply optimized and adapted for the corresponding chip platform and operating system. The embodiment of the present application found that skia supports many extended instruction sets by viewing the CPU information of the kirin9000s platform. It can be modified to implement single instruction stream multiple data stream (single instruction multiple data, SIMD) by replacing the instruction set, that is, to allow an assembly instruction to process multiple data in the same way at the same time, thereby improving the decoding operation of processing repeated large amounts of data and enhancing the performance tuning of software decoding. In one embodiment, after the electronic device 100 calls the zlib library to decode the compressed file of the picture, it can verify the decoded picture to determine whether the decoded picture is consistent with the original picture corresponding to the compressed file. When the electronic device 100 determines that it is consistent, it renders the decoded picture through skia. The above-mentioned verification of the decoded picture can be implemented by calling the second hotspot function, and the second hotspot function is, for example, the hotspot function adler32_simd. The embodiment of the present application can modify the macro definition of the second hotspot function to force the assembly compilation option of SIMD to increase the data parallel processing capability.
[0102] Figure 10 This is a flowchart of a decoding method provided in an embodiment of the present application. Figure 10 The illustrated method may be applied to the electronic device 100 . Figure 10 The method shown may include, but is not limited to, the following steps:
[0103] S101: The electronic device 100 obtains a compressed file of a first image (compressed by a first compression algorithm).
[0104] In one embodiment, the first image is a picture in a format such as png, joint photographic expert group (jpeg), graphics interchange format (gif), etc., but is not limited to this. The first image can also be a picture in other formats. The first image can also be an image in a video, and this embodiment of the present application does not limit this.
[0105] In one embodiment, the first image includes repeated data that appears multiple times in the first image (using the first data as an example for explanation, i.e., the first data appears multiple times in the first image), and independent data that appears once in the first image (using the second data as an example for explanation, i.e., the second data appears once in the first image). The compressed file of the first image may be obtained by compressing the first image using a first compression algorithm. The compressed file of the first image includes a codeword obtained by encoding the repeated data (using the first codeword as an example for explanation), and a codeword obtained by encoding the independent data (using the second codeword as an example for explanation). The first codeword is obtained by encoding the first data using the first compression algorithm, and the second codeword is obtained by encoding the second data using the first compression algorithm.
[0106] The first compression algorithm includes Huffman coding, and the first compression algorithm can be the above-mentioned DEFLATE algorithm (including the LZ77 algorithm and the Huffman algorithm). The LZ77 algorithm in the first compression algorithm is used to find repeated data and independent data in the first image during encoding. For specific examples, see the above Figure 7 The Huffman algorithm in the first compression algorithm is used to encode the repeated data and independent data in the first image. For specific examples, see the above Figure 8 .
[0107] S102: The electronic device 100 uses a first decompression algorithm to decode the compressed file and obtain a first image.
[0108] In one embodiment, the electronic device 100 can use a first decompression algorithm to decode the codewords of repeated data and the codewords of independent data in the above-mentioned compressed file and obtain a first image (including repeated data and independent data), wherein the electronic device 100 can use the first decompression algorithm to decode the first codeword in the compressed file and obtain first data, and the electronic device 100 can use the first decompression algorithm to decode the second codeword in the compressed file and obtain second data.
[0109] The first decompression algorithm corresponds to the first compression algorithm, and the first decompression algorithm includes Huffman decoding. The first decompression algorithm can be the above-mentioned DEFLATE algorithm (including the LZ77 algorithm and the Huffman algorithm). The LZ77 algorithm in the first decompression algorithm is used to find repeated data and independent data in the first image during decoding. For specific examples, see the above Figure 7 The Huffman algorithm in the first decompression algorithm is used to decode the repeated data and independent data in the first image. For specific examples, see the above Figure 8 and Figure 9 .
[0110] In one embodiment, when the electronic device 100 encodes the first image using the first compression algorithm, a coding mapping table can be constructed. The coding mapping table can be referred to as corresponding to the first image or the corresponding compressed file. The coding mapping table can include each data in the first image and each codeword in the compressed file, as well as the corresponding relationship between the two. The coding mapping table corresponds to a Huffman tree. The codeword length corresponding to the data with a lower frequency of occurrence in the coding mapping table is longer, and the codeword length corresponding to the data with a higher frequency of occurrence is shorter. For example, the coding mapping table includes the third data and the fourth data in the first image, and the third codeword and the fourth codeword in the above-mentioned compressed file. The third data corresponds to the third codeword (i.e., the third codeword is obtained by encoding the third data), and the fourth data corresponds to the fourth codeword (i.e., the fourth codeword is obtained by encoding the fourth data). The number of times the third data appears in the first image is less than the number of times the fourth data appears in the first image. Therefore, the length of the third codeword is greater than the length of the fourth codeword. For example, the first data in the encoding mapping table corresponds to the first codeword, the second data corresponds to the second codeword, the number of occurrences of the first data is greater than the number of occurrences of the second data (i.e., 1 time), and therefore, the length of the first codeword is less than the length of the second codeword. Figure 8 .
[0111] In one embodiment, S102 is implemented by calling a first function, which may be the first hotspot function mentioned above. The assembly instructions obtained by disassembling the first function include a first instruction and a second instruction. The first instruction is a memory read instruction (i.e., an ldr instruction), and the second instruction is an instruction that has no logical relationship with the first instruction. The first instruction and the second instruction use different registers. Therefore, the first instruction and the second instruction can be executed in parallel in the first function. For example, Figure 6 As shown, in the disassembly example of the new first hotspot function, the ldr instruction (i.e., the first instruction) and any other instruction (i.e., the second instruction, such as the mov instruction, 2 lsl instructions, the bic instruction, and the ldrb instruction) do not use the same register, so they can be executed in parallel, saving CPU cycles.
[0112] S103: The electronic device 100 displays a first image.
[0113] In one embodiment, Figure 10 The process shown can be applied to Figure 2 Specifically, in the process shown, S101 may include: upon detecting a first event, loading a compressed file of a first application, where the first event triggers display of a first interface of the first application. S102 may include: invoking a first decompression algorithm in the zlib library to decode the compressed file and obtain a first image. S103 may include: rendering the first image using skia and displaying the first image in the first interface.
[0114] In one embodiment, S102 may be specifically as follows: using a first decompression algorithm to decode the compressed file and obtain a second image, then calling a second function to verify whether the decoded second image is identical to the original first image. When the two are identical, the electronic device 100 obtains the correct second image (i.e., the first image). Accordingly, S103 may be specifically as follows: when the second image is identical to the first image, display the second image. The second function may be the second hotspot function described above, and the first macro definition included in the second function is modified. The first macro definition is used for the second function to force the SIMD assembly compilation option to execute, i.e., to enable an assembly instruction to process multiple data in the same manner at the same time, thereby increasing data parallel processing capabilities.
[0115] It is understandable that, considering the characteristics of the DEFLATE algorithm, in order to achieve the effect of effective compression and saving storage space, the current encoding and decoding methods can be: repeated data is encoded and decoded by the DEFLATE algorithm, and independent data is encoded and decoded by other algorithms, or long repeated data is encoded and decoded by the DEFLATE algorithm, and short repeated data and independent data are encoded and decoded by other algorithms. In the embodiment of the present application, whether it is repeated data or independent data, whether it is long repeated data or short repeated data, it will be encoded and decoded by the DEFLATE algorithm to achieve parallel decoding. Although it cannot achieve the effect of effective compression and saving storage space, it can effectively save decoding time. The embodiment of the present application can be understood as "trading space for time", thereby making the speed of loading and displaying the first image faster and improving the smoothness of refreshing the image of the electronic device.
[0116] The above embodiments are described by taking the electronic device 100 as an example in which both encoding and decoding of an image are performed. In other embodiments, decoding may be performed by the electronic device 100 and encoding may be performed by other devices. The electronic device 100 may obtain the encoded compressed file and perform decoding.
[0117] The electronic device 100 provided in an embodiment of the present application is exemplarily introduced below.
[0118] In the embodiment of the present application, the electronic device 100 can be a mobile phone, a tablet computer, a handheld computer, a desktop computer, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a cellular phone, a personal digital assistant (PDA), as well as smart home devices such as smart TVs, smart cameras, and smart speakers, wearable devices such as smart bracelets, smart watches, and smart glasses, extended reality (XR) devices such as augmented reality (AR), virtual reality (VR), and mixed reality (MR), in-vehicle devices, or smart city devices. The embodiment of the present application does not impose any special restrictions on the specific type of the electronic device 100.
[0119] It should be understood that the structures illustrated in the embodiments of the present application do not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0120] Figure 11 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application.
[0121] like Figure 11 As shown, the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0122] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU). The different processing units may be independent devices or integrated into one or more processors.
[0123] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.
[0124] Processor 110 may also include a memory for storing instructions and data. In one embodiment, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly retrieve it from the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0125] In one embodiment, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface.
[0126] The I2C interface is a bidirectional synchronous serial bus that includes a serial data line (SDA) and a serial clock line (SCL). In one embodiment, the processor 110 may include multiple I2C bus lines. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. via different I2C bus interfaces. For example, the processor 110 may be coupled to the touch sensor 180K via the I2C interface, enabling communication between the processor 110 and the touch sensor 180K via the I2C bus interface, thereby implementing the touch function of the electronic device 100.
[0127] The I2S interface can be used for audio communication. In one embodiment, the processor 110 can include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to enable communication between the processor 110 and the audio module 170. In one embodiment, the audio module 170 can transmit audio signals to the wireless communication module 160 via the I2S interface, enabling the function of answering calls via a Bluetooth headset.
[0128] The PCM interface can also be used for audio communication, sampling, quantizing, and encoding analog signals. In one embodiment, the audio module 170 and the wireless communication module 160 can be coupled via a PCM bus interface. In another embodiment, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface, enabling the function of answering calls via a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
[0129] The UART interface is a universal serial data bus used for asynchronous communication. This bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In one embodiment, the UART interface is typically used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 via the UART interface to implement Bluetooth functionality. In one embodiment, the audio module 170 can transmit audio signals to the wireless communication module 160 via the UART interface, enabling the playback of music via Bluetooth headphones.
[0130] The MIPI interface can be used to connect the processor 110 to peripheral devices such as the display 194 and the camera 193. MIPI interfaces include the camera serial interface (CSI) and the display serial interface (DSI). In one embodiment, the processor 110 and the camera 193 communicate via the CSI interface to implement the camera function of the electronic device 100. The processor 110 and the display 194 communicate via the DSI interface to implement the display function of the electronic device 100.
[0131] The GPIO interface can be configured via software. It can be configured as either a control signal or a data signal. In one embodiment, the GPIO interface can be used to connect the processor 110 to the camera 193, display 194, wireless communication module 160, audio module 170, sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0132] The USB interface 130 is an interface that complies with USB standards and may be a Mini USB interface, a Micro USB interface, a USB Type-C interface, or the like. The USB interface 130 can be used to connect a charger to charge the electronic device 100, or to transfer data between the electronic device 100 and peripheral devices. It can also be used to connect headphones to play audio. This interface can also be used to connect other electronic devices, such as augmented reality devices.
[0133] It is understood that the interface connection relationship between the modules illustrated in the embodiments of the present application is merely an illustrative illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods from the above embodiments, or a combination of multiple interface connection methods.
[0134] The charging management module 140 is configured to receive charging input from a charger. The charger can be either a wireless charger or a wired charger. In some wired charging implementations, the charging management module 140 can receive charging input from the wired charger via the USB interface 130. In some wireless charging implementations, the charging management module 140 can receive wireless charging input via the wireless charging coil of the electronic device 100. While charging the battery 142, the charging management module 140 can also provide power to the electronic device 100 via the power management module 141.
[0135] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140, and provides power to the processor 110, the internal memory 121, the display 194, the camera 193, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle count, and battery health status (leakage, impedance). In another embodiment, the power management module 141 can also be set in the processor 110. In another embodiment, the power management module 141 and the charging management module 140 can also be set in the same device.
[0136] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0137] Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In another embodiment, the antenna can be used in conjunction with a tuning switch.
[0138] The mobile communication module 150 can provide wireless communication solutions for the electronic device 100, including second generation (2G), third generation (3G), fourth generation (4G), fifth generation (5G), and sixth generation (6G). The mobile communication module 150 can include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), and the like. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, filter and amplify the received electromagnetic waves, and transmit them to the modem processor for demodulation. The mobile communication module 150 can also amplify the signals modulated by the modem processor and convert them into electromagnetic waves for radiation via the antenna 1. In one embodiment, at least some of the functional modules of the mobile communication module 150 can be located in the processor 110. In another embodiment, at least some of the functional modules of the mobile communication module 150 and at least some of the modules of the processor 110 can be located in the same device.
[0139] The modem processor may include a modulator and a demodulator. The modulator is used to modulate the low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After being processed by the baseband processor, the low-frequency baseband signal is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to the speaker 170A, the receiver 170B, etc.) or displays an image or video through the display screen 194. In one embodiment, the modem processor may be an independent device. In another embodiment, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.
[0140] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, frequency modulate it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0141] In one embodiment, the antenna 1 of the electronic device 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the electronic device 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).
[0142] Electronic device 100 implements display functionality through a GPU, display screen 194, and an application processor. A GPU is a microprocessor for image processing that connects display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.
[0143] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-oLed, or a quantum dot light-emitting diode (QLED). In one embodiment, electronic device 100 may include one or N display screens 194, where N is a positive integer greater than 1.
[0144] The electronic device 100 can implement a shooting function through an ISP, a camera 193, a video codec, a GPU, a display screen 194, and an application processor.
[0145] The ISP processes data fed back by camera 193. For example, when taking a photo, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, which is then passed to the ISP for processing and transformed into a visible image. The ISP can also perform algorithmic optimization on image noise, brightness, and other factors. It can also optimize parameters such as exposure and color temperature of the captured scene. In one embodiment, the ISP can be located within camera 193.
[0146] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then passes the electrical signal to the ISP for conversion into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In one embodiment, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.
[0147] The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0148] Video codecs are used to compress or decompress digital video. Electronic device 100 may support one or more video codecs. This allows electronic device 100 to play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, and MPEG4.
[0149] The NPU is a neural network (NN) computing processor. Drawing on the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it rapidly processes input information and can continuously self-learn. The NPU can enable intelligent cognitive applications in electronic device 100, such as image recognition, face recognition, speech recognition, and text comprehension.
[0150] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 via the external memory interface 120 to implement data storage functions. For example, files such as music and videos can be stored on the external memory card.
[0151] The internal memory 121 can be used to store computer executable program codes, which include instructions. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 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, a universal flash storage (UFS), etc. The processor 110 executes various functional applications and data processing of the electronic device 100 by running instructions stored in the internal memory 121 and / or instructions stored in a memory provided in the processor.
[0152] The electronic device 100 can implement audio functions such as music playback and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0153] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In one embodiment, the audio module 170 can be provided in the processor 110, or some functional modules of the audio module 170 can be provided in the processor 110.
[0154] The speaker 170A, also called a "speaker", is used to convert audio electrical signals into sound signals. The electronic device 100 can listen to music or listen to hands-free calls through the speaker 170A.
[0155] The receiver 170B, also called a "handset", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or a voice message, the user can place the receiver 170B close to the ear to hear the voice.
[0156] Microphone 170C, also known as "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can speak by putting their mouth close to the microphone 170C to input the sound signal into the microphone 170C. The electronic device 100 can be provided with at least one microphone 170C. In another embodiment, the electronic device 100 can be provided with two microphones 170C, which can not only collect sound signals but also realize noise reduction function. In another embodiment, the electronic device 100 can also be provided with three, four or more microphones 170C to realize sound signal collection, noise reduction, and can also identify the source of sound, realize directional recording function, etc.
[0157] The headphone jack 170D is used to connect a wired headphone and can be the USB interface 130 or a 3.5mm open mobile terminal platform (OMTP) standard interface or a cellular telecommunications industry association of the USA (CTIA) standard interface.
[0158] Pressure sensor 180A is used to sense pressure signals and convert them into electrical signals. In one embodiment, pressure sensor 180A can be located on display screen 194. There are many types of pressure sensors 180A, such as resistive, inductive, and capacitive. A capacitive pressure sensor can include at least two parallel plates made of conductive material. When force acts on pressure sensor 180A, the capacitance between the electrodes changes. Electronic device 100 determines the intensity of the pressure based on this change in capacitance. When a touch operation is applied to display screen 194, electronic device 100 detects the touch intensity based on pressure sensor 180A. Electronic device 100 can also calculate the touch location based on the detection signal from pressure sensor 180A. In one embodiment, touch operations applied to the same touch location but with different touch intensities can correspond to different operation instructions. For example, when a touch operation with an intensity less than a first pressure threshold is applied to a short message application icon, a command to view short messages is executed. When a touch operation with an intensity greater than or equal to the first pressure threshold is applied to a short message application icon, a command to create a new short message is executed.
[0159] The gyroscope sensor 180B can be used to determine the motion posture of the electronic device 100. In one embodiment, the angular velocity of the electronic device 100 around three axes (i.e., x, y, and z axes) can be determined by the gyroscope sensor 180B. The gyroscope sensor 180B can be used for anti-shake shooting. For example, when the shutter is pressed, the gyroscope sensor 180B detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyroscope sensor 180B can also be used for navigation and somatosensory game scenes.
[0160] The air pressure sensor 180C is used to measure air pressure. In one embodiment, the electronic device 100 calculates the altitude using the air pressure value measured by the air pressure sensor 180C to assist in positioning and navigation.
[0161] The magnetic sensor 180D includes a Hall sensor. The electronic device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip case. In one embodiment, if the electronic device 100 is a flip phone, the electronic device 100 can detect the opening and closing of the flip cover based on the magnetic sensor 180D. Based on the detected opening and closing status of the case or flip cover, features such as automatic unlocking of the flip cover can be configured.
[0162] Accelerometer 180E can detect the magnitude of acceleration of electronic device 100 in all directions (generally three axes). It can also detect the magnitude and direction of gravity when electronic device 100 is stationary. It can also be used to identify the electronic device's posture, enabling applications such as switching between landscape and portrait modes and pedometers.
[0163] The distance sensor 180F is used to measure distance. The electronic device 100 can measure distance using infrared or laser. In one embodiment, when shooting a scene, the electronic device 100 can use the distance sensor 180F to measure distance to achieve fast focusing.
[0164] The proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The electronic device 100 emits infrared light outward through the light emitting diode. The electronic device 100 uses a photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the electronic device 100. When insufficient reflected light is detected, the electronic device 100 can determine that there is no object near the electronic device 100. The electronic device 100 can use the proximity light sensor 180G to detect that the user is holding the electronic device 100 close to the ear to talk, so as to automatically turn off the screen to save power. The proximity light sensor 180G can also be used in leather case mode and pocket mode to automatically unlock and lock the screen.
[0165] Ambient light sensor 180L is used to sense ambient light brightness. Electronic device 100 can adaptively adjust the brightness of display screen 194 based on the perceived ambient light. Ambient light sensor 180L can also be used to automatically adjust white balance when taking photos. Ambient light sensor 180L can also work with proximity light sensor 180G to detect whether electronic device 100 is in a pocket to prevent accidental touches.
[0166] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.
[0167] The temperature sensor 180J is used to detect temperature. In one embodiment, the electronic device 100 uses the temperature detected by the temperature sensor 180J to execute a temperature processing strategy. For example, when the temperature reported by the temperature sensor 180J exceeds a threshold, the electronic device 100 reduces the performance of the processor located near the temperature sensor 180J to reduce power consumption and implement thermal protection. In another embodiment, when the temperature is lower than another threshold, the electronic device 100 heats the battery 142 to prevent the electronic device 100 from shutting down abnormally due to low temperature. In another embodiment, when the temperature is lower than another threshold, the electronic device 100 boosts the output voltage of the battery 142 to prevent abnormal shutdown due to low temperature.
[0168] The touch sensor 180K is also called a "touch-sensitive device." The touch sensor 180K can be disposed on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen." The touch sensor 180K is used to detect touch operations applied thereto or in the vicinity thereof. The touch sensor can transmit the detected touch operations to the application processor to determine the type of touch event. Visual output related to the touch operations can be provided via the display screen 194. In another embodiment, the touch sensor 180K can also be disposed on the surface of the electronic device 100, in a location different from that of the display screen 194.
[0169] The bone conduction sensor 180M can obtain vibration signals. In one embodiment, the bone conduction sensor 180M can obtain vibration signals of the vibrating bones of the vocal part of the human body. The bone conduction sensor 180M can also contact the human pulse to receive blood pressure pulse signals. In one embodiment, the bone conduction sensor 180M can also be set in headphones to form bone conduction headphones. The audio module 170 can parse out the voice signal based on the vibration signal of the vibrating bones of the vocal part obtained by the bone conduction sensor 180M to realize the voice function. The application processor can parse the heart rate information based on the blood pressure pulse signal obtained by the bone conduction sensor 180M to realize the heart rate detection function.
[0170] The buttons 190 include a power button, a volume button, and the like. The buttons 190 may be mechanical buttons or touch buttons. The electronic device 100 may receive key inputs and generate key signal inputs related to user settings and function control of the electronic device 100.
[0171] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.
[0172] The indicator 192 may be an indicator light, which may be used to indicate the charging status, power level changes, messages, missed calls, notifications, etc.
[0173] The SIM card interface 195 is used to connect a SIM card. The SIM card can be connected to and separated from the electronic device 100 by inserting it into or removing it from the SIM card interface 195. The electronic device 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The electronic device 100 interacts with the network through the SIM card to implement functions such as calls and data communications. In one embodiment, the electronic device 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.
[0174] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a microservice architecture, or a cloud architecture. For example, the software system with a layered architecture can be an Android system, or a ChromeOS, or a Flutter, or an OpenHarmony system, or other software systems. The embodiment of the present application takes the Android system with a layered architecture as an example to illustrate the software architecture of the electronic device 100.
[0175] Figure 12 Schematic diagram of the software architecture of an electronic device 100 provided in an embodiment of the present application.
[0176] A layered architecture divides software into several layers, each with distinct roles and responsibilities. Layers communicate with each other through software interfaces. In one embodiment, the Android system is divided into four layers: the application layer, the application framework layer, the Android runtime and system libraries, and the kernel layer.
[0177] The application layer can include a series of application packages.
[0178] like Figure 12 As shown, the application package may include applications such as camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, etc. The applications in this application can also be replaced by other software such as mini-programs and atomic services.
[0179] The application framework layer provides an application programming interface (API) and programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0180] like Figure 12 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.
[0181] The window manager is used to manage window programs. The window manager can obtain the display size, determine whether there is a status bar, lock the screen, take screenshots, etc.
[0182] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0183] The view system includes visual controls, such as those for displaying text and images. The view system is used to build applications. A display interface can consist of one or more views. For example, a display interface containing a text notification icon might include a view for displaying text and a view for displaying images.
[0184] The phone manager is used to provide communication functions of the electronic device 100, such as management of call status (including answering, hanging up, etc.).
[0185] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0186] The notification manager enables applications to display notification information in the status bar. This can be used to convey notification-type messages and can disappear automatically after a short period of time without user interaction. For example, the notification manager is used to notify the completion of downloads, message reminders, etc. The notification manager can also be used to display notifications in the form of icons or scrolling text in the top status bar of the system, such as notifications from applications running in the background, or notifications that appear on the screen in the form of dialog windows. For example, a text message can be displayed in the status bar, a notification sound can be emitted, the electronic device 100 can vibrate, an indicator light can flash, etc.
[0187] Android Runtime includes core libraries and a virtual machine. Android runtime is responsible for scheduling and management of the Android system.
[0188] The core library consists of two parts: one is the function that needs to be called by the Java language, and the other is the Android core library.
[0189] The application layer and application framework layer run in a virtual machine. The virtual machine executes Java files in the application layer and application framework layer as binary files. The virtual machine manages object lifecycles, stack management, thread management, security and exception management, and garbage collection.
[0190] The system library can include multiple functional modules, such as a surface manager, media libraries, a 3D graphics processing library (e.g., OpenGL ES), and a 2D graphics engine (e.g., SGL).
[0191] The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications.
[0192] The media library supports playback and recording of a variety of common audio and video formats, as well as static image files. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0193] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0194] A 2D graphics engine is a drawing engine for 2D drawings.
[0195] The kernel layer is the layer between hardware and software. The kernel layer includes at least display driver, camera driver, audio driver, and sensor driver.
[0196] The following describes the workflow of the software and hardware of the electronic device 100 in conjunction with capturing a photo scene.
[0197] When the touch sensor 180K receives a touch operation, the corresponding hardware interrupt is sent to the kernel layer. The kernel layer processes the touch operation into a raw input event (including touch coordinates, touch operation timestamp, and other information). The raw input event is stored in the kernel layer. The application framework layer obtains the raw input event from the kernel layer and identifies the control corresponding to the input event. For example, if the touch operation is a touch single-click operation and the control corresponding to the single-click operation is the control of the camera application icon, the camera application calls the interface of the application framework layer to start the camera application, and then starts the camera driver by calling the kernel layer to capture a still image or video through the camera 193.
[0198] The methods provided in the various embodiments of the present application may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, they may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, a network device, a user device, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, or a magnetic tape), an optical medium (e.g., a digital video disc (DWD), or a semiconductor medium (e.g., a solid state drive (SSD)). As mentioned above, the above embodiments are only used to illustrate the technical solutions of the present application, and are not intended to limit the same. Although the present application has been described in detail with reference to the above embodiments, a person skilled in the art should understand that the technical solutions described in the above embodiments may be modified, or some of the technical features thereof may be replaced by equivalents. However, such modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A decoding method, characterized in that: Applied to electronic equipment, the method includes: Obtaining a compressed file of a first image, wherein the first image includes first data and second data, the first data appearing multiple times in the first image, and the second data appearing once in the first image, the compressed file including a first codeword and a second codeword, the first codeword being obtained by encoding the first data using a first compression algorithm, and the second codeword being obtained by encoding the second data using the first compression algorithm, wherein the first compression algorithm includes Huffman coding; Decoding the compressed file using a first decompression algorithm to obtain the first image, wherein the first data in the first image is obtained by decoding the first codeword in the compressed file using the first decompression algorithm, and the second data in the first image is obtained by decoding the second codeword in the compressed file using the first decompression algorithm, the first decompression algorithm corresponds to the first compression algorithm, and the first decompression algorithm includes Huffman decoding; The first image is displayed.
2. The method according to claim 1, wherein The using a first decompression algorithm to decode the compressed file and obtain the first image includes: Read the encoding mapping table corresponding to the compressed file, and obtain data corresponding to each codeword in the compressed file from the encoding mapping table to obtain the first image, wherein the encoding mapping table is determined based on Huffman coding, and the encoding mapping table includes a correspondence between each data in the first image and each codeword in the compressed file, the first data in the encoding mapping table corresponds to the first codeword, and the second data in the encoding mapping table corresponds to the second codeword.
3. The method according to claim 2, wherein The encoding mapping table corresponds to a Huffman tree, and the encoding mapping table includes the third data and the fourth data in the first image, and the third codeword and the fourth codeword in the compressed file, the third data corresponds to the third codeword, the fourth data corresponds to the fourth codeword, the number of times the third data appears in the first image is less than the number of times the fourth data appears in the first image, and the length of the third codeword is greater than the length of the fourth codeword.
4. The method according to any one of claims 1 to 3, wherein The step of obtaining the compressed file of the first image includes: When a first event is detected, the compressed file of the first application is loaded, wherein the first event is used to trigger display of a first interface of the first application; The using a first decompression algorithm to decode the compressed file and obtain the first image includes: Calling the first decompression algorithm in the zlib library to decode the compressed file and obtain the first image; The displaying of the first image includes: The first image is rendered using skia, and the first image is displayed on the first interface.
5. The method according to any one of claims 1 to 4, characterized in that The using a first decompression algorithm to decode the compressed file and obtain the first image includes: A first function is called and the compressed file is decoded using the first decompression algorithm, wherein assembly instructions obtained by disassembling the first function include a first instruction and a second instruction, the first instruction is a memory read instruction, the first instruction and the second instruction use different registers, and the first instruction and the second instruction are executed in parallel in the first function.
6. The method according to any one of claims 1 to 5, wherein: The first compression algorithm and the first decompression algorithm are DEFLATE algorithms, and the DEFLATE algorithm includes an LZ77 algorithm and a Huffman algorithm. The LZ77 algorithm is used to search for the first data and the second data in the first image, and the Huffman algorithm is used to encode and decode the first data and the second data in the first image.
7. The method according to any one of claims 1 to 6, wherein: The using a first decompression algorithm to decode the compressed file and obtain the first image includes: Decoding the compressed file using the first decompression algorithm to obtain a second image; calling a second function to verify whether the second image is identical to the first image, whereby the electronic device obtains the first image if the second image is identical to the first image, wherein the second function includes a first macro definition, and the first macro definition is used for the second function to execute a single instruction multiple data (SIMD) stream; The displaying of the first image includes: When the second image is identical to the first image, the second image is displayed.
8. The method according to any one of claims 1 to 7, wherein: The first image is a picture in the portable network graphics png format.
9. An electronic device, characterized in that: The method comprises a transceiver, a processor and a memory, wherein the memory is used to store a computer program, and the processor calls the computer program to execute the method according to any one of claims 1 to 8.
10. A computer storage medium, characterized in that The computer storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.