Coding method and device, decoding method and device, electronic equipment and storage medium
By detecting specific conditions in electronic devices and reducing JPEG images to solve the problem of excessive storage space in JPEG image occupation of storage space, it has realized the saving and efficiency of storage space.
Patent Information
- Application Number
- CN202310923312.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-25
- Publication Date
- 2025-01-28
AI Technical Summary
JPEG images take up a large storage space, resulting in insufficient storage space for electronic devices. A method is needed to effectively reduce the storage space of JPEG images.
By detecting the opening status, idle state, preset period of time or camera event in electronic devices, heavy compression of the JPEG image is used to use the preset heavy compression unit to the random access memory application unit memory, and in the memory, and in the memory, and in the memory application unit, it is in the memory, and it is in the memory application unit, and it is in the memory application unit. Each preset weight compression unit is remedied in the memory.
Realize the non -destructive compression of JPEG images, save the storage space of electronic equipment, and improve the efficiency of the use of storage space.
Smart Images

Figure CN119383353A_ABST
Abstract
Description
[Technical field]
[0001] The embodiments of the present application relate to the field of image processing technology, and in particular to an encoding method, a decoding method, an apparatus, an electronic device, and a storage medium. [Background technology]
[0002] At present, images in the Joint Photographic Experts Group (JPEG) format (hereinafter referred to as JPEG images) are widely used. Since JPEG images occupy more storage space than images in new standard formats, such as High Efficiency Image File Format (HEIF), once a large number of JPEG images are stored, the storage space of electronic devices will be insufficient. Therefore, how to effectively reduce the storage space occupied by JPEG images is an urgent problem to be solved. [Summary of the invention]
[0003] The embodiments of the present application provide an encoding method, a decoding method, an apparatus, an electronic device, and a storage medium, which can re-compress JPEG images, thereby saving storage space of the electronic device.
[0004] In a first aspect, an embodiment of the present application provides an encoding method, the method comprising:
[0005] In response to reaching a preset recompression condition, determining a compressed image to be processed, wherein the preset recompression condition at least includes detecting that a recompression option in a target interface is switched from an off state to an on state, or, when the recompression option in the target interface has been turned on in advance, detecting that the target interface is in an idle state, or, when the recompression option in the target interface has been turned on in advance, detecting that the target interface is in a preset time period for executing the recompression function, or, when the recompression option in the target interface has been turned on in advance, detecting a photo taking event;
[0006] The compressed image is recompressed to obtain a recompressed image.
[0007] In an embodiment of the present application, if the electronic device detects that the re-compression option is switched from an off state to an on state in the target interface, or the re-compression function is pre-enabled in the target interface, and any of the following sub-conditions is met: when the electronic device is detected to be in an idle state, or when a preset time period for executing the re-compression function is reached, or when a user's photo taking event is detected, the determined compressed image can be re-compressed, thereby saving storage space of the electronic device.
[0008] Optionally, the compressed image includes a plurality of preset re-compression units, and re-compressing the compressed image to obtain the re-compressed image includes:
[0009] Applying for a unit memory from a random access memory based on the preset re-compression unit, the number of bytes of the unit memory is equal to the number of bytes of the preset re-compression unit, and the number of bytes of the preset re-compression unit is less than the number of bytes of the compressed image;
[0010] Each of the preset recompression units is recompressed in the unit memory to obtain the recompressed image.
[0011] In the embodiment of the present application, the preset recompression unit is used as the minimum processing unit in the process of recompressing the compressed image. Since the number of bytes occupied by the preset recompression unit is less than the number of bytes occupied by the entire compressed image, the unit memory of the same number of bytes requested from the random access memory with the number of bytes required by the preset recompression unit is less than the memory occupied by the above-mentioned entire compressed image. On this basis, the multiple preset recompression units in the compressed image are sequentially recompressed in the above-mentioned unit memory, that is, the multiple preset recompression units in the compressed image share the above-mentioned same unit memory. Compared with the prior art in which memory is allocated for the entire compressed image during the recompression process, in the present application, memory is only allocated for one preset recompression unit, thereby saving the memory occupied during the recompression process of the entire compressed image.
[0012] Optionally, applying for unit memory from a random access memory based on the preset re-compression unit includes:
[0013] Dividing the compressed image into a preset number of sub-images;
[0014] The preset number of rows of each sub-image in the preset number of sub-images is used as the preset re-compression unit, and the corresponding unit memory is applied to the random access memory, and the preset number of rows is less than the total number of rows of a single sub-image.
[0015] In an embodiment of the present application, the compressed image is divided into multiple sub-images, and the preset number of rows of each sub-image is used as a preset re-compression unit to apply for the corresponding unit memory. That is, the number of applied unit memories is equal to the number of sub-images, and the number of bytes of each unit memory is equal to the number of bytes occupied by the preset number of rows in a single sub-image. This ensures that the sum of multiple unit memories is smaller than the memory occupied by the entire compressed image, and also facilitates the subsequent parallel re-compression of different sub-images in different unit memories.
[0016] Optionally, dividing the compressed image into a preset number of sub-images includes:
[0017] Locally decoding a plurality of coding units in the compressed image to obtain a direct current (DC) coefficient corresponding to each coding unit in the plurality of coding units;
[0018] The locally decoded multiple coding units are divided into sub-images of the preset number of sub-images, each sub-image in the preset number of sub-images includes at least two coding units.
[0019] In an embodiment of the present application, the DC coefficient in the compressed image is differentially encoded, and the compressed image cannot be directly divided into sub-images. Therefore, by locally decoding the compressed image with the coding unit as the minimum processing unit, the DC coefficient in each coding unit can be obtained. On this basis, the compressed image can be divided into sub-images to facilitate subsequent parallel re-compression.
[0020] Optionally, locally decoding a plurality of coding units in the compressed image to obtain a direct current (DC) coefficient corresponding to each of the plurality of coding units includes:
[0021] Parsing the compressed image to obtain basic information of Joint Photographic Experts Group JPEG, wherein the basic information includes JPEG width and height information and a Huffman table;
[0022] Based on the JPEG width and height information and the Huffman table, starting from the first coding unit in the compressed image, the multiple coding units are locally decoded in sequence to obtain a DC coefficient corresponding to each coding unit.
[0023] In an embodiment of the present application, the compressed image is parsed to obtain the JPEG image width and height information and the Huffman table. On this basis, starting from the first coding unit in the compressed image, all coding units are locally decoded in sequence, so that the DC coefficient of each coding unit can be accurately obtained.
[0024] Optionally, the basic information further includes a Huffman switching word, where the Huffman switching word is used to indicate a starting position of each coding unit in the compressed image, and each of the preset re-compression units is re-compressed in the unit memory to obtain the re-compressed image, including:
[0025] Determining a starting position of each of the subgraphs based on the Huffman switch word;
[0026] Based on the starting position, writing a preset number of rows in each of the sub-graphs into the corresponding unit memory in parallel;
[0027] In each of the unit memories, parallel recompression is performed for a preset number of rows in the corresponding sub-image until a first code stream of each of the sub-images is obtained;
[0028] Splicing the first code streams corresponding to each of the sub-images to obtain a sub-image splicing code stream;
[0029] The second code stream is spliced with the sub-image splicing code stream to obtain the heavily compressed image, wherein the second code stream is formed by encoding the basic information of the JPEG.
[0030] In the embodiment of the present application, since the Huffman switching words can be used to locate each coding unit in the compressed image, after the multiple coding units in the compressed image are divided into sub-images, it can be considered that the Huffman switching words can be used to accurately locate each sub-image. On this basis, each preset number of rows in each sub-image is written into the unit memory corresponding to the sub-image, and then each preset number of rows is recompressed in parallel in the unit memory to obtain the first code stream corresponding to each sub-image, and then it is spliced together with the second code stream encoded by the basic information of JPEG to obtain a recompressed image. In other words, by accurately locating the starting position of each sub-image, and then recompressing each preset number of rows in each sub-image in parallel, the efficiency of recompression can be improved.
[0031] Optionally, in each of the unit memories, parallel recompression is performed for a preset number of rows in the corresponding sub-image until a first bitstream of each of the sub-image is obtained, including:
[0032] In each of the unit memories, parallel Huffman decoding is performed for a preset number of rows in the corresponding sub-image until an AC coefficient corresponding to each of the sub-images is obtained, wherein the DC coefficient and the AC coefficient of each of the sub-images together constitute a discrete cosine transform DCT coefficient;
[0033] In each of the unit memories, parallel entropy coding is performed on the DCT coefficients contained in the preset number of rows in the corresponding sub-image until a first code stream corresponding to each sub-image is obtained.
[0034] In the embodiment of the present application, in each unit memory, parallel Huffman decoding is performed for the preset number of rows in the corresponding sub-image until the AC coefficient of each sub-image is obtained. Since the DC coefficient of each sub-image has been obtained in the local decoding stage, the AC coefficient and the DC coefficient can form the DCT of each sub-image together. On this basis, parallel entropy coding is performed for the DCT coefficients contained in the preset number of rows in the corresponding sub-image until the first bit stream of each sub-image is obtained. In other words, by performing parallel AC decoding on multiple sub-images in the Huffman decoding stage, the processing efficiency of the Huffman decoding stage is improved, and the processing efficiency of the entire recompression stage is also improved.
[0035] Optionally, splicing the first code streams corresponding to each of the sub-images to obtain a sub-image splicing code stream includes:
[0036] Performing a write operation on the first code stream of the ith sub-image to obtain M bytes that have been written and N bytes that have not been written, wherein both M and N are positive integers not less than 1;
[0037] The first code stream of the N-bit ith sub-image is stored in the Huffman switch word;
[0038] When performing a write operation on the first code stream of the i+1th sub-image, writing the N bits of the first code stream of the i-th sub-image in the Huffman switch word into the M+1th byte;
[0039] In the M+1th byte, starting from the N+1th digit, a write operation is performed on the first code stream of the i+1th sub-image until the sub-image splicing code stream is obtained, where i is a positive integer not greater than the preset number of sub-images.
[0040] In an embodiment of the present application, when splicing the first code streams corresponding to each sub-image, a write operation can be first performed on the complete bytes in the first code stream of the i-th sub-image, and the remaining bits are temporarily stored in the Huffman switching word. Then, before the write operation is performed on the first code stream of the i+1-th sub-image, the above-mentioned remaining bits are first written to the new bytes, and then the write operation is performed on the first code stream of the i+1-th sub-image. This avoids the need for a large amount of shift processing after the write operation is performed on the first code stream of the i+1-th sub-image, thereby improving the splicing efficiency of the sub-images and reducing the possibility of errors in the sub-image splicing process.
[0041] In a second aspect, an embodiment of the present application provides a decoding method, the method comprising:
[0042] In response to reaching a preset decompression condition, determining a recompressed image to be processed, wherein the preset decompression condition at least includes detecting a viewing operation on the recompressed image, or detecting an editing operation on the recompressed image;
[0043] The heavily compressed image is decompressed to obtain a compressed image.
[0044] In an embodiment of the present application, when a heavily compressed image needs to be viewed or edited, the electronic device supports decompression of the heavily compressed image, thereby ensuring that the user can view or edit it normally, thereby improving the user experience.
[0045] Optionally, the recompressed image includes a plurality of preset decompression units, and decompressing the recompressed image to obtain a compressed image includes:
[0046] Applying for a unit memory from a random access memory based on the preset decompression unit, the number of bytes of the unit memory is equal to the number of bytes of the preset decompression unit, and the number of bytes of the preset decompression unit is less than the number of bytes of the recompressed image;
[0047] Decompress each of the preset decompression units in the unit memory to obtain a compressed image.
[0048] In the embodiment of the present application, the preset decompression unit is used as the minimum processing unit in the process of decompressing the heavily compressed image. Since the number of bytes occupied by the preset decompression unit is less than the number of bytes occupied by the entire heavily compressed image, the unit memory of the same number of bytes requested from the random access memory with the number of bytes required by the preset decompression unit is less than the memory occupied by the above-mentioned entire heavily compressed image. On this basis, multiple preset decompression units in the heavily compressed image are sequentially decompressed in the above-mentioned unit memory, that is, multiple preset decompression units in the heavily compressed image share the above-mentioned same unit memory. Compared with the prior art in which memory is allocated to the entire heavily compressed image during the decompression process, in the present application, memory is only allocated to one preset decompression unit, thereby saving the memory occupied during the decompression process of the entire heavily compressed image.
[0049] Optionally, applying for a corresponding unit memory from a random access memory based on the preset decompression unit includes:
[0050] Dividing the recompressed image into a preset number of recompressed data segments;
[0051] The preset number of rows of each heavily compressed data segment in the preset number of data segments is used as the preset decompression unit, and the corresponding unit memory is applied to the random access memory, and the preset number of rows is less than the total number of rows of a single heavily compressed data segment.
[0052] In an embodiment of the present application, a heavily compressed image is divided into multiple data segments, and then the preset number of rows of each heavily compressed data segment is used as a preset decompression unit to apply for corresponding unit memories. That is, the number of applied unit memories is equal to the number of heavily compressed data segments, and the number of bytes of each unit memory is equal to the number of bytes occupied by the preset number of rows in a single heavily compressed data segment. This ensures that the sum of multiple unit memories is smaller than the memory occupied by the entire heavily compressed image, and also facilitates subsequent parallel decompression of different heavily compressed data segments in different unit memories.
[0053] Optionally, dividing the recompressed image into a preset number of recompressed data segments includes:
[0054] Parsing the recompressed image to obtain a target segmentation flag and a preset number of sub-images, wherein the target segmentation flag is used to indicate a starting position of recompressed data in the recompressed image;
[0055] The preset number of sub-images is used as the preset number of data segments, and the re-compressed data located after the target segmentation flag is divided into the re-compressed data segments of the preset number of data segments.
[0056] In an embodiment of the present application, by parsing the recompressed image, the target segmentation flag used to characterize the starting position of the recompressed data and the preset number of sub-images in the recompression stage can be obtained. The preset number of sub-images is used to characterize the number of sub-images divided in the process of forming the recompressed image, and is also used to characterize the amount of parallel threads (or the amount of parallel tasks) in the recompression stage. Then, here, the preset number of sub-images can be used as a benchmark to divide the recompressed data located after the target segmentation flag into multiple data segments equal to the preset number of sub-images, so that when recompression and decompression are performed in the same electronic device, recompression and decompression can be completed without adding new threads (or the number of tasks).
[0057] Optionally, decompressing each of the preset decompression units in the unit memory to obtain a compressed image includes:
[0058] Writing a preset number of rows in each of the recompressed data segments into the corresponding unit memory in parallel;
[0059] In each of the unit memories, parallel decompression is performed for a preset number of rows in the corresponding heavily compressed data segment until a first code stream of each of the heavily compressed data segments is obtained;
[0060] splicing the first code stream of each of the recompressed data segments to obtain a data segment splicing code stream;
[0061] The compressed image is obtained by splicing a second code stream with the data segment splicing code stream, wherein the second code stream is formed by decompressing the data segments representing image attributes in the heavily compressed image.
[0062] In the embodiment of the present application, each preset number of lines in each recompressed data segment is written into the unit memory corresponding to the recompressed data segment, and then each preset number of lines is compressed in parallel in the unit memory to obtain the first code stream corresponding to each recompressed data segment. Then, it is spliced with the second code stream formed after the data segment representing the image data is decompressed, so as to obtain a compressed image. In other words, each preset number of lines in each recompressed data segment is decompressed in parallel, so as to improve the efficiency of decompression.
[0063] Optionally, splicing the first code stream of each of the recompressed data segments to obtain a data segment splicing code stream includes:
[0064] Perform a write operation on the i-th recompressed data segment to obtain a first code stream of P bytes that have been written and Q bytes that have not been written, where both P and Q are positive integers not less than 1;
[0065] storing the first code stream of the Q-th recompressed data segment in the Huffman switch word;
[0066] When performing a write operation on the first code stream of the i+1th re-compressed data segment, writing the first code stream of the i-th re-compressed data segment in the Q bit of the Huffman switch word into the P+1th byte;
[0067] In the P+1th byte, starting from the Q+1th bit number, a write operation is performed on the first code stream of the i+1th recompressed data segment until the data segment splicing code stream is obtained, where i is a positive integer less than the preset number of data segments.
[0068] In an embodiment of the present application, when splicing each re-compressed data segment, a write operation can be first performed on the complete bytes in the first code stream of the i-th re-compressed data segment, and the remaining bits are temporarily stored in the Huffman switch word. Then, before the write operation is performed on the first code stream of the i+1-th re-compressed data segment, the above-mentioned remaining bits are first written to the new bytes, and then the write operation is performed on the first code stream of the i+1-th re-compressed data segment. This avoids the need for a large amount of shift processing due to byte misalignment after the write operation is performed on the first code stream of the i+1-th re-compressed data segment, thereby improving the splicing efficiency between the re-compressed data segments and reducing the possibility of errors in the splicing process of the re-compressed data segments.
[0069] In a third aspect, an embodiment of the present application provides a coding device, the coding device comprising:
[0070] A first determining unit is used to determine a compressed image to be processed in response to reaching a preset recompression condition, wherein the preset recompression condition at least includes detecting that a recompression option in a target interface is switched from an off state to an on state, or, when the recompression option in the target interface has been turned on in advance, detecting that the target interface is in an idle state, or, when the recompression option in the target interface has been turned on in advance, detecting that the target interface is in a preset time period for executing the recompression function, or, when the recompression option in the target interface has been turned on in advance, detecting a photo taking event;
[0071] The recompression unit is used to recompress the compressed image to obtain a recompressed image.
[0072] Optionally, the compressed image includes a plurality of preset re-compression units, and the re-compression units include:
[0073] A first application unit is used to apply for a unit memory from a random access memory based on the preset re-compression unit, the number of bytes of the unit memory is equal to the number of bytes of the preset re-compression unit, and the number of bytes of the preset re-compression unit is less than the number of bytes of the compressed image;
[0074] The image recompression unit is used to recompress each of the preset recompression units in the unit memory to obtain the recompressed image.
[0075] Optionally, the first application unit includes:
[0076] A sub-image division unit, used for dividing the compressed image into sub-images of a preset number;
[0077] A row memory application unit is used to apply for the corresponding unit memory from the random access memory using the preset number of rows of each sub-image in the preset number of sub-images as the preset re-compression unit, and the preset number of rows is less than the total number of rows of a single sub-image.
[0078] Optionally, the subgraph division unit includes:
[0079] A local decoding unit, used for locally decoding a plurality of coding units in the compressed image to obtain a direct current (DC) coefficient corresponding to each coding unit in the plurality of coding units;
[0080] A dividing unit is used to divide the multiple coding units that have been locally decoded into sub-images of the preset number of sub-images, each sub-image in the preset number of sub-images includes at least two coding units.
[0081] Optionally, the local decoding unit is specifically used for:
[0082] Parsing the compressed image to obtain basic information of Joint Photographic Experts Group JPEG, wherein the basic information includes JPEG width and height information and a Huffman table;
[0083] Based on the JPEG width and height information and the Huffman table, starting from the first coding unit in the compressed image, the multiple coding units are locally decoded in sequence to obtain a DC coefficient corresponding to each coding unit.
[0084] Optionally, the basic information further includes a Huffman switching word, where the Huffman switching word is used to indicate a starting position of each coding unit in the compressed image, and the image recompression unit includes:
[0085] A subgraph position determination unit, configured to determine a starting position of each of the subgraphs based on the Huffman switch word;
[0086] A parallel writing unit, used for writing a preset number of rows in each of the sub-images into the corresponding unit memory in parallel based on the starting position;
[0087] A parallel recompression unit, used for performing parallel recompression on a preset number of rows in the corresponding sub-image in each of the unit memories, until a first code stream of each of the sub-images is obtained;
[0088] A splicing unit, used for splicing the first code stream corresponding to each of the sub-images to obtain a sub-image splicing code stream;
[0089] The splicing unit is further used to splice the second code stream with the sub-image splicing code stream to obtain the re-compressed image, and the second code stream is formed by encoding the basic information of the JPEG.
[0090] Optionally, the parallel recompression unit is specifically used for:
[0091] In each of the unit memories, parallel Huffman decoding is performed for a preset number of rows in the corresponding sub-image until an AC coefficient corresponding to each of the sub-images is obtained, wherein the DC coefficient and the AC coefficient of each sub-image together constitute a discrete cosine transform DCT coefficient;
[0092] In each of the unit memories, parallel entropy coding is performed on the DCT coefficients contained in the preset number of rows in the corresponding sub-image until a first code stream corresponding to each of the sub-images is obtained.
[0093] Optionally, the splicing unit is specifically used for:
[0094] Performing a write operation on the first code stream of the ith sub-image to obtain M bytes that have been written and N bytes that have not been written, wherein both M and N are positive integers not less than 1;
[0095] The first code stream of the N-bit ith sub-image is stored in the Huffman switch word;
[0096] When performing a write operation on the first code stream of the i+1th sub-image, writing the N bits of the first code stream of the i-th sub-image in the Huffman switch word into the M+1th byte;
[0097] In the M+1th byte, starting from the N+1th digit, a write operation is performed on the first code stream of the i+1th sub-image until the sub-image splicing code stream is obtained, where i is a positive integer less than the preset number of sub-images.
[0098] In a fourth aspect, an embodiment of the present application provides a decoding device, the decoding device comprising:
[0099] A second determining unit, configured to determine the recompressed image to be processed in response to reaching a preset decompression condition, wherein the preset decompression condition at least includes detecting a viewing operation on the recompressed image, or detecting an editing operation on the recompressed image;
[0100] The decompression unit is used to decompress the heavily compressed image to obtain a compressed image.
[0101] Optionally, the recompressed image includes a plurality of preset decompression units, and the decompression units include:
[0102] A second application unit is used to apply for a unit memory from a random access memory based on the preset decompression unit, the number of bytes of the unit memory is equal to the number of bytes of the preset recompression unit, and the number of bytes of the preset decompression unit is less than the number of bytes of the recompressed image;
[0103] The image decompression unit is used to decompress each of the preset decompression units in the unit memory to obtain a compressed image.
[0104] Optionally, the second application unit includes:
[0105] A division unit, used for dividing the recompressed image into recompressed data segments of a preset number of data segments;
[0106] A row memory application unit is used to apply for the corresponding unit memory using the preset number of rows of each heavily compressed data segment in the preset number of data segments as the preset decompression unit, and the preset number of rows is less than the total number of rows of a single heavily compressed data segment.
[0107] Optionally, the division unit includes:
[0108] A parsing unit, used for parsing the recompressed image to obtain a target segmentation flag and a preset number of sub-images, wherein the target segmentation flag is used to indicate a starting position of the recompressed data in the recompressed image;
[0109] The data segment division unit is used to use the preset number of sub-images as the preset number of data segments, and divide the re-compressed data located after the target segmentation flag into the preset number of re-compressed data segments.
[0110] Optionally, the image decompression unit includes:
[0111] A parallel writing unit, used for writing a preset number of rows in each of the re-compressed data segments into the corresponding unit memory in parallel;
[0112] A parallel decompression unit, used for performing parallel decompression on a preset number of rows in the corresponding heavily compressed data segment in each of the unit memories, until a first code stream of each of the heavily compressed data segments is obtained;
[0113] A splicing unit, used for splicing the first code stream of each of the recompressed data segments to obtain a data segment splicing code stream;
[0114] The splicing unit is further used to splice a second code stream with the data segment splicing code stream to obtain the compressed image, wherein the second code stream is formed by decompressing the data segments representing image attributes in the heavily compressed image.
[0115] Optionally, the splicing unit is specifically used for:
[0116] Perform a write operation on the i-th re-compressed data segment to obtain a first code stream of P bytes that have been written and Q bytes that have not been written, where both P and Q are positive integers not less than 1;
[0117] storing the first code stream of the Q-th recompressed data segment in the Huffman switch word;
[0118] When performing a write operation on the first code stream of the i+1th re-compressed data segment, writing the first code stream of the i-th re-compressed data segment in the Q bit of the Huffman switch word into the P+1th byte;
[0119] In the P+1th byte, starting from the Q+1th bit number, a write operation is performed on the first code stream of the i+1th recompressed data segment until the data segment splicing code stream is obtained, where i is a positive integer less than the preset number of data segments.
[0120] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising a memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, the electronic device is triggered to execute the steps of the method described in any embodiment of the first aspect or the second aspect.
[0121] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store computer instructions, and when the computer is running, the computer enables the computer to execute the steps of the method described in any embodiment of the first aspect or the second aspect.
[0122] In a seventh aspect, an embodiment of the present application provides a computer program product, which includes computer instructions. When the computer instructions are executed in a computer, the computer executes the steps of the method described in any embodiment of the first aspect or the second aspect.
[0123] It should be understood that the third to seventh aspects of the embodiments of the present invention are consistent with the technical solutions of the first or second aspect of the embodiments of the present invention, and the beneficial effects achieved by each aspect and the corresponding feasible implementation methods are similar and will not be repeated herein.
Brief Description of the Drawings
[0124] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0125] Figure 1 A schematic diagram of a flow chart of an encoding method provided in an embodiment of the present application;
[0126] Figure 2 (a)- Figure 2 (d) is a schematic diagram of triggering lossless re-compression on the terminal side provided in an embodiment of the present application;
[0127] Figure 3 A schematic diagram of a process of a re-compression method proposed in an embodiment of the present application;
[0128] Figure 4 A flowchart of a method for re-compressing application unit memory provided in an embodiment of the present application;
[0129] Figure 5 (a)- Figure 5 (c) is a schematic diagram of a subgraph division method provided in an embodiment of the present application;
[0130] Figure 6 (a)- Figure 6 (b) is a schematic diagram of a preset re-compression unit provided in an embodiment of the present application;
[0131] Figure 7 A schematic diagram of a flow chart of a subgraph partitioning method provided in an embodiment of the present application;
[0132] Figure 8 A flowchart of a local decoding method provided in an embodiment of the present application;
[0133] Fig. 9 A schematic diagram of locally decoding a coding unit provided in an embodiment of the present application;
[0134] Fig.10 A schematic diagram of a process flow of a parallel re-compression method provided in an embodiment of the present application;
[0135] Fig.11 A schematic diagram of parallel recompression of multiple sub-graphs in an embodiment of the present application;
[0136] Fig.12 A schematic diagram of a process of parallel Huffman decoding and parallel entropy coding provided in an embodiment of the present application;
[0137] Fig.13 A schematic diagram of a flow chart of a method for splicing bitstreams in a re-compression phase provided in an embodiment of the present application;
[0138] Fig.14 A schematic diagram of splicing first bitstreams corresponding to adjacent sub-images provided in an embodiment of the present application;
[0139] Fig.15 A flowchart of a decoding method provided in an embodiment of the present application;
[0140] Fig.16 A flowchart of a decompression method provided in an embodiment of the present application;
[0141] Fig.17 A flowchart of a method for decompressing application unit memory provided in an embodiment of the present application;
[0142] Fig.18 (a)- Fig.18 (b) is a schematic diagram of a preset decompression unit provided in an embodiment of the present application;
[0143] Fig.19 A flowchart of a data segment division method provided in an embodiment of the present application;
[0144] Fig. 20 A schematic diagram of a parallel decompression process provided in an embodiment of the present application;
[0145] Fig.21 A schematic diagram of parallel decompression of multiple heavily compressed data segments in an embodiment of the present application;
[0146] Fig. 22 A schematic flow chart of a first code stream splicing method corresponding to a heavily compressed data segment provided in an embodiment of the present application;
[0147] Fig.23 A schematic diagram of splicing first code streams of adjacent heavily compressed data segments provided in an embodiment of the present application;
[0148] Fig.24 A schematic diagram of a terminal side providing a re-compression process and a display process in an embodiment of the present application;
[0149] Fig.25This is a schematic diagram of recompression and decompression on the cloud side in an embodiment of the present application;
[0150] Fig.26 (a)- Fig.26 (b) is a schematic diagram of a terminal side and a cloud side in a collaborative scenario provided by an embodiment of the present application, in which one side performs heavy compression and the other side performs decompression;
[0151] Fig. 27 A schematic diagram of a terminal-side and terminal-side collaborative scenario in which one side performs heavy compression and the other side performs decompression provided in an embodiment of the present application;
[0152] Fig.28 A schematic diagram of the structure of an encoding device provided in an embodiment of the present application;
[0153] Fig.29 A schematic diagram of the structure of a decoding device provided in an embodiment of the present application;
[0154] Fig.30 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. [Specific implementation method]
[0155] In order to better understand the technical solution of this specification, the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0156] It should be clear that the described embodiments are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this specification.
[0157] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit this specification. The singular forms of "a", "said" and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0158] The professional terms appearing in the embodiments of the present application are introduced below.
[0159] Huffman coding: It is a variable-length coding method. Its core idea is to use the probability of character occurrence as its coding length. Specifically, shorter codes are used for symbols with high probability of occurrence, and longer codes are used for symbols with low probability of occurrence, thereby achieving data compression.
[0160] Huffman table: It is a data structure used to store the encoding information of each character in the Huffman coding algorithm. The Huffman table is a dictionary-like structure used to record the code corresponding to each character and the length of each code. A basic Huffman table includes the following information: character, frequency, code, and code length. Among them, the character refers to a character in the original data, and the frequency refers to the number of times the character appears in the original data. The code refers to the unique code generated by the Huffman coding algorithm, and the code length refers to the length of the code corresponding to the character.
[0161] For example, you need to encode a text containing 500 characters. The text contains 4 characters, a, b, c, and d. The frequency of occurrence of each character is different, as shown in Table 1:
[0162] Table 1
[0163] a b c d Frequency (hundred times) 40 30 20 10 Fixed length code 000 001 010 011 Variable length code 0 100 101 1100
[0164] If the text is encoded by fixed length, assuming that each character is represented by 3 bits, the encoding result requires a total of 1500 bits of storage space, while if variable length encoding is used, the encoding result requires (40*1+30*3+20*3+10*4)*5=1150 bits, saving about 23.3% of the required storage space. At the same time, the Huffman decoder uses the same Huffman table to decode the encoded bit stream. In the Huffman encoding process, the Huffman table is stored in the header information of the compressed image, so that the Huffman table can be obtained by parsing the JPEG header information for decoding.
[0165] DCT coefficient: refers to a set of coefficients obtained after performing discrete cosine transform (DCT) on a JPEG image. DCT coefficients include direct current coefficients (DC) and alternating current coefficients (AC). The AC coefficient represents the characteristics of the low-frequency components of the image, that is, the average value of the image brightness information. If the DC coefficient is relatively large, the brightness of the JPEG image will be higher; conversely, if the DC coefficient is small, the brightness of the JPEG image will be lower. The AC coefficient represents the changes in the high-frequency components of the image, mainly including texture information and detail information.
[0166] Coding unit: the unit for DCT transformation of JPEG images and the unit for Huffman decoding of JPEG compressed images. For example, a JPEG image is composed of multiple pixels. When performing DCT transformation, DCT transformation is usually performed in blocks consisting of 8*8 or 16*16 pixels. These 8*8 or 16*16 pixels are called coding units. At the same time, for JPEG compressed images, since they are obtained after DCT transformation and Huffman encoding of JPEG images, when Huffman decoding is performed, Huffman decoding is also performed in blocks consisting of 8*8 or 16*16 pixels of DCT transformation. Taking an 8*8 coding unit as an example, after DCT transformation or Huffman decoding, it includes 1 DC coefficient and 63 AC coefficients.
[0167] Lossless re-compression: refers to the use of a lossless compression algorithm to compress JPEG compressed images again, thereby further reducing the file size of the JPEG compressed image while ensuring the image quality.
[0168] Arithmetic Coding (AC): refers to an entropy coding algorithm used for lossless data compression in computer data processing, which can directly encode the input data into a decimal greater than or equal to 0 and less than 1. Specifically, first select an original interval, usually [0, 1). When performing arithmetic coding, the original interval is divided into several segments according to the probability of occurrence of each element of the data to be encoded, and each element corresponds to a certain interval. After each element is encoded, the original interval is reduced to a new interval according to the type of the element. The interval is adjusted in turn according to the type of the element of the data to be encoded until all elements of the data to be encoded are encoded. At this time, any number in the current interval can be output as the encoding result.
[0169] Asymmetric Numeral Systems (ANS): is an entropy coding algorithm for lossless data compression that maps an input symbol sequence to an integer. Specifically, the probability of each element in the data to be encoded is first counted, and then a probability codeword is assigned based on the probability. When performing ANS encoding, a state variable is first initialized, usually with an initial value of 1. For each element of the data to be encoded, the value of the state variable is adjusted using multiplication and division operations according to the probability codeword corresponding to the element. In each encoding step, the range of the state variable needs to be limited to a small fixed range to avoid overflow. When the state variable needs to be range-limited by a division operation, the encoded bits are extracted based on the result of the division and added to the output bit stream. Repeat the above process until all the data to be encoded is processed.
[0170] At present, JPEG images have become one of the most widely used image formats due to their good compatibility. However, compared with new standard format images, such as HEIF images, JPEG images occupy more storage space. Especially as the use of electronic devices to take pictures has become mainstream, and the camera pixels in electronic devices are constantly improving, the resolution of a single JPEG image is getting higher and higher, resulting in a single JPEG image occupying more and more storage space in electronic devices, thus causing the problem of insufficient storage space in electronic devices. Therefore, how to effectively reduce the storage space occupied by JPEG images in electronic devices is an urgent problem to be solved.
[0171] In view of this, an embodiment of the present application provides an encoding method, in which the electronic device can recompress the determined compressed image when it detects that the re-compression option is selected, or when the re-compression function is turned on by default, detects that the electronic device is in an idle state, or detects that a preset time period for executing the re-compression function is reached, or detects a user's photo taking event, thereby saving storage space of the electronic device.
[0172] The following is an introduction to the technical solution provided by the embodiment of the present application in conjunction with the accompanying drawings. Figure 1 The embodiment of the present application provides an encoding method, which is applied to an electronic device. The electronic device can be a smart phone, a laptop computer, a desktop computer, a tablet computer, a server, etc., and is not particularly limited here. The process of the method is described as follows:
[0173] Step 10: In response to reaching a preset re-compression condition, determining a compressed image to be processed.
[0174] In an embodiment of the present application, a compressed image can be considered to be a compressed JPEG image in an electronic device, and the sources of the JPEG image here include but are not limited to: JPEG images from social software (for example, JPEG images from WeChat friends, or JPEG images from QQ friends), JPEG images from work collaboration software (for example, JPEG images from DingTalk friends, or JPEG images from enterprise WeChat friends), JPEG images downloaded from the Internet (for example, JPEG images downloaded from news applications, or JPEG images downloaded from Weibo, or JPEG images downloaded from QQ Space or WeChat Moments), and JPEG images taken by electronic devices.
[0175] Before recompressing the compressed JPEG image, it is necessary to determine at what time the electronic device will start the recompression function. It should be understood that the recompression function here refers to lossless recompression, that is, the recompression process will not lose image quality. Figure 2 , is a schematic diagram of a triggering lossless recompression function of an electronic device provided in an embodiment of the present application. Figure 2 As shown in (a), the electronic device displays a target interface, and the "lossless recompression" option in the target interface, which indicates the activation of the lossless recompression function, is in an off state by default. When it is detected that the user has implemented an activation operation on the above-mentioned "lossless recompression" option in the target interface, the above-mentioned "lossless recompression" option is switched from an off state to an on state, that is, the lossless recompression function is switched from an off state to an on state. First, the compressed image to be processed can be determined, and then the terminal is triggered to recompress the determined compressed image. Here, the option name can be called "recompression" or "lossless recompression", and there is no special restriction here. Figure 2 As shown in (b), the compressed image to be processed here can be manually selected by the user, or it can be a JPEG image with a low viewing frequency of the user selected by the terminal through scanning and screening, and then manually selected by the user, without any special restrictions here; Figure 2 As shown in (c), in the target interface of the electronic device, the "lossless recompression" option indicating that the lossless recompression function can be performed in a preset time period or an idle time period has been pre-enabled. The electronic device can determine the compressed image to be processed in the preset time period set by the user (e.g., 9 p.m. to 7 a.m.) in which the recompression function can be performed, or the electronic device can determine when it detects that it is in an idle time period, and then trigger the electronic device to recompress the determined compressed image. Here, the compressed image can be screened out by the electronic device through a global scan without any conditions, or can be screened out according to the screening conditions set by the user. For example, the screening conditions can be the generation time of the compressed image. The user can choose to recompress the compressed image whose generation time is far away from the current time, such as recompressing the compressed image one day ago or one week ago. Figure 2 As shown in (d), in the target interface of the electronic device, the "lossless recompression" option indicating that the image lossless recompression function can be performed when taking a photo has been pre-enabled. Once a photo taking event is detected, the electronic device will perform preliminary compression on the newly generated JPEG image, and then immediately perform lossless recompression on the newly generated compressed image.
[0176] It should be understood that the target interface can be a setting interface or other interface in the electronic device, and there is no special limitation here. At the same time, the electronic device can support a combination of any one or more of the above trigger conditions to enable the re-compression function, and there is no special limitation here.
[0177] Step 20: Re-compress the compressed image to obtain a re-compressed image.
[0178] In an embodiment of the present application, after any preset re-compression condition in step 10 is met and the compressed image to be processed is determined, the re-compression function can be started to losslessly re-compress the determined compressed image, thereby saving storage space of the electronic device.
[0179] See also Figure 3 20 is a flowchart of a re-compression method proposed in an embodiment of the present application. Step 20 can be implemented by executing sub-steps 201 and 202:
[0180] Step 201: Apply for unit memory from a random access memory based on a preset re-compression unit.
[0181] In the embodiment of the present application, the number of bytes of the preset re-compression unit is less than the number of bytes of the entire compressed image, that is, the preset re-compression unit is a part of the compressed image, and the compressed image may include multiple preset re-compression units, so the unit memory of the same byte size applied to the random access memory based on the preset re-compression unit must be less than the memory occupied by the entire compressed image. It should be understood that the unit memory here refers to the running memory.
[0182] Step 202: recompress each preset recompression unit in the unit memory to obtain a recompressed image.
[0183] In an embodiment of the present application, after applying for unit memory from the random access memory, multiple preset re-compression units can be written into the above-mentioned unit memory in sequence, and each preset re-compression unit can be re-compressed. That is to say, multiple preset re-compression units contained in the compressed image share the same unit memory, thereby achieving re-compression of the compressed image while reducing memory occupancy, so that electronic devices with limited running memory can still normally execute the re-compression function for the compressed image, so as to achieve the purpose of saving storage space.
[0184] For example, the compressed image includes 6 preset re-compression units, and the compressed image is 12M, then each preset re-compression unit is 2M, firstly, 2M of unit memory is applied to the random access memory based on a single preset re-compression unit, and then the 6 preset re-compression units are re-compressed in turn in the 2M unit memory, then compared with the prior art that requires applying for 12M of unit memory, only 2M of unit memory is required in the present application, saving 83.3% of the memory.
[0185] In some embodiments, multiple unit memories may be requested from a random access memory based on multiple preset re-compression units, so that the multiple preset re-compression units may be subsequently re-compressed in parallel in the multiple unit memories, thereby improving the re-compression processing efficiency.
[0186] See also Figure 4 , is a flowchart of a method for applying for unit memory provided in an embodiment of the present application. Step 201 can be implemented by executing sub-steps 2011 and 2012:
[0187] Step 2011: Divide the compressed image into a preset number of sub-images.
[0188] In the embodiment of the present application, the preset number of sub-images can be considered to be pre-configured by the user according to actual needs, and no special restrictions are made here. When the preset number of sub-images is constant, different division methods can also be used to divide the compressed image.
[0189] See also Figure 5 , which is a schematic diagram of a sub-graph division method provided in an embodiment of the present application. If the number of sub-graphs is preset to 4, that is, divided into sub-graphs Figure 1 ,son Figure 2 ,son Figure 3 and son Figure 4 For compressed images of the same size, the first division method is as follows Figure 5 As shown in (a), the width of the compressed image is used as the basis, and the height is divided into 4 equal parts, that is, the width of each sub-image is the same as the original compressed image, and the height of each sub-image is 1 / 4 of the original compressed image; the second division method is as follows Figure 5 As shown in (b), the width and height of the compressed image are taken as 1 / 2, that is, the width and height of each sub-image are 1 / 2 of the original compressed image. Figure 5 As shown in (c), the width of the compressed image is divided into four equal parts based on the height of the compressed image, that is, the height of each sub-image is the same as the original compressed image, and the width of each sub-image is 1 / 4 of the original compressed image.
[0190] Step 2012: taking the preset number of rows of each sub-image in the preset number of sub-images as a preset re-compression unit, and applying for a corresponding unit memory from the random access memory.
[0191] In the embodiment of the present application, after the compressed image is divided into a preset number of sub-images, for each sub-image, the preset number of rows of the sub-image can be used as a preset re-compression unit. For example, the preset number of rows can be one row, two rows, or even multiple rows. It is only necessary to ensure that the number of bytes of the preset re-compression unit is less than the number of bytes of a single sub-image. There is no special restriction on how many rows a preset re-compression unit includes in a single sub-image. After determining the preset re-compression unit from each sub-image, a unit memory can be applied based on the preset re-compression unit. That is, a corresponding unit memory will be applied for each sub-image, and the size of the unit memory is equal to the number of bytes required for the preset number of rows in the corresponding sub-image.
[0192] It should be understood that in the above embodiments, when the preset re-compression unit includes only one row of the sub-image, the memory occupied in the re-compression process can be reduced compared to when the preset re-compression unit includes multiple rows of sub-images. However, when the preset re-compression unit includes only one row of the sub-image, the memory required to apply for is relatively less.
[0193] See also Figure 6 , is a schematic diagram of a preset re-compression unit provided in an embodiment of the present application. For example, if the compressed image is 16M, the preset number of sub-images is 4, then each sub-image is 4M, and if each sub-image has 4 rows, the number of bytes in each row is 1M. Figure 6 As shown in (a), if the preset number of rows is one row, one row of each sub-image is used as the preset re-compression unit, that is, each preset re-compression unit is 1M, then 1M of memory needs to be applied for each sub-image, and 4 sub-images need to apply for a total of 4M of memory, which is equivalent to applying for 4M of memory for compressing the image; Figure 6 As shown in (b), if the preset number of rows is two, the two rows in each sub-image are used as the preset re-compression unit, that is, each preset re-compression unit is 2M, then 2M of memory needs to be applied for each sub-image, and a total of 8M of memory needs to be applied for the four sub-images, which is equivalent to applying 8M of memory for the compressed image. Figure 6 (a) or Figure 6 (b) The two methods of setting the preset re-compression unit both reduce the memory occupied during the re-compression process compared to the prior art which requires applying for 16M memory for the compressed image. Figure 6 In (a), the method of using a row of the subgraph as the preset re-compression unit is relatively better.
[0194] In some embodiments, when a compressed image is obtained by performing DCT transformation and Huffman coding with a coding unit as a basic processing unit in a JPEG image, the DC coefficient formed by the DCT transformation of the coding unit is not directly Huffman coded, but the DC coefficients of adjacent coding units are subtracted, and then the difference is used as the coding amount for Huffman coding. Therefore, when the compressed image is divided into sub-images, it is necessary to first decode the DC coefficient of each coding unit in the compressed image before the difference operation is performed, and eliminate the data dependency between the coding units, so that the sub-image division can be performed normally.
[0195] See also Figure 7 , which is a flow chart of a subgraph partitioning method provided in an embodiment of the present application. Step 2011 can be implemented by executing sub-steps 20111 and 20112:
[0196] Step 20111: Locally decode multiple coding units in the compressed image to obtain a DC coefficient corresponding to each of the multiple coding units.
[0197] Step 20112: Divide the locally decoded multiple coding units into a preset number of sub-images, where each sub-image in the preset number of sub-images includes at least two coding units.
[0198] In the embodiment of the present application, since the compressed image includes multiple coding units, the compressed image is locally decoded with the coding unit as the minimum processing unit, which can be considered as locally decoding each of the multiple coding units, that is, only the DC coefficient in each coding unit is decoded, so as to obtain the DC coefficient in each coding unit, thereby eliminating the data dependency between the multiple coding units in the compressed image. On this basis, at least two coding units after local decoding can be used as a sub-image based on the preset number of sub-images, thereby completing the sub-image division of the compressed image. Here, the data dependency between the coding units after local decoding is eliminated, so after being divided into different sub-images, there is no data dependency between different sub-images, thereby preparing for the subsequent parallel re-compression of each sub-image. It should be understood that during local decoding, it is also possible to apply for an equal-sized running memory according to the size of the coding unit to locally decode each coding unit in the compressed image one by one, so that the running memory occupied can also be reduced in the local decoding process.
[0199] See also Figure 8 , which is a flow chart of a local decoding method provided in an embodiment of the present application. Step 20111 can be implemented by executing sub-steps 301 and 302:
[0200] Step 301: parse the compressed image to obtain basic information of the Joint Photographic Experts Group JPEG, which includes JPEG width and height information and a Huffman table.
[0201] Step 302: Based on the JPEG width and height information and the Huffman table, starting from the first coding unit in the compressed image, multiple coding units are locally decoded in sequence to obtain a DC coefficient corresponding to each coding unit.
[0202] In an embodiment of the present application, the compressed image is parsed to obtain the JPEG image width and height information and the Huffman table. On this basis, starting from the first coding unit in the compressed image, all coding units are locally decoded in sequence, so that the DC coefficient of each coding unit can be accurately obtained.
[0203] See also Fig. 9, is a schematic diagram of local decoding of a coding unit provided in an embodiment of the present application. Taking the nth coding unit as an example, n is a positive integer greater than 1 and less than the total number of coding units in the compressed image. The coding unit includes 64 coefficients to be decoded, including one DC coefficient to be decoded, and 63 AC coefficients to be decoded. The so-called local decoding of the coding unit is to decode the DC coefficient therein. Taking the upper left corner as the origin, the position (0,0) represents the intermediate value obtained after local decoding using the Huffman table, that is, 00. The intermediate value can be considered as the difference between the true DC coefficient of the nth coding unit and the true DC coefficient of the n-1th coding unit. If the true DC coefficient of the n-1th coding unit is 20, then the true DC coefficient of the nth coding unit is 20+0=20.
[0204] In some embodiments, after the compressed image is divided into a plurality of sub-images, the plurality of independent sub-images may be re-compressed in parallel, thereby improving the processing efficiency of the re-compression.
[0205] See also Fig.10 , is a flow chart of a parallel recompression method provided in an embodiment of the present application. Step 202 can be implemented by executing sub-steps 2021 to 2025:
[0206] Step 2021: Determine the starting position of each subgraph based on the Huffman switch word.
[0207] In an embodiment of the present application, when parsing the compressed image, a Hoffman switching word can also be obtained. The Hoffman switching word can be used to indicate the starting position of each coding unit in the compressed image. On this basis, after the multiple coding units contained in the compressed image are divided into sub-graphs, it can be considered that the Hoffman switching word can be used to indicate the starting position of each sub-graph. Then, before parallel recompression, the Hoffman switching word can be used to determine the starting position of each sub-graph, so that each sub-graph can be recompressed in parallel starting from the starting position of each sub-graph.
[0208] Step 2022: Based on the starting position, write a preset number of rows in each sub-graph into the corresponding unit memory in parallel.
[0209] In an embodiment of the present application, each sub-image has a corresponding unit memory. After the starting position of each sub-image is determined, the preset number of rows can be used as a preset re-compression unit and written in parallel into the corresponding unit memory starting from the starting position of each sub-image.
[0210] Step 2023: In each unit memory, parallel recompression is performed for a preset number of rows in the corresponding sub-image until the first code stream of each sub-image is obtained.
[0211] In an embodiment of the present application, after writing the preset number of rows in each sub-image into the corresponding unit memory, the preset number of rows in the corresponding sub-image can be recompressed in parallel in each unit memory, that is, in each unit memory, the first preset recompression unit in the corresponding sub-image is recompressed in parallel. After the first preset recompression unit in each sub-image is recompressed, the second preset recompression unit in each sub-image is written into the corresponding unit memory, and then the second preset recompression unit in the corresponding sub-image is recompressed in parallel in each unit memory, and so on, to complete the recompression of each sub-image and obtain the first code stream of each image. Since the recompression is performed in parallel, the efficiency of the recompression is improved.
[0212] See also Fig.11 , is a schematic diagram of parallel recompression of multiple sub-graphs in an embodiment of the present application. Fig.11 As shown in the figure, the compressed image is divided into two sub-images, namely Figure 1 ,son Figure 2 In the sub Figure 1 In the example, a row is used as the default recompression unit, and a unit memory of 1 is requested, and then the sub Figure 1 The first row (i.e., the first preset re-compression unit) in the sub-data is written into the unit memory 1, and the first row (i.e., the first preset re-compression unit) is re-compressed in the unit memory 1; at the same time, Figure 2 Select a row as the default recompression unit, apply for unit memory 2, and then Figure 2 The first row in (i.e., the first preset recompression unit) is written into unit memory 2, and the sub Figure 2 The first row in the recompression unit (i.e., the first preset recompression unit) is recompressed. Figure 1 With the child Figure 2 The first row of each of the sub-units is recompressed in parallel, and so on, the second row is written and pre-compressed in parallel in the corresponding unit memory, until the sub-unit memory is Figure 1 With the child Figure 2 The last row of each is also written and recompressed, thus ending the parallel recompression process.
[0213] Step 2024: splice the first code stream corresponding to each sub-image to obtain a sub-image splicing code stream.
[0214] Step 2025: splice the second code stream with the sub-image splicing code stream to obtain a heavily compressed image, wherein the second code stream is formed by encoding the basic information of JPEG.
[0215] In the embodiment of the present application, the compressed image is parsed in step 301, and after obtaining the basic information of JPEG, the basic information of JPEG is encoded to obtain the corresponding second code stream. When encoding the basic information of JPEG here, any one of the general encoding methods can be used, such as differential encoding, Huffman encoding, and Brunsli encoding, which are not particularly limited here. After respectively obtaining the first code stream corresponding to each sub-image and the second code stream corresponding to the basic information of JPEG, the second code stream can be spliced with the first code stream to obtain the final re-compressed file.
[0216] It should be understood that since the basic information of JPEG can be considered to include header information and tail information, the second code stream formed after encoding the basic information of JPEG can be considered to include a header information code stream and a tail information code stream. When the second code stream is spliced with the first code stream of each sub-image, the header information code stream is spliced before the spliced code stream composed of the first code streams of each sub-image, and the tail information code stream is spliced after the spliced code stream composed of the first code streams of each sub-image.
[0217] In some embodiments, the recompression process includes Huffman decoding and entropy coding, wherein entropy coding includes ANS coding and arithmetic coding, and the combination of Huffman decoding and entropy coding can be used to achieve lossless recompression of compressed files. In the related art, the Huffman decoding process is not parallelized, but the entropy coding process is parallelized. In the embodiments of the present application, after eliminating the data dependency between multiple sub-graphs in the compressed file, parallel Huffman decoding and parallel entropy coding can be achieved.
[0218] See also Fig.12 , is a flow chart of parallel Huffman decoding and parallel entropy coding provided in an embodiment of the present application. Step 2023 can be implemented by executing sub-steps 20231 and 20232:
[0219] Step 20231: In each unit memory, parallel Huffman decoding is performed for a preset number of rows in the corresponding sub-image until an AC coefficient corresponding to each sub-image is obtained, wherein the DC coefficient and AC coefficient of each sub-image together constitute a discrete cosine transform DCT coefficient.
[0220] Step 20232: In each unit memory, parallel entropy coding is performed on the DCT coefficients contained in the preset number of rows in the corresponding sub-image until a first bit stream corresponding to each sub-image is obtained.
[0221] In the embodiment of the present application, since the DC coefficients of the respective coding units contained in the compressed image are decoded through local decoding in step 20111, and since the multiple codes are divided into different sub-images, it can be considered that the DC coefficients in each sub-image have been decoded. Then, when the preset number of rows in each sub-image is subjected to parallel Huffman decoding, the AC coefficients of the preset number of rows in each sub-image are actually decoded in parallel. Compared with the related art, in which the DC coefficients and the AC coefficients are not decoded in parallel, the present application improves the decoding efficiency of the Huffman decoding stage to a certain extent. After respectively decoding the AC coefficients and the DC coefficients of each sub-image, that is, after decoding the DCT coefficients of each sub-image, it is possible to further perform parallel entropy coding on the DCT coefficients contained in the preset number of rows in the corresponding sub-image in each unit memory, thereby obtaining the first bit stream of each sub-image.
[0222] In some embodiments, when splicing the first code streams corresponding to multiple sub-images, there may be byte misalignment. For example, when splicing the first code streams corresponding to adjacent sub-images, the first code stream of the previous sub-image occupies 10 complete bytes, but there are 3 bits remaining; and the first code stream of the next sub-image occupies 10 bytes, and there are 4 bits remaining, then the first code stream corresponding to the next sub-image needs to be shifted after writing, and the shift operation is usually time-consuming, thereby affecting the efficiency of the re-compression process.
[0223] See also Fig.13 , which is a flow chart of a method for splicing bitstreams in a recompression stage provided in an embodiment of the present application. Step 2024 can be implemented by executing sub-steps 20241 and 20244:
[0224] Step 20241: perform a write operation on the first code stream of the ith sub-image to obtain the M bytes that have been written and the N bytes that have not been written of the first code stream of the ith sub-image, where M and N are both positive integers not less than 1.
[0225] Step 20242: Store the first code stream of the N-bit i-th sub-image in the Huffman switch word.
[0226] Step 20243: When performing a write operation on the first code stream of the i+1th sub-image, write the N-bit first code stream of the i-th sub-image in the Huffman switch word into the M+1th byte.
[0227] Step 20244: starting from the N+1 digit in the M+1 th byte, write the first code stream of the i+1 th sub-image until a sub-image splicing code stream is obtained, where i is a positive integer less than the preset number of sub-images.
[0228] In the embodiment of the present application, when the first code stream of the i-th sub-image is written, a single complete byte is used as a writing basic unit, and the M complete bytes in the first code stream of the i-th sub-image are written, and the remaining N bits of the code stream are not written temporarily. Instead, before the first code stream of the i+1-th sub-image is written, starting from the M+1-th byte, the N bits of the first code stream of the i-th sub-image stored in the Huffman switch word are first written into the M+1-th byte, and then starting from the N+1th bit of the M+1-th byte, the first code stream of the i+1-th sub-image is written using a single complete byte as a writing basic unit. If the first code stream of the i+1-th sub-image has K bits of the first code stream of the i+1-th sub-image remaining after the L-th byte (L is a positive integer greater than M), K is a positive integer not less than 1, at this time, the K bits of the first code stream of the i+1-th sub-image are temporarily stored in the Huffman switch word. When it is necessary to write the first code stream of the i+2th sub-image, start from the L+1th byte. At this time, the K-bit first code stream of the i+1th sub-image stored in the Huffman switch word is first written into the L+1th byte, and then starting from the K+1th bit of the L+1th byte, the first code stream of the i+2th sub-image is written with a single complete byte as the basic writing unit, and so on, until the first code streams of all sub-images are written, and the sub-image splicing code stream is obtained.
[0229] See also Fig.14 , which is a schematic diagram of splicing the first code streams corresponding to adjacent sub-images provided in an embodiment of the present application. After the first code stream of the i-th sub-image is written with a single complete byte as the basic writing unit, the first code stream of the i-th sub-image that has been written is 1 byte, that is, the first byte 01100011, and the first code stream of the i-th sub-image that has not been written is 3 bits, that is, 101. At this time, the 3 bits of the first code stream of the i-th sub-image that have not been written can be saved in the Huffman switching word. When it is necessary to write the first code stream of the i+1-th sub-image, it can be considered to start from the 3rd byte. At this time, the 3 bits of the first code stream of the i-th sub-image that have not been written and stored in the Huffman switching word are first written to the first 3 bits of the third byte, and then the first code stream of the i+1-th sub-image is written from the 4th bit of the 3rd byte, thereby avoiding the shift processing when the first code stream of the i+1-th sub-image is written, and the splicing efficiency is improved.
[0230] In some embodiments, after the compressed file is re-compressed, it can be stored using a smaller storage space. When the user needs to view the JPEG image, the re-compressed image needs to be decompressed.
[0231] See also Fig.15, is a decoding method provided in an embodiment of the present application, and the method is applied to an electronic device, and the electronic device can be a smart phone, a laptop computer, a desktop computer, a tablet computer, a server, etc., and is not particularly limited here. The process of the method is described as follows:
[0232] Step 40: In response to reaching a preset decompression condition, determining a recompressed image to be processed, wherein the preset decompression condition at least includes detecting a viewing operation on the recompressed image, or detecting an editing operation on the recompressed image.
[0233] Step 50: Decompress the heavily compressed image to obtain a compressed image.
[0234] In an embodiment of the present application, when a heavily compressed image needs to be viewed or edited, the electronic device supports decompression of the heavily compressed image, thereby ensuring that the user can view or edit it normally, thereby improving the user experience.
[0235] See also Fig.16 , is a flowchart of a decompression method provided in an embodiment of the present application. Step 50 can be implemented by executing sub-steps 501 and 502:
[0236] Step 501: Apply for corresponding unit memory from a random access memory based on a preset decompression unit.
[0237] In the embodiment of the present application, the number of bytes of the preset decompression unit is less than the number of bytes of the entire recompressed image, that is, the preset decompression unit is a part of the recompressed image, and the recompressed image may include multiple preset decompression units. Then, based on the preset decompression unit, a unit memory of the same byte size as the preset decompression unit is applied to the random access memory, and the unit memory must be smaller than the memory occupied by the entire recompressed image. It should be understood that the unit memory here refers to the running memory.
[0238] Step 502: Decompress each preset decompression unit in the unit memory to obtain a compressed image.
[0239] In the embodiment of the present application, after applying for a unit memory from the random access memory, multiple preset decompression units can be written into the above unit memory in sequence, and each preset decompression unit can be decompressed, that is, the multiple preset decompression units contained in the recompressed image share the above same unit memory, so as to achieve decompression of the recompressed image while reducing memory usage, so that electronic devices with limited running memory can still perform the decompression function for the recompressed image normally, so as to achieve the purpose of saving storage space. It should be understood that since the recompression process includes Huffman decoding and entropy coding, wherein entropy coding includes ANS coding and arithmetic coding, then correspondingly, the decompression process includes entropy decoding and Huffman decoding, and entropy decoding includes ANS decoding and arithmetic decoding.
[0240] For example, the recompressed image includes 6 preset decompression units. If the recompressed image is 12M, each preset decompression unit is 2M. First, a 2M unit memory is applied to the random access memory based on a single preset decompression unit, and then the 6 preset decompression units are decompressed in sequence in the 2M unit memory. Compared with the prior art, which requires applying for a 12M unit memory, only a 2M unit memory is required in the present application, saving 83.3% of the memory.
[0241] In some embodiments, multiple unit memories may be requested from a random access memory based on multiple preset decompression units, so that the multiple preset decompression units may be subsequently recompressed in parallel in the multiple unit memories, thereby improving the decompression processing efficiency.
[0242] See also Fig.17 , is a flowchart of a method for decompressing application unit memory provided by an embodiment of the present application. Step 501 can be implemented by executing sub-steps 5011 and 5012:
[0243] Step 5011: Divide the re-compressed image into a preset number of re-compressed data segments.
[0244] In the embodiment of the present application, the preset number of data segments can be considered to be pre-configured by the user according to actual needs, and no special restrictions are made here. It should be understood that the preset number of data segments of the data segments divided by the recompressed image here can be equal to or different from the preset number of sub-images divided by the compressed image in the recompression stage.
[0245] Step 5012: Using the preset number of rows of each heavily compressed data segment in the preset number of data segments as a preset decompression unit, apply for a corresponding unit memory from the random access memory.
[0246] In an embodiment of the present application, after the recompressed image is divided into a preset number of data segments, for each recompressed data segment, the preset number of rows of the recompressed data segment can be used as a preset decompression unit. For example, the preset number of rows can be one row, two rows, or even multiple rows. It is only necessary to ensure that the number of bytes of the preset decompression unit is less than the number of bytes of a single recompressed data segment. Here, there is no special restriction on how many rows of a single recompressed data segment the preset decompression unit includes. After determining the preset decompression unit from each recompressed data segment, a unit memory can be applied based on the preset decompression unit. That is, a corresponding unit memory will be applied for each recompressed data segment, and the size of the unit memory is equal to the number of bytes required for the preset number of rows in the corresponding recompressed data segment.
[0247] It should be understood that in the above embodiments, when the preset decompression unit includes only one row of the re-compressed data segment, the memory occupied in the decompression process can be reduced compared to when the preset decompression unit includes multiple rows of the re-compressed data segment. However, when the preset decompression unit includes only one row of the re-compressed data segment, the memory required to apply for is relatively less.
[0248] See also Fig.18 , is a schematic diagram of a preset decompression unit provided in an embodiment of the present application. For example, if the recompressed image is 16M, the preset number of data segments is 4, then each recompressed data segment is 4M, and if each recompressed data segment has 4 rows, the number of bytes in each row is 1M. Fig.18 As shown in (a), if the preset number of rows is one row, one row of each heavily compressed data segment is used as the preset decompression unit, that is, each preset decompression unit is 1M, then 1M of memory needs to be applied for each heavily compressed data segment, and 4 heavily compressed data segments need to apply for a total of 4M of memory, which is equivalent to applying for 4M of memory for the heavily compressed image; Fig.18 As shown in (b), if the preset number of rows is two, two rows in each heavily compressed data segment are used as the preset decompression unit, that is, each preset decompression unit is 2M, then 2M of memory needs to be applied for each heavily compressed data segment, and 8M of memory is required for the four heavily compressed data segments, which is equivalent to 4M of memory required for the heavily compressed image. Fig.18 (a) or Fig.18 (b) The two methods of setting the preset decompression unit both reduce the memory occupied during the decompression process compared to the prior art which requires applying for 16M memory for the heavily compressed image.
[0249] In some embodiments, during the recompression process of a compressed image, corresponding segmentation flags are added for the contents of different attributes in the compressed image, and the number of sub-images divided during the recompression process is also recorded in a specific field in the recompressed image, that is, the number of parallel threads in the recompression stage. The recompressed image can then be divided into data segments based on the above-mentioned segmentation flags and specific fields added during the recompression stage.
[0250] See also Fig.19 , which is a flow chart of a data segment division method provided in an embodiment of the present application. Step 5011 can be implemented by executing sub-steps 50111 and 50112:
[0251] Step 50111: parse the heavily compressed image to obtain the target segmentation flag and the preset number of sub-images.
[0252] In an embodiment of the present application, the recompressed image includes multiple types of segmentation flags, for example, the segmentation flag of the data segment representing the image attribute, that is, the field content after the segmentation flag, represents the image attribute of the recompressed image; the segmentation flag of the data segment representing the recompressed data, that is, the field content after the segmentation flag, represents the recompressed data in the recompressed image. Of course, there are other types of segmentation flags, which are not particularly limited here. By parsing the recompressed image, the target segmentation flag representing the starting position of the recompressed data and the second target segmentation flag representing the starting position of the attribute data can be obtained. At the same time, since the relevant information of the preset number of sub-images divided in the recompression stage can also be stored in the recompressed image, the preset number of sub-images can also be obtained when the recompressed image is parsed.
[0253] Step 50112: The preset number of sub-images is used as the preset number of data segments, and the re-compressed data located after the target segmentation flag is divided into the preset number of re-compressed data segments.
[0254] In the embodiment of the present application, the preset number of sub-images is not only used to characterize the number of sub-images divided in the process of forming a recompressed image, but also used to characterize the number of parallel threads (or parallel tasks) in the recompression stage. Since the decompression stage corresponds to the recompression stage, if the decompression stage wants to perform parallel decompression, the number of parallel threads in the recompression stage can be used as the number of parallel threads in the decompression stage, that is, the preset number of sub-images is used as the preset number of data segments, and the recompressed data segments located after the target segmentation flag are divided into the preset number of data segments, so that when recompression and decompression are performed in the same electronic device, recompression and decompression can be completed without adding new threads (or number of tasks). Of course, the decompression stage and the recompression stage can also use different numbers of parallel threads, that is, the preset number of sub-images may not be equal to the preset number of data segments, and there is no special restriction here.
[0255] It should be understood that after the re-compressed data is divided into a preset number of data segments, the starting position of each re-compressed data segment may be recorded and stored in the Huffman switch word.
[0256] In some embodiments, after the heavily compressed image is divided into a plurality of data segments, the plurality of independent data segments may be decompressed in parallel, thereby improving the processing efficiency of the decompression.
[0257] See also Fig. 20 , which is a schematic diagram of a parallel decompression process provided by an embodiment of the present application. Step 502 can be implemented by executing sub-steps 5021 and 5024:
[0258] Step 5021: Write a preset number of rows in each re-compressed data segment into the corresponding unit memory in parallel.
[0259] In an embodiment of the present application, each re-compressed data segment has a corresponding unit memory. Based on the predetermined starting position of each re-compressed data segment, a preset number of rows can be used as a preset re-compression unit and written in parallel into the corresponding unit memory starting from the starting position of each re-compressed data segment.
[0260] Step 5022: In each unit memory, parallel decompression is performed for a preset number of rows in the corresponding heavily compressed data segment until a first code stream of each heavily compressed data segment is obtained.
[0261] In the embodiment of the present application, after the preset number of rows of each recompressed data segment is written into the corresponding unit memory, the preset number of rows in the corresponding recompressed data segment can be recompressed in parallel in each unit memory, that is, in each unit memory, the first preset decompression unit in the corresponding recompressed data segment is decompressed in parallel. After the first preset decompression unit in each recompressed data segment is decompressed, the second preset decompression unit in each recompressed data segment is written into the corresponding unit memory, and then the second preset decompression unit in the corresponding recompressed data segment is decompressed in parallel in each unit memory, and so on, to complete the decompression of each recompressed data segment and obtain the first code stream of each recompressed data segment. Since the decompression is performed in parallel, the efficiency of decompression is improved.
[0262] See also Fig.21 , is a schematic diagram of parallel decompression of multiple heavily compressed data segments in an embodiment of the present application. Fig.21 As shown, for example, the recompressed image is divided into two recompressed data segments, namely, recompressed data segment 1 and recompressed data segment 2. In recompressed data segment 1, a row is selected as a preset decompression unit, and unit memory 1 is applied, then the first row in recompressed data segment 1 (i.e., the first preset recompression unit) is written into unit memory 1, and the first row (i.e., the first preset decompression unit) is decompressed in unit memory 1; at the same time, a row is selected as a preset decompression unit in recompressed data segment 2, and unit memory 2 is applied, then the first row in recompressed data segment 2 (i.e., the first preset recompression unit) is written into unit memory 2, and the first row (i.e., the first preset decompression unit) is decompressed in unit memory 2, that is, the first row in recompressed data segment 1 and recompressed data segment 2 is decompressed in parallel, and so on, the second row is also written and decompressed in parallel in the corresponding unit memory, until the last row of recompressed data segment 1 and recompressed data segment 2 is also written and decompressed, thereby ending the parallel decompression process.
[0263] Step 5023: splice the first code stream of each heavily compressed data segment to obtain a data segment splicing code stream.
[0264] Step 5024: splice the second code stream with the data segment splicing code stream to obtain the compressed image, wherein the second code stream is formed by decompressing the data segment representing the image attribute in the heavily compressed image.
[0265] In the embodiment of the present application, after parsing the heavily compressed image in step 50111, the data segment representing the JPEG image attribute located after the second target segmentation flag can be decompressed, that is, ANS decoding and arithmetic decoding, as well as Huffman encoding, to obtain the corresponding second code stream. After respectively obtaining the first code stream corresponding to each heavily compressed data segment and the above-mentioned second code stream, the second code stream can be spliced with the first code stream to obtain the final compressed file.
[0266] It should be understood that, since the data segments representing the image attributes of JPEG can be considered to include a header information data segment and a tail information data segment, the second code stream formed after decompressing the data segments representing the image attributes of JPEG can be considered to include a header information code stream and a tail information code stream, and when the second code stream is spliced with the first code stream of each heavily compressed data segment, the header information code stream is spliced before the spliced code stream composed of the first code streams of each heavily compressed data segment, and the tail information code stream is spliced after the spliced code stream composed of the first code streams of each heavily compressed data segment.
[0267] In some embodiments, when the second code stream is spliced with the first code stream of each re-compressed data segment, there may be byte misalignment. For example, when the first code streams corresponding to adjacent re-compressed data segments are spliced, the first code stream of the previous re-compressed data segment occupies 5 complete bytes, but there are 2 bits remaining; and the first code stream of the next re-compressed data segment occupies 6 bytes, and there are 3 bits remaining, then it is necessary to shift the write position of the first code stream corresponding to the next re-compressed data segment, and the shift operation is usually time-consuming, thereby affecting the efficiency of the decompression process.
[0268] See also Fig. 22 , is a flow chart of a first code stream splicing method for a recompressed data segment provided in an embodiment of the present application. Step 5023 can be specifically implemented by executing sub-steps 50231-50234:
[0269] Step 50231: perform a write operation on the i-th re-compressed data segment to obtain the first code stream of the i-th re-compressed data segment, which includes P bytes that have been written and Q bytes that have not been written. Both P and Q are positive integers not less than 1.
[0270] Step 50232: Store the first code stream of the Q-bit i-th re-compressed data segment in the Huffman switching word.
[0271] Step 50233: When performing a write operation on the first code stream of the i+1th re-compressed data segment, write the first code stream of the i-th re-compressed data segment of the Q bit in the Huffman switch word into the P+1th byte.
[0272] Step 50234: Starting from the Q+1 digit in the P+1 byte, write the first code stream of the i+1 th recompressed data segment until a data segment splicing code stream is obtained, where i is a positive integer less than the preset number of data segments.
[0273] In the embodiment of the present application, when performing a write operation on the first code stream corresponding to the i-th recompressed data segment, a single complete byte can be used as a basic writing unit to perform a write operation on P complete bytes in the first code stream corresponding to the i-th recompressed data segment, and the remaining Q bits of the first code stream corresponding to the i-th recompressed data segment are not temporarily written, but are stored in the Huffman switching word. When the first code stream corresponding to the i+1-th recompressed data segment needs to be written, starting from the P+1-th byte, at this time, the Q bits of the first code stream corresponding to the i-th recompressed data segment stored in the Huffman switching word are first written into the P+1-th byte, and then starting from the Q+1-th bit of the P+1-th byte, the first code stream corresponding to the i+1-th recompressed data segment is written using a single complete byte as a basic writing unit. If after writing the Sth byte (S is a positive integer greater than P) of the first code stream corresponding to the i+1th recompressed data segment, there are still T bits of the first code stream corresponding to the i+1th recompressed data segment, where T is a positive integer not less than 1, the T bits of the first code stream corresponding to the i+1th recompressed data segment are temporarily stored in the Huffman switch word. When it is necessary to write the first code stream corresponding to the i+2th recompressed data segment, starting from the S+1th byte, the T bits of the first code stream corresponding to the i+1th recompressed data segment stored in the Huffman switch word are first written into the S+1th byte, and then starting from the T+1th bit of the S+1th byte, the first code stream corresponding to the i+2th recompressed data segment is written with a single complete byte as the writing basic unit, and so on, until the first code streams of all recompressed data segments are written, and the data segment splicing code stream is obtained.
[0274] See also Fig.23, which is a schematic diagram of splicing the first code streams corresponding to adjacent recompressed data segments provided in an embodiment of the present application. After the first code stream of the i-th recompressed data segment is written with a single byte as the basic writing unit, the first code stream of the i-th recompressed data segment that has been written is 1 byte, that is, the first byte 11011001, and the first code stream of the i-th recompressed data segment that has not been written is 2 bits, that is, 01. At this time, the 2 bits of the first code stream (01) of the i-th recompressed data segment that have not been written can be saved in the Huffman switch word. When it is necessary to write the first code stream of the i+1th re-compressed data segment, it can be considered to start from the second byte. At this time, the 2-bit first code stream (01) of the i-th re-compressed data segment that has not been written in the Huffman switch word is first written to the first 2 bits of the second byte, and then the first code stream of the i+1th re-compressed data segment is written starting from the third bit of the second byte, thereby avoiding the shift processing when writing the first code stream of the i+1th re-compressed data segment, and improving splicing efficiency.
[0275] The application scenarios of the solution protected by this application are described in detail below.
[0276] Scenario 1: Applied to the terminal side.
[0277] The terminal side can implement recompression methods and decompression methods, thereby saving running memory while improving the efficiency of recompression and decompression on the terminal side. Of course, it can also reduce the storage space occupied by JPEG images on the terminal side, allowing the terminal side to accommodate more storage resources.
[0278] See also Fig.24 , is a schematic diagram of a terminal side internal re-compression processing and display processing provided in an embodiment of the present application. Fig.24 As shown, the image-related system application can be a gallery, and the image-related third-party application can be WeChat, etc., and there is no special restriction here. The A.JPEG image in the memory can be considered as a compressed image. When the user needs to view the A.JPEG image, the operating system reads the A.JPEG image and decompresses it for display; when the user does not view the A.JPEG image, and the preset recompression condition is met, the operating system reads the A.JPEG image and recompresses it, and then saves the recompressed B.JPEG to the memory. It should be understood that the recompressed B.JPEG can overwrite the original A.JPEG image.
[0279] Scenario 2: Applied on the cloud side.
[0280] See also Fig.25 , is a schematic diagram of recompression and decompression on the cloud side in an embodiment of the present application. Fig.25As shown, before recompression / decompression, parameter settings are performed, such as setting the preset number of sub-images, the preset number of data segments, the number of threads, decoding-related settings, etc., which are not particularly limited here. After the settings are completed, when the terminal side determines that the preset recompression conditions are met, the compressed image can be sent to the cloud side, and then the cloud side can implement the recompression method, thereby saving running memory while improving the efficiency of recompression on the cloud side. Of course, it can also reduce the JPEG image's occupation of the cloud storage space, so that the cloud side can accommodate more storage resources. When the user needs to view the JPEG image on the cloud side, a decompression command can be sent to the cloud side to control the cloud side to decompress the JPEG image, thereby saving running memory while improving the efficiency of decompression on the cloud side.
[0281] Scenario 3: Collaboration between the terminal and the cloud.
[0282] See also Fig.26 , is a schematic diagram of a terminal side and a cloud side in a collaborative scenario provided by an embodiment of the present application, in which one side performs heavy compression and the other side performs decompression. Fig.26 As shown in (a), parameters are set in advance, such as setting the preset number of sub-images, the preset number of data segments, the number of threads, decoding-related settings, etc., and no special restrictions are made here. When the terminal side needs to download a JPEG image from the cloud side, the terminal side can manually trigger the preset recompression condition, that is, after selecting the recompression option, select the JPEG image to be downloaded, then the terminal side can send a recompression instruction to the cloud side, and the cloud side responds to the recompression instruction to recompress the JPEG image that the user needs to download, thereby saving running memory and storage space, while improving the recompression efficiency of the cloud side, and also improving the image transmission rate of the JPEG image to the terminal side. When the terminal side needs to view the downloaded recompressed JPEG image, the recompressed JPEG image can be decompressed on the terminal side, thereby saving running memory while improving the decompression efficiency of the terminal side. As shown in Fig.24As shown in (b), parameters are set in advance, such as setting the preset number of sub-images, the preset number of data segments, the number of threads, decoding-related settings, etc., and no special restrictions are made here. When the JPEG image on the terminal side needs to be uploaded to the cloud side, the terminal side can manually trigger the preset recompression condition, that is, after selecting the recompression option, the JPEG image to be uploaded is selected, then the terminal side can recompress the JPEG image to be uploaded, thereby saving the terminal side's running memory and storage space, while improving the terminal side's recompression efficiency, and at the same time, it can also improve the image transmission rate of transmitting JPEG images to the cloud side. When the cloud side needs to view the recompressed image, the terminal side can send a decompression command to the cloud side, and the cloud side responds to the decompression command to decompress the recompressed JPEG image, thereby saving the running memory while improving the decompression efficiency of the cloud side.
[0283] Scenario 4: Between terminals.
[0284] See also Fig. 27 , is a schematic diagram of a terminal side and a terminal side in a collaborative scenario provided by an embodiment of the present application, in which one side performs heavy compression and the other side performs decompression. Fig. 27 As shown, parameters are set in advance, such as setting the preset number of sub-images, the preset number of data segments, the number of threads, decoding-related settings, etc., which are not particularly limited here. When the first terminal side needs to send a JPEG image to the second terminal side, for example, the first terminal side and the second terminal side correspond to different users. For example, user A sends the JPEG image required by user B to the second terminal side corresponding to user B through the first terminal side, or the first terminal side and the second terminal side correspond to the same user, and the same user wants to clone the JPEG image in the first terminal side to the second terminal side, and can manually trigger the recompression function, that is, switch the "recompression option" from the closed state to the open state, and then select the JPEG image to be sent. Then, the first terminal side can recompress the selected JPEG image, thereby saving the running memory and storage space of the first terminal side, while improving the efficiency of the recompression of the first terminal side, and at the same time, it can also improve the image transmission rate of the JPEG image transmitted to the second terminal side. When the second terminal side needs to view the recompressed JPEG image, the recompressed JPEG image can be decompressed on the second terminal side, thereby saving the running memory and improving the efficiency of the decompression on the second terminal side.
[0285] See also Fig.28 , is a schematic diagram of the structure of an encoding device provided in an embodiment of the present application. The encoding device includes: a first determining unit 601 and a re-compression unit 602.
[0286] A first determining unit 601 is configured to determine a compressed image to be processed in response to reaching a preset recompression condition, wherein the preset recompression condition at least includes detecting that a recompression option in a target interface is switched from an off state to an on state, or, when the recompression option in the target interface has been turned on in advance, detecting that the target interface is in an idle state, or, when the recompression option in the target interface has been turned on in advance, detecting that the target interface is in a preset time period for executing the recompression function, or, when the recompression option in the target interface has been turned on in advance, detecting a photo taking event;
[0287] The recompression unit 602 is used to recompress the compressed image to obtain a recompressed image.
[0288] Optionally, the compressed image includes a plurality of preset re-compression units, and the re-compression unit 602 includes:
[0289] A first application unit is used to apply for a unit memory from a random access memory based on a preset re-compression unit, the number of bytes of the unit memory is equal to the number of bytes of the preset re-compression unit, and the number of bytes of the preset re-compression unit is less than the number of bytes of the compressed image;
[0290] The image recompression unit is used to recompress each preset recompression unit in the unit memory to obtain a recompressed image.
[0291] Optionally, the first application unit includes:
[0292] A sub-image division unit, used for dividing the compressed image into sub-images of a preset number;
[0293] The row memory application unit is used to apply for the corresponding unit memory from the random access memory using the preset number of rows of each sub-image in the preset number of sub-images as the preset re-compression unit, and the preset number of rows is less than the total number of rows of a single sub-image.
[0294] Optionally, the subgraph partitioning unit includes:
[0295] A local decoding unit, used for locally decoding a plurality of coding units in the compressed image to obtain a DC coefficient corresponding to each of the plurality of coding units;
[0296] The dividing unit is used to divide the locally decoded multiple coding units into a preset number of sub-pictures, each of which includes at least two coding units.
[0297] Optionally, the local decoding unit is specifically used for:
[0298] Parse the compressed image to obtain the basic information of the Joint Photographic Experts Group JPEG, including JPEG width and height information and Huffman table;
[0299] Based on the JPEG width and height information and the Huffman table, starting from the first coding unit in the compressed image, multiple coding units are locally decoded in sequence to obtain a DC coefficient corresponding to each coding unit.
[0300] Optionally, the basic information also includes a Huffman switch word, which is used to indicate the starting position of each coding unit in the compressed image. The image recompression unit includes:
[0301] A subgraph position determination unit, used for determining a starting position of each subgraph based on a Huffman switch word;
[0302] A parallel writing unit, used for writing a preset number of rows in each sub-graph into a corresponding unit memory in parallel based on a starting position;
[0303] A parallel recompression unit, used for performing parallel recompression on a preset number of rows in a corresponding sub-image in each unit memory until a first code stream of each sub-image is obtained;
[0304] A splicing unit, used for splicing the first code stream corresponding to each sub-image to obtain a sub-image splicing code stream;
[0305] The splicing unit is further used to splice the second code stream with the sub-image splicing code stream to obtain a heavily compressed image, wherein the second code stream is formed after encoding the basic information of JPEG.
[0306] Optionally, the parallel recompression unit is specifically used to:
[0307] In each unit memory, parallel Huffman decoding is performed for a preset number of rows in the corresponding sub-image until an AC coefficient corresponding to each sub-image is obtained, wherein the DC coefficient and the AC coefficient of each sub-image together constitute a discrete cosine transform DCT coefficient;
[0308] In each of the unit memories, parallel entropy coding is performed on the DCT coefficients contained in the preset number of rows in the corresponding sub-image until a first code stream corresponding to each sub-image is obtained.
[0309] Optionally, the splicing unit is specifically used for:
[0310] Perform a write operation on the first bitstream of the ith sub-image to obtain the M bytes that have been written and the N bytes that have not been written, where both M and N are positive integers not less than 1;
[0311] The first bit stream of the N-bit i-th sub-image is stored in the Huffman switch word;
[0312] When the write operation is performed on the first code stream of the i+1th sub-image, the first code stream of the N-bit i-th sub-image in the Huffman switch word is written into the M+1th byte;
[0313] In the M+1th byte, starting from the N+1th digit, a write operation is performed on the first code stream of the i+1th sub-image until a sub-image splicing code stream is obtained, where i is a positive integer less than the preset number of sub-images.
[0314] See also Fig.29 Based on the same inventive concept, an embodiment of the present application provides a decoding device, which includes: a second determination unit 701 and a decompression unit 702.
[0315] A second determining unit 701 is configured to determine a recompressed image to be processed in response to reaching a preset decompression condition, wherein the preset decompression condition at least includes detecting a viewing operation on the recompressed image, or detecting an editing operation on the recompressed image;
[0316] The decompression unit 702 is used to decompress the heavily compressed image to obtain a compressed image.
[0317] Optionally, the recompressed image includes a plurality of preset decompression units, and the decompression unit 70 includes:
[0318] A second application unit is used to apply for a unit memory from the random access memory based on the preset decompression unit, the number of bytes of the unit memory is equal to the number of bytes of the preset recompression unit, and the number of bytes of the preset decompression unit is less than the number of bytes of the recompressed image;
[0319] The image decompression unit is used to decompress each preset decompression unit in the unit memory to obtain a compressed image.
[0320] Optionally, the second application unit includes:
[0321] A division unit, used for dividing the recompressed image into recompressed data segments of a preset number of data segments;
[0322] The row memory application unit is used to apply for corresponding unit memory by taking the preset number of rows of each heavily compressed data segment in the preset number of data segments as the preset decompression unit, and the preset number of rows is less than the total number of rows of a single heavily compressed data segment.
[0323] Optionally, the division unit includes:
[0324] A parsing unit, used to parse the recompressed image to obtain a target segmentation flag and a preset number of sub-images, wherein the target segmentation flag is used to indicate a starting position of the recompressed data in the recompressed image;
[0325] The data segment division unit is used to use the preset number of sub-images as the preset number of data segments, and divide the re-compressed data after the target segmentation flag into the preset number of re-compressed data segments.
[0326] Optionally, the image decompression unit includes:
[0327] A parallel decompression unit, used for performing parallel decompression on a preset number of rows in a corresponding heavily compressed data segment in each unit memory until a first code stream of each heavily compressed data segment is obtained;
[0328] A splicing unit, used for splicing the first code stream of each recompressed data segment to obtain a data segment splicing code stream;
[0329] The splicing unit is further used to splice the second code stream with the data segment splicing code stream to obtain a compressed image, wherein the second code stream is formed by decompressing the data segment representing the image attribute in the heavily compressed image.
[0330] Optionally, the splicing unit is specifically used for:
[0331] Perform a write operation on the i-th recompressed data segment to obtain the first bit stream of the i-th recompressed data segment with P bytes written and Q bytes not written, where P and Q are both positive integers not less than 1;
[0332] The first code stream of the Q-bit i-th recompressed data segment is stored in the Huffman switching word;
[0333] When the first code stream of the i+1th recompressed data segment is written, the first code stream of the i-th recompressed data segment of the Q bit in the Huffman switch word is written into the P+1th byte;
[0334] In the P+1th byte, starting from the Q+1th digit, a write operation is performed on the first code stream of the i+1th recompressed data segment until a data segment splicing code stream is obtained, where i is a positive integer not less than the preset number of data segments.
[0335] See also Fig.30 Based on the same inventive concept, the embodiment of the present application further provides an electronic device 100, which may include at least one processor, and the at least one processor is used to execute a computer program stored in a memory to implement the embodiment of the present application. Figure 1 , Figure 3-4 , Figure 7-8 , Fig.10 , Figure 12-13 The encoding method shown, or Figure 15-17 , Figure 19-20 as well as Fig. 22 The steps of the decoding method are shown.
[0336] Optionally, the processor may specifically be a central processing unit, a specific ASIC, or one or more integrated circuits for controlling program execution.
[0337] Optionally, the electronic device 100 may further include a memory connected to the at least one processor, and the memory may include a ROM, a RAM, and a disk memory. The memory is used to store data required by the processor when it is running, that is, it stores instructions that can be executed by the at least one processor. The at least one processor executes the instructions stored in the memory to execute the program. Figure 1 , Figure 3-4 , Figure 7-8 , Fig.10 , Figure 12-13 , Figure 15-17 , Figure 19-20 as well as Fig. 22 The method shown in the figure. Wherein, the number of memories is one or more.
[0338] The physical devices corresponding to the first determination unit 601 and the recompression unit 602, or the second determination unit 701 and the decompression unit 702, can all be the aforementioned processors. Figure 1 , Figure 3-4 , Figure 7-8 , Fig.10 , Figure 12-13 , Figure 15-17 , Figure 19-20 as well as Fig. 22 Therefore, for the functions that can be realized by each functional module in the electronic device, please refer to Figure 1 , Figure 3-4 , Figure 7-8 , Fig.10 , Figure 12-13 , Figure 15-17 , Figure 19-20 as well as Fig. 22 The corresponding description in the illustrated embodiment will not be repeated here.
[0339] The electronic device 100 may be a smart electronic device such as a smart phone or a tablet computer, and this embodiment does not limit the form of the electronic device.
[0340] Instance, Fig.30 Taking a smart phone as an example, a schematic diagram of the structure of the electronic device 100 is shown. Fig.30As 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.
[0341] It is to be understood that the structure illustrated in the embodiment of the present application does 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 in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0342] 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 processor (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), etc. Different processing units may be independent devices or integrated into one or more processors.
[0343] 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.
[0344] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0345] In some embodiments, the processor 110 may include one or more interfaces. The interface 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, etc.
[0346] The charging management module 140 is used to receive charging input from a charger.
[0347] The power management module 141 is used to connect the battery 142 , the charging management module 140 and the processor 110 .
[0348] In some embodiments, 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).
[0349] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor.
[0350] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel.
[0351] The ISP is used to process data fed back by the camera 193 .
[0352] The camera 193 is used to capture still images or videos.
[0353] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0354] Video codecs are used to compress or decompress digital videos. The electronic device 100 may support one or more video codecs. Thus, the electronic device 100 may play or record videos in a variety of coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0355] 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 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.
[0356] 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.
[0357] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0358] 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.
[0359] The speaker 170A, also called a "horn", is used to convert audio electrical signals into sound signals.
[0360] The receiver 170B, also called a "handset", is used to convert audio electrical signals into sound signals.
[0361] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals.
[0362] The earphone interface 170D is used to connect a wired earphone and can be a USB interface 130 or a 3.5 mm open mobile terminal platform (OMTP) standard interface or a cellular telecommunications industry association of the USA (CTIA) standard interface.
[0363] Buttons 190 include a power button, a volume button, and the like.
[0364] Motor 191 can generate vibration prompts.
[0365] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.
[0366] The SIM card interface 195 is used to connect a SIM card. In some embodiments, the electronic device 100 uses an eSIM, that is, an embedded SIM card. The eSIM card can be embedded in the electronic device 100 and cannot be separated from the electronic device 100.
[0367] The present application also provides a computer storage medium, wherein the computer storage medium stores computer instructions, and when the computer instructions are executed on a computer, the computer executes Figure 1 , Figure 3-4 , Figure 7-8 , Fig.10 , Figure 12-13 , Figure 15-17 , Figure 19-20 as well as Fig. 22 The method described.
[0368] The present application provides a computer program product, which includes computer instructions. When the computer instructions are executed on a computer, the computer executes Figure 1 , Figure 3-4 , Figure 7-8 , Fig.10 , Figure 12-13 , Figure 15-17 , Figure 19-20 as well as Fig. 22 The method described.
[0369] The above embodiments can be implemented in whole or in part by software, hardware, firmware or any other combination. When implemented by software, the above embodiments can 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 or executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can 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 can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that contains one or more available media sets. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium. The semiconductor medium can be a solid state drive (SSD).
[0370] The above description is only a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of this specification should be included in the scope of protection of this specification.
Claims
1. A coding method, characterized in that: The method comprises: In response to reaching a preset recompression condition, determining a compressed image to be processed, wherein the preset recompression condition at least includes detecting that a recompression option in a target interface is switched from an off state to an on state, or, when the recompression option in the target interface has been turned on in advance, detecting that the target interface is in an idle state, or detecting that a preset time period for executing the recompression function is in progress, or detecting a photo taking event; The compressed image is recompressed to obtain a recompressed image.
2. The method according to claim 1, characterized in that The compressed image includes a plurality of preset re-compression units, and re-compressing the compressed image to obtain the re-compressed image includes: Applying for a unit memory from a random access memory based on the preset re-compression unit, the number of bytes of the unit memory is equal to the number of bytes of the preset re-compression unit, and the number of bytes of the preset re-compression unit is less than the number of bytes of the compressed image; Each of the preset recompression units is recompressed in the unit memory to obtain the recompressed image.
3. The method according to claim 2, characterized in that Applying for unit memory from a random access memory based on the preset re-compression unit includes: Dividing the compressed image into a preset number of sub-images; The preset number of rows of each sub-image in the preset number of sub-images is used as the preset re-compression unit, and the corresponding unit memory is applied to the random access memory, and the preset number of rows is less than the total number of rows of a single sub-image.
4. The method according to claim 3, characterized in that Dividing the compressed image into sub-images of a preset number of sub-images comprises: Locally decoding a plurality of coding units in the compressed image to obtain a direct current (DC) coefficient corresponding to each coding unit in the plurality of coding units; The locally decoded multiple coding units are divided into sub-images of the preset number of sub-images, each sub-image in the preset number of sub-images includes at least two coding units.
5. The method according to claim 4, characterized in that Locally decoding a plurality of coding units in the compressed image to obtain a direct current (DC) coefficient corresponding to each of the plurality of coding units comprises: Parsing the compressed image to obtain basic information of Joint Photographic Experts Group JPEG, wherein the basic information includes JPEG width and height information and a Huffman table; Based on the JPEG width and height information and the Huffman table, starting from the first coding unit in the compressed image, the multiple coding units are locally decoded in sequence to obtain a DC coefficient corresponding to each coding unit.
6. The method according to claim 5, characterized in that The basic information further includes a Huffman switching word, where the Huffman switching word is used to indicate a starting position of each coding unit in the compressed image, and each of the preset re-compression units is re-compressed in the unit memory to obtain the re-compressed image, including: Determining a starting position of each of the subgraphs based on the Huffman switch word; Based on the starting position, writing a preset number of rows in each of the sub-graphs into the corresponding unit memory in parallel; In each of the unit memories, parallel recompression is performed for a preset number of rows in the corresponding sub-image until a first code stream of each of the sub-images is obtained; Splicing the first code streams corresponding to each of the sub-images to obtain a sub-image splicing code stream; The second code stream is spliced with the sub-image splicing code stream to obtain the heavily compressed image, wherein the second code stream is formed by encoding the basic information of the JPEG.
7. The method according to claim 6, characterized in that In each of the unit memories, parallel recompression is performed for a preset number of rows in the corresponding sub-image until a first code stream of each of the sub-images is obtained, including: In each of the unit memories, parallel Huffman decoding is performed for a preset number of rows in the corresponding sub-image until an AC coefficient corresponding to each of the sub-images is obtained, wherein the DC coefficient and the AC coefficient of each of the sub-images together constitute a discrete cosine transform DCT coefficient; In each of the unit memories, parallel entropy coding is performed on the DCT coefficients contained in the preset number of rows corresponding to the sub-image, until a first code stream corresponding to each of the sub-images is obtained.
8. The method according to claim 6, characterized in that The first bitstreams corresponding to each of the sub-images are spliced to obtain a sub-image splicing bitstream, including: Performing a write operation on the first code stream of the ith sub-image to obtain M bytes that have been written and N bytes that have not been written, wherein both M and N are positive integers not less than 1; The first code stream of the N-bit ith sub-image is stored in the Huffman switch word; When performing a write operation on the first code stream of the i+1th sub-image, writing the N bits of the first code stream of the i-th sub-image in the Huffman switch word into the M+1th byte; In the M+1th byte, starting from the N+1th digit, a write operation is performed on the first code stream of the i+1th sub-image until the sub-image splicing code stream is obtained, where i is a positive integer less than the preset number of sub-images.
9. A decoding method, characterized in that: The method comprises: In response to reaching a preset decompression condition, determining a recompressed image to be processed, wherein the preset decompression condition at least includes detecting a viewing operation on the recompressed image, or detecting an editing operation on the recompressed image; The heavily compressed image is decompressed to obtain a compressed image.
10. The method according to claim 9, characterized in that The recompressed image includes a plurality of preset decompression units, and decompressing the recompressed image to obtain a compressed image includes: Applying for a unit memory from a random access memory based on the preset decompression unit, the number of bytes of the unit memory is equal to the number of bytes of the preset decompression unit, and the number of bytes of the preset decompression unit is less than the number of bytes of the recompressed image; Decompress each of the preset decompression units in the unit memory to obtain a compressed image.
11. The method according to claim 10, characterized in that Applying for corresponding unit memory from a random access memory based on the preset decompression unit includes: Dividing the recompressed image into a preset number of recompressed data segments; The preset number of rows of each heavily compressed data segment in the preset number of data segments is used as the preset decompression unit, and the corresponding unit memory is applied to the random access memory, and the preset number of rows is less than the total number of rows of a single heavily compressed data segment.
12. The method according to claim 11, characterized in that Dividing the recompressed image into a preset number of recompressed data segments comprises: Parsing the recompressed image to obtain a target segmentation flag and a preset number of sub-images, wherein the target segmentation flag is used to indicate a starting position of recompressed data in the recompressed image; The preset number of sub-images is used as the preset number of data segments, and the re-compressed data located after the target segmentation flag is divided into the re-compressed data segments of the preset number of data segments.
13. The method according to claim 11, characterized in that Decompressing each of the preset decompression units in the unit memory to obtain a compressed image includes: Writing a preset number of rows in each of the recompressed data segments into the corresponding unit memory in parallel; In each of the unit memories, parallel decompression is performed for a preset number of rows in the corresponding heavily compressed data segment until a first code stream of each of the heavily compressed data segments is obtained; splicing the first code stream of each of the recompressed data segments to obtain a data segment splicing code stream; The compressed image is obtained by splicing a second code stream with the data segment splicing code stream, wherein the second code stream is formed by decompressing the data segments representing image attributes in the heavily compressed image.
14. The method according to claim 13, characterized in that Splicing the first code stream of each of the recompressed data segments to obtain a data segment splicing code stream, including: Perform a write operation on the i-th re-compressed data segment to obtain a first code stream of P bytes that have been written and Q bytes that have not been written, where both P and Q are positive integers not less than 1; storing the first code stream of the Q-th recompressed data segment in the Huffman switch word; When performing a write operation on the first code stream of the i+1th re-compressed data segment, writing the first code stream of the i-th re-compressed data segment in the Q bit of the Huffman switch word into the P+1th byte; In the P+1th byte, starting from the Q+1th bit number, a write operation is performed on the first code stream of the i+1th recompressed data segment until the data segment splicing code stream is obtained, where i is a positive integer less than the preset number of data segments.
15. A coding device, characterized in that: The encoding device comprises: A first determining unit is configured to determine a compressed image to be processed in response to reaching a preset recompression condition, wherein the preset recompression condition at least includes detecting a selection operation of a recompression option, when the recompression option is turned on, detecting an idle state, a preset time period for executing the recompression function, or detecting a photo taking event; The recompression unit is used to recompress the compressed image to obtain a recompressed image.
16. A decoding device, characterized in that: The decoding device comprises: A second determining unit, configured to determine a recompressed image to be processed in response to reaching a preset decompression condition, wherein the preset decompression condition at least includes detecting a viewing operation on the recompressed image, or detecting an editing operation on the recompressed image; The decompression unit is used to decompress the heavily compressed image to obtain a compressed image.
17. An electronic device, characterized in that: The electronic device comprises a memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, the electronic device is triggered to execute the steps of the method as described in any one of claims 1-8 or 9-14.
18. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store computer instructions, and when the computer instructions are executed in a computer, the computer is caused to execute the steps of the method as claimed in any one of claims 1-8 or 9-14.
19. A computer program product, characterized in that The computer program product comprises computer instructions, and when the computer instructions are executed in a computer, the computer is caused to perform the steps of the method according to any one of claims 1 to 8 or 9 to 14.
Citation Information
Patent Citations
An image compression method and device
CN109842803A
Data file compression method, device and equipment and readable storage medium
CN110008192A
Image sharing method and mobile device
CN112352215A
Image processing method, intelligent terminal and storage medium
CN115604589A
Quick joint image expert group Huffman coding and decoding method
CN1359196A