pura-jpeg 0.1.0 → 0.1.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: b497cc2d62e912f13269111752139cdede385a5a4f0fb0a020743c9270f969a6
4
- data.tar.gz: 6712cb8189a06cfd4ea1fe4af6c0dbd713d286f79acd29e24f0e9123c4f09843
3
+ metadata.gz: d1b5a78d34756e46d68ef37832cba567cf899b60d35d7a02e995a97bf51c8fb9
4
+ data.tar.gz: adbfcacde61c32ffae7f65bdc8cc362a811f03591815581d98548e977d761814
5
5
  SHA512:
6
- metadata.gz: 533b5753fb406eac2f2590b719cba7d1ab282ccbadf333fbb16b51bc35432b9e436552f85d9fd30336f6028b46f98fcfa879ce40d4957ee006591c60d99fa1d8
7
- data.tar.gz: a4f52d7145e529abd3c12ea8363d5f36fc3853f3095c1f82f953dbe098eeabd4859422678a5bc68755beca89c4577e9c6571ee90ef8fd4d201fb0de4a422ed9b
6
+ metadata.gz: 5bf8ab077fcd23611500408b81ae7b2f378e53eab58032672b4d43804bf9976e6a8c1080821416b278a4b995077c7d4ba67b1b84f9f9c54f2a82a67cf3acfe26
7
+ data.tar.gz: 7530e39696e9ede62cfade0d890b5f2c963d8d984d70cbe174818126987cffd7478a8e233ae3193df3364cd2304c63e64434ff88dfe218c45611a110acf01e27
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # pura-jpeg
2
2
 
3
- A pure Ruby JPEG decoder/encoder with zero C extension dependencies.
3
+ A pure Ruby JPEG decoder/encoder without additional image-processing libraries.
4
4
 
5
5
  Part of the **pura-*** series — pure Ruby image codec gems.
6
6
 
@@ -10,7 +10,7 @@ Part of the **pura-*** series — pure Ruby image codec gems.
10
10
  - Image resizing (bilinear / nearest-neighbor interpolation)
11
11
  - Huffman coding, fast integer IDCT/FDCT, YCbCr ↔ RGB conversion
12
12
  - 4:2:0, 4:2:2, and 4:4:4 chroma subsampling
13
- - No native extensions, no FFI, no external dependencies
13
+ - No image-specific native extension or FFI dependency
14
14
  - CLI tool included
15
15
 
16
16
  ## Installation
@@ -48,6 +48,8 @@ pura-jpeg resize input.jpg --fit 800x600 --out fitted.jpg
48
48
 
49
49
  ## Benchmark
50
50
 
51
+ These historical measurements include ffmpeg process startup. They do not compare against an in-process C codec or establish Rails pipeline throughput.
52
+
51
53
  400×400 image, Ruby 4.0.2 + YJIT.
52
54
 
53
55
  ### Decode
@@ -75,13 +77,10 @@ pura-jpeg resize input.jpg --fit 800x600 --out fitted.jpg
75
77
  | Encode (quality 85) | 243 ms |
76
78
  | Full pipeline | ~547 ms |
77
79
 
78
- pura-jpeg is **2× faster than ptjd** (Tcl) and within **2× of jpeg-js running without JIT**. These are the only three pure scripting-language JPEG implementations that exist — Python, Perl, PHP, and Lua all rely on C extensions.
79
80
 
80
81
  ## Why pure Ruby?
81
82
 
82
83
  - **`gem install` and go** — no `brew install`, no `apt install`, no C compiler needed
83
- - **Works everywhere Ruby works** — CRuby, ruby.wasm, mruby, JRuby, TruffleRuby
84
- - **Edge/Wasm ready** — runs in Cloudflare Workers, browsers (via ruby.wasm), sandboxed environments where you can't install system libraries
85
84
  - **Perfect for dev/CI** — no ImageMagick or libvips setup. `rails new` → image upload → it just works
86
85
  - **Unix philosophy** — one format, one gem, composable
87
86
 
@@ -98,6 +97,12 @@ pura-jpeg is **2× faster than ptjd** (Tcl) and within **2× of jpeg-js running
98
97
  | [pura-webp](https://github.com/komagata/pura-webp) | WebP | ✅ Available |
99
98
  | [pura-image](https://github.com/komagata/pura-image) | All formats | ✅ Available |
100
99
 
100
+ ## Pixel model and limitations
101
+
102
+ Images contain 8-bit RGB pixels. Baseline JPEG only; progressive JPEG is unsupported. EXIF orientation and color profiles are not applied or retained. `decode` accepts a file path or a binary JPEG string.
103
+
104
+ `crop(x, y, width, height)` requires integer coordinates, positive dimensions, and a region entirely inside the image; invalid regions raise `ArgumentError`.
105
+
101
106
  ## License
102
107
 
103
108
  MIT
@@ -29,7 +29,11 @@ module Pura
29
29
  end
30
30
 
31
31
  def self.decode(input)
32
- data = input.is_a?(String) && File.exist?(input) ? File.binread(input) : input
32
+ data = if input.is_a?(String) && !input.include?("\0") && input.bytesize < 4096 && File.exist?(input)
33
+ File.binread(input)
34
+ else
35
+ input
36
+ end
33
37
  new(data).decode
34
38
  end
35
39
 
@@ -527,7 +531,7 @@ module Pura
527
531
  0, 1, 8, 16, 9, 2, 3, 10,
528
532
  17, 24, 32, 25, 18, 11, 4, 5,
529
533
  12, 19, 26, 33, 40, 48, 41, 34,
530
- 27, 20, 13, 6, 7, 14, 21, 28,
534
+ 27, 20, 13, 6, 7, 14, 21, 28,
531
535
  35, 42, 49, 56, 57, 50, 43, 36,
532
536
  29, 22, 15, 23, 30, 37, 44, 51,
533
537
  58, 59, 52, 45, 38, 31, 39, 46,
@@ -5,12 +5,12 @@ module Pura
5
5
  class Encoder
6
6
  # Standard JPEG luminance quantization table (ITU-T T.81, Annex K)
7
7
  LUMINANCE_QUANT_TABLE = [
8
- 16, 11, 10, 16, 24, 40, 51, 61,
9
- 12, 12, 14, 19, 26, 58, 60, 55,
10
- 14, 13, 16, 24, 40, 57, 69, 56,
11
- 14, 17, 22, 29, 51, 87, 80, 62,
12
- 18, 22, 37, 56, 68, 109, 103, 77,
13
- 24, 35, 55, 64, 81, 104, 113, 92,
8
+ 16, 11, 10, 16, 24, 40, 51, 61,
9
+ 12, 12, 14, 19, 26, 58, 60, 55,
10
+ 14, 13, 16, 24, 40, 57, 69, 56,
11
+ 14, 17, 22, 29, 51, 87, 80, 62,
12
+ 18, 22, 37, 56, 68, 109, 103, 77,
13
+ 24, 35, 55, 64, 81, 104, 113, 92,
14
14
  49, 64, 78, 87, 103, 121, 120, 101,
15
15
  72, 92, 95, 98, 112, 100, 103, 99
16
16
  ].freeze
@@ -87,6 +87,11 @@ module Pura
87
87
 
88
88
  # Crop a region from the image
89
89
  def crop(x, y, w, h)
90
+ unless [x, y, w, h].all?(Integer) &&
91
+ x >= 0 && y >= 0 && w.positive? && h.positive? && x + w <= @width && y + h <= @height
92
+ raise ArgumentError, "crop must be a positive integer region within the image"
93
+ end
94
+
90
95
  out = String.new(encoding: Encoding::BINARY, capacity: w * h * 3)
91
96
  h.times do |row|
92
97
  src_offset = (((y + row) * @width) + x) * 3
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pura
4
4
  module Jpeg
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pura-jpeg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - komagata