A kind of method of compressed picture fileTechnical field
The present invention relates to the picture process field, particularly a kind of method of compressed picture file.
Background technology
During mobile phone power-on, first width of cloth picture of demonstration generally is a LOGO picture, may be the LOGO of operator, also may be the LOGO of manufacturer.Because all restrictions during mobile phone power-on have little time to load large-scale pattern storehouse this moment, therefore can not show the picture of conventional form.More common way is in the flash memory of mobile phone at present, stores original picture pixel data.But these pixel datas relatively take up space, and the QCIF on-screen data of storing one 16 needs 176 * 220 * 2=77440 byte, and one 16 QVGA on-screen data needs 240 * 320 * 2=153600 byte.In the at present more common mobile phone hardware configuration, flash memory space does not wait to the 128M byte from the 8M byte, and especially for the configuration than low side, as the configuration of 16M, this width of cloth figure has taken 153600/ (1024*1024*16) ≈ 1%.Perhaps, 1% is not a big figure, still, in the mobile phone development process of reality, sometimes in order to reduce the space hold of 10K, all is quite difficult.
Summary of the invention
The method that the purpose of this invention is to provide a kind of compressed picture file, it can be realized with less storage space picture file.
The invention provides a kind of method of compressed picture file, may further comprise the steps:
1.1, the storage format of described picture is set;
1.2, the color in the described picture is compiled color table, for its each pixel, the subscript in the color table that it is corresponding is stored in the concordance list;
1.3, the concordance list in the read step 1.2, and picture is carried out the RLE compression according to the picture format in the step 1.1, adjacent point is represented with color value and the homochromy color number of external phase.
The picture format that described step 1.1 is provided with comprises picture width, picture height, color depth, color table length, color table and image content.
Described step 1.2 may further comprise the steps;
1.2.1, read next pixel color in the picture, be designated as color C;
If 1.2.2 color C in the color table of setting up, changes step 1.2.4, otherwise change step 1.2.3;
1.2.3, color C is deposited in the color table;
1.2.4, the subscript of color C is deposited in the color index table;
If, then carry out step 1.3, otherwise change step 1.2.1 1.2.5 run through last pixel of picture.
Described step 1.3 may further comprise the steps:
1.3.1, read next index in the described color index table, be designated as index I;
If 1.3.2 index I catch up with one identical, change step 1.3.3, otherwise change step 1.3.4;
1.3.3, the last item of an index numerical table L is added 1;
1.3.4, index I is added index value table K, an index numerical table L end increases one newly, its value is 1;
If, change step 1.3.6 1.3.5 run through all index; Otherwise, change step 1.3.1;
1.3.6, read the next item down among the index value table K, and deposit it in compaction table Z; Read the next item down among the index numerical table L, be designated as λ;
1.3.7 if λ is zero, changes step 1.3.6, otherwise change step 1.3.8;
1.3.8 if λ>maximum length is changeed step 1.3.9; Otherwise change step 1.3.10, wherein, the maximum integer that the byte number that maximum length needs for the largest index in the expression concordance list can be represented deducts maximum index value;
1.3.9, will represent that the maximum integer that the byte number of the largest index needs in the concordance list can be represented deposits compaction table in, λ=λ-maximum length;
1.3.10 if λ is zero, changes step 1.3.12, otherwise change step 1.3.11;
1.3.11, deposit the color number in λ-color table in compaction table;
1.3.12, with the picture width, highly, color depth, color table length write compressed file successively;
1.3.13, color table is write compressed file;
1.3.14, compaction table is write compressed file.
Described method also comprises the picture decompression step:
Step S1, read the picture width, highly, color depth, color table length, be designated as LC;
Step S2, read next color, and deposit this color in color table;
If the color number that step S3 has read surpasses LC, change step S4; Otherwise, change step S2;
If step S4 is LC<and 200, index length L I=1; If 200=<LC<65000; Index length L I=2; If LC>65000, index length L I=4;
Step S5, read the data that length is the LI byte, be designated as D;
If step S6 is D<LC, change step S7; Otherwise, change step S8;
Step S7, deposit D in the pixel table;
Step S8, the last element of pixel table is deposited 1+D-LC time again;
Do not finish if step S9 reads, change step S5; Otherwise, change step S10;
Step S10, according to the pixel table, Show Picture.
Adopt the method for a kind of compressed picture file of the present invention, be specially adapted to the LOGO picture, the characteristics that this method is simple relatively at LOGO picture color, exist the large tracts of land same color, adopt the compress mode of color table in conjunction with the RLE compression algorithm, promptly to each pixel of picture, only store the subscript in the color table, and adjacent point is represented with color value and the homochromy color number of external phase, the present invention has reached the picture compression rate that both keeps higher, again the purpose of easy operating realization.
Description of drawings
Fig. 1 is a compression algorithm process flow diagram of the present invention;
Fig. 2 is a decompression algorithm process flow diagram of the present invention.
Embodiment
Further specify technical scheme of the present invention below in conjunction with drawings and Examples.
Referring to Fig. 1, the invention provides a kind of method of compressed picture file, may further comprise the steps:
1.1, the storage format of described picture is set.
The picture format that described step 1.1 is provided with comprises picture width, picture height, color depth, color table length, color table and image content.Form specifically sees the following form 1:
| Byte number | Content |
| 2 | The picture width |
| ?2 | The picture height |
| ?1 | Color depth (in byte) |
| ?4 | Color table length |
| Color depth * color table length | Color table |
| Indefinite length | Image content |
1.2, the color in the described picture is compiled color table, for its each pixel, the subscript in the color table that it is corresponding is stored in the concordance list.
1.3, the concordance list in the read step 1.2, and picture is carried out the RLE compression according to the picture format in the step 1.1, adjacent point is represented with color value and the homochromy color number of external phase.
Referring to Fig. 1, Fig. 1 has shown flow process Figure 100 of compression algorithm of the present invention:
S1, read next pixel color in the picture, be designated as color C;
If S2 color C in the color table of setting up, changes step S4, otherwise change step S3;
S3, color C is deposited in the color table;
S4, the subscript of color C is deposited in the color index table;
If S5 has run through last pixel of picture, then carry out step 1.3, otherwise change step S1.
S6, read next index in the described color index table, be designated as index I;
If S7 index I catch up with one identical, change step S8, otherwise change step S9;
S8, the last item of an index numerical table L is added 1;
S9, index I is added index value table K, an index numerical table L end increases one newly, and its value is 1;
If S10 has run through all index, change step 11; Otherwise, change step S6;
S11, read the next item down among the index value table K, and deposit it in compaction table Z; Read the next item down among the index numerical table L, be designated as L;
If S12 L is zero, changes step S11, otherwise change step S13;
If S13 L>maximum length is changeed step S14; Otherwise change step S15, wherein, the maximum integer that the byte number that maximum length needs for the largest index in the expression concordance list can be represented deducts maximum index value;
S14, will represent that the maximum integer that the byte number of the largest index needs in the concordance list can be represented deposits compaction table in, the L=L-maximum length;
If S15 L is zero, changes step S17, otherwise change step S16;
S16, deposit the color number in the L-color table in compaction table;
S17, with the picture width, highly, color depth, color table length write compressed file successively;
S18, color table is write compressed file;
S19, compaction table is write compressed file.
The process of above process for picture is compressed is the file of the defined form of table 1 with a width of cloth LOGO picture compression, and this document is stored on the flash memory of mobile phone.
Referring to Fig. 2, Fig. 2 has shown decompression algorithm flow process Figure 200 of the present invention:
C1, read the picture width, highly, color depth, color table length, be designated as LC;
C2, read next color, and deposit this color in color table;
If the color number that C3 has read surpasses LC, change C4; Otherwise, change C2;
If C4 is LC<and 200, index length L I=1; If 200=<LC<65000; Index length L I=2; If LC>65000, index length L I=4;
C5, read the data that length is the LI byte, be designated as D;
If C6 is D<LC, change C7; Otherwise, change C8;
C7, deposit D in the pixel table;
C8, the last element of pixel table is deposited 1+D-LC time again;
Do not finish if C9 reads, change C5; Otherwise, change C10;
C10, according to the pixel table, Show Picture.
Above process is the picture decompression process: the decompression algorithm that adopts Fig. 2 to provide, this document is reduced into original pixel matrix, and obtain the width of picture, highly, information such as color depth simultaneously.The pixel matrix that obtains according to top decompression and the information such as width, height and color depth of picture show corresponding LOGO picture on mobile phone screen.
Those of ordinary skill in the art will be appreciated that, above embodiment is used for illustrating the present invention, and be not to be used as limitation of the invention, as long as in connotation scope of the present invention, all will drop in claims scope of the present invention variation, the modification of above embodiment.