diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 40 |
1 files changed, 26 insertions, 14 deletions
@@ -1,41 +1,54 @@ gif-encode ========== +This uses a gif encoding library based on a venerable GIF library, a port of a port of a port: + +* Base class : http://www.java2s.com/Code/Java/2D-Graphics-GUI/AnimatedGifEncoder.htm +* @author Kevin Weiner (original Java version - kweiner@fmsware.com) +* @author Thibault Imbert (AS3 version - bytearray.org) +* @author Kevin Kwok (JS version - antimatter15.org) + +It has been converted to use web workers and is hence more event-driven (using tim's tube class). + +Because of the worker-based environment, quantization (using NeuQuant) is split into its own step. The "brain" from NeuQuant may be passed into the encoder, which distributes it to the workers. However NeuQuant is very slow, and does not produce great results for whatever reason, so this documentation leaves it out. The encoder still seems to generate a palette, probably using the first 256 colors (row-major) in the gif. + +The worker code contains a (still untraced) memory leak which causes it to slow down with each run. This is particularly noticeable if you try to encode more than 60 frames, alas. Call "reset" to fire the workers. ```js +// set up a new encoder var encoder = new GifEncoder() +// listen to the "quantized" event if you're using neuquant encoder.on("quantized", function(url){ - status("encoding") encoder.encode() }) +// listen for when a frame is done encoding encoder.on("encoded-frame", function(done,count){ status("encoded " + done + " / " + count) }) +// listen for the end of rendering, returns size of gif encoder.on("rendered", function(bytes){ + status(filesize(bytes)) +}) + +// listen for the end of rendering, returns gif in bytes +encoder.on("rendered-bytes", function(bytes){ status(filesize(bytes.length)) }) +// listen for the end of rendering, returns gif as a data URI (most useful) encoder.on("rendered-url", function(url){ var image = new Image () lastGif = image.src = url - $("#workspace canvas").hide() - $("#workspace").append(image) - $("#uploaded-url").hide().val("") - $("#uploaded-url + br").hide() - $("#save,#upload,#rendered").show() - $("#pause,#render,#add-frame,#save,#upload").enable() - $("#render").html("render gif") - rendering = false - pause(true) + // $("#workspace").append(image) }) - +// render a gif: pass frames into the encoder, then listen function render (frames) { - rendering = true - + if (encoder.working) return; + encoder.reset() var delay = 60 // milliseconds @@ -47,7 +60,6 @@ function render (frames) { try { encoder.encode() } catch (e) { - rendering = false status(e) throw e } |
