gifenc 0.1.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f9e18acc20b6acafb26735998f88134ede1cef587114377b996c6ec1c3e6432
4
- data.tar.gz: 7a18a82e735f39c023bf9b7cf4918ad13fa2e0ea59e6c5594f9ddf969f7e8624
3
+ metadata.gz: 5c38b840026c2289d2524c5e06bf2d1943b468662bd45a0f7abe456a6405badc
4
+ data.tar.gz: fc17037791eff68a2fec84b7689b082726e51aa1363b1e94885a9535f4b37db1
5
5
  SHA512:
6
- metadata.gz: b11f2d061f5443a35d4134f077a2ae529b5084bde5ae42f449fb11c7ac0b8c9c7b7c359110b978494e2f96ac5b0f8bc9cae8e0156d1fb5598e22f2c06d92f2f1
7
- data.tar.gz: f9c1e03801eebffbf4e78c48a90c49e040e1b87f3bc3f8d34c8ec8d069008456276e5c3333d5af53edfe4006518ec2f65ff92bdcf4730856556615682c41e411
6
+ metadata.gz: 54367e7f3751f0370fe6e4a297fb29b323a25d25ad9ef0e9a435ec8df3cc6010ff2f012d41cda0195cb8a42456069e15a03f3fdfd78f0990be1ecb78fd5f35f9
7
+ data.tar.gz: 12e4facd900f5628554bfc479044ffe33df18dfaf365586dbc259eeace2e643c9cecb6b187c7276f0eba64b04c1e4f987486635d0e4bae0d2572453d9b795962
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,41 @@
1
+ # Changelog
2
+
3
+ ### 0.2.1 (18/Mar/2024)
4
+
5
+ Improved the image copy method. It now automatically corrects both source and destination offsets / dimensions to prevent any out of bounds errors, allows to specify a bounding box to which the copying should be restricted to, and allows to "copy with transparency", which will copy every color except for the transparent one.
6
+
7
+ ### 0.2.0 (05/Mar/2024)
8
+
9
+ A big update, with the main changes being divided in two categories: mathematical methods and drawing methods.
10
+
11
+ - 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:
12
+ * Bound checking, calculation of bounding boxes and convex hulls.
13
+ * Changes of coordinates, cartesian and polar coordinate support, etc.
14
+ * Point operations, such as translations, dilations / scalings, linear and convex combinations, scalar product, center of mass, etc.
15
+ * Point transformations, such as rotations, projections and reflections.
16
+ * Norms (L1, euclidean, supremum), normalization, distances.
17
+ * Angles, parallelism, orthogonality, normal vectors...
18
+
19
+ - Significantly expanded the drawing functionality, including:
20
+ * Improved line drawing, and added line styles (dashed, dotted, etc).
21
+ * Added circles and general (axis-aligned) ellipses.
22
+ * Added grids, polygonal chains and spirals.
23
+ * Arbitrary parametric curves and function graphs given a lambda function.
24
+ * Implemented the flood fill / bucket tool.
25
+ * Added a general Brush class to enable more flexible drawing.
26
+
27
+ Many sample GIFs, showcasing all this new functionality, were added in the [Examples](https://github.com/edelkas/gifenc/tree/master/examples) folder as well.
28
+
29
+ - Additional new functionality includes:
30
+ * Copy: Ability to copy a region from one image to another.
31
+ * Compress: Ability to LZW-compress image data on the fly, instead of keeping
32
+ everything raw in memory until final encode time. Particularly helpful for
33
+ GIFs with thousands of frames on systems with low memory.
34
+
35
+ ### 0.1.0 (14/Feb/2024)
36
+
37
+ Initial release. Includes:
38
+
39
+ - Encoding working, with support for most of the specification (missing interlacing and Plain Text / Comment extensions).
40
+ - Basic color table and image manipulation.
41
+ - A few drawing primitives (lines and rectangles).
data/README.md CHANGED
@@ -1,12 +1,17 @@
1
1
  # gifenc
2
2
 
3
+ [![Gem Version](https://img.shields.io/gem/v/gifenc.svg)](https://rubygems.org/gems/gifenc)
4
+ [![Gem](https://img.shields.io/gem/dt/gifenc.svg)](https://rubygems.org/gems/gifenc)
5
+ [![Documentation](https://img.shields.io/badge/docs-grey.svg)](https://www.rubydoc.info/gems/gifenc)
6
+ [![Examples](https://img.shields.io/badge/examples-grey.svg)](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, but will be soon. There's a solid `Geometry` module and decent drawing functionality. 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
 
@@ -46,7 +51,7 @@ end
46
51
  gif.save('test.gif')
47
52
  ```
48
53
 
49
- Let's see a step-by-step overview, refer to the following sections for an in-depth explanation of the actual details for each of the topics involved.
54
+ Let's see a step-by-step overview, refer to the documentation for an in-depth explanation of the actual details for each of the topics involved.
50
55
  1. The first thing we do is create two **Color Tables**, one with red shades, and another with green shades. Since GIF is an indexed image format, it can only use colors from predefined palettes of at most 256 colors. `Gifenc` comes equipped with several default ones, but you can build your own, and operate with them.
51
56
  2. We create the GIF object. We select the red color table to be the **GCT** (_Global Color Table_), which is used for all frames that do not contain an explicit **LCT** (_Local Color Table_). We also set the GIF to loop indefinitely.
52
57
  3. We create the first frame, this will act as the background. We use the green color table as LCT for this frame. We set a few attributes, such as the default color of the canvas, the length of the frame, and the color used for transparency. We draw a sequence of centered green squares, they will help to see the transparency of the next frames.
@@ -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.chr # Extension label
24
- stream << body # Extension content
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 = 0xF9
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" # Block size (always 4 bytes)
158
- str += flags # Packed fields
159
- str += [@delay].pack('S<') # Delay time
160
- str += [trans_color].pack('C') # Transparent index
161
- str += BLOCK_TERMINATOR
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 = 0xFF
196
+ LABEL = "\xFF".freeze
197
197
 
198
198
  # Application identifier. Must be an 8 character ASCII string.
199
199
  # @return [String] The identifier string.