snowkit / gif Goto Github PK
View Code? Open in Web Editor NEWHaxe GIF encoder, implementing the NeuQuant and LZW encoding algorithms
Haxe GIF encoder, implementing the NeuQuant and LZW encoding algorithms
See 4 pixel gif here using code below:
And what it should look like.
/*
-neko bin/test.n
#-cpp cpp
-debug
-cp src
-main Main
-cmd cd bin
-cmd neko test.n
*/
package;
import haxe.io.UInt8Array;
import gif.GifEncoder;
/*
import bitsAndBytes.HexViewer;
import sys.io.File;
import sys.io.FileInput;
import sys.io.FileOutput;
*/
import Sys;
class Main
{
var fname = "test.gif";
var width = 2;
var height = 2;
var fin: FileInput;
static function main(){ new Main(); } public function new(){
trace( 'Main running, saving pixles to ' + fname );
var encoder = new GifEncoder(-1, 100, false);
encoder.startFile( fname );
var data = UInt8Array.fromArray( smallGif() );
var frame = {
width: width,
height: height,
data: data
}
trace( 'adding frame' );
var t1 = Sys.time();
encoder.addFrame( frame );
trace( Sys.time() - t1 );
encoder.finish();
trace('now read ');
//readHexToTerminal( fname, HEX );
}
/*
public function readHexToTerminal( nom: String, mode: Mode ){
fin = File.read( nom, true );
var reader = new HexViewer( fin );
reader.mode = mode;
reader.read();
fin.close;
trace('close');
}
*/
function smallGif():Array<Int>{
var red = { r: 0xff, g: 0x00, b:0x00 };
var green = { r: 0x00, g: 0x99, b:0x66 };
var blue = { r: 0x00, g: 0x99, b: 0xcc };
var pink = { r: 0xFF, g: 0x66, b: 0x99 };
var arr = new Array<Int>();
arr.push( pink.r ); arr.push( pink.g ); arr.push( pink.b );
arr.push( green.r ); arr.push( green.g ); arr.push( green.b );
arr.push( blue.r ); arr.push( blue.g ); arr.push( blue.b );
arr.push( red.r ); arr.push( red.g ); arr.push( red.b );
return arr;
}
}
Produced hex
47 49 46 38 39 61 02 00 02 00 F7 00 00 E6 00 00 E6 00 00 E5
00 00 E4 00 00 E2 00 00 DF 00 00 DC 00 00 D9 01 01 D5 01 01
D0 01 01 CB 02 02 C5 02 02 BF 03 03 B8 03 03 B1 04 04 A9 05
05 A1 06 06 98 07 07 8F 08 08 86 09 09 7C 0B 0B 71 0C 0C 66
0E 0E 5B 10 10 4F 12 12 43 14 14 36 16 16 29 19 19 1C 1C 1C
1D 1D 1D 1E 1E 1E 1F 1F 1F 20 20 20 21 21 21 22 22 22 23 23
23 24 24 24 25 25 25 26 26 26 27 27 27 28 28 28 29 29 29 2A
2A 2A 2B 2B 2B 2C 2C 2C 2D 2D 2D 2E 2E 2E 2F 2F 2F 30 30 30
31 31 31 32 32 32 33 33 33 34 34 34 35 35 35 36 36 36 37 37
37 38 38 38 39 39 39 3A 3A 3A 3B 3B 3B 3C 3C 3C 3D 3D 3D 3E
3E 3E 3F 3F 3F 40 40 40 41 41 41 42 42 42 43 43 43 44 44 44
45 45 45 46 46 46 47 47 47 48 48 48 44 4E 4A 40 53 4D 39 5D
57 32 65 61 2C 6D 6A 26 73 72 21 79 7A 1D 7E 81 18 82 88 15
86 8E 11 89 93 0F 8C 99 0C 8F 9E 0A 91 A2 08 92 A6 06 93 AA
05 95 AE 04 95 B1 03 96 B4 02 97 B7 02 97 B9 01 98 BC 01 98
BD 00 98 BF 00 98 C1 00 98 C2 00 98 C3 00 98 C4 00 98 C4 00
98 C5 00 98 C5 00 98 C5 00 98 C4 00 98 C4 00 98 C3 00 98 C2
01 98 C1 01 98 BF 01 98 BE 02 98 BC 03 97 BA 04 97 B8 05 97
B5 07 96 B3 09 96 B0 0B 95 AD 0E 94 AA 11 94 A7 15 93 A4 1C
92 A1 23 90 9E 2D 8E 9B 38 8C 99 45 8A 96 54 87 94 66 84 93
7A 81 91 92 7C 90 AC 78 90 CA 72 8F CF 72 91 D4 71 92 D9 70
93 DD 6F 94 E1 6E 95 E5 6D 95 E8 6D 96 EC 6C 96 EE 6B 97 F1
6A 97 F4 6A 98 F6 69 98 F8 68 98 F9 68 98 FB 67 98 FC 67 98
FD 66 98 FE 66 98 FE 66 98 FE 66 98 FF 66 99 FE 66 99 FE 66
99 FE 66 99 FD 66 99 FC 67 99 FB 68 99 FA 68 99 F9 69 99 F7
6A 99 F6 6C 9A F4 6D 9A F2 6E 9A F0 70 9B EE 72 9B EB 74 9C
E9 76 9D E7 79 9D E4 7B 9E E1 7E 9F DE 81 A0 DC 85 A2 D9 88
A3 D6 8C A4 D3 90 A6 D0 94 A8 CC 98 AA C9 9D AC C6 A2 AE C3
A7 B0 BF AD B3 BC B3 B6 B9 B9 B9 BA BA BA BB BB BB BC BC BC
BD BD BD BE BE BE BF BF BF C0 C0 C0 C1 C1 C1 C2 C2 C2 C3 C3
C3 C4 C4 C4 C5 C5 C5 C6 C6 C6 C7 C7 C7 C8 C8 C8 C9 C9 C9 CA
CA CA CB CB CB CC CC CC CD CD CD CE CE CE CF CF CF D0 D0 D0
D1 D1 D1 D2 D2 D2 D3 D3 D3 D4 D4 D4 D5 D5 D5 D6 D6 D6 D7 D7
D7 D8 D8 D8 D9 D9 D9 DA DA DA DB DB DB DC DC DC DD DD DD DE
DE DE DF DF DF E0 E0 E0 E1 E1 E1 E2 E2 E2 E3 E3 E3 E4 E4 E4
E5 E5 E5 E6 E6 E6 E7 E7 E7 E8 E8 E8 E9 E9 E9 EA EA EA EB EB
EB EC EC EC ED ED ED EE EE EE EF EF EF F0 F0 F0 F1 F1 F1 F2
F2 F2 F3 F3 F3 F4 F4 F4 F5 F5 F5 F6 F6 F6 F7 F7 F7 F8 F8 F8
F9 F9 F9 FA FA FA FB FB FB FC FC FC FD FD FD FE FE FE FF FF
FF 21 F9 04 00 00 00 00 00 2C 00 00 00 00 02 00 02 00 00 08
07 00 33 59 39 13 20 20 00 3B
By comparisom I tried encoding 4 pixels with my unfinished gif encoder. I got correct colors and more sensible filesize.
47 49 46 38 39 61 02 00 02 00 91 00 00 FF 66 99 00 99 66 00
99 CC FF 00 00 21 F9 04 00 00 00 00 00 2C 00 00 00 00 02 00
02 00 00 02 03 44 34 05 00 00 00 00 00 3B
Obviously the snow one is more complete I am just trying to get more understanding of the comparative workings and I am thinking maybe it would be ideal to blend some aspects to get best performance for small images, and also seems to show an issue with color.
This is how the encoder works but the GifFrame stores the size too.
Instead, set it on construction and the frames infer the size from that.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.