Summary of the invention
The purpose of the embodiment of the invention is to propose a kind of image data sending method, and described method comprises:
View data is cut figure to be handled; Make all cut figure and have identical file header data block and palette data piece;
Receive view data and send instruction;
Said view data is sent the corresponding video data block of cutting figure of instruction compress, form image compression data; Send said image compression data.
Wherein, described " make all cut figure and have identical file header data block and palette data piece " is specially: use first palette that presets to cut figure all picture files.
Wherein, the described method that presets first palette is specially:
Travel through all images data block, obtain all color of pixel values of video data block;
Searching loop all colours value extracts the color value with a kind of color; The color value of each extraction is stored, generated first palette.
The present invention provides a kind of view data restoration methods, and described method comprises:
Receive image compression data; Image compression data is carried out decompression, obtain the video data block of decompress(ion);
Judge whether first palette exists; If do not exist, generate first palette through said video data block; If exist and then generate second palette according to described first palette;
Generate the index value tabulation of each video data block color through second palette;
Generate picture file according to said index value tabulation and described video data block.
Wherein, described " generating second palette according to described first palette " is specially:
Through Octree color quantizing algorithm first palette is generated second palette.
Wherein, described " generating the index value tabulation of each video data block color through second palette " is specially:
Read the AP data block;
Each pixel in the reads image data piece judges whether the current pixel that reads is first pixel of its place pixel column successively;
If the index value content of the color that the current pixel that reads is corresponding representes with 0, with the unique identification corresponding stored of described index value content and current pixel in the index value table that presets;
If not; Obtain preceding 3 rgb values of current pixel; With preceding 3 rgb values of current pixel respectively with second palette in each rgb value do comparison; From second palette, search the color value of coupling, as the index value content of the color of current pixel value, with the unique identification corresponding stored of described index value content and current pixel in the index value table that presets.
Wherein, described " with preceding 3 rgb values of current pixel respectively with second palette in each rgb value do comparison, from second palette, search the color value of coupling, as the color index value of current pixel value " be specially:
Obtain the color distance Δ C of each rgb value in preceding 3 rgb values of current pixel and second palette respectively;
With the color distance Δ C minimum value of obtaining, the color value in the second corresponding palette is as the color value of coupling;
With the color value of this color color index value content, leave in the index value table that presets as current pixel value.
Wherein, described " obtaining the color distance Δ C of each rgb value in preceding 3 rgb values of current pixel and second palette respectively " is specially: Δ C=|r1-r2|+|g1-g2|+|b1-b2|;
R1 wherein, g1, b1 are respectively preceding 3 RGB component values of current pixel; R2, g2, b2 are respectively the component value of each RGB in second palette;
Or
ΔC=A*|r1-r2|+B*|g1-g2|+C*|b1-b2|
Wherein A, B, C are the weights of each color component.
Wherein, described " generating picture file according to said index value tabulation and described video data block " is specially:
Structured data according to the palette data piece that presets generates the palette data piece;
Generate video data block according to video data block structured data that presets and described color index value list;
Generate picture file according to described palette data piece, video data block and the file header data block that presets, the combination of image end data piece.
The present invention provides a kind of Data Recapture Unit, and described Data Recapture Unit comprises:
Receiving element is used to receive image compression data; Image compression data is carried out decompression, obtain the video data block of decompress(ion);
Processing unit is used to judge whether first palette exists; If do not exist, generate first palette through said video data block; If exist and then generate second palette according to described first palette;
Recovery unit is used for generating through second palette index value tabulation of each video data block color; Generate picture file according to said index value tabulation and described video data block;
Described processing unit comprises, first judging unit, palette unit;
First judging unit is used to judge whether first palette exists;
The palette unit is used for when first palette does not exist, generating first palette through said video data block; If when existing, generate second palette according to described first palette; The method that wherein generates second palette according to said first palette is: through Octree color quantizing algorithm first palette is generated second palette;
Described recovery unit comprises: index value generation unit, picture file generation unit;
The index value generation unit comprises: reading unit, second judging unit, index value unit;
Reading unit is used to read the AP data block; Each pixel in the reads image data piece successively;
Second judging unit is used to judge whether the current pixel that reads is first pixel of its place pixel column;
The index value unit; Be used for when second judgment unit judges go out the current pixel that reads be its place pixel first pixel time; The index value content of the color that the current pixel that reads is corresponding representes with 0, with the unique identification corresponding stored of described index value content and current pixel in the index value table that presets; If second judgment unit judges go out the current pixel that reads be not its place pixel first pixel time; Obtain preceding 3 rgb values of current pixel; With preceding 3 rgb value values of current pixel respectively with second palette in each rgb value do comparison; From second palette, search the color value of coupling, as the index value content of the color of current pixel value, with the unique identification corresponding stored of described index value content and current pixel in the index value table that presets;
The picture file generation unit is used for generating the palette data piece according to the structured data of the palette data piece that presets; Generate video data block according to video data block structured data that presets and described color index value list; Generate picture file according to described palette data piece, video data block and the file header data block that presets, the combination of image end data piece.
In sum, transmission, restoration methods, device and the terminal of the present invention through a kind of view data is provided; Can realize sampling color values all on the map out, identical toning version of unified use, it all is identical making all IHDR that cuts figure and PLTE; The different IDAT values of just cutting figure in Network Transmission, is only transmitted the IDAT part of picture; Be view data); Can practice thrift the size of png file like this, when in use. merge to IDAT among IHDR and the PLTE again, can significantly reduce network traffics and time like this.
Embodiment
In order to make the object of the invention, technical scheme and advantage clearer, below in conjunction with accompanying drawing and embodiment, the present invention is further elaborated, for the ease of explanation, only show the part relevant with the embodiment of the invention.Should be appreciated that the specific embodiment that this place is described, only be used to explain the present invention, not in order to restriction the present invention.
The present invention provides a kind of transmission, restoration methods of view data.Can realize sampling color values all on the map out through the present invention of this method, identical toning version of unified use, it all is identical making all IHDR that cuts figure and PLTE; The different IDAT values of just cutting figure in Network Transmission, is only transmitted the IDAT part of picture; Be view data); Can practice thrift the size of png file like this, when in use. merge to IDAT among IHDR and the PLTE again, can significantly reduce network traffics and time like this.
For technical scheme of the present invention is described better, at first introduce the PNG file.
Portable network picture (Portable Network Graphics) is called for short PNG, is a kind of lossless data compression bga.
The PNG file generally has the type of PNG32 and PNG8:
Png32 master file block structure
IHDR (file header data block) |
IDAT (video data block) |
IEND (image end data) |
PNG8 master file block structure
The figure frame that map components is used is shown the PNG file format; What use is 32 true color images (being png32); Having only IHDR file header piece and IDAT content blocks in the data block, promptly is with a kind of color of 4 byte representations, is FF 00 00 FF like redness; Under situation about not compressing, if the size that the content blocks IDAT of the png32 picture of 80*60 does not compress is the 80*60*4+80=19280 byte.
The advantage of Png32 shows rich color exactly, and shortcoming is exactly that file is bigger, and for the color demonstration of map picture, the performance of color is not too obvious, so can be with being enough under 256 looks. and can lose lustre to handle with png8 and represent.
Wherein IDAT (video data block) can comprise structure in the table 1:
Table 1 IDAT block data structure
Because map color is not very complicated, therefore can use the PNG8 file format to represent, and cut the big or small identical of figure; Sample color values all on the map out, identical toning version of unified use, it all is identical making all IHDR that cuts figure and PLTE; The different IDAT values of just cutting figure; In network requests, only transmit the chunk piece (data block) of IDAT, the size that can practice thrift the png file like this; When in use. merge to IDAT among IHDR and the PLTE, can significantly reduce network traffics and time like this.
Embodiment 1, referring to Fig. 1, based on state map image is cut the sampling of figure, color, when transmission, only transmit the chunk piece of IDAT, the invention provides a kind of sending method of view data:
Step 101: in advance picture file is cut figure and handle, make each cut figure and have identical IHDR and PLTE;
" make each cut figure and have identical IHDR and PLTE " described in this step can for: use first palette preset to cut figure all images data.
Preset first palette method can for:
Step 1011: travel through all images data block, obtain all color of pixel values (rgb value) of video data block;
Step 1012: searching loop all colours value, extract the color value with a kind of color; The color value of each extraction is stored, generated first palette.
Described in this step to similar color value extract can for: for example when a kind of color value of color be 48,49,50,51,52; The color naked eyes of these 5 color values seem it all is with a kind of color, extract the color value of this color value mean value as this color so, and storage.The method that extracts can not averaged yet, and can extract the color value of one of them value as this color, and abstracting method does not limit in this patent, only need from a plurality of color data, extract a representational color value and get final product.
For example after the loop ends of step 1012, the content-form of first palette of generation is following:
byte?[]{15,15,14,42,14,8,50,41,22,48,48,47,8,76,2,63,64,64,73,19,26,64,51,25,71,61,50,97,16,21,127,26,42,105,62,62,77,71,54,106,81,43,118,101,53,81,80,79,94,97,98,97,93,86,100,93,97,108,103,86,112,111,109,5,90,-85,9,97,-111,22,100,-80,49,119,-70,48,123,-63,121,125,-127,36,-116,15,114,-83,68,43,-109,-46,64,-127,-65,125,-128,-126,82,-114,-57,102,-102,-52,121,-89,-46,-110,52,42,-65,25,31,-95,12,39,-76,44,34,-116,93,58,-112,114,58,-113,121,75,-122,122,111,-90,111,71,-45,13,17,-52,51,51,-26,30,25,-24,58,57,-50,71,68,-37,109,125,-15,89,95,-11,102,104,-123,124,-127,-108,-120,84,-113,-118,119,-79,-115,80,-79,-107,109,-68,-87,90,-73,-87,114,-65,-56,121,-46,-113,47,-49,-83,53,-29,-91,59,-48,-106,73,-47,-81,79,-46,-79,112,-30,-85,69,-29,-84,86,-22,-77,71,-25,-74,87,-15,-71,72,-16,-66,92,-27,-71,108,-35,-60,78,-40,-59,113}
After in step 1012, all colours value being extracted, can further generate external resource file (as: plte256.dat) storage, use to supply the third party easily and efficiently.
Step 102: receive the transmission instruction of view data;
Step 103: said view data is sent the corresponding chunk that cuts figure of instruction compress; Form image compression data, and send the structured data of said image compression data PLTE: Length (length), Chunk Type Code (data block type codes), Chunk Data (data block data) and CRC (cyclic redundancy detection).
Embodiment 2, and referring to Fig. 2, corresponding to the image data sending method that embodiment 1 provides, the embodiment of the invention 2 provides a kind of view data restoration methods;
Step 201: receive image compression data;
Step 202: through said image compression data reads image data piece IDAT and storage;
The method that reads IDAT in this step is promptly according to sequencing read block (chunk) length (4 byte) from data flow respectively; Data block (chunk) type codes (4 byte); Data block data (chunk Data); CRC consists of the piece that fetches data (chunk) and records Hashtable and uses as buffering.
Step 203: said data block chunk is decompressed; The index value that generates color for the back is prepared.Wherein the realization of decompression process is a kind of known method in common, does not specify here.
Step 204: judge whether to exist first palette, if there is not then execution in step 205; If there is execution in step 206;
Step 205: generate first palette;
The method that generates first palette is described in detail in the step 1011 and 1012 of embodiment 1, this no longer tired stating.
Step 206: generate second palette according to said first palette;
Owing to directly recover the picture file distortion rate than higher with first palette; Therefore can the method for first palette through the Octree color quantizing be generated second palette; This Octree color quantizing algorithm is to well known to a person skilled in the art general knowledge; Do not belong to inventive point of the present invention, specifically can be with reference to " based on the color quantization algorithm of octree structure " honest and just state Hua Zhouming complete (Northwest University's computer science department, Xi'an 710069).Therefore this no longer tired stating.
Step 207: generate the index value tabulation of each video data block color through second palette;
Referring to Fig. 3, wherein generate color index value method can for:
Step 2071: read the AP data block; Read the AP data block just: after reading a video data block; The color figure place of computed image data block (validity of check data piece); If this color figure place, explains that this video data block is useless data, then loses this video data block less than first threshold 4; Again obtain next video data block, computing formula is following:
Color figure place=(video data block total length-256)/256/256
Step 2072: each pixel in the reads image data piece successively;
Step 2073: judge whether the current pixel that reads is first pixel of its place pixel column; If then execution in step 1073; Execution in step 2074 then if not;
Step 2074: the index value content of the color that the current pixel that reads is corresponding representes with 0, with the unique identification corresponding stored of described index value content and current pixel in the index value table that presets;
Step 2075: preceding 3 rgb values that obtain current pixel; With preceding 3 rgb value values of current pixel respectively with second palette in each rgb value do comparison; From second palette, search the color value of coupling; As the index value content of the color of current pixel value, with the unique identification corresponding stored of described index value content and current pixel in the index value table that presets.
In this step, with preceding 3 rgb values of current pixel with respectively with second palette in each value do comparison, from second palette, search coupling color value method can for:
Step 2076: the color distance Δ C that obtains each rgb value in preceding 3 rgb values of current pixel and second palette respectively;
ΔC=|r1-r2|+|g1-g2|+|b1-b2|;
R1 wherein, g1, b1 are respectively preceding 3 RGB component values of current pixel; R2, g2, b2 are respectively the component value of each RGB in second palette.
Further, can consider that when obtaining color distance Δ C human eye is to the sensitivity of red, green, blue look different, when reality is used, add certain weight often for the increment of each color component, the color distance computing formula of experience is:
ΔC=A*|r1-r2|+B*|g1-g2|+C*|b1-b2|
Wherein A, B, C are the weights of each color component, and A can be 3, and B can be 4, and C can be 2;
Step 2077: with the color distance Δ C minimum value of obtaining, the color value in the second corresponding palette is as the color value of coupling.
What wherein, value was minimum is the color of mating most;
Step 2078: the color value of this color is worth color index value content as current pixel, leaves in the index value table that presets.
Step 208: the structured data according to the palette data piece that presets generates the palette data piece;
Just, the length of this PLTE is set according to the structured data of the PLTE that presets, type codes, the value of data block data (chunk Data), and carry out Cyclic Redundancy Check, and guarantee the correctness of generation, generate the PLTE data block at last.
Step 209 generates video data block according to video data block structured data that presets and described color index value list;
According to described color index value table; Generate video data block (IDAT); Just according to the corresponding color value of inquiry in unique identification to the color index value table of each pixel; Structured data according to described color value and the IDAT that presets compresses data (the PNG form is a lossless data compression), carries out Cyclic Redundancy Check at last, guarantees the correctness that generates.
Step 210: generate picture file according to PLTE data block that generates and video data block combination.
Because png file header data block IHDR, tail data block IEND is fixing, so only need in program, to define to get final product.
Embodiment 3, referring to figure, and 4, the embodiment of the invention also provides a kind of Data Recapture Unit, and described Data Recapture Unit comprises:
Receiving element is used to receive image compression data; Image compression data is carried out decompression, obtain the video data block of decompress(ion);
Processing unit is used to judge whether first palette exists; If do not exist, generate first palette through said video data block; If exist and then generate second palette according to described first palette;
Recovery unit is used for generating through second palette index value tabulation of each video data block color; Generate picture file according to said index value tabulation and described video data block;
Described processing unit comprises, first judging unit, palette unit;
First judging unit is used to judge whether first palette exists;
The palette unit is used for when first palette does not exist, generating first palette through said video data block; If when existing, generate second palette according to described first palette; The method that wherein generates second palette according to said first palette is: through Octree color quantizing algorithm first palette is generated second palette;
Described recovery unit comprises: index value generation unit, picture file generation unit;
The index value generation unit comprises: reading unit, second judging unit, index value unit;
Reading unit is used to read the AP data block; Each pixel in the reads image data piece successively;
Second judging unit is used to judge whether the current pixel that reads is first pixel of its place pixel column;
The index value unit; Be used for when second judgment unit judges go out the current pixel that reads be its place pixel first pixel time; The index value content of the color that the current pixel that reads is corresponding representes with 0, with the unique identification corresponding stored of described index value content and current pixel in the index value table that presets; If second judgment unit judges go out the current pixel that reads be not its place pixel first pixel time; Obtain preceding 3 rgb values of current pixel; With preceding 3 rgb value values of current pixel respectively with second palette in each rgb value do comparison; From second palette, search the color value of coupling, as the index value content of the color of current pixel value, with the unique identification corresponding stored of described index value content and current pixel in the index value table that presets;
The picture file generation unit is used for generating the palette data piece according to the structured data of the palette data piece that presets; Generate video data block according to video data block structured data that presets and described color index value list; Generate picture file according to described palette data piece, video data block and the file header data block that presets, the combination of image end data piece.
Those having ordinary skill in the art will appreciate that; All or part of step in realization the foregoing description method can be accomplished through the program command related hardware; Described program can be stored in the computer read/write memory medium, and described storage medium can be ROM, RAM, disk, CD etc.
The above is merely preferred embodiment of the present invention, not in order to restriction the present invention, all any modifications of within spirit of the present invention and principle, being done, is equal to and replaces and improvement etc., all should be included within protection scope of the present invention.