oil 0.2.1 → 0.3.0
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 +4 -4
- data/README.rdoc +0 -5
- data/Rakefile +1 -29
- data/ext/oil/jpeg.c +65 -48
- data/ext/oil/oil.c +2 -1
- data/ext/oil/oil_libjpeg.c +12 -3
- data/ext/oil/oil_libjpeg.h +1 -0
- data/ext/oil/oil_libpng.c +24 -11
- data/ext/oil/oil_libpng.h +1 -0
- data/ext/oil/oil_resample.c +1003 -540
- data/ext/oil/oil_resample.h +63 -23
- data/ext/oil/oil_resample_internal.h +59 -0
- data/ext/oil/oil_resample_sse2.c +1930 -0
- data/ext/oil/png.c +26 -19
- data/lib/oil.rb +1 -1
- data/oil.gemspec +39 -0
- data/test/test_jpeg.rb +3 -3
- data/test/test_png.rb +2 -2
- metadata +14 -9
data/ext/oil/png.c
CHANGED
|
@@ -50,19 +50,33 @@ static void write_data_fn(png_structp png_ptr, png_bytep data, png_size_t length
|
|
|
50
50
|
|
|
51
51
|
/* Ruby GC */
|
|
52
52
|
|
|
53
|
-
static void deallocate(
|
|
53
|
+
static void deallocate(void *ptr)
|
|
54
54
|
{
|
|
55
|
+
struct readerdata *reader = ptr;
|
|
55
56
|
png_destroy_read_struct(&reader->png, &reader->info, NULL);
|
|
56
57
|
free(reader);
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
static void mark(
|
|
60
|
+
static void mark(void *ptr)
|
|
60
61
|
{
|
|
62
|
+
struct readerdata *reader = ptr;
|
|
61
63
|
if (!NIL_P(reader->source_io)) {
|
|
62
64
|
rb_gc_mark(reader->source_io);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
|
|
68
|
+
static size_t memsize(const void *ptr)
|
|
69
|
+
{
|
|
70
|
+
return sizeof(struct readerdata);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static const rb_data_type_t png_reader_type = {
|
|
74
|
+
"Oil::PNGReader",
|
|
75
|
+
{ mark, deallocate, memsize },
|
|
76
|
+
0, 0,
|
|
77
|
+
RUBY_TYPED_FREE_IMMEDIATELY
|
|
78
|
+
};
|
|
79
|
+
|
|
66
80
|
static void allocate2(struct readerdata *reader)
|
|
67
81
|
{
|
|
68
82
|
reader->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, (png_error_ptr)error, (png_error_ptr)warning);
|
|
@@ -74,7 +88,7 @@ static VALUE allocate(VALUE klass)
|
|
|
74
88
|
struct readerdata *reader;
|
|
75
89
|
VALUE self;
|
|
76
90
|
|
|
77
|
-
self =
|
|
91
|
+
self = TypedData_Make_Struct(klass, struct readerdata, &png_reader_type, reader);
|
|
78
92
|
allocate2(reader);
|
|
79
93
|
return self;
|
|
80
94
|
}
|
|
@@ -92,7 +106,7 @@ static VALUE initialize(VALUE self, VALUE io)
|
|
|
92
106
|
{
|
|
93
107
|
struct readerdata *reader;
|
|
94
108
|
|
|
95
|
-
|
|
109
|
+
TypedData_Get_Struct(self, struct readerdata, &png_reader_type, reader);
|
|
96
110
|
|
|
97
111
|
if (reader->info) {
|
|
98
112
|
png_destroy_read_struct(&reader->png, &reader->info, NULL);
|
|
@@ -124,7 +138,7 @@ static VALUE initialize(VALUE self, VALUE io)
|
|
|
124
138
|
static VALUE width(VALUE self)
|
|
125
139
|
{
|
|
126
140
|
struct readerdata *reader;
|
|
127
|
-
|
|
141
|
+
TypedData_Get_Struct(self, struct readerdata, &png_reader_type, reader);
|
|
128
142
|
return INT2FIX(png_get_image_width(reader->png, reader->info));
|
|
129
143
|
}
|
|
130
144
|
|
|
@@ -138,7 +152,7 @@ static VALUE width(VALUE self)
|
|
|
138
152
|
static VALUE height(VALUE self)
|
|
139
153
|
{
|
|
140
154
|
struct readerdata *reader;
|
|
141
|
-
|
|
155
|
+
TypedData_Get_Struct(self, struct readerdata, &png_reader_type, reader);
|
|
142
156
|
return INT2FIX(png_get_image_height(reader->png, reader->info));
|
|
143
157
|
}
|
|
144
158
|
|
|
@@ -153,7 +167,7 @@ static VALUE height(VALUE self)
|
|
|
153
167
|
static VALUE scale_width(VALUE self)
|
|
154
168
|
{
|
|
155
169
|
struct readerdata *reader;
|
|
156
|
-
|
|
170
|
+
TypedData_Get_Struct(self, struct readerdata, &png_reader_type, reader);
|
|
157
171
|
return INT2FIX(reader->scale_width);
|
|
158
172
|
}
|
|
159
173
|
|
|
@@ -168,7 +182,7 @@ static VALUE scale_width(VALUE self)
|
|
|
168
182
|
static VALUE set_scale_width(VALUE self, VALUE scale_width)
|
|
169
183
|
{
|
|
170
184
|
struct readerdata *reader;
|
|
171
|
-
|
|
185
|
+
TypedData_Get_Struct(self, struct readerdata, &png_reader_type, reader);
|
|
172
186
|
raise_if_locked(reader);
|
|
173
187
|
reader->scale_width = NUM2INT(scale_width);
|
|
174
188
|
return scale_width;
|
|
@@ -185,7 +199,7 @@ static VALUE set_scale_width(VALUE self, VALUE scale_width)
|
|
|
185
199
|
static VALUE scale_height(VALUE self)
|
|
186
200
|
{
|
|
187
201
|
struct readerdata *reader;
|
|
188
|
-
|
|
202
|
+
TypedData_Get_Struct(self, struct readerdata, &png_reader_type, reader);
|
|
189
203
|
return INT2FIX(reader->scale_height);
|
|
190
204
|
}
|
|
191
205
|
|
|
@@ -200,7 +214,7 @@ static VALUE scale_height(VALUE self)
|
|
|
200
214
|
static VALUE set_scale_height(VALUE self, VALUE scale_height)
|
|
201
215
|
{
|
|
202
216
|
struct readerdata *reader;
|
|
203
|
-
|
|
217
|
+
TypedData_Get_Struct(self, struct readerdata, &png_reader_type, reader);
|
|
204
218
|
raise_if_locked(reader);
|
|
205
219
|
reader->scale_height = NUM2INT(scale_height);
|
|
206
220
|
return scale_height;
|
|
@@ -241,14 +255,7 @@ static VALUE each2(struct each_args *args)
|
|
|
241
255
|
* call-seq:
|
|
242
256
|
* reader.each(opts, &block) -> self
|
|
243
257
|
*
|
|
244
|
-
* Yields a series of binary strings that make up the output
|
|
245
|
-
*
|
|
246
|
-
* Options is a hash which may have the following symbols:
|
|
247
|
-
*
|
|
248
|
-
* :quality - JPEG quality setting. Betweein 0 and 100.
|
|
249
|
-
* :markers - Custom markers to include in the output JPEG. Must be a hash where
|
|
250
|
-
* the keys are :APP[0-15] or :COM and the values are arrays of strings that
|
|
251
|
-
* will be inserted into the markers.
|
|
258
|
+
* Yields a series of binary strings that make up the output PNG image.
|
|
252
259
|
*/
|
|
253
260
|
|
|
254
261
|
static VALUE each(int argc, VALUE *argv, VALUE self)
|
|
@@ -263,7 +270,7 @@ static VALUE each(int argc, VALUE *argv, VALUE self)
|
|
|
263
270
|
|
|
264
271
|
rb_scan_args(argc, argv, "01", &opts);
|
|
265
272
|
|
|
266
|
-
|
|
273
|
+
TypedData_Get_Struct(self, struct readerdata, &png_reader_type, reader);
|
|
267
274
|
|
|
268
275
|
raise_if_locked(reader);
|
|
269
276
|
reader->locked = 1;
|
data/lib/oil.rb
CHANGED
data/oil.gemspec
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = 'oil'
|
|
3
|
+
s.version = '0.3.0'
|
|
4
|
+
s.license = 'MIT'
|
|
5
|
+
s.required_ruby_version = '>= 2.7'
|
|
6
|
+
s.summary = 'Resize JPEG and PNG images.'
|
|
7
|
+
s.description = 'Resize JPEG and PNG images, aiming for fast performance and low memory use.'
|
|
8
|
+
s.authors = ['Timothy Elliott']
|
|
9
|
+
s.email = 'tle@holymonkey.com'
|
|
10
|
+
s.files = %w{
|
|
11
|
+
Rakefile
|
|
12
|
+
README.rdoc
|
|
13
|
+
MIT-LICENSE
|
|
14
|
+
oil.gemspec
|
|
15
|
+
lib/oil.rb
|
|
16
|
+
ext/oil/oil_resample.c
|
|
17
|
+
ext/oil/oil_resample.h
|
|
18
|
+
ext/oil/oil_resample_internal.h
|
|
19
|
+
ext/oil/oil_resample_sse2.c
|
|
20
|
+
ext/oil/oil_libjpeg.c
|
|
21
|
+
ext/oil/oil_libjpeg.h
|
|
22
|
+
ext/oil/oil_libpng.c
|
|
23
|
+
ext/oil/oil_libpng.h
|
|
24
|
+
ext/oil/jpeg.c
|
|
25
|
+
ext/oil/png.c
|
|
26
|
+
ext/oil/oil.c
|
|
27
|
+
ext/oil/extconf.rb
|
|
28
|
+
test/helper.rb
|
|
29
|
+
test/test_jpeg.rb
|
|
30
|
+
test/test_png.rb
|
|
31
|
+
}
|
|
32
|
+
s.homepage = 'https://github.com/ender672/oil'
|
|
33
|
+
s.metadata = {
|
|
34
|
+
'source_code_uri' => 'https://github.com/ender672/oil',
|
|
35
|
+
'bug_tracker_uri' => 'https://github.com/ender672/oil/issues'
|
|
36
|
+
}
|
|
37
|
+
s.extensions << 'ext/oil/extconf.rb'
|
|
38
|
+
s.extra_rdoc_files = ['README.rdoc']
|
|
39
|
+
end
|
data/test/test_jpeg.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'oil'
|
|
|
4
4
|
require 'stringio'
|
|
5
5
|
require 'helper'
|
|
6
6
|
|
|
7
|
-
class TestJPEG <
|
|
7
|
+
class TestJPEG < Minitest::Test
|
|
8
8
|
# http://stackoverflow.com/a/2349470
|
|
9
9
|
JPEG_DATA = "\
|
|
10
10
|
\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46\x00\x01\x01\x01\x00\x48\x00\x48\x00\
|
|
@@ -16,7 +16,7 @@ class TestJPEG < MiniTest::Test
|
|
|
16
16
|
\x01\x01\x00\x00\x3f\x00\xd2\xcf\x20\xff\xd9".b
|
|
17
17
|
|
|
18
18
|
BIG_JPEG = begin
|
|
19
|
-
s =
|
|
19
|
+
s = String.new
|
|
20
20
|
r = Oil::JPEGReader.new(StringIO.new(JPEG_DATA))
|
|
21
21
|
r.scale_width = 2000
|
|
22
22
|
r.scale_height = 2000
|
|
@@ -157,7 +157,7 @@ class TestJPEG < MiniTest::Test
|
|
|
157
157
|
end
|
|
158
158
|
|
|
159
159
|
def test_marker_roundtrip
|
|
160
|
-
str =
|
|
160
|
+
str = String.new
|
|
161
161
|
opts = { markers: { COM: ["hello world", "foobar123"]}}
|
|
162
162
|
Oil::JPEGReader.new(jpeg_io).each(opts){ |s| str << s }
|
|
163
163
|
|
data/test/test_png.rb
CHANGED
|
@@ -4,7 +4,7 @@ require 'oil'
|
|
|
4
4
|
require 'stringio'
|
|
5
5
|
require 'helper'
|
|
6
6
|
|
|
7
|
-
class TestPNG <
|
|
7
|
+
class TestPNG < Minitest::Test
|
|
8
8
|
# http://garethrees.org/2007/11/14/pngcrush/
|
|
9
9
|
PNG_DATA = "\
|
|
10
10
|
\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52\x00\x00\x00\
|
|
@@ -13,7 +13,7 @@ class TestPNG < MiniTest::Test
|
|
|
13
13
|
\x57\xBF\xAB\xD4\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42\x60\x82".b
|
|
14
14
|
|
|
15
15
|
BIG_PNG = begin
|
|
16
|
-
s =
|
|
16
|
+
s = String.new
|
|
17
17
|
r = Oil::PNGReader.new(StringIO.new(PNG_DATA))
|
|
18
18
|
r.scale_width = 500
|
|
19
19
|
r.scale_height = 1000
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: oil
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Timothy Elliott
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-04-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Resize JPEG and PNG images, aiming for fast performance and low memory
|
|
14
14
|
use.
|
|
@@ -31,16 +31,21 @@ files:
|
|
|
31
31
|
- ext/oil/oil_libpng.h
|
|
32
32
|
- ext/oil/oil_resample.c
|
|
33
33
|
- ext/oil/oil_resample.h
|
|
34
|
+
- ext/oil/oil_resample_internal.h
|
|
35
|
+
- ext/oil/oil_resample_sse2.c
|
|
34
36
|
- ext/oil/png.c
|
|
35
37
|
- lib/oil.rb
|
|
38
|
+
- oil.gemspec
|
|
36
39
|
- test/helper.rb
|
|
37
40
|
- test/test_jpeg.rb
|
|
38
41
|
- test/test_png.rb
|
|
39
|
-
homepage:
|
|
42
|
+
homepage: https://github.com/ender672/oil
|
|
40
43
|
licenses:
|
|
41
44
|
- MIT
|
|
42
|
-
metadata:
|
|
43
|
-
|
|
45
|
+
metadata:
|
|
46
|
+
source_code_uri: https://github.com/ender672/oil
|
|
47
|
+
bug_tracker_uri: https://github.com/ender672/oil/issues
|
|
48
|
+
post_install_message:
|
|
44
49
|
rdoc_options: []
|
|
45
50
|
require_paths:
|
|
46
51
|
- lib
|
|
@@ -48,15 +53,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
48
53
|
requirements:
|
|
49
54
|
- - ">="
|
|
50
55
|
- !ruby/object:Gem::Version
|
|
51
|
-
version: '
|
|
56
|
+
version: '2.7'
|
|
52
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
58
|
requirements:
|
|
54
59
|
- - ">="
|
|
55
60
|
- !ruby/object:Gem::Version
|
|
56
61
|
version: '0'
|
|
57
62
|
requirements: []
|
|
58
|
-
rubygems_version: 3.
|
|
59
|
-
signing_key:
|
|
63
|
+
rubygems_version: 3.5.22
|
|
64
|
+
signing_key:
|
|
60
65
|
specification_version: 4
|
|
61
66
|
summary: Resize JPEG and PNG images.
|
|
62
67
|
test_files: []
|