Embedded device texture adaptive compression and display method and device and medium
By adaptively compressing the compression ratio of the texture image and recording it to the texture head, the problem of computing resource occupation when decoding the compressed image in the prior art is solved, and efficient compression and display of the texture image is achieved.
Patent Information
- Application Number
- CN202411949318.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-27
- Publication Date
- 2025-06-06
AI Technical Summary
In the prior art, decoding compressed images requires a large amount of computing resources, resulting in lag in image display.
By gradually compressing the original texture, compute the compression ratio of the texture, adaptively obtain the compression ratio of the texture, and record it to the texture header to reduce storage space and eliminate decoding when displayed.
Without affecting the display effect of texture images, maximum compression of texture images can be achieved, memory space usage is reduced, and computing resources required for image display are reduced.
Smart Images

Figure CN120111149A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of embedded device display rendering technology, and in particular to an embedded device texture adaptive compression and display method, device, computer-readable storage medium and computer program product. Background Art
[0002] Texture compression is an important computer storage and display technology. The original format of an image, such as Bitmap, stores the RGBA8888 data of each pixel, that is, one pixel takes up 4 bytes of storage space. In order to reduce the storage space occupied by the image, the existing technology generally converts the image into PNG format without lossy compression, or converts it into JPEG format with lossy compression.
[0003] However, in the embedded field, there is often a lack of PNG decoders or JPEG decoders for image display. Even if there are PNG decoders or JPEG decoders, the CPU computing burden they bring will cause lags when the image is displayed, making it necessary to abandon the image compression method using decoders in practical applications.
[0004] For example, patent document CN116471412A provides an adaptive image compression method based on density clustering, but the compressed image still requires a lot of CPU calculation when displayed, and this method uses a dedicated texture decoding algorithm, which requires additional processing when decoding and displaying, and also increases the computing burden of embedded devices. Summary of the invention
[0005] Therefore, the technical problem to be solved by the present invention is to overcome the problem in the prior art that a large amount of computing resources are required when decoding compressed images, resulting in image display freeze.
[0006] In order to solve the above technical problems, the present invention provides a texture adaptive compression and display method for an embedded device, comprising:
[0007] Traverse the texture for adaptive compression, including:
[0008] S1: Calculate the current compression ratio with a preset step value, and compress the original texture with the current compression ratio;
[0009] S2: enlarge the compressed texture to its original size to obtain a compressed texture of the original size;
[0010] S3: Calculate the similarity between the original texture and the compressed texture of the original size; if the similarity is less than or equal to the preset similarity threshold, return to S1 to calculate the next compression ratio with the preset step value; if the similarity is greater than the preset similarity threshold, output the previous compression ratio as the target compression ratio;
[0011] S4: compress the original texture at a target compression ratio, and record the target compression ratio in the texture header;
[0012] Traverse the texture for display, including:
[0013] Read the target compression ratio from the texture header and calculate the original size of the texture;
[0014] Draws the texture and displays it at its original size.
[0015] Preferably, the preset step value ranges from 0.05 to 0.1.
[0016] Preferably, the method of compressing the original texture includes bilinear filtering, nearest neighbor interpolation, bilinear interpolation and bicubic interpolation.
[0017] Preferably, the similarity between the compressed texture and the compressed texture of the original size is calculated using a structural similarity index or a peak signal-to-noise ratio.
[0018] Preferably, the preset similarity threshold value ranges from 0.70 to 0.85.
[0019] Preferably, the original texture is divided into blocks, each texture is traversed into blocks, and adaptive compression is performed, including:
[0020] S101: Calculating a current compression ratio of a current block with a preset step value, and compressing the texture of the current block with the current compression ratio;
[0021] S201: Enlarging the compressed block texture to the original block size to obtain a compressed block texture of the original block size;
[0022] S301: Calculate the similarity between the original texture and the compressed block texture of the original block size; if the similarity is less than or equal to the preset similarity threshold, return to S1 to calculate the next compression ratio of the current block with the preset step value; if the similarity is greater than the preset similarity threshold, output the previous compression ratio as the target compression ratio of the current block;
[0023] S401: compressing the current block texture at a target compression ratio, and recording the target compression ratio of the current block into the current block texture header;
[0024] Each texture is traversed in blocks and processed in parallel for display, including:
[0025] Read the target compression ratio of each block from the texture header of each block in parallel, and calculate the original size of each block in parallel;
[0026] Draw each tile texture in parallel at its original size and display it.
[0027] Preferably, the original texture is divided into 8×8 blocks or 16×16 blocks.
[0028] The present invention also provides an embedded device texture adaptive compression and display device, comprising:
[0029] Texture compression module, used to traverse textures for adaptive compression, including:
[0030] An initial compression unit, used to calculate a current compression ratio with a preset step value, and compress the original texture with the current compression ratio;
[0031] An enlargement unit, used for enlarging the compressed texture to the original size to obtain a compressed texture of the original size;
[0032] A compression ratio output unit is used to calculate the similarity between the original texture and the compressed texture of the original size; if the similarity is less than or equal to a preset similarity threshold, return to the initial compression unit to calculate the next compression ratio with a preset step value; if the similarity is greater than the preset similarity threshold, output the previous compression ratio as the target compression ratio;
[0033] A compression storage unit, used for compressing the original texture at a target compression ratio, and recording the target compression ratio into the texture header;
[0034] Texture display module, used to traverse the texture for display, including:
[0035] The original size acquisition unit is used to read the target compression ratio from the texture header and calculate the original size of the texture;
[0036] Texture drawing unit, used to draw textures at their original size and display them.
[0037] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned texture adaptive compression and display method for embedded devices are implemented.
[0038] The present invention also provides a computer program product, comprising a computer program, which implements the steps of the above-mentioned texture adaptive compression and display method for embedded devices when executed by a processor.
[0039] The above technical solution of the present invention has the following beneficial effects compared with the prior art:
[0040] The method for adaptively compressing and displaying textures of an embedded device described in the present invention compresses the original texture step by step, and adaptively obtains the compression ratio of the texture by calculating the similarity between the original texture and the compressed texture of the original size. Under the premise of not affecting the display effect of the texture image, the texture image is compressed to the maximum extent, and the storage space occupied by the texture image is reduced. Moreover, when displaying, there is no need to decode the image, and the adaptively compressed texture image is only enlarged to the original size at the target compression ratio in the form of parameters, thereby reducing the computing resources required for image display and reducing the display burden of the embedded device. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to make the content of the present invention more clearly understood, the present invention is further described in detail below according to specific embodiments of the present invention in conjunction with the accompanying drawings, wherein:
[0042] Figure 1 It is a flowchart for adaptively compressing an image;
[0043] Figure 2 is a schematic diagram of calculating the similarity between the original texture and the compressed texture of the original size;
[0044] Figure 3 It is a flowchart of displaying images on embedded devices;
[0045] Figure 4 This is a flow chart of the second embodiment for adaptively compressing an image after dividing it into blocks;
[0046] Figure 5 This is a flow chart of displaying segmented images by an embedded device in Embodiment 2. DETAILED DESCRIPTION
[0047] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0048] Embodiment 1
[0049] The present invention provides an embedded device texture adaptive compression and display method, comprising:
[0050] Reference Figure 1 As shown, traverse the texture for adaptive compression, including:
[0051] S1: Calculate the current compression ratio with a preset step value, and compress the original texture with the current compression ratio.
[0052] Since a preset step value that is too small will waste computing resources, and a value that is too large will make it difficult to achieve a suitable scaling effect, this embodiment has found through experiments that compressing the original texture to 50% to 25% usually does not affect the display effect of the texture. Therefore, this embodiment selects 0.05 to 0.1 as the preset step value.
[0053] S2: Enlarge the compressed texture to its original size to obtain a compressed texture of the original size.
[0054] Common embedded graphics systems have corresponding filtering algorithms, such as bilinear filtering, to smoothly process texture scaling.
[0055] At the same time, other filtering algorithms can also be used to compress textures, such as nearest neighbor interpolation, bilinear interpolation, and bicubic interpolation. Nearest neighbor interpolation is suitable for scenarios with low quality requirements and priority for processing speed, such as fast preview or pixel art. Bilinear interpolation is often used in general scenarios, such as real-time video scaling or general image processing, and can strike a balance between speed and quality. Bicubic interpolation: Suitable for scenarios with high quality requirements, such as printing, image editing tools (such as Photoshop), fine texture magnification, etc.
[0056] The specific code for compressing the original texture using bilinear interpolation and enlarging the compressed texture to the original size is as follows:
[0057]
[0058]
[0059] S3: Reference Figure 2 As shown, the similarity between the original texture and the compressed texture of the original size is calculated; if the similarity is less than or equal to the preset similarity threshold, return to S1 to calculate the next compression ratio with the preset step value; if the similarity is greater than the preset similarity threshold, output the previous compression ratio as the target compression ratio.
[0060] As long as the lower limit of the compression ratio can be determined, the image size can be reduced as much as possible without affecting people's viewing experience.
[0061] Preferably, the similarity between the original texture and the compressed texture of the original size is calculated using the Structural Similarity Index (SSIM). The Structural Similarity Index can detect the structural similarity between two images. SSIM takes into account the brightness, contrast and structural information of the image, so it can measure the visual quality of the image well, and is very sensitive to the degree of preservation of structure and texture, which is a factor that the human eye pays priority attention to when observing an image. Therefore, SSIM is suitable for evaluating the impact of different image processing techniques (such as compression, scaling, filtering, etc.) on image quality.
[0062] Preferably, the preset similarity threshold value ranges from 0.70 to 0.85. This is because the image representation quality within this threshold range is good. Although there may be a slight loss of details, the overall visual difference is difficult to detect. It is suitable for general image processing applications such as compression, scaling or video streaming.
[0063] S4: compress the original texture at a target compression ratio, and record the target compression ratio in the texture header.
[0064] Specifically, the process of performing adaptive compression in this embodiment includes:
[0065] Preprocess each texture on the PC or elsewhere. Select a preset step value, such as 0.5, and start from 0.95, use bilinear filtering or other filtering algorithms to reduce the width and height of the texture to 0.95 times the original size, and then enlarge it to the original size to obtain a compressed texture of the original size. Calculate the SSIM between the original texture and the compressed texture of the original size. If the similarity is less than or equal to the preset similarity threshold, it means that the compression ratio is acceptable, and then return to calculate the next compression ratio with the preset step value, such as 0.9; if the similarity is greater than the preset similarity threshold, it means that the compression ratio is unacceptable, and then output the previous compression ratio as the target compression ratio.
[0066] After calculating the target compression ratio, compress the texture to the target compression ratio and write it into the texture header.
[0067] The Python code to calculate the SSIM between the original texture and the compressed texture of the original size is as follows:
[0068]
[0069] The above score represents the structural similarity of the images, and the range is [0,1], where 1 means that the two images are exactly the same, and 0 means that they are completely different.
[0070] This embodiment also provides a method for calculating the similarity between the original texture and the compressed texture of the original size by using the peak signal-to-noise ratio. The Python code is as follows:
[0071]
[0072] If the target compression ratio is 0.9, the memory occupied by the texture is 0.9*0.9=81% of the original memory.
[0073] Reference Figure 3 As shown, traverse the texture for display, including:
[0074] Read the target compression ratio from the texture header and calculate the original size of the texture;
[0075] Draws the texture and displays it at its original size.
[0076] In summary, the method for adaptively compressing and displaying textures of embedded devices described in the present invention gradually compresses the original texture, and adaptively obtains the compression ratio of the texture by calculating the similarity between the original texture and the compressed texture of the original size. Under the premise of not affecting the display effect of the texture image, the texture image is compressed to the maximum extent, and the storage space occupied by the texture image is reduced. Moreover, when displaying, there is no need to consume additional embedded CPU computing resources for image decoding, and the adaptively compressed texture image is only enlarged to the original size at the target compression ratio in the form of parameters, thereby reducing the computing resources required for image display and reducing the display burden of the embedded device.
[0077] Furthermore, the method of the present invention can also be combined with other compression algorithms, such as PNG, to further reduce the space occupied by the image.
[0078] Embodiment 2
[0079] GPU is a computing unit dedicated to processing graphics. Common PC GPUs can process 3D models and render millions of triangles in parallel. Although the performance of embedded GPU devices is weaker than that of PC devices, they also have the function of processing images in parallel. With this function, images can be easily segmented, processed and rendered in blocks.
[0080] Therefore, this embodiment utilizes the function of GPU to process graphics in parallel to divide the original image into blocks, so as to further improve the effect of image adaptive compression, including:
[0081] Reference Figure 4 As shown, the original texture is divided into blocks, and each texture is traversed into blocks for adaptive compression, including:
[0082] S101: Calculating a current compression ratio of a current block with a preset step value, and compressing the texture of the current block with the current compression ratio;
[0083] S201: Enlarging the compressed block texture to the original block size to obtain a compressed block texture of the original block size;
[0084] S301: Calculate the similarity between the original texture and the compressed block texture of the original block size; if the similarity is less than or equal to a preset similarity threshold, return to S101 to calculate the next compression ratio of the current block with a preset step value; if the similarity is greater than the preset similarity threshold, output the previous compression ratio as the target compression ratio of the current block;
[0085] S401: compressing the current block texture at a target compression ratio, and recording the target compression ratio of the current block into the current block texture header;
[0086] Reference Figure 5 As shown, each texture is traversed in blocks and processed in parallel for display, including:
[0087] Read the target compression ratio of each block from the texture header of each block in parallel, and calculate the original size of each block in parallel;
[0088] Draw each tile texture in parallel at its original size and display it.
[0089] Preferably, the original texture may be divided into 8×8 blocks or 16×16 blocks.
[0090] Embodiment 3
[0091] Based on the method for adaptively compressing and displaying textures of an embedded device described in Embodiment 1, this embodiment provides an apparatus for adaptively compressing and displaying textures of an embedded device, including:
[0092] Texture compression module, used to traverse textures for adaptive compression, including:
[0093] An initial compression unit, used to calculate a current compression ratio with a preset step value, and compress the original texture with the current compression ratio;
[0094] An enlargement unit, used for enlarging the compressed texture to the original size to obtain a compressed texture of the original size;
[0095] A compression ratio output unit is used to calculate the similarity between the original texture and the compressed texture of the original size; if the similarity is less than or equal to a preset similarity threshold, return to the initial compression unit to calculate the next compression ratio with a preset step value; if the similarity is greater than the preset similarity threshold, output the previous compression ratio as the target compression ratio;
[0096] A compression storage unit, used for compressing the original texture at a target compression ratio, and recording the target compression ratio into the texture header;
[0097] Texture display module, used to traverse the texture for display, including:
[0098] The original size acquisition unit is used to read the target compression ratio from the texture header and calculate the original size of the texture;
[0099] Texture drawing unit, used to draw textures at their original size and display them.
[0100] This embodiment further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method for adaptively compressing and displaying textures of an embedded device are implemented.
[0101] This embodiment also provides a computer program product, including a computer program, which implements the steps of the embedded device texture adaptive compression and display method when executed by a processor.
[0102] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0103] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0104] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0105] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0106] Obviously, the above embodiments are merely examples for the purpose of clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived therefrom are still within the scope of protection of the present invention.
Claims
1. A texture adaptive compression and display method for embedded devices, characterized in that: include: Traverse the texture for adaptive compression, including: S1: Calculate the current compression ratio with a preset step value, and compress the original texture with the current compression ratio; S2: enlarge the compressed texture to its original size to obtain a compressed texture of the original size; S3: Calculate the similarity between the original texture and the compressed texture of the original size; if the similarity is less than or equal to the preset similarity threshold, return to S1 to calculate the next compression ratio with the preset step value; if the similarity is greater than the preset similarity threshold, output the previous compression ratio as the target compression ratio; S4: compress the original texture at a target compression ratio, and record the target compression ratio in the texture header; Traverse the texture for display, including: Read the target compression ratio from the texture header and calculate the original size of the texture; Draws the texture and displays it at its original size.
2. The method for adaptively compressing and displaying textures of an embedded device according to claim 1, characterized in that: The preset step value ranges from 0.05 to 0.
1.
3. The method for adaptively compressing and displaying textures of an embedded device according to claim 1, characterized in that: Methods for compressing raw textures include bilinear filtering, nearest neighbor interpolation, bilinear interpolation, and bicubic interpolation.
4. The method for adaptively compressing and displaying textures of an embedded device according to claim 1, characterized in that: The similarity between the compressed texture and the compressed texture of the original size is calculated using the structural similarity index or peak signal-to-noise ratio.
5. The method for adaptively compressing and displaying textures of an embedded device according to claim 1, characterized in that: The preset similarity threshold value ranges from 0.70 to 0.
85.
6. The method for adaptively compressing and displaying textures of an embedded device according to claim 1, characterized in that: Divide the original texture into blocks, traverse each texture block, and perform adaptive compression, including: S101: Calculating a current compression ratio of a current block with a preset step value, and compressing the texture of the current block with the current compression ratio; S201: Enlarging the compressed block texture to the original block size to obtain a compressed block texture of the original block size; S301: Calculate the similarity between the original texture and the compressed block texture of the original block size; if the similarity is less than or equal to a preset similarity threshold, return to S101 to calculate the next compression ratio of the current block with a preset step value; if the similarity is greater than the preset similarity threshold, output the previous compression ratio as the target compression ratio of the current block; S401: compressing the current block texture at a target compression ratio, and recording the target compression ratio of the current block into the current block texture header; Each tile traverses the texture and processes it in parallel for display, including: Read the target compression ratio of each block from the texture header of each block in parallel, and calculate the original size of each block in parallel; Draw each tile texture in parallel at its original size and display it.
7. The method for adaptively compressing and displaying textures of an embedded device according to claim 6, characterized in that: Divide the original texture into 8×8 blocks or 16×16 blocks.
8. An embedded device texture adaptive compression and display device, characterized in that: include: Texture compression module, used to traverse textures for adaptive compression, including: An initial compression unit, used to calculate a current compression ratio with a preset step value, and compress the original texture with the current compression ratio; An enlargement unit, used for enlarging the compressed texture to the original size to obtain a compressed texture of the original size; A compression ratio output unit is used to calculate the similarity between the original texture and the compressed texture of the original size; if the similarity is less than or equal to a preset similarity threshold, return to the initial compression unit to calculate the next compression ratio with a preset step value; if the similarity is greater than the preset similarity threshold, output the previous compression ratio as the target compression ratio; A compression storage unit, used for compressing the original texture at a target compression ratio, and recording the target compression ratio into the texture header; Texture display module, used to traverse the texture for display, including: The original size acquisition unit is used to read the target compression ratio from the texture header and calculate the original size of the texture; Texture drawing unit, used to draw textures at their original size and display them.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the texture adaptive compression and display method for an embedded device as claimed in any one of claims 1 to 7 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method for adaptively compressing and displaying textures of an embedded device as claimed in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Self-adaptive image compression method and system based on density clustering
CN116471412A