gifenc 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/CHANGELOG.md +36 -0
- data/README.md +7 -2
- data/lib/errors.rb +4 -0
- data/lib/extensions.rb +11 -11
- data/lib/geometry.rb +599 -23
- data/lib/gif.rb +47 -2
- data/lib/gifenc.rb +7 -0
- data/lib/image.rb +808 -115
- data/lib/util.rb +10 -0
- metadata +11 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6f67cc6f62dedeaa913d3de8a8729ff5af750799a5d9bbbd8b9693092fadc5ee
|
|
4
|
+
data.tar.gz: 7b22b1ca32a728372175f58affa8eeeaf495eff2f6357557b88554406ab4e375
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14483dee19a0cfdc922d14f90816662ee13aeccbe78b247f69c84f805be243799c74141a169610f9420a935143744a85325e9ea57fa344e43c37e27631d3387d
|
|
7
|
+
data.tar.gz: 31a19387a6f2581f54ba6c1ad2fca893021b3e82c55d092adab6e274214f613fc3ccad52158e93c2dcdb51f4c9d1cfa7b839750af20949967cf5bc1bfca8a78f
|
data/.yardopts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
lib/**/*.rb -m markdown --no-private - docs/**/*
|
|
1
|
+
lib/**/*.rb -m markdown --no-private - CHANGELOG.md docs/**/*
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
### 0.2.0 (05/Mar/2024)
|
|
4
|
+
|
|
5
|
+
A big update, with the main changes being divided in two categories: mathematical methods and drawing methods.
|
|
6
|
+
|
|
7
|
+
- Added a `Geometry` module that abstracts a lot of mathematical - and more specifically geometrical - functionality, that is useful throughout the program, but particularly for drawing. A Point class is included, which represents both 2D points and vectors, depending on context. This module includes:
|
|
8
|
+
* Bound checking, calculation of bounding boxes and convex hulls.
|
|
9
|
+
* Changes of coordinates, cartesian and polar coordinate support, etc.
|
|
10
|
+
* Point operations, such as translations, dilations / scalings, linear and convex combinations, scalar product, center of mass, etc.
|
|
11
|
+
* Point transformations, such as rotations, projections and reflections.
|
|
12
|
+
* Norms (L1, euclidean, supremum), normalization, distances.
|
|
13
|
+
* Angles, parallelism, orthonality, normal vectors...
|
|
14
|
+
|
|
15
|
+
- Significantly expanded the drawing functionality, including:
|
|
16
|
+
* Improved line drawing, and added line styles (dashed, dotted, etc).
|
|
17
|
+
* Added circles and general (axis-aligned) ellipses.
|
|
18
|
+
* Added grids, polygonal chains and spirals.
|
|
19
|
+
* Arbitrary parametric curves and function graphs given a lambda function.
|
|
20
|
+
* Implemented the flood fill / bucket tool.
|
|
21
|
+
|
|
22
|
+
Many sample GIFs, showcasing all this new functionality, were added in the [Examples](https://github.com/edelkas/gifenc/tree/master/examples) folder as well.
|
|
23
|
+
|
|
24
|
+
- Other functionality added includes:
|
|
25
|
+
* Copy: Ability to copy a region from one image to another.
|
|
26
|
+
* Compress: Ability to LZW-compress image data on the fly, instead of keeping
|
|
27
|
+
everything raw in memory until final encode time. Particularly helpful for
|
|
28
|
+
GIFs with thousands of frames on systems with low memory.
|
|
29
|
+
|
|
30
|
+
### 0.1.0 (14/Feb/2024)
|
|
31
|
+
|
|
32
|
+
Initial release. Includes:
|
|
33
|
+
|
|
34
|
+
- Encoding working, with support for most of the specification (missing interlacing and Plain Text / Comment extensions).
|
|
35
|
+
- Basic color table and image manipulation.
|
|
36
|
+
- A few drawing primitives (lines and rectangles).
|
data/README.md
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
# gifenc
|
|
2
2
|
|
|
3
|
+
[](https://rubygems.org/gems/gifenc)
|
|
4
|
+
[](https://rubygems.org/gems/gifenc)
|
|
5
|
+
[](https://www.rubydoc.info/gems/gifenc)
|
|
6
|
+
[](https://github.com/edelkas/gifenc/tree/master/examples)
|
|
7
|
+
|
|
3
8
|
A pure Ruby library with no external dependencies that allows to encode, decode and edit GIFs. Its main goals are to:
|
|
4
9
|
|
|
5
10
|
* Support the full GIF [specification](https://www.w3.org/Graphics/GIF/spec-gif89a.txt) for both encoding and decoding.
|
|
6
11
|
* Have a decent suite of editing functionalities, so that the need for external tools is avoided as much as possible.
|
|
7
12
|
* Have a succint and comfortable syntax to use.
|
|
8
13
|
|
|
9
|
-
Currently, the specs are almost fully supported for encoding. Decoding is not yet available, and the editing methods are very limited.
|
|
14
|
+
Currently, the specs are almost fully supported for encoding. Decoding is not yet available, and the editing methods are very limited. See the [Reference](https://www.rubydoc.info/gems/gifenc) for the full documentation, as well as [Examples](https://github.com/edelkas/gifenc/tree/master/examples) for a list of sample snippets and GIFs.
|
|
10
15
|
|
|
11
16
|
## A first example
|
|
12
17
|
|
|
@@ -55,7 +60,7 @@ Let's see a step-by-step overview, refer to the following sections for an in-dep
|
|
|
55
60
|
|
|
56
61
|
Producing the second variation is surprisingly simple. It suffices to add the option `disposal: Gifenc::DISPOSAL_PREV` to the frames (except for the background). More on this later.
|
|
57
62
|
|
|
58
|
-
See the [Examples](examples) folder for more code samples; the resulting GIFs are stored [here](res).
|
|
63
|
+
See the [Examples](https://github.com/edelkas/gifenc/tree/master/examples) folder for more code samples; the resulting GIFs are stored [here](https://github.com/edelkas/gifenc/tree/master/res).
|
|
59
64
|
|
|
60
65
|
## Resources
|
|
61
66
|
|
data/lib/errors.rb
CHANGED
|
@@ -20,5 +20,9 @@ module Gifenc
|
|
|
20
20
|
# such as trying to append 2 Graphic Control Extensions to the same image.
|
|
21
21
|
class ExtensionError < Exception
|
|
22
22
|
end
|
|
23
|
+
|
|
24
|
+
# Raised when a mathematic error happens in any of the calculations.
|
|
25
|
+
class GeometryError < Exception
|
|
26
|
+
end
|
|
23
27
|
end
|
|
24
28
|
end
|
data/lib/extensions.rb
CHANGED
|
@@ -7,7 +7,7 @@ module Gifenc
|
|
|
7
7
|
class Extension
|
|
8
8
|
|
|
9
9
|
# 1-byte field indicating the beginning of an extension block.
|
|
10
|
-
EXTENSION_INTRODUCER = '!'
|
|
10
|
+
EXTENSION_INTRODUCER = '!'.freeze
|
|
11
11
|
|
|
12
12
|
# Create a new generic extension block.
|
|
13
13
|
# @param label [Integer] Label of the extension, uniquely identifies the type of extension.
|
|
@@ -20,8 +20,8 @@ module Gifenc
|
|
|
20
20
|
# @param stream [IO] Stream to write the data to.
|
|
21
21
|
def encode(stream)
|
|
22
22
|
stream << EXTENSION_INTRODUCER
|
|
23
|
-
stream << @label
|
|
24
|
-
stream << body
|
|
23
|
+
stream << @label # Extension label
|
|
24
|
+
stream << body # Extension content
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
# This extension precedes a *single* image and controls several of its rendering
|
|
@@ -67,7 +67,7 @@ module Gifenc
|
|
|
67
67
|
class GraphicControl < Extension
|
|
68
68
|
|
|
69
69
|
# Label identifying a Graphic Control Extension block.
|
|
70
|
-
LABEL =
|
|
70
|
+
LABEL = "\xF9".freeze
|
|
71
71
|
|
|
72
72
|
# Specifies the time, in 1/100ths of a second, to leave this image onscreen
|
|
73
73
|
# before moving on to rendering the next one in the GIF. Must be between
|
|
@@ -150,15 +150,15 @@ module Gifenc
|
|
|
150
150
|
((@disposal || DEFAULT_DISPOSAL) & 0b111) << 2 |
|
|
151
151
|
((@user_input ? 1 : 0) & 0b1 ) << 1 |
|
|
152
152
|
((!!@trans_color ? 1 : 0) & 0b1 )
|
|
153
|
-
].pack('C')
|
|
153
|
+
].pack('C'.freeze)
|
|
154
154
|
trans_color = !@trans_color ? DEFAULT_TRANS_COLOR : @trans_color
|
|
155
155
|
|
|
156
156
|
# Main params
|
|
157
|
-
str = "\x04"
|
|
158
|
-
str
|
|
159
|
-
str
|
|
160
|
-
str
|
|
161
|
-
str
|
|
157
|
+
str = "\x04" # Block size (always 4 bytes)
|
|
158
|
+
str << flags # Packed fields
|
|
159
|
+
str << [@delay].pack('S<'.freeze) # Delay time
|
|
160
|
+
str << [trans_color].pack('C'.freeze) # Transparent index
|
|
161
|
+
str << BLOCK_TERMINATOR
|
|
162
162
|
|
|
163
163
|
str
|
|
164
164
|
end
|
|
@@ -193,7 +193,7 @@ module Gifenc
|
|
|
193
193
|
class Application < Extension
|
|
194
194
|
|
|
195
195
|
# Label identifying an Application Extension block.
|
|
196
|
-
LABEL =
|
|
196
|
+
LABEL = "\xFF".freeze
|
|
197
197
|
|
|
198
198
|
# Application identifier. Must be an 8 character ASCII string.
|
|
199
199
|
# @return [String] The identifier string.
|