A method and system for compressing and encrypting pictures

By dividing the pictures into grid data graphs and rearranging them using boxing algorithms, the problem of low processing efficiency in transparent areas in the prior art is solved, and smaller picture size and resource security are achieved.

CN113963073BActive Publication Date: 2024-12-27YONGSHI WANGLUO
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111248210.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-26
Publication Date
2024-12-27
Estimated Expiration
2041-10-26

AI Technical Summary

Technical Problem

The existing image compression scheme is inefficient when dealing with transparent areas, resulting in the image size being still large after compression and cannot effectively avoid resource abuse.

Method used

By dividing the original image into grid data maps, identifying and cutting transparent meshes, re-arrange and combine pictures using boxing algorithms, smaller compressed images are generated, and texture locations are recorded for encryption and storage.

Benefits of technology

It effectively reduces the size of the image, increases the compression efficiency, and prevents image resources from being abused through encryption, and cannot be used directly even if forced extraction is performed on the user side.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113963073B_ABST
    Figure CN113963073B_ABST
Patent Text Reader

Abstract

The present invention provides a method and system for compressing and encrypting and saving pictures, including dividing the original picture into several grids according to certain rules to construct a grid data map of the original picture; checking the image transparency of each grid in the grid data map to find the transparent grid; in the grid data map, grids that do not contain transparent grids and are continuous in both horizontal and vertical directions are connected to form a rectangle, calculating the area of ​​each rectangle, taking out the rectangle with the largest area as a cut picture, and setting the grid where the taken rectangle is located as a transparent grid; based on the box packing algorithm, all the generated cut pictures are rearranged on the canvas in order from large to small and then combined to obtain a compressed picture. The compressed picture obtained by the method cannot be used directly even if it is forcibly extracted at the user end, thereby avoiding the abuse of picture resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of picture compression, and in particular to a method and system for compressing and encrypting pictures. Background Art

[0002] There are many different image compression schemes, such as ETC2 and ASTC. They all process the original image information with a certain algorithm and decode and restore the image information when used. We hope to do some processing on the original image before using these compression schemes to reduce the transparent area of ​​the original image, thereby reducing the size of the original image, and then compress it to get a smaller image. Summary of the invention

[0003] The present invention proposes a method and system for compressing and encrypting and saving pictures to solve the defects of the prior art mentioned above.

[0004] In one aspect, the present invention provides a method for compressing and encrypting a saved image, the method comprising the following steps:

[0005] S1: Divide the original image into a number of grids of equal size according to a certain rule to construct a grid data graph of the original image;

[0006] S2: Checking the image transparency of each grid in the grid data graph, if all pixels in the grid are transparent pixels, recording the grid as a transparent grid;

[0007] S3: In the grid data map, grids that do not contain transparent grids and are continuous in both horizontal and vertical directions are connected to form rectangles, the area of ​​each rectangle is calculated, the rectangle with the largest area is taken out as the cut picture, and the grid at the position of the taken out rectangle is set as a transparent grid, and this step is repeated until all grids in the grid data map are taken out;

[0008] S4: rearrange all the cut images generated in S3 in descending order on the canvas based on a binning algorithm, and then combine them to obtain a compressed image that is smaller than the original image;

[0009] S5: exporting the position information of each of the cut images after the rearrangement, acquiring and recording the texture position of each of the cut images according to the position information, thereby completing the encrypted storage of the original images.

[0010] The above method processes the image by filtering out the area with fewer transparent pixels in the original image, which can reduce the size of the original image, and then reassemble it into a new image by cutting and rearranging the image. An algorithm for filtering areas with fewer transparent pixels is provided, and a certain encryption effect is formed by reorganizing the pixel area. The image file obtained by compression and encryption using this method cannot be used directly even if it is forcibly extracted on the user side, thereby avoiding the abuse of image resources.

[0011] In a specific embodiment, the information including pixels in the grid is stored using a two-dimensional array.

[0012] In a specific embodiment, the checking of the image transparency of each grid in the grid data map specifically includes: traversing each pixel in each grid by traversing the two-dimensional array and determining whether the pixel is a transparent pixel.

[0013] In a specific embodiment, the S2 further includes: marking the data corresponding to the transparent grid in the two-dimensional array as empty, thereby indicating that the transparent grid is removed.

[0014] In a specific embodiment, if the cut picture exceeds a preset size range, the cut picture is split to obtain a plurality of rectangular pictures that meet the preset size range as the cut picture generated in S3.

[0015] In a specific embodiment, the specific steps of S4 include:

[0016] S401: Create a canvas and set the width range and height range of the canvas;

[0017] S402: placing the cut images upward in descending order starting from the lower left corner of the canvas;

[0018] S403: each time a cut picture is placed, the total height of the cut pictures placed at this time is calculated, and when the total height is greater than the height range, the cut picture placed last on the canvas is re-placed at the bottom on the right side adjacent to the original position;

[0019] S404: Continue to place the cut pictures according to the steps in S402-S403, and expand the size of the canvas during the placement process to accommodate the sizes of all the cut pictures placed in the canvas until all the cut pictures are placed in the canvas.

[0020] In a specific embodiment, two different data structures are constructed in the bin packing algorithm, namely a first data structure and a second data structure:

[0021] The first data structure is used to: record the starting position, the ending position and the height of the arrangement space of the cut picture in the canvas when the bin packing algorithm is running;

[0022] The second data structure is used to: describe and record information of the cut picture, wherein the information of the cut picture includes the width and height of the cut picture;

[0023] All values ​​of the first data structure are stored in a list for traversing the list when rearranging the cut pictures.

[0024] In a specific embodiment, the method further comprises the step of decoding the compressed image when rendering it:

[0025] When rendering the compressed image, the texture coordinates corresponding to each of the cut images and the pixels within the texture coordinate range are rendered according to the texture position, thereby restoring the original image.

[0026] According to a second aspect of the present invention, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a computer processor, the above method is implemented.

[0027] According to a third aspect of the present invention, a system for compressing and encrypting a picture is provided, the system comprising:

[0028] A grid data graph construction module: configured to divide the original image into a number of grids of equal size according to certain rules so as to construct a grid data graph of the original image;

[0029] A transparent pixel inspection module: configured to inspect the image transparency of each grid in the grid data map, and if all pixels in the grid are transparent pixels, the grid is recorded as a transparent grid;

[0030] Image cutting module: configured to form a rectangle in the grid data map by connecting grids that do not contain transparent grids and are continuous in both horizontal and vertical directions, calculate the area of ​​each rectangle, take out the rectangle with the largest area as the cut image, and set the grid at the position of the taken out rectangle as a transparent grid, and repeat this step until all grids in the grid data map are taken out;

[0031] An image reorganization module: configured to rearrange all the cut images generated by the image cutting module on the canvas in descending order based on a binning algorithm, and then combine them to obtain a compressed image smaller than the original image;

[0032] Image encryption storage module: configured to export the position information of each of the cut images after the rearrangement, obtain and record the texture position of each of the cut images according to the position information, so as to complete the encryption and storage of the original images.

[0033] The present invention divides the original image into several grids according to certain rules to construct a grid data map of the original image; checks the image transparency of each grid in the grid data map to find the transparent grid; in the grid data map, the grids that do not contain transparent grids and are continuous in both horizontal and vertical directions are connected to form a rectangle, calculate the area of ​​each rectangle, take out the rectangle with the largest area as the cut image, and set the grid where the taken rectangle is located as a transparent grid; based on the box packing algorithm, all the generated cut images are rearranged on the canvas in order from large to small and then combined to obtain a compressed image; the position information of each cut image after rearrangement is exported, and the texture position of each cut image is recorded. The compressed image obtained by this method cannot be used directly even if it is forcibly extracted at the user end, thereby avoiding the abuse of image resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The accompanying drawings are included to provide a further understanding of the embodiments and are incorporated into and constitute a part of this specification. The accompanying drawings illustrate the embodiments and together with the description are used to explain the principles of the present invention. Other embodiments and many expected advantages of the embodiments will be readily appreciated as they become better understood by reference to the following detailed description. Other features, objects and advantages of the present application will become more apparent by reading the detailed description of the non-limiting embodiments made with reference to the following drawings:

[0035] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;

[0036] Figure 2 It is a flow chart of a method for compressing and encrypting and saving a picture according to an embodiment of the present invention;

[0037] Figure 3 is a grid data diagram of a specific embodiment of the present invention;

[0038] Figure 4 is a grid data graph after removing the transparent grid according to a specific embodiment of the present invention;

[0039] Figure 5 is a schematic diagram of a process of searching for a rectangle in a grid data graph according to a specific embodiment of the present invention;

[0040] Figure 6 is a schematic diagram of image cutting according to a specific embodiment of the present invention;

[0041] Figure 7 This is a picture cutting result diagram of a specific embodiment of the present invention;

[0042] Figure 8 It is a data structure SkyLine of a specific embodiment of the present invention;

[0043] Fig. 9 It is a data structure Area of ​​a specific embodiment of the present invention;

[0044] Fig.10 is a schematic diagram of a packing algorithm process of a specific embodiment of the present invention;

[0045] Fig.11 is a compressed image result diagram of a specific embodiment of the present invention;

[0046] Fig.12 It is a framework diagram of a system for compressing and encrypting and saving pictures according to an embodiment of the present invention;

[0047] Fig.13 It is a structural diagram of a computer system suitable for implementing an electronic device of an embodiment of the present application. DETAILED DESCRIPTION

[0048] The present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It should also be noted that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.

[0049] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0050] Figure 1 An exemplary system architecture 100 is shown to which a method for compressing and encrypting and saving pictures according to an embodiment of the present application can be applied.

[0051] like Figure 1 As shown, the system architecture 100 may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0052] Users can use terminal devices 101, 102, 103 to interact with server 105 through network 104 to receive or send messages, etc. Various applications can be installed on terminal devices 101, 102, 103, such as data processing applications, data visualization applications, web browser applications, etc.

[0053] Terminal devices 101, 102, 103 can be hardware or software. When terminal devices 101, 102, 103 are hardware, they can be various electronic devices, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, etc. When terminal devices 101, 102, 103 are software, they can be installed in the electronic devices listed above. They can be implemented as multiple software or software modules (for example, software or software modules used to provide distributed services), or they can be implemented as a single software or software module. No specific limitation is made here.

[0054] The server 105 may be a server that provides various services, such as a background information processing server that provides support for the grid data images displayed on the terminal devices 101, 102, and 103. The background information processing server may process the obtained cut images and generate processing results (such as compressed images).

[0055] It should be noted that the method provided in the embodiment of the present application can be executed by the server 105, and can also be executed by the terminal devices 101, 102, 103. The corresponding device is generally set in the server 105, and can also be set in the terminal devices 101, 102, 103.

[0056] It should be noted that the server can be hardware or software. When the server is hardware, it can be implemented as a distributed server cluster consisting of multiple servers, or it can be implemented as a single server. When the server is software, it can be implemented as multiple software or software modules (for example, software or software modules used to provide distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.

[0057] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0058] According to an embodiment of the present invention, a method for compressing and encrypting a picture is provided. Figure 2 FIG. 1 is a flow chart showing a method for compressing and encrypting a picture according to an embodiment of the present invention. Figure 2 As shown, the method comprises the following steps:

[0059] S1: Divide the original image into a number of grids of equal size according to certain rules to construct a grid data graph of the original image.

[0060] In a specific embodiment, the information including pixels in the grid is stored using a two-dimensional array.

[0061] Figure 3-11 A simple graphical diagram is used to illustrate the complete process of image compression and encrypted storage in a specific embodiment. The process will be described in order below.

[0062] Figure 3 A grid data diagram of a specific embodiment of the present invention is shown, in which the pattern in the original image is represented by gray. In this embodiment, a square grid is taken as an example. First, we divide the image into a number of square grids according to certain rules. Assuming that the grid size is 32x32 and the original image size is 320x320, the following can be generated: Figure 3 The grid shown in the figure uses a two-dimensional array to store the information of each grid, where the white part represents the transparent grid.

[0063] S2: Check the image transparency of each grid in the grid data map, and if all pixels in the grid are transparent pixels, record the grid as a transparent grid.

[0064] In a specific embodiment, the checking of the image transparency of each grid in the grid data map specifically includes: traversing each pixel in each grid by traversing the two-dimensional array and determining whether the pixel is a transparent pixel.

[0065] In a specific embodiment, the S2 further includes: marking the data corresponding to the transparent grid in the two-dimensional array as empty, thereby indicating that the transparent grid is removed.

[0066] In a specific embodiment, the above method is specifically as follows:

[0067] Traverse the two-dimensional array, perform transparency check on each grid area, check each pixel in the grid, if they are all transparent, it means that the grid is transparent and can be removed; mark the data as empty in the two-dimensional array to indicate that the grid is removed. Figure 4 A grid data diagram after removing transparent grids according to a specific embodiment of the present invention is shown, which shows the two-dimensional array after removing the transparent grids, wherein gray represents the pattern in the original image, and dark gray represents the deleted transparent grids.

[0068] S3: In the grid data map, grids that do not contain transparent grids and are continuous in the horizontal and vertical directions are connected to form rectangles, the area of ​​each rectangle is calculated, the rectangle with the largest area is taken out as the cut image, and the grid at the position of the taken out rectangle is set as a transparent grid, and this step is repeated until all grids in the grid data map are taken out.

[0069] In a specific embodiment, if the cut picture exceeds a preset size range, the cut picture is split to obtain a plurality of rectangular pictures that meet the preset size range as the cut picture generated in S3.

[0070] Figure 5 A schematic diagram of a process of searching for a rectangle in a grid data graph according to a specific embodiment of the present invention is shown. In this embodiment, the process of searching for a rectangle is as follows:

[0071] Traverse each grid with pixels (i.e. not a transparent grid), try to search for grids in the horizontal and vertical directions, form a rectangle with adjacent grids, take out the rectangle with the largest area that can form a rectangle, and repeat the above steps until all grids are selected.

[0072] like Figure 5 , which simply shows the above search process:

[0073] Each grid is numbered 0 to 9 from left to right and from top to bottom. The rectangle searched from the 1-1 grid is the rectangle occupied by the lightest gray part in Figure 501; the rectangle searched from the 2-2 grid is the rectangle occupied by the lightest gray part in Figure 502;

[0074] Since the rectangle formed by 2-2 has a larger area, we choose this rectangle to form the first cropping range;

[0075] Then set a maximum width and maximum height, for example, set the maximum width and height to 128. When the width and height of the rectangle we screen exceeds this value, it will be split. If the split rectangle still exceeds 128x128, it will continue to be split in half until the split rectangles are all smaller than 128x128.

[0076] Finally, a rectangle composed of 2-2 will be split into Figure 6 The four rectangles;

[0077] After repeating the above operations, the entire image will be divided into multiple rectangular areas.

[0078] Figure 3 After the grid data graph in the above steps is cut, all the cut images obtained are as follows Figure 7 As shown, the cutting images in the figure have been sorted from large to small according to the area size.

[0079] S4: Based on a box packing algorithm, all the cut images generated by S3 are rearranged on the canvas in order from large to small, and then combined to obtain a compressed image that is smaller than the original image.

[0080] In a specific embodiment, the specific steps of S4 include:

[0081] S401: Create a canvas and set the width range and height range of the canvas;

[0082] S402: placing the cut images upward in descending order starting from the lower left corner of the canvas;

[0083] S403: each time a cut picture is placed, the total height of the cut pictures placed at this time is calculated, and when the total height is greater than the height range, the cut picture placed last on the canvas is re-placed at the bottom on the right side adjacent to the original position;

[0084] S404: Continue to place the cut pictures according to the steps in S402-S403, and expand the size of the canvas during the placement process to accommodate the sizes of all the cut pictures placed in the canvas until all the cut pictures are placed in the canvas.

[0085] In a specific embodiment, two different data structures are constructed in the bin packing algorithm, namely a first data structure and a second data structure:

[0086] The first data structure is used to: record the starting position, the ending position and the height of the arrangement space of the cut picture in the canvas when the bin packing algorithm is running;

[0087] The second data structure is used to: describe and record information of the cut picture, wherein the information of the cut picture includes the width and height of the cut picture;

[0088] All values ​​of the first data structure are stored in a list for traversing the list when rearranging the cut pictures.

[0089] according to Figure 7 The steps to rearrange the cut images using the binning algorithm are as follows:

[0090] Create a canvas and set the width and height to size, then start from the lower left corner and place the tiles upwards first, then to the right. When the height exceeds the expected image size, the tiles will be placed to the right.

[0091] To this end, we construct a data structure SkyLine to record the starting position, end position and height of the arrangement space. Figure 8 The data structure SkyLine of a specific embodiment of the present invention is shown;

[0092] At the same time, an Area data structure is constructed to describe the tiles. Fig. 9 The data structure Area of ​​a specific embodiment of the present invention is shown.

[0093] Fig.10 A schematic diagram of a bin packing algorithm process of a specific embodiment of the present invention is shown. The specific process of the bin packing algorithm in this embodiment is as follows:

[0094] Divide the canvas area by SkyLine and use the list Edges to store all SkyLines;

[0095] The initial Edges stores a SkyLine data with from=0, to=size, height=0;

[0096] When adding a tile Area, all SkyLine data in Edges will be traversed in turn, and the tile will be placed on top of the SkyLine;

[0097] If SkyLine.height+Area.height is greater than the canvas size, it means that the tile cannot be placed on top of the current SkyLine. At this time, the next SkyLine will be searched until a Skyline that can be placed is found. The current SkyLine will be split into two new Skylines based on the currently added tiles. When new tiles are added later, these SkyLines will be traversed again and the steps of the above packing algorithm will be executed;

[0098] If it can be placed, the current SkyLine will be split into two directly, which will be provided for subsequent new tiles to be added and used.

[0099] Similarly, when it is determined that the entire canvas cannot accommodate the cut block placed at this time, the canvas size will be expanded.

[0100] Figure 7 The final arrangement result of the compressed image shown is as follows Fig.11 As shown, we can see that the image we finally generated is much smaller than the original image.

[0101] S5: exporting the position information of each of the cut images after the rearrangement, acquiring and recording the texture position of each of the cut images according to the position information, thereby completing the encrypted storage of the original images.

[0102] In a specific embodiment, the method further comprises the step of decoding the compressed image when rendering it:

[0103] When rendering the compressed image, the texture coordinates corresponding to each of the cut images and the pixels within the texture coordinate range are rendered according to the texture position, thereby restoring the original image.

[0104] Fig.12 The framework diagram of a system for compressing and encrypting and storing pictures according to an embodiment of the present invention is shown. The system includes a grid data graph construction module 1201, a transparent pixel inspection module 1202, a picture cutting module 1203, a picture reorganization module 1204 and a picture encryption storage module 1205.

[0105] In a specific embodiment, the grid data graph construction module 1201 is configured to divide the original image into a number of grids of equal size according to a certain rule so as to construct a grid data graph of the original image;

[0106] The transparent pixel checking module 1202 is configured to check the image transparency of each of the grids in the grid data map, and if all pixels in the grid are transparent pixels, the grid is recorded as a transparent grid;

[0107] The image cutting module 1203 is configured to form a rectangle by connecting grids that do not contain transparent grids and are continuous in both horizontal and vertical directions in the grid data map, calculate the area of ​​each rectangle, take out the rectangle with the largest area as the cut image, and set the grid at the position of the taken out rectangle as a transparent grid, and repeat this step until all grids in the grid data map are taken out;

[0108] The picture reorganization module 1204 is configured to rearrange all the cut pictures generated by the picture cutting module on the canvas in a descending order based on a binning algorithm, and then combine them to obtain a compressed picture smaller than the original picture;

[0109] The picture encryption storage module 1205 is configured to export the position information of each of the cut pictures after the rearrangement, and obtain and record the texture position of each of the cut pictures according to the position information, so as to complete the encryption and storage of the original pictures.

[0110] This system divides the original image into several grids according to certain rules to construct a grid data map of the original image; checks the image transparency of each grid in the grid data map to find the transparent grid; in the grid data map, the grids that do not contain transparent grids and are continuous in both horizontal and vertical directions are connected to form a rectangle, calculate the area of ​​each rectangle, take out the rectangle with the largest area as the cut image, and set the grid where the taken rectangle is located as a transparent grid; based on the box packing algorithm, all the generated cut images are rearranged on the canvas in order from large to small and then combined to obtain a compressed image; the position information of each cut image after rearrangement is exported, and the texture position of each cut image is recorded. The compressed image obtained by this method cannot be used directly even if it is forcibly extracted on the user side, thereby avoiding the abuse of image resources.

[0111] Reference below Fig.13 , which shows a schematic diagram of the structure of a computer system 1300 suitable for implementing an electronic device of an embodiment of the present application. Fig.13 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0112] like Fig.13 As shown, the computer system 1300 includes a central processing unit (CPU) 1301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1302 or a program loaded from a storage part 1308 into a random access memory (RAM) 1303. In the RAM 1303, various programs and data required for the operation of the system 1300 are also stored. The CPU 1301, the ROM 1302, and the RAM 1303 are connected to each other via a bus 1304. An input / output (I / O) interface 1305 is also connected to the bus 1304.

[0113] The following components are connected to the I / O interface 1305: an input section 1306 including a keyboard, a mouse, etc.; an output section 1307 including a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 1308 including a hard disk, etc.; and a communication section 1309 including a network interface card such as a LAN card, a modem, etc. The communication section 1309 performs communication processing via a network such as the Internet. A drive 1310 is also connected to the I / O interface 1305 as needed. A removable medium 1311, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1310 as needed, so that a computer program read therefrom is installed into the storage section 1308 as needed.

[0114] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1309, and / or installed from the removable medium 1311. When the computer program is executed by the central processing unit (CPU) 1301, the above functions defined in the method of the present application are executed. It should be noted that the computer-readable storage medium described in the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, - but not limited to - an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more conductors, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable storage medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, device, or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wireless, wireline, optical cable, RF, etc., or any suitable combination of the foregoing.

[0115] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0116] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0117] The modules involved in the embodiments described in the present application may be implemented by software or hardware. The units described may also be arranged in a processor, and the names of these units do not constitute limitations on the units themselves in certain circumstances.

[0118] An embodiment of the present invention further relates to a computer-readable storage medium having a computer program stored thereon, which implements the method described above when the computer program is executed by a computer processor. The computer program includes program code for executing the method shown in the flowchart. It should be noted that the computer-readable medium of the present application may be a computer-readable signal medium or a computer-readable medium or any combination of the above two.

[0119] The present invention divides the original image into several grids according to certain rules to construct a grid data map of the original image; checks the image transparency of each grid in the grid data map to find the transparent grid; in the grid data map, the grids that do not contain transparent grids and are continuous in both horizontal and vertical directions are connected to form a rectangle, calculate the area of ​​each rectangle, take out the rectangle with the largest area as the cut image, and set the grid where the taken rectangle is located as a transparent grid; based on the box packing algorithm, all the generated cut images are rearranged on the canvas in order from large to small and then combined to obtain a compressed image; the position information of each cut image after rearrangement is exported, and the texture position of each cut image is recorded. The compressed image obtained by this method cannot be used directly even if it is forcibly extracted at the user end, thereby avoiding the abuse of image resources.

[0120] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.

Claims

1. A method for compressing and encrypting a picture, characterized in that: The following steps are involved: S1: Divide the original image into a number of grids of equal size according to a certain rule to construct a grid data graph of the original image; S2: Checking the image transparency of each grid in the grid data graph, if all pixels in the grid are transparent pixels, recording the grid as a transparent grid; S3: In the grid data map, grids that do not contain transparent grids and are continuous in both horizontal and vertical directions are connected to form rectangles, the area of ​​each rectangle is calculated, the rectangle with the largest area is taken out as the cut picture, and the grid at the position of the taken out rectangle is set as a transparent grid, and this step is repeated until all grids in the grid data map are taken out; S4: rearrange all the cut images generated in S3 on the canvas in descending order based on a binning algorithm, and then combine them to obtain a compressed image that is smaller than the original image; S5: exporting the position information of each of the cut images after the rearrangement, acquiring and recording the texture position of each of the cut images according to the position information, thereby completing the encrypted storage of the original images.

2. The method according to claim 1, characterized in that The information including pixels in the grid is stored using a two-dimensional array.

3. The method according to claim 2, characterized in that The checking of the image transparency of each grid in the grid data map specifically includes: traversing each pixel in each grid by traversing the two-dimensional array and determining whether the pixel is a transparent pixel.

4. The method according to claim 2, characterized in that: The S2 further includes: marking the data corresponding to the transparent grid in the two-dimensional array as empty, thereby indicating that the transparent grid is removed.

5. The method according to claim 1, characterized in that If the cut picture exceeds the preset size range, the cut picture is split to obtain a plurality of rectangular pictures that meet the preset size range as the cut picture generated in S3.

6. The method according to claim 1, characterized in that The specific steps of S4 include: S401: Create a canvas and set the width range and height range of the canvas; S402: placing the cut images upward in descending order starting from the lower left corner of the canvas; S403: each time a cut picture is placed, the total height of the cut pictures placed at this time is calculated, and when the total height is greater than the height range, the cut picture placed last on the canvas is re-placed at the bottom on the right side adjacent to the original position; S404: Continue to place the cut pictures according to the steps in S402-S403, and expand the size of the canvas during the placement process to accommodate the sizes of all the cut pictures placed in the canvas until all the cut pictures are placed in the canvas.

7. The method according to claim 1, characterized in that Two different data structures are constructed in the bin packing algorithm, namely the first data structure and the second data structure: The first data structure is used to: record the starting position, the ending position and the height of the arrangement space of the cut picture in the canvas when the bin packing algorithm is running; The second data structure is used to: describe and record information of the cut picture, wherein the information of the cut picture includes the width and height of the cut picture; All values ​​of the first data structure are stored in a list for traversing the list when rearranging the cut pictures.

8. The method according to claim 1, characterized in that: The method further comprises the step of decoding the compressed image when rendering it: When rendering the compressed image, the texture coordinates corresponding to each of the cut images and the pixels within the texture coordinate range are rendered according to the texture position, thereby restoring the original image.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a computer processor, the method according to any one of claims 1 to 8 is implemented.

10. A system for compressing and encrypting a picture, characterized in that: include: A grid data graph construction module: configured to divide the original image into a number of grids of equal size according to certain rules so as to construct a grid data graph of the original image; A transparent pixel inspection module: configured to inspect the image transparency of each grid in the grid data map, and if all pixels in the grid are transparent pixels, the grid is recorded as a transparent grid; Image cutting module: configured to form a rectangle in the grid data map by connecting grids that do not contain transparent grids and are continuous in both horizontal and vertical directions, calculate the area of ​​each rectangle, take out the rectangle with the largest area as the cut image, and set the grid at the position of the taken out rectangle as a transparent grid, and repeat this step until all grids in the grid data map are taken out; An image reorganization module: configured to rearrange all the cut images generated by the image cutting module on the canvas in descending order based on a binning algorithm, and then combine them to obtain a compressed image smaller than the original image; Image encryption storage module: configured to export the position information of each of the cut images after the rearrangement, obtain and record the texture position of each of the cut images according to the position information, so as to complete the encryption and storage of the original images.

Citation Information

Patent Citations

  • Method and device for generating image

    CN110675465A

  • Panoramic video image display method and display equipment

    CN112218132A