Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit ed0cbb4

Browse files
author
Duncan MacKenzie
committed
git subrepo clone https://github.com/mathatan/gifuct-js.git lib/image/gifuct-js
subrepo: subdir: "lib/image/gifuct-js" merged: "961f796" upstream: origin: "https://github.com/mathatan/gifuct-js.git" branch: "master" commit: "961f796" git-subrepo: version: "0.4.0" origin: "https://github.com/ingydotnet/git-subrepo" commit: "5d6aba9"
1 parent 49f2c5c commit ed0cbb4

21 files changed

Lines changed: 2227 additions & 0 deletions

lib/image/gifuct-js/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
bower_components

lib/image/gifuct-js/.gitrepo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; DO NOT EDIT (unless you know what you are doing)
2+
;
3+
; This subdirectory is a git "subrepo", and this file is maintained by the
4+
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
5+
;
6+
[subrepo]
7+
remote = https://github.com/mathatan/gifuct-js.git
8+
branch = master
9+
commit = 961f796dabb1561a0101c310655ec2658beb1cd5
10+
parent = 49f2c5c9a32da0247617fe8ef1e2b52b951327ae
11+
method = merge
12+
cmdver = 0.4.0

lib/image/gifuct-js/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Matt Way
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

lib/image/gifuct-js/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# gifuct-js
2+
A Simple to use javascript .GIF decoder.
3+
4+
We needed to be able to efficiently load and manipulate GIF files for the **[Ruffle][1]** hybrid app (for mobiles). There are a couple of example libraries out there like [jsgif][2] & its derivative [libgif-js][3], however these are admittedly inefficient, and a mess. After pulling our hair out trying to understand the ancient, mystic gif format (hence the project name), we decided to just roll our own. This library also removes any specific drawing code, and simply parses, and decompresses gif files so that you can manipulate and display them however you like. We do include `imageData` patch construction though to get you most of the way there.
5+
6+
### Demo
7+
8+
You can see a demo of this library in action **[here][4]**
9+
10+
### Usage
11+
12+
*Installation:*
13+
14+
bower install --save gifuct-js
15+
16+
*Decoding:*
17+
18+
This decoder uses **[js-binary-schema-parser][5]** to parse the gif files (you can examine the schema in the source). This means the gif file must firstly be converted into a `Uint8Array` buffer in order to decode it. Some examples:
19+
20+
* *Angularjs*
21+
22+
23+
return $http.get(gifURL, {
24+
responseType: 'arraybuffer'
25+
}).then(function(result){
26+
var gif = new GIF(result.data);
27+
// return the frame data as the promise result
28+
return gif.decompressFrames(true);
29+
});
30+
31+
* *XMLHttpRequest*
32+
33+
34+
var oReq = new XMLHttpRequest();
35+
oReq.open("GET", gifURL, true);
36+
oReq.responseType = "arraybuffer";
37+
38+
oReq.onload = function (oEvent) {
39+
var arrayBuffer = oReq.response; // Note: not oReq.responseText
40+
if (arrayBuffer) {
41+
var gif = new GIF(arrayBuffer);
42+
var frames = gif.decompressFrames(true);
43+
// do something with the frame data
44+
}
45+
};
46+
47+
oReq.send(null);
48+
49+
*Result:*
50+
51+
The result of the `decompressFrames(buildPatch)` function returns an array of all the GIF image frames, and their meta data. Here is a an example frame:
52+
53+
{
54+
// The color table lookup index for each pixel
55+
pixels: [...],
56+
// the dimensions of the gif frame (see disposal method)
57+
dims: {
58+
top: 0,
59+
left: 10,
60+
width: 100,
61+
height: 50
62+
},
63+
// the time in milliseconds that this frame should be shown
64+
delay: 50,
65+
// the disposal method (see below)
66+
disposalType: 1,
67+
// an array of colors that the pixel data points to
68+
colorTable: [...],
69+
// An optional color index that represents transparency (see below)
70+
transparentIndex: 33,
71+
// Uint8ClampedArray color converted patch information for drawing
72+
patch: [...]
73+
}
74+
75+
*Automatic Patch Generation:*
76+
77+
If the `buildPatch` param of the `dcompressFrames()` function is `true`, the parser will not only return the parsed and decompressed gif frames, but will also create canvas ready `Uint8ClampedArray` arrays of each gif frame image, so that they can easily be drawn using `ctx.putImageData()` for example. This requirement is common, however it was made optional because it makes assumptions about transparency. The [demo][4] makes use of this option.
78+
79+
*Disposal Method:*
80+
81+
The `pixel` data is stored as a list of indexes for each pixel. These each point to a value in the `colorTable` array, which contain the color that each pixel should be drawn. Each frame of the gif may not be the full size, but instead a patch that needs to be drawn over a particular location. The `disposalType` defines how that patch should be drawn over the gif canvas. In most cases, that value will be `1`, indicating that the gif frame should be simply drawn over the existing gif canvas without altering any pixels outside the frames patch dimensions. More can be read about this [here][6].
82+
83+
*Transparency:*
84+
85+
If a `transparentIndex` is defined for a frame, it means that any pixel within the pixel data that matches this index should not be drawn. When drawing the patch using canvas, this means setting the alpha value for this pixel to `0`.
86+
87+
### Drawing the GIF
88+
89+
Check out the **[demo][4]** for an example of how to draw/manipulate a gif using this library. We wanted the library to be drawing agnostic to allow users to do what they wish with the raw gif data, rather than impose a method that has to be altered. On this note however, we provide an easy interface for creating commonly used canvas pixel data for drawing ease.
90+
91+
### Thanks to
92+
93+
We underestimated the convolutedness of the GIF format, so this library couldn't have been made without the help of:
94+
95+
- [Project: What's In A GIF - Bit by Byte][7] - An amazingly detailed blog by Matthew Flickinger
96+
- [jsgif][2]
97+
- The [*almost correct*] LZW decompression from [this neat gist][8]
98+
99+
### Who are we?
100+
101+
[Unassigned][9]
102+
103+
[1]: http://ruffle.us
104+
[2]: http://slbkbs.org/jsgif/
105+
[3]: https://github.com/buzzfeed/libgif-js
106+
[4]: http://matt-way.github.io/gifuct-js/
107+
[5]: https://github.com/matt-way/jsBinarySchemaParser
108+
[6]: http://www.matthewflickinger.com/lab/whatsinagif/animation_and_transparency.asp
109+
[7]: http://www.matthewflickinger.com/lab/whatsinagif/index.html
110+
[8]: https://gist.github.com/devunwired/4479231
111+
[9]: http://unassigned.co

lib/image/gifuct-js/bower.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "gifuct-js",
3+
"version": "1.0.0",
4+
"homepage": "https://github.com/matt-way/gifuct-js",
5+
"authors": [
6+
"Matt Way <matt__way@hotmail.com>"
7+
],
8+
"main": "dist/gifuct-js.js",
9+
"description": "Easy to use efficient .GIF parsing in the browser",
10+
"keywords": [
11+
"gif",
12+
"parser",
13+
"javascript"
14+
],
15+
"license": "MIT",
16+
"ignore": [
17+
"**/.*",
18+
"node_modules",
19+
"bower_components",
20+
"demo",
21+
"gulpfile.js",
22+
"package.json"
23+
],
24+
"devDependencies": {
25+
"js-binary-schema-parser": "~1.0.0"
26+
}
27+
}

lib/image/gifuct-js/build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
cd $DIR
6+
7+
mkdir -p dist
8+
mkdir -p tmp
9+
10+
npm install
11+
node_modules/.bin/babel src -q -d tmp
12+
node_modules/.bin/browserify --standalone gifuct tmp/gif.js -o tmp/gifuct.js
13+
node_modules/.bin/uglifyjs tmp/gifuct.js -o dist/gif.js --beautify
14+
node_modules/.bin/uglifyjs dist/gif.js -o dist/gif.min.js --compress --mangle --source-map "filename=dist/gif.min.js.map"
15+
16+
rm -rf tmp

lib/image/gifuct-js/demo/demo.css

Whitespace-only changes.

0 commit comments

Comments
 (0)