sjpeg 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/sjpeg/bit_writer.cc +122 -0
- data/ext/sjpeg/bit_writer.h +169 -0
- data/ext/sjpeg/colors_rgb.cc +691 -0
- data/ext/sjpeg/dichotomy.cc +290 -0
- data/ext/sjpeg/enc.cc +2132 -0
- data/ext/sjpeg/extconf.rb +3 -0
- data/ext/sjpeg/fdct.cc +627 -0
- data/ext/sjpeg/headers.cc +218 -0
- data/ext/sjpeg/jpeg_tools.cc +274 -0
- data/ext/sjpeg/libsjpeg.pc.in +11 -0
- data/ext/sjpeg/score_7.cc +6220 -0
- data/ext/sjpeg/sjpeg.h +353 -0
- data/ext/sjpeg/sjpegi.h +427 -0
- data/ext/sjpeg/yuv_convert.cc +698 -0
- data/lib/sjpeg/version.rb +3 -0
- data/lib/sjpeg.rb +35 -0
- data/sjpeg.gemspec +36 -0
- metadata +143 -0
data/lib/sjpeg.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "sjpeg/version"
|
2
|
+
require "ffi"
|
3
|
+
require "base64"
|
4
|
+
|
5
|
+
module Sjpeg
|
6
|
+
def self.compress(pixels, width, height, quality: 70)
|
7
|
+
in_pointer = FFI::MemoryPointer.new(:uint8, pixels.size)
|
8
|
+
in_pointer.write_array_of_uint8(pixels)
|
9
|
+
out_pointer = FFI::MemoryPointer.new(:pointer)
|
10
|
+
out_size_t = Unstable.SjpegCompress(
|
11
|
+
in_pointer,
|
12
|
+
width,
|
13
|
+
height,
|
14
|
+
quality,
|
15
|
+
out_pointer,
|
16
|
+
)
|
17
|
+
out_result = out_pointer.get_pointer(0)
|
18
|
+
result = out_result.read_array_of_uint8(out_size_t)
|
19
|
+
Unstable.SjpegFreeBuffer(out_result)
|
20
|
+
|
21
|
+
"data:image/jpg;base64," + Base64.encode64(result.pack('C*')).split("\n").join
|
22
|
+
ensure
|
23
|
+
in_pointer.free if in_pointer
|
24
|
+
end
|
25
|
+
|
26
|
+
module Unstable
|
27
|
+
extend FFI::Library
|
28
|
+
ffi_lib File.join(File.expand_path(__dir__), 'sjpeg', 'sjpeg.' + RbConfig::CONFIG['DLEXT'])
|
29
|
+
|
30
|
+
attach_function :SjpegCompress, %i(pointer int int float pointer), :size_t
|
31
|
+
attach_function :SjpegFreeBuffer, %i(pointer), :void
|
32
|
+
end
|
33
|
+
|
34
|
+
private_constant :Unstable
|
35
|
+
end
|
data/sjpeg.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "sjpeg/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sjpeg"
|
7
|
+
spec.version = Sjpeg::VERSION
|
8
|
+
spec.authors = ["Stefano Verna"]
|
9
|
+
spec.email = ["s.verna@datocms.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby bindings for sjpeg"
|
12
|
+
spec.description = "Ruby bindings for sjpeg"
|
13
|
+
spec.homepage = "https://github.com/stefanoverna/sjpeg"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/stefanoverna/sjpeg"
|
18
|
+
spec.metadata["changelog_uri"] = "https://github.com/stefanoverna/sjpeg"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.extensions = %w[ext/sjpeg/extconf.rb]
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency "ffi"
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rake-compiler"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sjpeg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefano Verna
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake-compiler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: Ruby bindings for sjpeg
|
84
|
+
email:
|
85
|
+
- s.verna@datocms.com
|
86
|
+
executables: []
|
87
|
+
extensions:
|
88
|
+
- ext/sjpeg/extconf.rb
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- ext/sjpeg/bit_writer.cc
|
100
|
+
- ext/sjpeg/bit_writer.h
|
101
|
+
- ext/sjpeg/colors_rgb.cc
|
102
|
+
- ext/sjpeg/dichotomy.cc
|
103
|
+
- ext/sjpeg/enc.cc
|
104
|
+
- ext/sjpeg/extconf.rb
|
105
|
+
- ext/sjpeg/fdct.cc
|
106
|
+
- ext/sjpeg/headers.cc
|
107
|
+
- ext/sjpeg/jpeg_tools.cc
|
108
|
+
- ext/sjpeg/libsjpeg.pc.in
|
109
|
+
- ext/sjpeg/score_7.cc
|
110
|
+
- ext/sjpeg/sjpeg.h
|
111
|
+
- ext/sjpeg/sjpegi.h
|
112
|
+
- ext/sjpeg/yuv_convert.cc
|
113
|
+
- lib/sjpeg.rb
|
114
|
+
- lib/sjpeg/version.rb
|
115
|
+
- sjpeg.gemspec
|
116
|
+
homepage: https://github.com/stefanoverna/sjpeg
|
117
|
+
licenses:
|
118
|
+
- MIT
|
119
|
+
metadata:
|
120
|
+
homepage_uri: https://github.com/stefanoverna/sjpeg
|
121
|
+
source_code_uri: https://github.com/stefanoverna/sjpeg
|
122
|
+
changelog_uri: https://github.com/stefanoverna/sjpeg
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.7.6
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Ruby bindings for sjpeg
|
143
|
+
test_files: []
|