Compression
We all say lossless compression, preserving dot matrix data.
This method compresses the data already close to BMP format picture size, my machine spends approximately 1 seconds processing 200*200 's picture, compared to uncompressed character's compression ratio is 50%. The concrete picture is more dark is compressed better.
Reference :
Uncompressed text: 295k
Compressed text: 143k
High-order compression: 127k
BMP picture (200*200 picture): 117k
The results of the compression are similar:
Reference :
200,200= ' C, ' C, ' C, ' C, ' C,eg, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C., ' C., ' C., ' C, ' C, ' C, ' C, ' C, ' C, '
C, ' C,eg,eg,eg, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C., ' C., ' C., ' C, ' C, ' C,r9,r9,
R9,r9,0i,0i,0i,0i,0i,0i,0i,0i,0i,0i,0i,0i,eg,q9,) {,) C,0i,eg,eg,0i,0i,0i,r9,r9,r9,r9,) C,/E, ' c,0i,R9,0i,R9,R9,R9 , r9,r9,r9,0i,) C, C,r9,r9,r9,r9,r9,r9,r9,r9,r9,r9,ee
My idea here is to use a custom system to handle the problem of digital compression.
principle : According to characters, a number of 2 is the longest, with a decimal is shorter, with a shorter 16, that exhaust a large number of characters in the system.
Advanced compression Algorithm : Select the starting point algorithm, piecewise compression, adjacent to the same character in the range of the number expressed.
First of all, the algorithm:
Program by Hqlulu
Www.aslibra.com
Import Flash.display.BitmapData;
Custom width and height
var max_w:number = 200;
var max_h:number = 200;
var mybitmap:bitmapdata = new BitmapData (Max_w, Max_h, True, 0x000000);
Mybitmap.draw (_root);
View_mc.attachbitmap (Mybitmap, 10);
Whether to compress
My test data:
true:1382 ms
false:364 ms
var Is_compress:boolean = true;
//
Define the character, where almost all the characters used, the more compression the better, but the choice of FFFFFF to achieve the best number of characters
Here for image encryption also has a lot of help!
var code:string = "0123456789qwertyuiop[]asdfghjkl;zxcvbnm./qwertyuiop{}| asdfghjkl:zxcvbnm<>?~!@#$%^&* () _+ ' ";
var Code_array:array = Code.split ("");
How many characters are in the system?
var byte:number = code.length;
function GetCode (i:number): String {
The method of seeking remainder by taking the whole
var return_code:string = "";
while ((I=math.ceil (i/byte)) >byte) {
Return_code + = Code_array[i%byte];
}
Return_code + = Code_array[i];
return return_code;
}
//
Array of records
var p_array:array = new Array ();
var timer:number = Gettimer ();
function Save2array (): Void {
for (var i:number = 0; i<max_w; i++) {
P_array[i] = new Array ();
for (var j:number = 0; j<max_h; j + +) {
The speed can be improved without judgment.
if (is_compress) {
P_array[i].push (GetCode (Mybitmap.getpixel (i+1, j+1)));
} else {
P_array[i].push (Mybitmap.getpixel (i+1, j+1));
}
}
}
}
Save2array ();
Trace ("Conversion Time:" + (Gettimer ()-timer) + "MS");
Delimiters are to be used with those that are not in the in-process character
var my_data:string = max_w+ "," +max_h+ "=";
Trace (My_data);
My_data + + p_array.join (",");
Trace ("Character length:" +my_data.length);
Character length
My test data:
false:302419
true:147174
Trace (My_data);
The execution time is not much, it is better for the valid line of the program.
You can take a look at the execution effect of the code
The principle of advanced compression:
Reference :
' C, ' C, ' C, ' C, ' C,eg, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C., ' C., ' C., ' C, ' C, ' C, ' C, ' C, ' C, ' C,eg,
Eg,eg, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C, ' C., ' C., ' C., ' C, ' C, ' C,
See the above data, for repeat points, you can consider this process:
Reference :
' C (5), Eg, ' C (Ten), Eg,eg,eg, ' C (15),
This algorithm needs to be processed by the logarithm group, I did not write, the increase of compression ratio is objective.
Of course "()" needs to be processed in the later stage, the "()" Multiple characters Fusen recovery.
Reference :
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
For the above characters, you can see, if the photo is dark, black as the basis for the operation, the photo is light, it is appropriate to white as the basis of the operation.
Piecewise compression algorithm is not very efficient, after all, now is three characters, if the partition, you can use two characters to represent the color, but also use a character to represent the interval.
Image compression method
The color of adjacent dots is the same as the "(number)" representation
If the color difference is not large, the difference is N, in a two-dimensional array of comparisons, some points approximate to that point, so there are more numbers, fewer characters.