image_pack 0.2.2 → 0.2.3

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.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/README.md +23 -4
  4. data/ext/image_pack/extconf.rb +35 -124
  5. data/ext/image_pack/image_pack.c +638 -595
  6. data/ext/image_pack/mozjpeg_sources.rb +178 -0
  7. data/ext/image_pack/vendor/mozjpeg/BUILDING.md +744 -0
  8. data/ext/image_pack/vendor/mozjpeg/CODE_OF_CONDUCT.md +15 -0
  9. data/ext/image_pack/vendor/mozjpeg/ChangeLog.md +1996 -0
  10. data/lib/image_pack/configuration.rb +54 -8
  11. data/lib/image_pack/version.rb +1 -1
  12. data/lib/image_pack.rb +65 -18
  13. metadata +13 -78
  14. data/ext/image_pack/vendor/mozjpeg/README.ijg +0 -258
  15. data/ext/image_pack/vendor/mozjpeg/cdjpeg.c +0 -156
  16. data/ext/image_pack/vendor/mozjpeg/cjpeg.c +0 -961
  17. data/ext/image_pack/vendor/mozjpeg/djpeg.c +0 -855
  18. data/ext/image_pack/vendor/mozjpeg/jaricom.c +0 -157
  19. data/ext/image_pack/vendor/mozjpeg/jcarith.c +0 -972
  20. data/ext/image_pack/vendor/mozjpeg/jcstest.c +0 -126
  21. data/ext/image_pack/vendor/mozjpeg/jdarith.c +0 -782
  22. data/ext/image_pack/vendor/mozjpeg/jdatadst-tj.c +0 -198
  23. data/ext/image_pack/vendor/mozjpeg/jdatasrc-tj.c +0 -194
  24. data/ext/image_pack/vendor/mozjpeg/jpegtran.c +0 -827
  25. data/ext/image_pack/vendor/mozjpeg/jpegyuv.c +0 -172
  26. data/ext/image_pack/vendor/mozjpeg/rdbmp.c +0 -690
  27. data/ext/image_pack/vendor/mozjpeg/rdcolmap.c +0 -253
  28. data/ext/image_pack/vendor/mozjpeg/rdgif.c +0 -720
  29. data/ext/image_pack/vendor/mozjpeg/rdjpeg.c +0 -160
  30. data/ext/image_pack/vendor/mozjpeg/rdjpgcom.c +0 -494
  31. data/ext/image_pack/vendor/mozjpeg/rdpng.c +0 -194
  32. data/ext/image_pack/vendor/mozjpeg/rdppm.c +0 -781
  33. data/ext/image_pack/vendor/mozjpeg/rdswitch.c +0 -642
  34. data/ext/image_pack/vendor/mozjpeg/rdtarga.c +0 -508
  35. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch32/jccolext-neon.c +0 -148
  36. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch32/jchuff-neon.c +0 -334
  37. data/ext/image_pack/vendor/mozjpeg/simd/arm/aarch32/jsimd.c +0 -976
  38. data/ext/image_pack/vendor/mozjpeg/simd/i386/jsimd.c +0 -1312
  39. data/ext/image_pack/vendor/mozjpeg/simd/mips/jsimd.c +0 -1143
  40. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jccolext-mmi.c +0 -455
  41. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jccolor-mmi.c +0 -148
  42. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jcgray-mmi.c +0 -132
  43. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jcgryext-mmi.c +0 -374
  44. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jcsample-mmi.c +0 -98
  45. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdcolext-mmi.c +0 -415
  46. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdcolor-mmi.c +0 -139
  47. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdmerge-mmi.c +0 -149
  48. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdmrgext-mmi.c +0 -615
  49. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jdsample-mmi.c +0 -304
  50. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jfdctfst-mmi.c +0 -255
  51. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jfdctint-mmi.c +0 -398
  52. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jidctfst-mmi.c +0 -395
  53. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jidctint-mmi.c +0 -571
  54. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jquanti-mmi.c +0 -124
  55. data/ext/image_pack/vendor/mozjpeg/simd/mips64/jsimd.c +0 -866
  56. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jccolext-altivec.c +0 -269
  57. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jccolor-altivec.c +0 -116
  58. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jcgray-altivec.c +0 -111
  59. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jcgryext-altivec.c +0 -228
  60. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jcsample-altivec.c +0 -159
  61. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdcolext-altivec.c +0 -276
  62. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdcolor-altivec.c +0 -106
  63. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdmerge-altivec.c +0 -130
  64. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdmrgext-altivec.c +0 -329
  65. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jdsample-altivec.c +0 -400
  66. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jfdctfst-altivec.c +0 -154
  67. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jfdctint-altivec.c +0 -258
  68. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jidctfst-altivec.c +0 -255
  69. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jidctint-altivec.c +0 -357
  70. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jquanti-altivec.c +0 -250
  71. data/ext/image_pack/vendor/mozjpeg/simd/powerpc/jsimd.c +0 -884
  72. data/ext/image_pack/vendor/mozjpeg/strtest.c +0 -170
  73. data/ext/image_pack/vendor/mozjpeg/tjbench.c +0 -1044
  74. data/ext/image_pack/vendor/mozjpeg/tjexample.c +0 -406
  75. data/ext/image_pack/vendor/mozjpeg/tjunittest.c +0 -961
  76. data/ext/image_pack/vendor/mozjpeg/tjutil.c +0 -70
  77. data/ext/image_pack/vendor/mozjpeg/transupp.c +0 -2373
  78. data/ext/image_pack/vendor/mozjpeg/turbojpeg-jni.c +0 -1259
  79. data/ext/image_pack/vendor/mozjpeg/turbojpeg.c +0 -2320
  80. data/ext/image_pack/vendor/mozjpeg/wrbmp.c +0 -552
  81. data/ext/image_pack/vendor/mozjpeg/wrgif.c +0 -580
  82. data/ext/image_pack/vendor/mozjpeg/wrjpgcom.c +0 -577
  83. data/ext/image_pack/vendor/mozjpeg/wrppm.c +0 -366
  84. data/ext/image_pack/vendor/mozjpeg/wrtarga.c +0 -258
  85. data/ext/image_pack/vendor/mozjpeg/yuvjpeg.c +0 -268
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 301f10cb975250ef59e3bf1beae23208aeb3e40d6598721323b93e4ea8d2eee8
4
- data.tar.gz: cc8b9139d2a16ebe94f2c32a047202ea9e9fdf04a608c1bc4608eb5d9e53d589
3
+ metadata.gz: 606688569aac1fa1515edefe270b18a04e5b0042de602b18663964726d8fbb34
4
+ data.tar.gz: 9092fcf9fa3c061edc87ce2a22544acfe52dfa6ce4fe39961c95a1d17220a6b0
5
5
  SHA512:
6
- metadata.gz: 2f9bbde96c6269da00a9514aa6eb7660024435ddcb05ae10e57e02338ce69b8a3465b6f7380c551986e0b0e067db041c34fc640074b86e3da189442486e2c111
7
- data.tar.gz: 906df1d615b6ae0fb0fbb05636fcb8916ff671886b7319aad70801099974bc742da54444fcb858293c4777ffe89a87390c8d4de78d83c1a613314132dbf1661a
6
+ metadata.gz: ad6b0db99c56d69c99d9216559e3c114a2079941a4f879e69508126bbf12b070844dc53e806b3da7637783a205528c10136c3cd3bac8f60b5fd6ee2ddcad01eb
7
+ data.tar.gz: f1acfa9f5a7154d1ea201ae66658da704a5ee5d207886b096d284b7b69eca175d668993dba127b0a609d6fb5b68492196edb8d3bb70d12575f129c095c6b7704
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Changelog
2
2
 
3
+ - Lowered the runtime floor to Ruby >= 3.1.0 while keeping `execution: :offload` Ruby >= 3.4-only and explicitly unsupported on older Rubies.
3
4
  ## 0.2.2
4
5
 
5
6
  - Fixed native cleanup safety: native contexts are now released through `rb_ensure`, including Ruby exception paths from argument coercion, config reads, native status errors, output `String` allocation, and file-output failures.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # image_pack
2
2
 
3
- `image_pack` is a Ruby-native JPEG compressor prototype for Ruby `>= 3.4.0`.
3
+ `image_pack` is a Ruby-native JPEG compressor prototype for Ruby `>= 3.1.0`.
4
4
 
5
5
  Current version: `0.2.2`.
6
6
 
@@ -123,6 +123,25 @@ The metric is a fast native luma SSIM-like guard based on 8x8 blocks, not a full
123
123
 
124
124
  ## Execution modes
125
125
 
126
+ ### Ruby compatibility for offload
127
+
128
+ ImagePack supports Ruby `>= 3.1.0`. Ruby `>= 3.4.0` is required only for the scheduler-aware `execution: :offload` path.
129
+
130
+ On Ruby 3.1–3.3:
131
+
132
+ - `execution: :direct` works.
133
+ - `execution: :nogvl` works.
134
+ - `execution: :auto` works, but never selects `:offload`.
135
+ - explicit `execution: :offload` raises `ImagePack::UnsupportedError`.
136
+
137
+ On Ruby 3.4+:
138
+
139
+ - `execution: :offload` is available.
140
+ - `execution: :auto` may select `:offload` when a Fiber scheduler is active.
141
+
142
+ Use `ImagePack.offload_safe?` or `ImagePack.build_info[:offload_safe]` to check the native capability at runtime.
143
+
144
+
126
145
  ```ruby
127
146
  ImagePack.compress(jpeg, execution: :direct)
128
147
  ImagePack.compress(jpeg, execution: :nogvl)
@@ -132,8 +151,8 @@ ImagePack.compress(jpeg, execution: :auto)
132
151
 
133
152
  - `:direct` — executes under GVL, intended for small images.
134
153
  - `:nogvl` — uses `rb_nogvl(..., flags: 0)`.
135
- - `:offload` — uses `rb_nogvl(..., RB_NOGVL_OFFLOAD_SAFE)` on Ruby 3.4+.
136
- - `:auto` — header-first policy chooses direct/nogvl/offload.
154
+ - `:offload` — uses `rb_nogvl(..., RB_NOGVL_OFFLOAD_SAFE)` on Ruby 3.4+; raises `ImagePack::UnsupportedError` on Ruby 3.1–3.3.
155
+ - `:auto` — header-first policy chooses direct/nogvl/offload; on Ruby 3.1–3.3 it never selects offload.
137
156
 
138
157
  ## Cancellation
139
158
 
@@ -148,7 +167,7 @@ Cancellation is cooperative at decode, encode, and SSIM-search checkpoints, not
148
167
 
149
168
  ```ruby
150
169
  ImagePack.build_info
151
- # => { version: "0.2.2", mozjpeg: "4.1.5", simd: true }
170
+ # => { version: "0.2.2", mozjpeg: "4.1.5", simd: true, offload_safe: true }
152
171
  ```
153
172
 
154
173
  ## Vendoring
@@ -4,127 +4,19 @@ require "mkmf"
4
4
  require "fileutils"
5
5
  require "rbconfig"
6
6
 
7
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.4.0")
8
- abort "image_pack requires Ruby >= 3.4.0; got #{RUBY_VERSION}"
7
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.1.0")
8
+ abort "image_pack requires Ruby >= 3.1.0; got #{RUBY_VERSION}"
9
9
  end
10
10
 
11
- MOZJPEG_CORE_SOURCES = %w[
12
- jcapimin.c
13
- jcapistd.c
14
- jccoefct.c
15
- jccolor.c
16
- jcdctmgr.c
17
- jchuff.c
18
- jcext.c
19
- jcicc.c
20
- jcinit.c
21
- jcmainct.c
22
- jcmarker.c
23
- jcmaster.c
24
- jcomapi.c
25
- jcparam.c
26
- jcphuff.c
27
- jcprepct.c
28
- jcsample.c
29
- jctrans.c
30
- jdapimin.c
31
- jdapistd.c
32
- jdatadst.c
33
- jdatasrc.c
34
- jdcoefct.c
35
- jdcolor.c
36
- jddctmgr.c
37
- jdhuff.c
38
- jdicc.c
39
- jdinput.c
40
- jdmainct.c
41
- jdmarker.c
42
- jdmaster.c
43
- jdmerge.c
44
- jdphuff.c
45
- jdpostct.c
46
- jdsample.c
47
- jdtrans.c
48
- jerror.c
49
- jfdctflt.c
50
- jfdctfst.c
51
- jfdctint.c
52
- jidctflt.c
53
- jidctfst.c
54
- jidctint.c
55
- jidctred.c
56
- jquant1.c
57
- jquant2.c
58
- jutils.c
59
- jmemmgr.c
60
- jmemnobs.c
61
- ].freeze
62
-
63
- NEON_AARCH64_SOURCES = [
64
- "simd/arm/aarch64/jsimd.c",
65
- "simd/arm/aarch64/jchuff-neon.c",
66
- "simd/arm/jccolor-neon.c",
67
- "simd/arm/jcgray-neon.c",
68
- "simd/arm/jcphuff-neon.c",
69
- "simd/arm/jcsample-neon.c",
70
- "simd/arm/jdcolor-neon.c",
71
- "simd/arm/jdmerge-neon.c",
72
- "simd/arm/jdsample-neon.c",
73
- "simd/arm/jfdctfst-neon.c",
74
- "simd/arm/jfdctint-neon.c",
75
- "simd/arm/jidctfst-neon.c",
76
- "simd/arm/jidctint-neon.c",
77
- "simd/arm/jidctred-neon.c",
78
- "simd/arm/jquanti-neon.c",
79
- ].freeze
80
-
81
- X86_64_C_SOURCES = [
82
- "simd/x86_64/jsimd.c",
83
- ].freeze
84
-
85
- X86_64_ASM_SOURCES = %w[
86
- simd/x86_64/jsimdcpu.asm
87
- simd/x86_64/jfdctflt-sse.asm
88
- simd/x86_64/jccolor-sse2.asm
89
- simd/x86_64/jcgray-sse2.asm
90
- simd/x86_64/jchuff-sse2.asm
91
- simd/x86_64/jcphuff-sse2.asm
92
- simd/x86_64/jcsample-sse2.asm
93
- simd/x86_64/jdcolor-sse2.asm
94
- simd/x86_64/jdmerge-sse2.asm
95
- simd/x86_64/jdsample-sse2.asm
96
- simd/x86_64/jfdctfst-sse2.asm
97
- simd/x86_64/jfdctint-sse2.asm
98
- simd/x86_64/jidctflt-sse2.asm
99
- simd/x86_64/jidctfst-sse2.asm
100
- simd/x86_64/jidctint-sse2.asm
101
- simd/x86_64/jidctred-sse2.asm
102
- simd/x86_64/jquantf-sse2.asm
103
- simd/x86_64/jquanti-sse2.asm
104
- simd/x86_64/jccolor-avx2.asm
105
- simd/x86_64/jcgray-avx2.asm
106
- simd/x86_64/jcsample-avx2.asm
107
- simd/x86_64/jdcolor-avx2.asm
108
- simd/x86_64/jdmerge-avx2.asm
109
- simd/x86_64/jdsample-avx2.asm
110
- simd/x86_64/jfdctint-avx2.asm
111
- simd/x86_64/jidctint-avx2.asm
112
- simd/x86_64/jquanti-avx2.asm
113
- ].freeze
114
-
115
- X86_64_ASM_TEMPLATE_SOURCES = %w[
116
- simd/x86_64/jccolext-sse2.asm
117
- simd/x86_64/jcgryext-sse2.asm
118
- simd/x86_64/jdcolext-sse2.asm
119
- simd/x86_64/jdmrgext-sse2.asm
120
- simd/x86_64/jccolext-avx2.asm
121
- simd/x86_64/jcgryext-avx2.asm
122
- simd/x86_64/jdcolext-avx2.asm
123
- simd/x86_64/jdmrgext-avx2.asm
124
- ].freeze
125
-
126
- MOZJPEG_VERSION = "4.1.5"
127
- MOZJPEG_VERSION_NUMBER = "4001005"
11
+ require_relative "mozjpeg_sources"
12
+
13
+ MOZJPEG_CORE_SOURCES = ImagePackMozjpegSources::TOPLEVEL_C_SOURCES
14
+ MOZJPEG_INCLUDE_TEMPLATES = ImagePackMozjpegSources::TOPLEVEL_INCLUDE_TEMPLATES
15
+ NEON_AARCH64_SOURCES = ImagePackMozjpegSources::NEON_AARCH64_C_SOURCES
16
+ X86_64_C_SOURCES = ImagePackMozjpegSources::X86_64_C_SOURCES
17
+ X86_64_ASM_SOURCES = ImagePackMozjpegSources::X86_64_ASM_SOURCES
18
+ MOZJPEG_VERSION = ImagePackMozjpegSources::VERSION
19
+ MOZJPEG_VERSION_NUMBER = ImagePackMozjpegSources::VERSION_NUMBER
128
20
 
129
21
  def find_vendor_dir
130
22
  candidates = [
@@ -285,8 +177,14 @@ def select_simd_backend(mozjpeg_dir, arch)
285
177
  else
286
178
  missing = NEON_AARCH64_SOURCES.reject { |rel| File.exist?(File.join(mozjpeg_dir, rel)) }
287
179
  missing << "simd/arm/neon-compat.h.in" unless template_present
288
- warn "image_pack: ARM64 detected but NEON sources missing under #{mozjpeg_dir}:"
289
- missing.each { |m| warn " - #{m}" }
180
+ message = "image_pack: ARM64 detected but NEON sources are incomplete under #{mozjpeg_dir}:
181
+ " "#{missing.map { |m| " - #{m}" }.join("
182
+ ")}"
183
+ if ENV["IMAGE_PACK_REQUIRE_SIMD"] == "1"
184
+ abort "#{message}
185
+ image_pack: refusing scalar fallback because IMAGE_PACK_REQUIRE_SIMD=1."
186
+ end
187
+ warn message
290
188
  warn "image_pack: re-run `bundle exec rake vendor` after updating script/vendor_libs.rb."
291
189
  warn "image_pack: falling back to scalar."
292
190
  { kind: :none }
@@ -301,13 +199,25 @@ def select_simd_backend(mozjpeg_dir, arch)
301
199
  warn "#{message} Falling back to scalar; install nasm for ~3-4x speedup. Set IMAGE_PACK_REQUIRE_SIMD=1 to fail instead."
302
200
  { kind: :none }
303
201
  elsif !X86_64_C_SOURCES.all? { |rel| File.exist?(File.join(mozjpeg_dir, rel)) }
304
- warn "image_pack: x86_64 SIMD sources missing under #{mozjpeg_dir}/simd/x86_64/. Falling back to scalar."
202
+ missing = X86_64_C_SOURCES.reject { |rel| File.exist?(File.join(mozjpeg_dir, rel)) }
203
+ message = "image_pack: x86_64 SIMD C sources missing under #{mozjpeg_dir}: #{missing.join(', ')}"
204
+ ENV["IMAGE_PACK_REQUIRE_SIMD"] == "1" ? abort(message) : warn("#{message}. Falling back to scalar.")
305
205
  { kind: :none }
306
206
  else
207
+ missing_asm = X86_64_ASM_SOURCES.reject { |rel| File.exist?(File.join(mozjpeg_dir, rel)) }
208
+ unless missing_asm.empty?
209
+ message = "image_pack: x86_64 SIMD ASM sources missing under #{mozjpeg_dir}: #{missing_asm.join(', ')}"
210
+ if ENV["IMAGE_PACK_REQUIRE_SIMD"] == "1"
211
+ abort message
212
+ end
213
+ warn "#{message}. Falling back to scalar."
214
+ return { kind: :none }
215
+ end
216
+
307
217
  {
308
218
  kind: :x86_64_simd,
309
219
  c_sources: X86_64_C_SOURCES,
310
- asm_sources: X86_64_ASM_SOURCES.select { |rel| File.exist?(File.join(mozjpeg_dir, rel)) },
220
+ asm_sources: X86_64_ASM_SOURCES,
311
221
  extra_includes: [
312
222
  File.join(mozjpeg_dir, "simd"),
313
223
  File.join(mozjpeg_dir, "simd", "nasm"),
@@ -367,7 +277,8 @@ def configure_vendored_mozjpeg(vendor_dir)
367
277
 
368
278
  abort "vendored MozJPEG sources not found in #{mozjpeg_dir}" unless Dir.exist?(mozjpeg_dir)
369
279
 
370
- missing_sources = MOZJPEG_CORE_SOURCES.reject { |source| File.exist?(File.join(mozjpeg_dir, source)) }
280
+ required_sources = MOZJPEG_CORE_SOURCES + MOZJPEG_INCLUDE_TEMPLATES
281
+ missing_sources = required_sources.reject { |source| File.exist?(File.join(mozjpeg_dir, source)) }
371
282
  abort "vendored MozJPEG sources are incomplete: #{missing_sources.join(', ')}" unless missing_sources.empty?
372
283
 
373
284
  arch = detect_simd_arch