CN113971702A - Picture compression method, decompression method and electronic equipment - Google Patents
Picture compression method, decompression method and electronic equipment Download PDFInfo
- Publication number
- CN113971702A CN113971702A CN202111273611.XA CN202111273611A CN113971702A CN 113971702 A CN113971702 A CN 113971702A CN 202111273611 A CN202111273611 A CN 202111273611A CN 113971702 A CN113971702 A CN 113971702A
- Authority
- CN
- China
- Prior art keywords
- compressed
- data
- file
- byte length
- index
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000007906 compression Methods 0.000 title claims abstract description 92
- 230000006835 compression Effects 0.000 title claims abstract description 92
- 238000000034 method Methods 0.000 title claims abstract description 85
- 230000006837 decompression Effects 0.000 title claims abstract description 54
- 230000006870 function Effects 0.000 claims description 21
- 238000004422 calculation algorithm Methods 0.000 abstract description 9
- 238000013144 data compression Methods 0.000 abstract description 5
- 238000004364 calculation method Methods 0.000 abstract description 4
- 238000010586 diagram Methods 0.000 description 13
- 239000011159 matrix material Substances 0.000 description 6
- 230000008569 process Effects 0.000 description 5
- 238000004590 computer program Methods 0.000 description 4
- 230000009286 beneficial effect Effects 0.000 description 3
- 238000006243 chemical reaction Methods 0.000 description 3
- 230000002452 interceptive effect Effects 0.000 description 3
- 229920001621 AMOLED Polymers 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 239000010409 thin film Substances 0.000 description 2
- 230000009471 action Effects 0.000 description 1
- 238000004458 analytical method Methods 0.000 description 1
- 239000003086 colorant Substances 0.000 description 1
- 230000000295 complement effect Effects 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 239000010408 film Substances 0.000 description 1
- 239000003550 marker Substances 0.000 description 1
- 238000010295 mobile communication Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000003252 repetitive effect Effects 0.000 description 1
- 230000002441 reversible effect Effects 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T9/00—Image coding
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/10—File systems; File servers
- G06F16/17—Details of further file system functions
- G06F16/174—Redundancy elimination performed by the file system
- G06F16/1744—Redundancy elimination performed by the file system using compression, e.g. sparse files
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- General Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Compression, Expansion, Code Conversion, And Decoders (AREA)
Abstract
The invention relates to the technical field of data compression and decompression, and discloses a picture compression method, a decompression method and electronic equipment. The picture compression method comprises the following steps: the method comprises the steps of obtaining a picture file to be compressed, wherein the picture file to be compressed comprises data to be compressed, creating an initial compressed file, wherein the initial compressed file comprises a compressed data area, converting the data to be compressed into compressed data according to a preset compressed frame format and information of each pixel point in the data to be compressed, writing the compressed data into the compressed data area, and obtaining a final compressed file. In the embodiment, the pixel points to be compressed in the data to be compressed are compressed according to the preset compression frame format, so that lossless compression can be realized on the basis that the size of the compressed file is smaller than that of the file before compression; and because the compression algorithm is relatively simple, the calculation amount is small, and the performance requirement on a processing chip is low, the application range can be widened.
Description
Technical Field
The present invention relates to the field of data compression and decompression technologies, and in particular, to a picture compression method, a picture decompression method, and an electronic device.
Background
At present, in order to improve the usability of electronic products, a rich graphical interactive interface is generally provided in the electronic products. When the graphical interactive interface is provided, firstly, the picture files in various file formats (such as a bmp format, a jpg format and the like) are stored through the storage medium, then, the picture files stored in the storage medium are read through the main control chip, data of pictures to be displayed are transmitted to the display module, and the pictures are displayed through the display module, so that the graphical interactive interface is provided. When too many picture files are in the storage medium, the storage space is tense, and at the moment, the picture files are compressed and then stored, so that the storage space can be saved to a certain extent, and the capacity requirement on the storage medium is reduced.
Conventional mainstream file compression tools include RARs, ZIP, and the like. Generally, the compression algorithms used by these mainstream file compression tools are complex, and the requirements on the processor are high, so these file compression tools generally need to be run on a system platform, and cannot be run in some low-end electronic products (such as embedded electronic products), which has a disadvantage of narrow application range.
Disclosure of Invention
The embodiment of the invention provides a picture compression method, a decompression method and electronic equipment, which can solve the technical problem of narrow application range of compression calculation in the related technology.
The embodiment of the invention provides the following technical scheme for improving the technical problems:
in a first aspect, an embodiment of the present invention provides a picture compression method, including:
acquiring a picture file to be compressed, wherein the picture file to be compressed comprises data to be compressed;
creating an initial compressed file, wherein the initial compressed file comprises a compressed data area;
and converting the data to be compressed into compressed data according to a preset compressed frame format and the information of each pixel point in the data to be compressed, and writing the compressed data into the compressed data area to obtain a final compressed file.
In a second aspect, an embodiment of the present invention provides a decompression method, applied to a final compressed file as described above, where the decompression method includes:
determining an image file to be decompressed, wherein the image file to be decompressed is the final compressed file;
and converting the compressed data in the picture file to be decompressed into decompressed data according to a preset compressed frame format.
In a third aspect, an embodiment of the present invention provides an electronic device, including:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform a picture compression method as described above or a decompression method as described above.
The embodiment of the invention has the beneficial effects that: provided are a picture compression method, a decompression method and an electronic device. The picture compression method comprises the following steps: the method comprises the steps of obtaining a picture file to be compressed, wherein the picture file to be compressed comprises data to be compressed, creating an initial compressed file, wherein the initial compressed file comprises a compressed data area, converting the data to be compressed into compressed data according to a preset compressed frame format and information of each pixel point in the data to be compressed, writing the compressed data into the compressed data area, and obtaining a final compressed file. In the embodiment, the pixel points to be compressed in the data to be compressed are compressed according to the preset compression frame format, so that lossless compression can be realized on the basis that the size of the compressed file is smaller than that of the file before compression; and because the compression algorithm is relatively simple, the calculation amount is small, and the performance requirement on a processing chip is low, the application range can be widened.
Drawings
The embodiments are illustrated by way of example only in the accompanying drawings, in which like reference numerals refer to similar elements and which are not to be construed as limiting the embodiments, and in which the figures are not to scale unless otherwise specified.
Fig. 1 is a schematic structural diagram of a compression and decompression system according to an embodiment of the present invention;
fig. 2 is a schematic flowchart of a picture compression method according to an embodiment of the present invention;
FIG. 3 is a diagram illustrating a segment of data in a picture file to be compressed according to an embodiment of the present invention;
fig. 4 is a schematic flow chart of S23 shown in fig. 2;
fig. 5 is a schematic diagram of information of a pixel point read from a piece of data by an electronic device according to an embodiment of the present invention;
FIG. 6 is a diagram illustrating a default compressed frame format according to an embodiment of the present invention;
fig. 7 is a flowchart illustrating a decompression method according to an embodiment of the present invention;
fig. 8 is a schematic flow chart of S72 shown in fig. 7;
FIG. 9 is a diagram illustrating a segment of data in compressed data according to an embodiment of the present invention;
FIG. 10 is a schematic structural diagram of a picture compression apparatus according to an embodiment of the present invention;
FIG. 11 is a schematic diagram of another image compression apparatus according to an embodiment of the present invention;
fig. 12 is a schematic structural diagram of the first conversion module 103 shown in fig. 10;
fig. 13 is a schematic structural diagram of a decompression apparatus according to an embodiment of the present invention;
FIG. 14 is a schematic diagram of the second converting module 132 shown in FIG. 13;
fig. 15 is a schematic circuit diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that, if not conflicted, the various features of the embodiments of the invention may be combined with each other within the scope of protection of the invention. Additionally, while functional block divisions are performed in apparatus schematics, with logical sequences shown in flowcharts, in some cases, steps shown or described may be performed in sequences other than block divisions in apparatus or flowcharts. The terms "first", "second", "third", and the like used in the present invention do not limit data and execution order, but distinguish the same items or similar items having substantially the same function and action.
The picture compression method or decompression method provided herein is applicable to any suitable type of electronic device, such as computers, embedded devices, and the like.
Referring to fig. 1, fig. 1 is a schematic structural diagram of a compression and decompression system according to an embodiment of the present invention. As shown in fig. 1, the compression and decompression system includes an upper computer 100, a storage medium 200, a controller 300, and a display module 400.
The upper computer 100 is configured to compress an uncompressed picture file to obtain a compressed picture file.
In some embodiments, the upper computer 100 includes any computer or PC capable of directly issuing a control command, such as a computer, an industrial personal computer, a workstation, and the like.
The memory 200 is used for storing compressed picture files.
The controller 300 may read the compressed picture file from the storage medium 200 and decompress the compressed picture file to restore the compressed picture file to the picture file before compression.
In some embodiments, the controller 300 may be any general purpose processor, Digital Signal Processor (DSP), Application Specific Integrated Circuit (ASIC), Field Programmable Gate Array (FPGA), single chip, ARM (Acorn RISC machine) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination of these components. Also, the controller 300 may be any conventional processor, controller, microcontroller, or state machine. The controller 300 may also be implemented as a combination of computing devices, e.g., a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors in conjunction with a DSP, and/or any other such configuration.
The display module 400 is configured to receive data related to picture display transmitted by the controller 300, and display picture information according to the data.
In some embodiments, the display module 400 includes any type of touch screen or non-touch screen, such as a TFT screen (TFT Thin Film Transistor), a TFD screen (TFD Thin Film Diode), a UFB screen (Ultra Film Bright, UFB), an STN screen (Super-Twisted Nematic, STN), an OLED screen (Organic Light-Emitting Diode), an AMOLED screen (Active Matrix/Organic Light-Emitting Diode, led Active Matrix Organic Light-Emitting Diode), and so on.
Different from electronic devices based on a system platform, some electronic devices (e.g., embedded devices) with lower end have smaller configured storage capacity, and when the embedded devices need to store more file resources, the embedded devices occupy more storage space, which causes a risk of storage space shortage or even storage space shortage. In order to avoid insufficient memory space, a larger memory capacity can be configured, but this increases the hardware cost. In order to avoid the increase of hardware cost and fully utilize the limited storage capacity, compressing some file resources is a feasible way to relieve the problem of shortage of storage space. However, since the embedded device is a relatively low-end device, the configured processor has low performance, which makes the embedded device unable to smoothly run the traditional mainstream file compression tool that can only run on the system platform.
Based on this, the invention provides a picture compression method, which can be applied to lower-end electronic equipment, and the method can losslessly compress a pixel point set occupying a larger memory in a picture file into data occupying a frame and a frame with a smaller memory by using a preset compression frame format, and can realize lossless compression on the basis of compressing the size of the picture file. The method has the advantages of simple algorithm, small calculation amount and low requirement on the performance of the processor of the equipment, so the method has wide application range.
Based on the above-mentioned picture compression method, the following embodiments are proposed in the embodiments of the present invention, and it should be noted that the technical features related to the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other, and are not limited to the embodiments proposed below.
Referring to fig. 2, fig. 2 is a schematic flowchart illustrating a picture compression method according to an embodiment of the present invention. As shown in fig. 2, the picture compression method S200 includes, but is not limited to, the following steps:
and S21, acquiring the picture file to be compressed, wherein the picture file to be compressed comprises data to be compressed.
By way of example and not limitation, the picture file to be compressed refers to an uncompressed picture file that needs to be compressed. The picture file to be compressed can store the related information of the picture to be compressed according to a specific file format, and the file format determines the storage sequence and structure of the picture data in the file. The file format of the picture file to be compressed can comprise a plurality of different memory areas, and different information can be stored in different memory areas. The picture file to be compressed comprises data to be compressed, and the data to be compressed can be stored in a specific memory area in a file format. The data to be compressed is used for expressing the data containing all pixel point information in the picture file to be compressed.
S22, creating an initial compressed file, wherein the initial compressed file includes a compressed data area.
By way of example and not limitation, the initial compressed file is a file generated according to a preset file format, the preset file format may include a plurality of memory areas, and different memory areas may store different information. The initial compressed file includes a compressed data area, and the compressed data area may correspond to a specific memory area in a predetermined file format.
And S23, converting the data to be compressed into compressed data according to the preset compressed frame format and the information of each pixel point in the data to be compressed, and writing the compressed data into a compressed data area to obtain a final compressed file.
By way of example and not limitation, a pixel point refers to a minimum unit in an image represented by a numerical sequence, different pixel points are located at different positions in the image, each pixel point is assigned color value information, and one color value information is used for representing the color of the corresponding pixel point. The preset compressed frame format is a storage format capable of representing information of a plurality of pixel points in data to be compressed, that is, the preset compressed frame format can be used for carrying out data compression on a plurality of pixel points to be compressed to obtain data of one frame, and each frame of data is represented by using the preset compressed frame format.
The preset compressed frame format is a self-defined storage format, and the storage structure and the byte length of the preset compressed frame format can be freely set according to the service requirements. It can be understood that, if a plurality of pixels to be compressed are compressed into a frame of data using a predetermined compressed frame format, the byte length of the frame of data is less than or equal to the total byte length corresponding to the plurality of pixels before compression, because it is meaningful to perform data compression in such a case.
The compressed data refers to data obtained by compressing data to be compressed, and the compressed data comprises compressed data obtained by compressing pixel points to be compressed according to a preset compression frame format and original data reserved for the pixel points not to be compressed. The final compressed file is a file obtained by writing necessary data into all memory areas in the initial compressed file. The electronic equipment can read information of each pixel point of the data to be compressed and process each pixel point, determine pixel points meeting compression conditions and pixel points not meeting the compression conditions, compress the pixel points meeting the compression conditions according to a preset compression frame format to obtain compressed data, write the compressed data into a compressed data area, write data corresponding to the pixel points not meeting the compression conditions into the compressed data area, and after the electronic equipment finishes processing all the pixel points of the data to be compressed, the data compression process is finished, and a final compressed file is generated.
Therefore, in the embodiment, the pixel points to be compressed in the data to be compressed are compressed according to the preset compression frame format, so that lossless compression can be realized on the basis that the size of the compressed file is smaller than that of the file before compression. Compared with the traditional mainstream compression algorithm, the compression algorithm used in the embodiment is relatively simple, the calculated amount is small, and the requirement on a processing chip is low.
In some embodiments, the initial compressed file further includes a file information area, a file index area, and a compressed data length area, and S200 further includes, but is not limited to, the following steps:
and acquiring file information of the picture file to be compressed, and writing the file information into a file information area.
In this embodiment, the file information is used to describe various file information of the picture file to be compressed, such as occupied memory size information, width information, height information, horizontal resolution information, vertical resolution information, and the like of the picture to be compressed. The file information is located at a specific position of the data storage format of the picture to be compressed, and occupies a certain byte length. For example, the picture file to be compressed is a BMP (Bitmap) picture file, and assuming that the BMP picture file does not include a palette, the file format of the BMP picture file is a Bitmap file header having a length of 14 bytes, a Bitmap information header having a length of 40 bytes, and color dot matrix data. The bitmap file header and the bitmap information header are used as file information for describing various file information of the BMP picture file. The color dot matrix data is used for describing all pixel point information of the BMP picture. The electronic equipment can read the data of the BMP picture file according to bytes, read the data of the first 54 bytes to obtain the file information of the BMP picture file, and write the file information into the file information area of the initial compressed file.
And determining a compressed file index, and writing the compressed file index into a file index area.
By way of example and not limitation, the compressed file index serves as a compression marker for the final compressed file. If a compressed file has a compressed file index, it indicates that the compressed file is the final compressed file obtained by using the picture compression method provided by the present invention, so that when a subsequent electronic device decompresses a file to be decompressed, it can be determined whether the file to be decompressed needs to be decompressed by a corresponding decompression algorithm by identifying the compressed file index, that is, if the compressed file index is identified from the file to be decompressed, it indicates that the file to be decompressed is the final compressed file obtained by using the picture compression method provided by the present invention, and at this time, the final compressed file needs to be decompressed by a corresponding decompression algorithm to correctly restore the data before compression.
And calculating the total byte length of the compressed data, and writing the information of the total byte length of the compressed data into the compressed data length area.
In this embodiment, the information of the total byte length of the compressed data can be used as a condition for whether the subsequent decompression of the compressed data is completed. When the electronic device decompresses the compressed data, the processed data amount for processing the compressed data is continuously accumulated, and if the byte length corresponding to the processed data amount reaches the total byte length of the compressed data, it indicates that the compressed data is processed, and at this time, the decompression operation can be quitted.
It is understood that the file format of the final compressed file may include file information, a compressed file index, a total byte length of the compressed data, and the compressed data.
In some embodiments, although the compressed data is obtained by converting the data to be compressed, some of the compressed data is data that is not converted according to the preset compressed frame format, and the data is written into the compressed data area as it is. If the data includes a segment of data that is the same as the compressed file index, the electronic device may mistakenly process the segment of data that is the same as the compressed file index through a decompression algorithm during subsequent decompression, and finally the decompressed data is inconsistent with the data before compression, resulting in data confusion. In some embodiments, the electronic device may select a compressed file index that is different from any segment of data with the same byte length in the file to be compressed, so as to avoid the situation of data confusion during decompression.
In some embodiments, a compressed file index is determined, and the step of writing the compressed file index to the file index area includes, but is not limited to, the steps of:
a compressed file index having a first predetermined byte length is selected.
In the present embodiment, a compressed file index table is created in advance and the compressed file index is stored in the memory. The compressed file index table includes a plurality of compressed file indexes having the same byte length but different data. The electronic device may retrieve the table of compressed file indices from the memory and select one of the compressed file indices therefrom. The byte length of the compressed file index can be freely set according to the service requirement. In some embodiments, the first predetermined byte length is 5 bytes in length.
And judging whether the compressed file index exists in the picture file to be compressed or not.
In this embodiment, the electronic device may compare two segments of data with the same byte length through any suitable function, that is, compare the data segment of the selected compressed file index with the data segment of the picture file to be compressed, which is consistent with the byte length of the selected compressed file index. For example, if the selected compressed file index is 5 bytes long, any data segment occupying 5 bytes in the picture file to be compressed needs to be acquired. If the comparison result indicates that the data of the two data segments are the same, the selected compressed file index is indicated to be in the picture file to be compressed, and if the comparison result indicates that the data of the two data segments are different, the selected compressed file index is indicated not to be in the picture file to be compressed.
If the compressed file index exists in the picture file to be compressed, one compressed file index is continuously selected, and the step of judging whether the compressed file index exists in the picture file to be compressed is repeated.
In this embodiment, if the selected compressed file index exists in the picture file to be compressed, the compressed file index is invalid, a new compressed file index different from the previously selected compressed file index needs to be continuously selected, whether the new compressed file index exists in the picture file to be compressed is determined, and the process is continuously repeated until the currently selected compressed file index does not exist in the picture file to be compressed.
And if the compressed file index does not exist in the picture file to be compressed, writing the selected compressed file index into a file index area.
In this embodiment, if the currently selected compressed file index does not exist in the picture file to be compressed, it indicates that the currently selected compressed file index is valid, and the currently selected compressed file index can be written into the file index area.
Therefore, in the embodiment, a compressed file index is selected as a compression mark, and the compressed file index is different from any segment of the picture file to be compressed and data with the same byte length as the segment of the picture file to be compressed, so that the condition of data confusion during decompression can be avoided.
In some embodiments, the step of determining whether the compressed file index exists in the picture file to be compressed includes, but is not limited to, the steps of:
and intercepting all data segments with the length equal to the first preset byte length of the compressed file index in the picture file to be compressed.
For example, referring to fig. 3, fig. 3 is a section of data in a picture file to be compressed. As shown in fig. 3, the piece of data includes 7 pieces of data with a length of 1 byte, i.e., a1, a2, A3, a4, A5, A6, and a7, and assuming that the first preset byte length is 5 bytes, the electronic device reads the piece of data in order by bytes, and respectively intercepts a data segment composed of a1, a2, A3, a4, and A5, a data segment composed of a2, A3, a4, A5, and A6, and a data segment composed of A3, a4, A5, A6, and a 7.
And judging whether the character strings of the data segments are the same as the character strings of the compressed file indexes or not according to the comparison function.
In this embodiment, the comparison function is used to compare the character strings of two data segments, the character strings of two data segments have the same byte length, and during the comparison, it is determined whether the character strings of two data segments are the same according to the return value. Because the character strings of the data segments and the character strings of the compressed file index have the same byte length, the electronic equipment can compare the character strings of the data segments and the character strings of the compressed file index according to a comparison function and judge whether the character strings of the two segments of data are the same according to a comparison result.
The example is given by taking the comparison function as the memcmp () function. The memcmp () function is used to compare the first n characters of the memory interval indicated by the parameters s1 and s 2. It is assumed that the first n characters of the memory interval pointed by the parameter s1 correspond to the character string of each intercepted data segment, and the first n characters of the memory interval pointed by the parameter s2 correspond to the character string of the compressed file index. In comparing the two strings, the memcmp () function first subtracts the value of the first character of argument s2 from the value of the first character of argument s1, continues to compare the next character if the difference is 0, and returns the difference if the difference is not 0. Then, if the characters of the two character strings are identical, a value of 0 is returned, and if one character string is larger than the other character string, a value larger than 0 or a value smaller than 0 is returned, so that it is possible to determine whether the character string of each data segment is identical to the character string of the compressed file index, based on the return value of the memcmp () function.
And if the character string of each data segment is the same as that of the compressed file index, judging that the compressed file index exists in the picture file to be compressed.
If the character string of the compressed file index is the same as the character strings of one or more data segments in the character strings of all the intercepted data segments, it indicates that the image file to be compressed has data which is the same as the compressed file index.
And if the character string of each data segment is different from the character string of the compressed file index, judging that the compressed file index does not exist in the picture file to be compressed.
If the character string of the compressed file index is different from the character strings of all the intercepted data segments, it indicates that the same data as the compressed file index does not appear in the picture file to be compressed, and at this time, the compressed file index can be directly written into the file index area as a compression mark.
In some embodiments, referring to fig. 4, S23 includes, but is not limited to, the following steps:
s231, sequentially acquiring the information of each pixel point according to the arrangement sequence of each pixel point of the data to be compressed.
In this embodiment, the bytes occupied by each pixel point in the data to be compressed are consistent, and the pixel points are arranged in sequence in the data to be compressed. The information of the pixel points refers to color value information of the pixel points, and if the color value information of the two pixel points is consistent, it is indicated that the colors expressed by the two pixel points are also consistent, and the two pixel points are the same pixel points. The electronic equipment can read the data to be compressed according to bytes so as to obtain the color value information of each pixel point.
For example, the picture file to be compressed is a BMP picture file. If the BMP picture file is 16-bit, 24-bit or 32-bit color, the BMP picture file does not include a color palette, and the file format of the BMP picture file is a bitmap file header, a bitmap information header and color dot matrix data, and if the BMP picture file in the format is compressed, the color dot matrix data is to-be-compressed data. The color of the image of the BMP picture file adopting the file format is directly given in the color dot matrix data. The BMP picture files have different image bit numbers, and the byte lengths of all pixel points used for storing color value information are different. For example, a 16-bit image uses 2 bytes to hold color value information, a 24-bit image uses 3 bytes to hold color value information, and a 32-bit image uses 4 bytes to hold color value information. Assuming that the picture file to be compressed is a 24-bit image, each pixel point in the data to be compressed occupies 3 bytes in length, and each byte represents one color and is arranged according to red, green and blue. It should be noted that there may be 0-complement data in the data to be compressed, where the 0-complement data is data that is convenient for reading data and does not represent color value information. For example, the Windows system reads each row of data according to 4 bytes, and if the row of data is less than a multiple of 4 bytes, the row is complemented by 0 bytes, and the row complement bit is performed. For example, a row of color has two pixels occupying 6 bytes, and if 4 × 2 is to be filled, 8 bytes, two more 0 bytes are needed after the two pixels. Therefore, when the electronic device processes the data to be compressed with the 0 complementing data, the data is read according to the bytes, and then the invalid 0 complementing data is identified and skipped over to correctly read the information of each pixel point.
S232, determining each repeated pixel unit according to the information of each pixel point in the data to be compressed, wherein each repeated pixel unit comprises a plurality of continuous and same pixel points.
In this embodiment, it is assumed that each pixel occupies 3 bytes, the electronic device reads data by byte, and acquires information of one pixel every time 3 bytes are read, and if the information of the previous pixel is the same as the information of the next pixel, takes more than two pixels that are the same as each other as consecutive and same pixels. For example, referring to fig. 5, fig. 5 shows information of a pixel point read from a segment of data by an electronic device. Assuming that the information of two pixel points, B2 and B3, is the same, and the information of four pixel points, B5, B6, B7 and B8, is the same, the two pixel points, B2 and B3, are consecutive and the same pixel points, and the four pixel points, B5, B6, B7 and B8, are also consecutive and the same pixel points.
By way of example and not limitation, a repeating pixel unit refers to a plurality of consecutive and identical pixel points that satisfy a compression condition. This is illustrated by way of example in fig. 5. If two identical pixel points, namely B2 and B3, do not meet the compression condition, the two identical pixel points, namely B2 and B3, are not determined as the repeated pixel units as a whole, and if four identical pixel points, namely B5, B6, B7 and B8, meet the compression condition, the four identical pixel points, namely B5, B6 and B7B 8, are taken as the repeated pixel units as a whole.
And S233, compressing each repeated pixel unit into a data frame according to a preset compression frame format to obtain compressed data.
In this embodiment, the electronic device compresses a plurality of pixel points each determined as a repeating pixel unit into one data frame using a preset compressed frame format and writes the data into a compressed data region, and writes original data of pixel points not determined as a repeating pixel unit into a compressed data region. This is illustrated by way of example in fig. 5. In fig. 5, only four identical pixel points B5, B6, B7, and B8 are entirely repetitive pixel units, and then the electronic device writes information of the four pixel points B1, B2, B3, and B4 into a compressed data area as it is, compresses the four identical pixel points B5, B6, B7, and B8 into a data frame according to a preset compressed frame format, and writes the data frame into an area following the information of the pixel point B4 in the compressed data area.
It can be understood that the byte length corresponding to each repeating pixel unit is necessarily greater than or equal to the byte length corresponding to the preset compressed frame format, which ensures that the memory occupied by the compressed data is less than the memory occupied by the data before compression. For example, if the predetermined compressed frame format occupies 10 bytes, the length of the byte corresponding to the repeating pixel unit is greater than or equal to 10 bytes. Therefore, if there are many continuous and identical pixel points in the picture file to be compressed, these pixel points only need to be compressed according to a preset compression frame format occupying a very small byte length, and a considerable compression ratio can be obtained.
In some embodiments, referring to fig. 6, the predetermined compressed frame format includes a compressed frame index of a second predetermined byte length, information of a repetition number of a third predetermined byte length, and information of a repetition pixel of a fourth predetermined byte length, where the repetition number is the number of pixels in each repetition pixel unit, and the repetition pixel is each pixel in each repetition pixel unit.
In this embodiment, after determining a repeat pixel unit, the electronic device stores the number information of the repeat pixel unit and the information of one pixel point in the repeat pixel unit according to a preset compressed frame format, so that the information stored in the preset compressed frame format includes information of all pixel points in the repeat pixel unit, thereby implementing lossless compression.
The compressed frame index is used as a decompression flag of a certain data frame during subsequent decompression. If a data frame contains a compressed frame index, the data frame needs to be decompressed, and if a data frame does not contain a compressed frame index, the data frame is directly used.
And the second preset byte length, the third preset byte length or the fourth preset byte length can be freely set according to the service requirement. In some embodiments, the second predetermined byte length is 5 bytes long, the third predetermined byte length is 2 bytes long, and the fourth predetermined byte length is 3 bytes long.
It is worth noting that the data of the compressed frame index is consistent with the data of the compressed file index. After the electronic equipment selects an effective compressed file index, the data of the compressed file index is stored in a preset compressed frame format established in advance as a compressed frame index.
In some embodiments, S232 includes, but is not limited to, the following steps:
and determining continuous and same pixel points according to the comparison function and the information of each pixel point.
As an example but not limited to, the electronic device compares whether the information of the previous pixel is consistent with the information of the next pixel through a comparison function, if the information of the two pixels is consistent, it indicates that the two pixels are the same, and then continues to compare with the information of the next pixel until different pixels appear, at this time, the electronic device determines the adjacent pixels with consistent information as continuous and same pixels.
And judging whether the byte length corresponding to the continuous and same pixel points is greater than or equal to the byte length of the preset compressed frame format.
In this embodiment, the electronic device calculates the byte length corresponding to the continuous and same pixel points according to the number of the continuous and same pixel points and the byte length occupied by each pixel point, and then compares the byte length with the byte length in the preset compressed frame format.
And if the byte length corresponding to the continuous and same pixel points is greater than or equal to the byte length of the preset compressed frame format, determining the continuous and same pixel points as a repeated pixel unit.
In this embodiment, if the byte length corresponding to the continuous and same pixel points is greater than or equal to the byte length of the preset compressed frame format, it indicates that the continuous and same pixel points satisfy the compression condition, and it is necessary to use the continuous and same pixel points as the repeated pixel units and compress the pixel units according to the preset compressed frame format.
And if the byte length corresponding to the continuous and same pixel points is less than the byte length of the preset compressed frame format, the continuous and same pixel points are not determined as the repeated pixel units.
In this embodiment, if the byte length corresponding to the continuous and same pixel points is smaller than the byte length of the preset compressed frame format, it indicates that the continuous and same pixel points do not satisfy the compression condition, and the original data is directly used without compressing the same pixel points.
In some embodiments, the total byte length of the compressed data is calculated, and the step of writing information of the total byte length of the compressed data into the compressed data length area includes, but is not limited to, the steps of:
and calculating the first byte length corresponding to the data to be compressed.
As an example and not by way of limitation, the electronic device first determines a total byte length corresponding to the entire picture file to be compressed, then obtains byte lengths corresponding to the remaining data except the data to be compressed, and finally subtracts the byte lengths corresponding to the remaining data from the total byte length to obtain a first byte length corresponding to the data to be compressed. For example, the picture file to be compressed is a BMP picture file, and the file format of the BMP picture file includes a bitmap file header of 14 bytes, a bitmap information header of 40 bytes, and data to be compressed, so that the electronic device may subtract 56 bytes from the total byte length corresponding to the BMP picture file to obtain a byte length corresponding to the data to be compressed.
And calculating the length of a second byte corresponding to the processed data size for processing the data to be compressed.
In this embodiment, since the electronic device reads the data to be compressed according to bytes, each time the electronic device finishes processing one data, the electronic device may add the byte length of the currently processed data to the byte lengths corresponding to all the previously processed data to obtain the second byte length.
It is determined whether the second byte length is equal to the first byte length.
If the second byte length is equal to the first byte length, calculating the total byte length of the compressed data, and writing the information of the total byte length into the compressed data length area.
In this embodiment, if the second byte length is equal to the first byte length, it indicates that the data to be compressed has been completely processed, and the compressed data has been obtained, at this time, the electronic device may calculate the total byte length corresponding to the compressed data.
If the second byte length is not equal to the first byte length, returning to the step of calculating the second byte length corresponding to the processed data volume for processing the data to be compressed.
In this embodiment, if the second byte length is not equal to the first byte length, it indicates that the data to be compressed is not processed completely, and the whole compressed data is not obtained, so that the data to be compressed needs to be processed continuously at this time, and the second byte length corresponding to the current processed data amount is continuously calculated until the second byte length corresponding to the current processed data amount is equal to the first byte length.
In some embodiments, the compressed data length region occupies 4 bytes in length.
In order to decompress the final compressed file obtained by the above-mentioned picture compression method and correctly restore the picture file before the final compressed file is compressed, an embodiment of the present invention provides a decompression method, which is applied to the final compressed file as described above.
Referring to fig. 7, fig. 7 is a flowchart illustrating a decompression method according to an embodiment of the present invention. As shown in fig. 7, the decompression method S700 includes, but is not limited to, the following steps:
and S71, determining the picture file to be decompressed, wherein the picture file to be decompressed is a final compressed file.
In this embodiment, since the decompression method can only decompress the final compressed file obtained by the above-described image compression method, when the electronic device decompresses the image file to be processed, it is necessary to determine whether the image file to be processed is the final compressed file, if so, the image file to be processed needs to be decompressed, and if not, the image file to be processed is not decompressed.
And S72, converting the compressed data in the picture file to be decompressed into decompressed data according to a preset compressed frame format.
In this embodiment, the electronic device reads data of one frame by one frame according to bytes, and since the data to be compressed may include a data frame that does not need to be decompressed and a data frame that needs to be decompressed, the electronic device needs to determine whether the currently processed data frame needs to be decompressed, if so, decompress the data frame according to a preset compression frame format, and if not, directly use the data of the data frame itself.
Because the pixel points to be compressed in the data to be compressed are subjected to lossless compression according to the preset compression frame format, the information of each pixel point before compression can be restored in a lossless manner by performing reverse lossless analysis on the pixel point information stored in the picture file to be decompressed according to the preset compression frame format.
In some embodiments, S71 includes, but is not limited to, the following steps:
and acquiring a picture file to be processed.
By way of example and not limitation, the pending picture file is a picture file that has been compressed.
And judging whether the picture file to be processed has a compressed file index or not.
In this embodiment, the electronic device needs to read data of a to-be-processed picture file, and determine whether a specified memory area in the data has a compressed file index area. If the specified memory area has a compressed file index area, it is determined that a compressed file index necessarily exists in the data, that is, a compressed file index necessarily exists in the picture file to be processed.
And if the picture file to be processed has the compressed file index, determining that the picture file to be processed is the picture file to be decompressed.
In this embodiment, if the electronic device determines that the compressed file index exists in the to-be-processed picture file, it indicates that the to-be-processed picture file is obtained by compressing according to the picture compression method as described above, and at this time, the to-be-processed picture file may be decompressed by using a matching decompression method.
And if the picture file to be processed does not have the compressed file index, determining that the picture file to be compressed is not the picture file to be decompressed.
In this embodiment, if the electronic device determines that the compressed file index does not exist in the to-be-processed picture file, it indicates that the to-be-processed picture file is not compressed according to the picture compression method described above, and at this time, the to-be-processed picture file is not decompressed, and the decompression operation is directly exited.
In some embodiments, referring to fig. 8, S72 includes, but is not limited to, the following steps:
and S721, sequentially acquiring each data frame of the compressed data according to the arrangement sequence of each data frame in the compressed data.
In this embodiment, the byte lengths occupied by different data frames may be the same or different. For example, FIG. 9 is a segment of data in compressed data. As shown in fig. 9, the segment of data includes 5 data frames C1, C2, C3, C4 and C5, wherein each of the data frames C1, C2, C3 and C5 is a data frame that is not compressed using a preset compressed frame format, each of the data frames occupies 3 bytes in length, and the data frame C4 is a data frame processed using a preset compressed frame format, and occupies 10 bytes in length. The electronic equipment reads each data frame in turn according to the arrangement sequence of the data frames in the segment of data, namely reads 5 data frames of C1, C2, C3, C4 and C5 in turn.
And S722, judging whether the current data frame has a compressed frame index.
In this embodiment, if the current data frame is data compressed according to a preset compressed frame format, the electronic device is inevitably capable of identifying a compressed frame index from a specific position in the current data frame, and if the current data frame is not data compressed according to the preset compressed frame format, the electronic device is inevitably incapable of identifying a compressed frame index from a specific position in the current data frame.
And S723, if the current data frame has the compressed frame index, decompressing the current data frame according to a preset compressed frame format.
In this embodiment, if the current data frame is data obtained by compressing according to a preset compressed frame format, the current data frame needs to be reversely analyzed according to the preset compressed frame format to obtain data of each pixel point before the current data frame is compressed.
And S724, if the compressed frame index does not exist in the current data frame, keeping the current frame data.
In this embodiment, if the current data frame is data obtained without being compressed according to the preset compressed frame format, the current data frame does not need to be reversely analyzed according to the preset compressed frame format, and the current data frame is directly reserved.
In some embodiments, S722 includes, but is not limited to, the steps of:
and acquiring data of a specified position in the current data frame.
As described above, the predetermined compressed frame format includes the compressed file index of the second predetermined byte length, the information of the number of repetitions of the third predetermined byte length, and the information of the repetition pixel point of the fourth predetermined byte length. Therefore, if the compressed frame index exists in the data at the specified position (the first few bytes with the length equal to the second preset byte length) in the current data frame, it indicates that the compressed frame index exists in the current data frame, and otherwise, it indicates that the compressed frame index does not exist in the current data frame.
As described above, the data of the compressed frame index and the data of the compressed file index are consistent, so the electronic device may compare the previously acquired data of the compressed file index with the data at the specified position in each data frame to determine each data frame with the compressed frame index.
And judging whether the character string of the data at the specified position is the same as the character string of the compressed frame index or not according to the comparison function.
In this embodiment, the comparison function is used to compare the character strings of the two data segments, the character strings of the two data segments have the same byte length, and during the comparison, it is determined whether the character strings of the two data segments are the same according to the return value.
In some embodiments, the comparison function is a memcmp () function that compares, in bytes, a byte in a string of data at a specified position with a corresponding byte in a string of compressed file indices, returns a value of 0 if the characters of both strings are identical, and returns a value of more than 0 or less than 0 if one string is larger than the other string, so that whether each character in the string of data at the specified position is identical to each character in the string of compressed frame indices can be specified according to the return value of the memcmp () function.
And if the character string of the data at the specified position is the same as the character string of the compressed frame index, judging that the compressed frame index exists in the current frame data.
If the character string of the data at the designated position is the same as the character string of the compressed frame index, it indicates that the current data frame is the data obtained after being compressed according to the preset compressed frame format, and at this time, the current data frame needs to be decompressed.
And if the character string of the data at the designated position is not the same as the character string of the compressed frame index, judging that the compressed frame index does not exist in the current frame data.
If the character string of the data at the designated position is different from the character string of the compressed frame index, the current data frame is the data which is obtained after the data is not compressed according to the preset compressed frame format, and the current data frame is directly reserved at the moment.
In some embodiments, S700 further includes, but is not limited to, the steps of:
and acquiring a third byte length corresponding to a compressed data length area in the picture to be decompressed.
In the present embodiment, the third byte length refers to byte length information of compressed data stored in the compressed data length area. The electronic equipment reads the data of the picture file to be compressed, intercepts the data in the compressed data length area in the picture file to be compressed, and acquires the third byte length information according to the data in the compressed data length area.
A fourth byte length corresponding to a processed data amount for processing the compressed data is calculated.
In this embodiment, since the electronic device reads the compressed data by byte, each time the electronic device finishes processing one data frame, the byte length of the currently processed data frame may be added to the byte lengths corresponding to all the previously processed data frames to obtain the fourth byte length.
It is determined whether the fourth byte length is equal to the third byte length.
And if the fourth byte length is equal to the third byte length, the decompression is exited.
In this embodiment, if the fourth byte length is equal to the third byte length, it indicates that the compressed data has been completely processed, and the decompressed data has been obtained, and then the decompression can be exited.
And if the fourth byte length is not equal to the third byte length, returning to the step of calculating the fourth byte length corresponding to the processed data amount for processing the compressed data.
In this embodiment, if the fourth byte length is not equal to the third byte length, it indicates that the compressed data is not processed completely, and therefore, at this time, the compressed data needs to be processed continuously, and the fourth byte length corresponding to the currently processed data amount is continuously calculated until the fourth byte length corresponding to the currently processed data amount is equal to the third byte length.
It should be noted that, in the foregoing embodiments, a certain order does not necessarily exist between the foregoing steps, and those skilled in the art can understand, according to the description of the embodiments of the present invention, that in different embodiments, the foregoing steps may have different execution orders, that is, may be executed in parallel, may also be executed interchangeably, and the like.
Referring to fig. 10, a picture compression apparatus 1000 includes a first obtaining module 101, a creating module 102, and a first converting module 103, where the obtaining module 101 is configured to obtain a picture file to be compressed, where the picture file to be compressed includes data to be compressed, the creating module 102 is configured to create an initial compressed file, where the initial compressed file includes a compressed data region, and the first converting module 103 is configured to convert the data to be compressed into compressed data according to a preset compressed frame format and information of each pixel point in the data to be compressed, and write the compressed data into the compressed data region, so as to obtain a final compressed file.
In some embodiments, referring to fig. 11, the picture compression apparatus 1000 further includes a second obtaining module 104, a first determining module 105, and a calculating module 106, where the second obtaining module 104 is configured to obtain file information of a picture file to be compressed, the first determining module 105 is configured to determine a compressed file index, and the calculating module 106 is configured to calculate a total byte length of compressed data.
In some embodiments, referring to fig. 12, the first conversion module 103 includes a first obtaining unit 1031, a determining unit 1032 and a compressing unit 1033, where the first obtaining unit 1031 is configured to sequentially obtain information of each pixel point according to an arrangement order of each pixel point in the picture file to be compressed, the determining unit 1032 is configured to determine each repeating pixel unit according to the information of each pixel point in the data to be compressed, where the repeating pixel unit includes a plurality of continuous and same pixel points, and the compressing unit 1033 is configured to compress each repeating pixel unit into a data frame according to a preset compression frame format to obtain compressed data.
It should be noted that the above-mentioned image compression apparatus can execute the image compression method provided by the embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in the embodiments of the picture compression apparatus, reference may be made to the picture compression method provided in the embodiments of the present invention.
Referring to fig. 13, a decompression apparatus 1300 includes a second determining module 131 and a second converting module 132, where the second determining module 131 is configured to determine a picture file to be decompressed, where the picture file to be decompressed is a final compressed file, and the second converting module 132 is configured to convert compressed data in the picture file to be decompressed into decompressed data according to a preset compressed frame format.
In some embodiments, referring to fig. 14, the second conversion module 132 includes a second obtaining unit 1321, a determining unit 1322, a decompressing unit 1323 and a retaining unit 1324, where the second obtaining unit 1321 is configured to obtain each data frame of the compressed data in turn according to an arrangement order of the data frames in the compressed data, the determining unit 1322 is configured to determine whether a compressed frame index exists in the current data frame, the decompressing unit 1323 is configured to decompress the current data frame according to a preset compressed frame format when the compressed frame index exists in the current data frame, and the retaining unit 1324 is configured to retain the current data frame when the compressed frame index does not exist in the current data frame.
It should be noted that the decompression device can execute the decompression method provided by the embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. For technical details that are not described in detail in the embodiment of the decompression apparatus, reference may be made to the decompression method provided in the embodiment of the present invention.
Referring to fig. 15, fig. 15 is a schematic circuit structure diagram of an electronic device according to an embodiment of the present invention. As shown in fig. 15, the electronic device 1500 includes one or more processors 151 and memory 152. Fig. 15 illustrates an example of one processor 151.
The processor 151 and the memory 152 may be connected by a bus or other means, and fig. 15 illustrates the connection by a bus as an example.
The memory 152, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions/modules corresponding to the picture compression method or the decompression method in the embodiments of the present invention. The processor 151 executes various functional applications and data processing of the picture compression apparatus or decompression apparatus by running the nonvolatile software programs, instructions and modules stored in the memory 152, that is, implements the picture compression method or decompression method provided by the above-described method embodiments and the functions of the various modules or units of the above-described apparatus embodiments.
The memory 152 may include high speed random access memory and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some embodiments, memory 152 optionally includes memory located remotely from processor 151, which may be connected to processor 151 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The program instructions/modules are stored in the memory 152 and, when executed by the one or more processors 151, perform the picture compression method or the decompression method of any of the method embodiments described above.
Embodiments of the present invention further provide a non-volatile computer storage medium, where the computer storage medium stores computer-executable instructions, which are executed by one or more processors, for example, one of the processors 151 in fig. 15, and enable the one or more processors to execute the picture compression method or the decompression method in any of the above method embodiments.
Embodiments of the present invention further provide a computer program product, where the computer program product includes a computer program stored on a non-volatile computer-readable storage medium, where the computer program includes program instructions, and when the program instructions are executed by an electronic device, the electronic device is caused to execute the above-mentioned picture compression method or decompression method.
The above-described embodiments of the apparatus or device are merely illustrative, wherein the unit modules described as separate parts may or may not be physically separate, and the parts displayed as module units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network module units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a general hardware platform, and certainly can also be implemented by hardware. Based on such understanding, the above technical solutions substantially or contributing to the related art may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the embodiments or some parts of the embodiments.
Finally, it is to be understood that the present invention may be embodied in many different forms and is not limited to the embodiments described in the present specification, which are provided as additional limitations to the present disclosure, and which are provided for the purpose of providing a more thorough understanding of the present disclosure. In the light of the above, the above features are combined with each other and many other variations of the different aspects of the invention described above are considered to be within the scope of the present description; further, modifications and variations will occur to those skilled in the art in light of the foregoing description, and it is intended to cover all such modifications and variations as fall within the true spirit and scope of the invention as defined by the appended claims.
Claims (14)
1. A picture compression method, comprising:
acquiring a picture file to be compressed, wherein the picture file to be compressed comprises data to be compressed;
creating an initial compressed file, wherein the initial compressed file comprises a compressed data area;
and converting the data to be compressed into compressed data according to a preset compressed frame format and the information of each pixel point in the data to be compressed, and writing the compressed data into the compressed data area to obtain a final compressed file.
2. The method of claim 1, wherein the initial compressed file further comprises a file information area, a file index area, and a compressed data length area, the method further comprising:
acquiring file information of the picture file to be compressed, and writing the file information into the file information area;
determining a compressed file index, and writing the compressed file index into the file index area;
and calculating the total byte length of the compressed data, and writing the information of the total byte length of the compressed data into the compressed data length area.
3. The method of claim 2, wherein determining the compressed file index and writing the compressed file index to the file index area comprises:
selecting a compressed file index with a first preset byte length;
judging whether the compressed file index exists in the picture file to be compressed or not;
if the compressed file index exists in the picture file to be compressed, continuously selecting one compressed file index, and repeating the step of judging whether the compressed file index exists in the picture file to be compressed;
and if the compressed file index does not exist in the picture file to be compressed, writing the compressed file index into the file index area.
4. The method of claim 3, wherein the determining whether the compressed file index exists in the picture file to be compressed comprises:
intercepting all data segments with the same length as a first preset byte of the compressed file index in the picture file to be compressed;
judging whether the character string of each data segment is the same as the character string of the compressed file index or not according to a comparison function;
if the character string of each data segment is the same as the character string of the compressed file index, judging that the compressed file index exists in the picture file to be compressed;
and if the character string of each data segment is different from the character string of the compressed file index, judging that the compressed file index does not exist in the picture file to be compressed.
5. The method according to any one of claims 1 to 4, wherein the converting the data to be compressed into compressed data according to a preset compressed frame format and information of each pixel point in the data to be compressed comprises:
sequentially acquiring the information of each pixel point according to the arrangement sequence of each pixel point in the data to be compressed;
determining each repeated pixel unit according to the information of each pixel point in the data to be compressed, wherein the repeated pixel unit comprises a plurality of continuous and same pixel points;
and compressing each repeated pixel unit into a data frame according to the preset compression frame format to obtain the compressed data.
6. The method of claim 5, wherein determining each repeating pixel unit according to the information of each pixel point comprises:
determining continuous and same pixel points according to the comparison function and the information of each pixel point;
judging whether the byte length corresponding to the continuous and same pixel points is greater than or equal to the byte length of the preset compressed frame format;
if the byte length corresponding to the continuous and same pixel points is greater than or equal to the byte length of the preset compressed frame format, determining the continuous and same pixel points as the repeated pixel units;
and if the byte length corresponding to the continuous and same pixel points is smaller than the byte length of the preset compressed frame format, the continuous and same pixel points are not determined as the repeated pixel units.
7. The method according to claim 5, wherein the format of the predetermined compressed frame includes a compressed frame index of a second predetermined byte length, information of a repetition number of a third predetermined byte length, and information of a repetition pixel of a fourth predetermined byte length, wherein the repetition number is the number of pixels in each of the repetition pixel units, and the repetition pixel is each of the pixels in each of the repetition pixel units.
8. The method of claim 2, wherein the calculating the total byte length of the compressed data, and writing the total byte length information of the compressed data into the compressed data length area comprises:
calculating the length of a first byte corresponding to the data to be compressed;
calculating a second byte length corresponding to the processed data size for processing the data to be compressed;
judging whether the second byte length is equal to the first byte length;
if the second byte length is equal to the first byte length, calculating the total byte length of the compressed data, and writing the information of the total byte length into the compressed data length area;
and if the second byte length is not equal to the first byte length, returning to the step of calculating the second byte length corresponding to the processed data volume for processing the data to be compressed.
9. A decompression method applied to a final compressed file according to any one of claims 1 to 8, the decompression method comprising:
determining an image file to be decompressed, wherein the image file to be decompressed is the final compressed file;
and converting the compressed data in the picture file to be decompressed into decompressed data according to a preset compressed frame format.
10. The decompression method according to claim 9, wherein the converting the compressed data in the picture file to be decompressed into decompressed data according to a preset compressed frame format comprises:
sequentially acquiring each data frame of the compressed data according to the arrangement sequence of each data frame in the compressed data;
judging whether a compressed frame index exists in a current data frame;
if the current data frame has a compressed frame index, decompressing the current data frame according to the preset compressed frame format;
and if the current data frame does not have the compressed frame index, reserving the current data frame.
11. The decompression method according to claim 10, wherein the determining whether the compressed frame index exists in the current data frame comprises:
acquiring data of a specified position in a current data frame;
judging whether the character string of the data at the specified position is the same as the character string of the compressed frame index or not according to a comparison function;
if the character string of the data at the specified position is the same as the character string of the compressed frame index, judging that the compressed frame index exists in the current data frame;
and if the character string of the data at the specified position is different from the character string of the compressed frame index, judging that the compressed frame index does not exist in the current data frame.
12. The decompression method according to claim 9, wherein the determining the picture file to be decompressed comprises:
acquiring a picture file to be processed;
judging whether the picture file to be processed has a compressed file index or not;
if the picture file to be processed has a compressed file index, determining that the picture file to be processed is the picture file to be decompressed;
and if the picture file to be processed does not have the compressed file index, determining that the picture file to be processed is not the picture file to be decompressed.
13. The decompression method according to any one of claims 9 to 12, further comprising:
acquiring a third byte length corresponding to a compressed data length area in the picture to be decompressed;
calculating a fourth byte length corresponding to a processed data amount for processing the compressed data;
determining whether the fourth byte length is equal to the third byte length;
if the fourth byte length is equal to the third byte length, exiting decompression;
and if the fourth byte length is not equal to the third byte length, returning to the step of calculating the fourth byte length corresponding to the processed data amount for processing the compressed data.
14. An electronic device, comprising:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform a picture compression method as claimed in any one of claims 1 to 8 or a decompression method as claimed in any one of claims 9 to 13.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111273611.XA CN113971702A (en) | 2021-10-29 | 2021-10-29 | Picture compression method, decompression method and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202111273611.XA CN113971702A (en) | 2021-10-29 | 2021-10-29 | Picture compression method, decompression method and electronic equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN113971702A true CN113971702A (en) | 2022-01-25 |
Family
ID=79588982
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202111273611.XA Pending CN113971702A (en) | 2021-10-29 | 2021-10-29 | Picture compression method, decompression method and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113971702A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115098171A (en) * | 2022-05-20 | 2022-09-23 | 智绘微电子科技(南京)有限公司 | Method for optimizing picture compression processing in VBIOS |
Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1151558A (en) * | 1994-11-22 | 1997-06-11 | 国际商业机器公司 | Information searching method and system |
CN101192304A (en) * | 2006-11-29 | 2008-06-04 | 凌通科技股份有限公司 | Image compression and decompression device and method for embedded system |
CN101546434A (en) * | 2008-03-28 | 2009-09-30 | 深圳市同洲电子股份有限公司 | Method and system for compressing and decompressing BMP picture file |
CN102013105A (en) * | 2010-08-19 | 2011-04-13 | 上海闻泰电子科技有限公司 | Picture file compression method |
CN104142924A (en) * | 2013-05-06 | 2014-11-12 | 中国移动通信集团福建有限公司 | Compression method and device for animation picture format |
CN104575427A (en) * | 2015-01-23 | 2015-04-29 | 浙江工业大学 | A High Compression Ratio Lossless Image Compression Method Suitable for Embedded System Decoding |
CN107395209A (en) * | 2017-07-03 | 2017-11-24 | 北京京东尚科信息技术有限公司 | Data compression method, uncompressing data and its equipment |
CN108694735A (en) * | 2018-05-11 | 2018-10-23 | 歌尔科技有限公司 | Wearable device and analog dial pointer picture compression storage redraw method, equipment |
CN110799959A (en) * | 2017-05-26 | 2020-02-14 | 深圳配天智能技术研究院有限公司 | Data compression method, decompression method and related equipment |
CN111193948A (en) * | 2020-01-07 | 2020-05-22 | 上海步频电子科技有限公司 | Picture transmission and display method and system of display terminal |
-
2021
- 2021-10-29 CN CN202111273611.XA patent/CN113971702A/en active Pending
Patent Citations (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1151558A (en) * | 1994-11-22 | 1997-06-11 | 国际商业机器公司 | Information searching method and system |
CN101192304A (en) * | 2006-11-29 | 2008-06-04 | 凌通科技股份有限公司 | Image compression and decompression device and method for embedded system |
CN101546434A (en) * | 2008-03-28 | 2009-09-30 | 深圳市同洲电子股份有限公司 | Method and system for compressing and decompressing BMP picture file |
CN102013105A (en) * | 2010-08-19 | 2011-04-13 | 上海闻泰电子科技有限公司 | Picture file compression method |
CN104142924A (en) * | 2013-05-06 | 2014-11-12 | 中国移动通信集团福建有限公司 | Compression method and device for animation picture format |
CN104575427A (en) * | 2015-01-23 | 2015-04-29 | 浙江工业大学 | A High Compression Ratio Lossless Image Compression Method Suitable for Embedded System Decoding |
CN110799959A (en) * | 2017-05-26 | 2020-02-14 | 深圳配天智能技术研究院有限公司 | Data compression method, decompression method and related equipment |
CN107395209A (en) * | 2017-07-03 | 2017-11-24 | 北京京东尚科信息技术有限公司 | Data compression method, uncompressing data and its equipment |
CN108694735A (en) * | 2018-05-11 | 2018-10-23 | 歌尔科技有限公司 | Wearable device and analog dial pointer picture compression storage redraw method, equipment |
CN111193948A (en) * | 2020-01-07 | 2020-05-22 | 上海步频电子科技有限公司 | Picture transmission and display method and system of display terminal |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115098171A (en) * | 2022-05-20 | 2022-09-23 | 智绘微电子科技(南京)有限公司 | Method for optimizing picture compression processing in VBIOS |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108900843B (en) | Monochrome image compression method, apparatus, medium, and electronic device | |
CN111915673B (en) | Image processing method, image processing device, terminal equipment and storage medium | |
US11395010B2 (en) | Massive picture processing method converting decimal element in matrices into binary element | |
CN114531598B (en) | Image compression method, device, intelligent terminal and computer-readable storage medium | |
US10235738B2 (en) | Method of and apparatus for displaying an output surface in data processing systems | |
CN110235176B (en) | Image processing method and device, data transmission method and device and storage medium | |
CN111510718B (en) | Method and system for improving compression ratio through inter-block difference of image file | |
US9679348B2 (en) | Storage and compression methods for animated images | |
CN113343958B (en) | Text recognition method, device, equipment and medium | |
US12028539B2 (en) | Generating multi-pass-compressed-texture images for fast delivery | |
CN110113617A (en) | A kind of method and device of compression of images and decompression | |
CN110399511A (en) | Image cache method, equipment, storage medium and device based on Redis | |
CN110214338A (en) | Application of the increment color compressed to video | |
CN113971702A (en) | Picture compression method, decompression method and electronic equipment | |
CN102238376B (en) | Image processing system and method | |
CN118689437B (en) | A local display system of a server, a baseboard management controller and a server | |
US8942474B2 (en) | Method and system for interpolating index values of associated tiles in an image | |
CN118260443A (en) | Text drawing method, text drawing device, computer equipment and storage medium | |
CN108668170B (en) | Image information processing method and device, and storage medium | |
CN102023838B (en) | Processing method and system of MRC picture file | |
KR20020052199A (en) | Data transfer between rgb and ycrcb color spaces for dct interface | |
CN101065760A (en) | System and method for processing image data | |
WO2007099327A2 (en) | Data compression | |
CN111654704A (en) | Automatic multi-mode image compression control method and device | |
US10283094B1 (en) | Run-length compression and decompression of media tiles |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |