lilimg 0.2.0 → 0.2.2

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.
data/lilimg.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'lilimg'
5
- s.version = '0.2.0'
5
+ s.version = '0.2.2'
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ['Tomas Pollak']
8
8
  s.email = ['tomas@forkhq.com']
@@ -15,4 +15,4 @@ Gem::Specification.new do |s|
15
15
  # s.require_path = 'lib'
16
16
  # s.bindir = 'bin'
17
17
  # s.add_runtime_dependency 'rack-throttle', '~> 0.3'
18
- end
18
+ end
data/spec/lilimg_spec.rb CHANGED
@@ -1,22 +1,85 @@
1
1
  $VERBOSE = '1'
2
+ require 'zlib'
2
3
  require_relative('../ext/lilimg/lilimg.so')
3
4
 
4
5
  describe 'Lilimg' do
6
+ def chunk(type, data)
7
+ [data.bytesize].pack('N') + type + data + [Zlib.crc32(type + data)].pack('N')
8
+ end
9
+
10
+ def build_png(w = 8, h = 8)
11
+ raw = (0...h).map { "\x00".b + ("\xFF\x00\x00\xFF".b * w) }.join
12
+ "\x89PNG\r\n\x1A\n".b +
13
+ chunk('IHDR', [w, h, 8, 6, 0, 0, 0].pack('NNCCCCC')) +
14
+ chunk('IDAT', Zlib::Deflate.deflate(raw)) +
15
+ chunk('IEND', '')
16
+ end
17
+
18
+ let(:jpeg) { IO.read('./example/label.jpg', mode: 'rb') }
19
+
20
+ describe '.jpeg_to_gif' do
21
+ it 'works in threads' do
22
+ threads = 10.times.map do
23
+ Thread.new do
24
+ expect(jpeg[0]).to eql("\xFF".b)
25
+ expect(jpeg[1]).to eql("\xD8".b)
26
+ gif = Lilimg.jpeg_to_gif(jpeg, 4)
27
+ expect(gif.to_s[0..3]).to eql("GIF8")
28
+ end
29
+ end
30
+ threads.each(&:join)
31
+ end
5
32
 
6
- it 'works in threads' do
7
- threads = 10.times.map do
8
- jpeg = IO.read('./example/label.jpg')
9
- Thread.new do
10
- # check for JPEG header
11
- expect(jpeg[0]).to eql("\xFF")
12
- expect(jpeg[1]).to eql("\xD8")
13
- # convert to GIF
14
- gif = Lilimg.jpeg_to_gif(jpeg, 4)
15
- expect(gif.to_s[0..3]).to eql("GIF8")
33
+ it 'does not corrupt the heap when called repeatedly' do
34
+ 20.times do
35
+ expect(Lilimg.jpeg_to_gif(jpeg.dup, 4)[0..3]).to eql("GIF8")
36
+ GC.start
16
37
  end
17
38
  end
18
- # puts "Waiting for processes to finish"
19
- threads.each(&:join)
39
+
40
+ it 'converts grayscale JPEGs' do
41
+ gray = IO.read('./example/gray.jpg', mode: 'rb')
42
+ 5.times { expect(Lilimg.jpeg_to_gif(gray.dup, 4)[0..3]).to eql("GIF8") }
43
+ GC.start
44
+ end
45
+
46
+ it 'raises on non-JPEG data' do
47
+ expect { Lilimg.jpeg_to_gif('hello world, not a jpeg at all', 4) }.to raise_error(RuntimeError, /Not a JPEG/)
48
+ end
49
+
50
+ it 'raises on truncated data and keeps working' do
51
+ expect { Lilimg.jpeg_to_gif(jpeg[0, 200], 4) }.to raise_error(RuntimeError)
52
+ GC.start
53
+ expect(Lilimg.jpeg_to_gif(jpeg, 4)[0..3]).to eql("GIF8")
54
+ end
55
+
56
+ it 'raises on a non-string' do
57
+ expect { Lilimg.jpeg_to_gif(nil, 4) }.to raise_error(TypeError)
58
+ end
20
59
  end
21
60
 
61
+ describe '.png_to_gif' do
62
+ it 'converts a PNG to a GIF' do
63
+ expect(Lilimg.png_to_gif(build_png, 4)[0..3]).to eql("GIF8")
64
+ end
65
+
66
+ it 'does not corrupt the heap when called repeatedly' do
67
+ png = build_png(64, 64)
68
+ 20.times do
69
+ expect(Lilimg.png_to_gif(png.dup, 4)[0..3]).to eql("GIF8")
70
+ GC.start
71
+ end
72
+ end
73
+
74
+ it 'raises on non-PNG data' do
75
+ expect { Lilimg.png_to_gif('hello world, not a png at all', 4) }.to raise_error(RuntimeError, /Not a PNG/)
76
+ end
77
+
78
+ it 'raises on a corrupt PNG and keeps working' do
79
+ png = build_png
80
+ expect { Lilimg.png_to_gif(png[0, 40], 4) }.to raise_error(RuntimeError, /Unable to decode/)
81
+ GC.start
82
+ expect(Lilimg.png_to_gif(png, 4)[0..3]).to eql("GIF8")
83
+ end
84
+ end
22
85
  end
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lilimg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Pollak
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2018-06-15 00:00:00.000000000 Z
10
+ date: 2026-10-14 00:00:00.000000000 Z
12
11
  dependencies: []
13
- description:
14
12
  email:
15
13
  - tomas@forkhq.com
16
14
  executables: []
@@ -21,12 +19,15 @@ files:
21
19
  - ".gitignore"
22
20
  - Rakefile
23
21
  - example/build.sh
22
+ - example/gray.jpg
24
23
  - example/label.jpg
25
24
  - example/test.c
26
25
  - example/test.rb
27
26
  - ext/lilimg/extconf.rb
28
27
  - ext/lilimg/jo_gif.h
29
28
  - ext/lilimg/lilimg.c
29
+ - ext/lilimg/lodepng.c
30
+ - ext/lilimg/lodepng.h
30
31
  - ext/lilimg/nanojpeg.h
31
32
  - lib/lilimg.rb
32
33
  - lilimg.gemspec
@@ -35,7 +36,6 @@ files:
35
36
  homepage: https://github.com/tomas/lilimg
36
37
  licenses: []
37
38
  metadata: {}
38
- post_install_message:
39
39
  rdoc_options: []
40
40
  require_paths:
41
41
  - lib
@@ -50,9 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  - !ruby/object:Gem::Version
51
51
  version: 1.3.6
52
52
  requirements: []
53
- rubyforge_project:
54
- rubygems_version: 2.6.13
55
- signing_key:
53
+ rubygems_version: 3.6.2
56
54
  specification_version: 4
57
55
  summary: Native image processing in Ruby without deps.
58
56
  test_files: []