oily_png 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/LICENSE +1 -1
- data/README.rdoc +1 -1
- data/ext/oily_png/color.c +10 -0
- data/ext/oily_png/color.h +3 -0
- data/ext/oily_png/oily_png_ext.c +4 -1
- data/ext/oily_png/png_decoding.c +1 -0
- data/ext/oily_png/png_encoding.c +1 -0
- data/ext/oily_png/resampling.c +2 -2
- data/lib/oily_png/version.rb +1 -1
- data/oily_png.gemspec +1 -1
- data/spec/color_spec.rb +20 -9
- data/spec/resampling_spec.rb +9 -0
- data/spec/resources/nonsquaretall.png +0 -0
- metadata +23 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b84a04e46948ddd4be00b39c9875a2ab28f20b1
|
4
|
+
data.tar.gz: 75442b85ad8fde3f8bed8a49767c4b03739ff469
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2df5b8e3fdcb0c7bc55021231cbc06b077892de1a0cea5cdcbda979bdc7f94875a980520c67ca2e786c2ef5fb68780988c93d5ccf4e650bf67bbd108e3363ecf
|
7
|
+
data.tar.gz: 70137f6debdd292c3b9bc5b443e740e849fef83ec35175e154f8b0feb84211537dab1508b0f5427ac23f182c8e917df583a1bd6d3c1236ce2c163fb36a92cbb1
|
data/.travis.yml
CHANGED
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= OilyPNG
|
1
|
+
= OilyPNG {<img src="https://travis-ci.org/wvanbergen/oily_png.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/wvanbergen/oily_png]
|
2
2
|
|
3
3
|
OilyPNG is a Ruby C extension to speed up the pure Ruby ChunkyPNG library. It is a standalone
|
4
4
|
module, so it does not require LibPNG, ImageMagick or any other library. Currently it has an
|
data/ext/oily_png/color.c
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#include "oily_png_ext.h"
|
2
|
+
#include <math.h>
|
2
3
|
|
3
4
|
PIXEL oily_png_compose_color(PIXEL fg, PIXEL bg) {
|
4
5
|
BYTE a_com, new_r, new_g, new_b, new_a;
|
@@ -37,6 +38,15 @@ VALUE oily_png_color_compose_quick(VALUE self, VALUE fg_color, VALUE bg_color) {
|
|
37
38
|
return UINT2NUM(oily_png_compose_color(NUM2UINT(fg_color), NUM2UINT(bg_color)));
|
38
39
|
}
|
39
40
|
|
41
|
+
VALUE oily_png_euclidean_distance_rgba(VALUE self, VALUE color_after, VALUE color_before) {
|
42
|
+
UNUSED_PARAMETER(self);
|
43
|
+
|
44
|
+
return rb_float_new(sqrt(pow((R_BYTE(NUM2UINT(color_after)) - R_BYTE(NUM2UINT(color_before))), 2) +
|
45
|
+
pow((G_BYTE(NUM2UINT(color_after)) - G_BYTE(NUM2UINT(color_before))), 2) +
|
46
|
+
pow((B_BYTE(NUM2UINT(color_after)) - B_BYTE(NUM2UINT(color_before))), 2) +
|
47
|
+
pow((A_BYTE(NUM2UINT(color_after)) - A_BYTE(NUM2UINT(color_before))), 2)));
|
48
|
+
}
|
49
|
+
|
40
50
|
VALUE oily_png_color_r(VALUE self, VALUE value) {
|
41
51
|
UNUSED_PARAMETER(self);
|
42
52
|
return INT2FIX(R_BYTE(NUM2UINT(value)));
|
data/ext/oily_png/color.h
CHANGED
@@ -20,6 +20,9 @@ VALUE oily_png_color_compose_quick(VALUE self, VALUE fg_color, VALUE bg_color);
|
|
20
20
|
PIXEL oily_png_compose_color(PIXEL fg, PIXEL bg);
|
21
21
|
PIXEL oily_png_color_interpolate_quick(PIXEL fg, PIXEL bg, int alpha);
|
22
22
|
|
23
|
+
/* Color comparison */
|
24
|
+
VALUE oily_png_euclidean_distance_rgba(VALUE self, VALUE color_after, VALUE color_before);
|
25
|
+
|
23
26
|
/* Accessors */
|
24
27
|
VALUE oily_png_color_r(VALUE self, VALUE pixel);
|
25
28
|
VALUE oily_png_color_g(VALUE self, VALUE pixel);
|
data/ext/oily_png/oily_png_ext.c
CHANGED
@@ -20,6 +20,7 @@ void Init_oily_png() {
|
|
20
20
|
// Setup Color module
|
21
21
|
VALUE OilyPNG_Color = rb_define_module_under(OilyPNG, "Color");
|
22
22
|
rb_define_method(OilyPNG_Color, "compose_quick", oily_png_color_compose_quick, 2);
|
23
|
+
rb_define_method(OilyPNG_Color, "euclidean_distance_rgba", oily_png_euclidean_distance_rgba, 2);
|
23
24
|
rb_define_method(OilyPNG_Color, "r", oily_png_color_r, 1);
|
24
25
|
rb_define_method(OilyPNG_Color, "g", oily_png_color_g, 1);
|
25
26
|
rb_define_method(OilyPNG_Color, "b", oily_png_color_b, 1);
|
@@ -38,7 +39,9 @@ char oily_png_samples_per_pixel(char color_mode) {
|
|
38
39
|
case OILY_PNG_COLOR_INDEXED: return 1;
|
39
40
|
case OILY_PNG_COLOR_GRAYSCALE_ALPHA: return 2;
|
40
41
|
case OILY_PNG_COLOR_TRUECOLOR_ALPHA: return 4;
|
41
|
-
default:
|
42
|
+
default:
|
43
|
+
rb_raise(rb_eRuntimeError, "Unsupported color mode: %d", color_mode);
|
44
|
+
return 0;
|
42
45
|
}
|
43
46
|
}
|
44
47
|
|
data/ext/oily_png/png_decoding.c
CHANGED
data/ext/oily_png/png_encoding.c
CHANGED
@@ -236,6 +236,7 @@ VALUE oily_png_encode_palette(VALUE self) {
|
|
236
236
|
}
|
237
237
|
}
|
238
238
|
rb_raise(rb_eRuntimeError, "Could not retrieve a decoding palette for this image!");
|
239
|
+
return Qnil;
|
239
240
|
}
|
240
241
|
|
241
242
|
VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE color_mode, VALUE bit_depth, VALUE filtering) {
|
data/ext/oily_png/resampling.c
CHANGED
@@ -178,12 +178,12 @@ VALUE oily_png_canvas_resample_bilinear_bang(VALUE self, VALUE v_new_width, VALU
|
|
178
178
|
PIXEL pixel_top, pixel_bot;
|
179
179
|
for (y = 0; y < new_height; y++) {
|
180
180
|
y1 = index_y[y] < 0 ? 0 : index_y[y];
|
181
|
-
y2 =
|
181
|
+
y2 = index_y[y]+1 >= self_height ? self_height-1 : index_y[y]+1;
|
182
182
|
y_residue = interp_y[y];
|
183
183
|
|
184
184
|
for (x = 0; x < new_width; x++) {
|
185
185
|
x1 = index_x[x] < 0 ? 0 : index_x[x];
|
186
|
-
x2 =
|
186
|
+
x2 = index_x[x]+1 >= self_width ? self_width-1 : index_x[x]+1;
|
187
187
|
x_residue = interp_x[x];
|
188
188
|
|
189
189
|
pixel_11 = NUM2UINT(rb_ary_entry(source, y1*self_width + x1));
|
data/lib/oily_png/version.rb
CHANGED
data/oily_png.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.extensions = ["ext/oily_png/extconf.rb"]
|
26
26
|
s.require_paths = ["lib", "ext"]
|
27
27
|
|
28
|
-
s.add_runtime_dependency('chunky_png', '~> 1.3.
|
28
|
+
s.add_runtime_dependency('chunky_png', '~> 1.3.1')
|
29
29
|
|
30
30
|
s.add_development_dependency('rake')
|
31
31
|
s.add_development_dependency('rake-compiler')
|
data/spec/color_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe OilyPNG::Color do
|
4
|
-
|
5
4
|
include OilyPNG::Color
|
6
5
|
|
7
6
|
before(:each) do
|
@@ -13,26 +12,38 @@ describe OilyPNG::Color do
|
|
13
12
|
end
|
14
13
|
|
15
14
|
describe '#compose_quick' do
|
16
|
-
|
17
|
-
it "should use the foregorund color as is when the background color is fully transparent" do
|
15
|
+
it 'should use the foregorund color as is when the background color is fully transparent' do
|
18
16
|
compose_quick(@non_opaque, @fully_transparent).should == @non_opaque
|
19
17
|
end
|
20
18
|
|
21
|
-
it
|
19
|
+
it 'should use the foregorund color as is when an opaque color is given as foreground color' do
|
22
20
|
compose_quick(@opaque, @white).should == @opaque
|
23
21
|
end
|
24
22
|
|
25
|
-
it
|
23
|
+
it 'should use the background color as is when a fully transparent pixel is given as foreground color' do
|
26
24
|
compose_quick(@fully_transparent, @white).should == @white
|
27
25
|
end
|
28
26
|
|
29
|
-
it
|
27
|
+
it 'should compose pixels correctly' do
|
30
28
|
compose_quick(@non_opaque, @white).should == 0x9fc2d6ff
|
31
29
|
end
|
32
|
-
|
33
|
-
it
|
30
|
+
|
31
|
+
it 'should compose colors exactly the same as ChunkyPNG' do
|
34
32
|
fg, bg = rand(0xffffffff), rand(0xffffffff)
|
35
33
|
compose_quick(fg, bg).should == ChunkyPNG::Color.compose_quick(fg, bg)
|
36
34
|
end
|
37
35
|
end
|
38
|
-
|
36
|
+
|
37
|
+
describe '#euclidean_distance_rgba' do
|
38
|
+
let(:color_a) { rand(0xffffffff) }
|
39
|
+
let(:color_b) { rand(0xffffffff) }
|
40
|
+
subject { euclidean_distance_rgba(color_a, color_b) }
|
41
|
+
|
42
|
+
it { should == ChunkyPNG::Color.euclidean_distance_rgba(color_a, color_b) }
|
43
|
+
|
44
|
+
context 'when both colors are the same' do
|
45
|
+
let(:color_b) { color_a }
|
46
|
+
it { should == 0 }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/spec/resampling_spec.rb
CHANGED
@@ -47,5 +47,14 @@ describe OilyPNG::Resampling do
|
|
47
47
|
it "should resample an image to 11x19 as ChunkyPNG does" do
|
48
48
|
@reference.resample_bilinear(11,19).should == OilyPNG::Canvas.from_canvas(@reference).resample_bilinear(11,19)
|
49
49
|
end
|
50
|
+
|
51
|
+
it "should upsample an image to 88x44 as ChunkyPNG does" do
|
52
|
+
@reference.resample_bilinear(88,44).should == OilyPNG::Canvas.from_canvas(@reference).resample_bilinear(88,44)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not crash upsampling tall image" do
|
56
|
+
@reference = ChunkyPNG::Canvas.from_file(resource_file('nonsquaretall.png'))
|
57
|
+
expect { OilyPNG::Canvas.from_canvas(@reference).resample_bilinear(44,88) }.to_not raise_error
|
58
|
+
end
|
50
59
|
end
|
51
60
|
end
|
Binary file
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oily_png
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Bergen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chunky_png
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.3.
|
19
|
+
version: 1.3.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.3.
|
26
|
+
version: 1.3.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake-compiler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2'
|
69
69
|
description: |2
|
@@ -76,8 +76,8 @@ extensions:
|
|
76
76
|
extra_rdoc_files:
|
77
77
|
- README.rdoc
|
78
78
|
files:
|
79
|
-
-
|
80
|
-
-
|
79
|
+
- .gitignore
|
80
|
+
- .travis.yml
|
81
81
|
- Gemfile
|
82
82
|
- LICENSE
|
83
83
|
- README.rdoc
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- spec/resources/gray.png
|
139
139
|
- spec/resources/interlaced.png
|
140
140
|
- spec/resources/nonsquare.png
|
141
|
+
- spec/resources/nonsquaretall.png
|
141
142
|
- spec/resources/operations.png
|
142
143
|
- spec/resources/replaced.png
|
143
144
|
- spec/resources/s01i3p01.png
|
@@ -198,28 +199,28 @@ licenses:
|
|
198
199
|
metadata: {}
|
199
200
|
post_install_message:
|
200
201
|
rdoc_options:
|
201
|
-
-
|
202
|
+
- --title
|
202
203
|
- oily_png
|
203
|
-
-
|
204
|
+
- --main
|
204
205
|
- README.rdoc
|
205
|
-
-
|
206
|
-
-
|
206
|
+
- --line-numbers
|
207
|
+
- --inline-source
|
207
208
|
require_paths:
|
208
209
|
- lib
|
209
210
|
- ext
|
210
211
|
required_ruby_version: !ruby/object:Gem::Requirement
|
211
212
|
requirements:
|
212
|
-
- -
|
213
|
+
- - '>='
|
213
214
|
- !ruby/object:Gem::Version
|
214
215
|
version: '0'
|
215
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
216
217
|
requirements:
|
217
|
-
- -
|
218
|
+
- - '>='
|
218
219
|
- !ruby/object:Gem::Version
|
219
220
|
version: '0'
|
220
221
|
requirements: []
|
221
222
|
rubyforge_project: oily_png
|
222
|
-
rubygems_version: 2.
|
223
|
+
rubygems_version: 2.0.14
|
223
224
|
signing_key:
|
224
225
|
specification_version: 4
|
225
226
|
summary: Native mixin to speed up ChunkyPNG
|
@@ -263,6 +264,7 @@ test_files:
|
|
263
264
|
- spec/resources/gray.png
|
264
265
|
- spec/resources/interlaced.png
|
265
266
|
- spec/resources/nonsquare.png
|
267
|
+
- spec/resources/nonsquaretall.png
|
266
268
|
- spec/resources/operations.png
|
267
269
|
- spec/resources/replaced.png
|
268
270
|
- spec/resources/s01i3p01.png
|