oily_png 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +8 -0
- data/Rakefile +1 -0
- data/ext/oily_png/color.c +25 -0
- data/ext/oily_png/color.h +6 -0
- data/ext/oily_png/oily_png_ext.c +9 -0
- data/ext/oily_png/oily_png_ext.h +1 -0
- data/ext/oily_png/resampling.c +151 -0
- data/ext/oily_png/resampling.h +23 -0
- data/lib/oily_png.rb +6 -1
- data/lib/oily_png/canvas.rb +2 -1
- data/oily_png.gemspec +5 -5
- data/spec/resampling_spec.rb +39 -0
- data/tasks/github-gem.rake +5 -3
- metadata +11 -4
data/.travis.yml
ADDED
data/Rakefile
CHANGED
@@ -7,6 +7,7 @@ Rake::ExtensionTask.new('oily_png', gem_management_tasks.gemspec) do |ext|
|
|
7
7
|
ext.lib_dir = File.join('lib', 'oily_png')
|
8
8
|
end
|
9
9
|
|
10
|
+
Rake::Task['spec'].prerequisites << :compile
|
10
11
|
Rake::Task['spec:basic'].prerequisites << :compile
|
11
12
|
Rake::Task['spec:rcov'].prerequisites << :compile
|
12
13
|
Rake::Task['spec:specdoc'].prerequisites << :compile
|
data/ext/oily_png/color.c
CHANGED
@@ -17,5 +17,30 @@ PIXEL oily_png_compose_color(PIXEL fg, PIXEL bg) {
|
|
17
17
|
}
|
18
18
|
|
19
19
|
VALUE oily_png_color_compose_quick(VALUE self, VALUE fg_color, VALUE bg_color) {
|
20
|
+
UNUSED_PARAMETER(self);
|
20
21
|
return UINT2NUM(oily_png_compose_color(NUM2UINT(fg_color), NUM2UINT(bg_color)));
|
21
22
|
}
|
23
|
+
|
24
|
+
VALUE oily_png_color_r(VALUE self, VALUE value) {
|
25
|
+
UNUSED_PARAMETER(self);
|
26
|
+
BYTE red = R_BYTE(NUM2UINT(value));
|
27
|
+
return INT2FIX(red);
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE oily_png_color_g(VALUE self, VALUE value) {
|
31
|
+
UNUSED_PARAMETER(self);
|
32
|
+
BYTE green = G_BYTE(NUM2UINT(value));
|
33
|
+
return INT2FIX(green);
|
34
|
+
}
|
35
|
+
|
36
|
+
VALUE oily_png_color_b(VALUE self, VALUE value) {
|
37
|
+
UNUSED_PARAMETER(self);
|
38
|
+
BYTE blue = B_BYTE(NUM2UINT(value));
|
39
|
+
return INT2FIX(blue);
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE oily_png_color_a(VALUE self, VALUE value) {
|
43
|
+
UNUSED_PARAMETER(self);
|
44
|
+
BYTE alpha = A_BYTE(NUM2UINT(value));
|
45
|
+
return INT2FIX(alpha);
|
46
|
+
}
|
data/ext/oily_png/color.h
CHANGED
@@ -19,4 +19,10 @@ VALUE oily_png_color_compose_quick(VALUE self, VALUE fg_color, VALUE bg_color);
|
|
19
19
|
/* Color composition using alpha transparency. */
|
20
20
|
PIXEL oily_png_compose_color(PIXEL fg, PIXEL bg);
|
21
21
|
|
22
|
+
/* Accessors */
|
23
|
+
VALUE oily_png_color_r(VALUE self, VALUE pixel);
|
24
|
+
VALUE oily_png_color_g(VALUE self, VALUE pixel);
|
25
|
+
VALUE oily_png_color_b(VALUE self, VALUE pixel);
|
26
|
+
VALUE oily_png_color_a(VALUE self, VALUE pixel);
|
27
|
+
|
22
28
|
#endif
|
data/ext/oily_png/oily_png_ext.c
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
void Init_oily_png() {
|
4
4
|
VALUE OilyPNG = rb_define_module("OilyPNG");
|
5
5
|
|
6
|
+
VALUE OilyPNG_Canvas = rb_define_module_under(OilyPNG, "Resampling");
|
7
|
+
rb_define_private_method(OilyPNG_Canvas, "steps_residues", oily_png_canvas_steps_residues, 2);
|
8
|
+
rb_define_private_method(OilyPNG_Canvas, "steps", oily_png_canvas_steps, 2);
|
9
|
+
rb_define_method(OilyPNG_Canvas, "resample_nearest_neighbor!", oily_png_canvas_resample_nearest_neighbor_bang, 2);
|
10
|
+
|
6
11
|
// Setup decoding module
|
7
12
|
VALUE OilyPNG_PNGDecoding = rb_define_module_under(OilyPNG, "PNGDecoding");
|
8
13
|
rb_define_method(OilyPNG_PNGDecoding, "decode_png_image_pass", oily_png_decode_png_image_pass, 6);
|
@@ -14,6 +19,10 @@ void Init_oily_png() {
|
|
14
19
|
// Setup Color module
|
15
20
|
VALUE OilyPNG_Color = rb_define_module_under(OilyPNG, "Color");
|
16
21
|
rb_define_method(OilyPNG_Color, "compose_quick", oily_png_color_compose_quick, 2);
|
22
|
+
rb_define_method(OilyPNG_Color, "r", oily_png_color_r, 1);
|
23
|
+
rb_define_method(OilyPNG_Color, "g", oily_png_color_g, 1);
|
24
|
+
rb_define_method(OilyPNG_Color, "b", oily_png_color_b, 1);
|
25
|
+
rb_define_method(OilyPNG_Color, "a", oily_png_color_a, 1);
|
17
26
|
|
18
27
|
// Setup Operations module
|
19
28
|
VALUE OilyPNG_Operations = rb_define_module_under(OilyPNG, "Operations");
|
data/ext/oily_png/oily_png_ext.h
CHANGED
@@ -0,0 +1,151 @@
|
|
1
|
+
#include "oily_png_ext.h"
|
2
|
+
#include <math.h>
|
3
|
+
|
4
|
+
void oily_png_generate_steps_residues(long width, long new_width, long *steps, long *residues) {
|
5
|
+
long base_step = width / new_width;
|
6
|
+
long err_step = (width % new_width) << 1;
|
7
|
+
long denominator = new_width << 1;
|
8
|
+
|
9
|
+
long index;
|
10
|
+
long err;
|
11
|
+
/* We require an arithmetic modolus and rounding to the left of zero
|
12
|
+
* This is standard Ruby behaviour (I hope!) but differs with how C/Java
|
13
|
+
* typically handle integer division and modulo. But since we are workig
|
14
|
+
* in mixed numbers, Ruby's convention is especially convienent */
|
15
|
+
if (width >= new_width) {
|
16
|
+
index = (width - new_width) / denominator;
|
17
|
+
err = (width - new_width) % denominator;
|
18
|
+
} else {
|
19
|
+
index = (width - new_width) / denominator - 1;
|
20
|
+
err = denominator - ((new_width - width) % denominator);
|
21
|
+
}
|
22
|
+
|
23
|
+
long i;
|
24
|
+
for (i=0; i < new_width; i++){
|
25
|
+
if (residues != NULL) {
|
26
|
+
steps[i] = index;
|
27
|
+
residues[i] = (long) round(255.0 * (float) err / (float) denominator);
|
28
|
+
} else {
|
29
|
+
/* If residues aren't requested, we round to the nearest pixel */
|
30
|
+
if (err < new_width) {
|
31
|
+
steps[i] = index;
|
32
|
+
} else {
|
33
|
+
steps[i] = index + 1;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
index += base_step;
|
38
|
+
err += err_step;
|
39
|
+
if (err >= denominator) {
|
40
|
+
index += 1;
|
41
|
+
err -= denominator;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
VALUE oily_png_canvas_steps(VALUE self, VALUE v_width, VALUE v_new_width) {
|
47
|
+
long width = NUM2LONG(v_width);
|
48
|
+
long new_width = NUM2LONG(v_new_width);
|
49
|
+
|
50
|
+
long *steps = ALLOC_N(long, new_width);
|
51
|
+
|
52
|
+
VALUE ret = rb_ary_new2(new_width);
|
53
|
+
|
54
|
+
oily_png_generate_steps_residues(width, new_width, steps, NULL);
|
55
|
+
|
56
|
+
long i;
|
57
|
+
for (i=0; i < new_width; i++) {
|
58
|
+
rb_ary_store(ret, i, LONG2FIX(steps[i]));
|
59
|
+
}
|
60
|
+
|
61
|
+
/* This is an unprotected allocation; it will leak on exception.
|
62
|
+
* However, rb_ary_store should not generate one as we have
|
63
|
+
* pre-allocated the array.
|
64
|
+
*/
|
65
|
+
xfree(steps);
|
66
|
+
steps = NULL;
|
67
|
+
|
68
|
+
return ret;
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
VALUE oily_png_canvas_steps_residues(VALUE self, VALUE v_width, VALUE v_new_width) {
|
73
|
+
long width = NUM2LONG(v_width);
|
74
|
+
long new_width = NUM2LONG(v_new_width);
|
75
|
+
|
76
|
+
|
77
|
+
VALUE ret_steps = rb_ary_new2(new_width);
|
78
|
+
VALUE ret_residues = rb_ary_new2(new_width);
|
79
|
+
|
80
|
+
|
81
|
+
long *steps = ALLOC_N(long, new_width);
|
82
|
+
long *residues = ALLOC_N(long, new_width);
|
83
|
+
|
84
|
+
oily_png_generate_steps_residues(width, new_width, steps, residues);
|
85
|
+
|
86
|
+
|
87
|
+
long i;
|
88
|
+
for (i=0; i < new_width; i++) {
|
89
|
+
rb_ary_store(ret_steps, i, LONG2FIX(steps[i]));
|
90
|
+
rb_ary_store(ret_residues, i, LONG2FIX(residues[i]));
|
91
|
+
}
|
92
|
+
|
93
|
+
/* This is an unprotected allocation; it will leak on exception.
|
94
|
+
* However, rb_ary_store should not generate one as we have
|
95
|
+
* pre-allocated the array.
|
96
|
+
*/
|
97
|
+
xfree(steps);
|
98
|
+
steps = NULL;
|
99
|
+
|
100
|
+
xfree(residues);
|
101
|
+
residues = NULL;
|
102
|
+
|
103
|
+
|
104
|
+
/* We return multiple values */
|
105
|
+
VALUE ret = rb_ary_new2(2);
|
106
|
+
rb_ary_store(ret, 0, ret_steps);
|
107
|
+
rb_ary_store(ret, 1, ret_residues);
|
108
|
+
|
109
|
+
return ret;
|
110
|
+
}
|
111
|
+
|
112
|
+
VALUE oily_png_canvas_resample_nearest_neighbor_bang(VALUE self, VALUE v_new_width, VALUE v_new_height) {
|
113
|
+
long new_width = NUM2LONG(v_new_width);
|
114
|
+
long new_height = NUM2LONG(v_new_height);
|
115
|
+
|
116
|
+
long self_width = NUM2LONG(rb_funcall(self, rb_intern("width"), 0));
|
117
|
+
long self_height = NUM2LONG(rb_funcall(self, rb_intern("height"), 0));
|
118
|
+
|
119
|
+
VALUE pixels = rb_ary_new2(new_width*new_height);
|
120
|
+
VALUE source = rb_iv_get(self, "@pixels");
|
121
|
+
|
122
|
+
long *steps_x = ALLOC_N(long, new_width);
|
123
|
+
long *steps_y = ALLOC_N(long, new_height);
|
124
|
+
|
125
|
+
oily_png_generate_steps_residues(self_width, new_width, steps_x, NULL);
|
126
|
+
oily_png_generate_steps_residues(self_height, new_height, steps_y, NULL);
|
127
|
+
|
128
|
+
long index = 0;
|
129
|
+
long x, y;
|
130
|
+
long src_index;
|
131
|
+
for (y=0; y < new_height; y++) {
|
132
|
+
for (x = 0; x < new_width; x++) {
|
133
|
+
src_index = steps_y[y] * self_width + steps_x[x];
|
134
|
+
VALUE pixel = rb_ary_entry(source, src_index);
|
135
|
+
rb_ary_store(pixels, index, pixel);
|
136
|
+
index++;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
xfree(steps_x);
|
141
|
+
steps_x = NULL;
|
142
|
+
|
143
|
+
xfree(steps_y);
|
144
|
+
steps_y = NULL;
|
145
|
+
|
146
|
+
rb_iv_set(self, "@pixels", pixels);
|
147
|
+
rb_iv_set(self, "@width", LONG2NUM(new_width));
|
148
|
+
rb_iv_set(self, "@height", LONG2NUM(new_height));
|
149
|
+
|
150
|
+
return self;
|
151
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#ifndef OILY_PNG_RESAMPLING_H
|
2
|
+
#define OILY_PNG_RESAMPLING_H
|
3
|
+
|
4
|
+
/*
|
5
|
+
* Generates the interpolation steps (nearest neighbour) through two values.
|
6
|
+
*/
|
7
|
+
void oily_png_generate_steps_residues(long width, long new_width, long *steps, long *residues);
|
8
|
+
|
9
|
+
/*
|
10
|
+
* Generates the interpolation steps through two values.
|
11
|
+
*
|
12
|
+
* Returns a Ruby Array
|
13
|
+
*/
|
14
|
+
VALUE oily_png_canvas_steps_residues(VALUE self, VALUE width, VALUE new_width);
|
15
|
+
VALUE oily_png_canvas_steps(VALUE self, VALUE width, VALUE new_width);
|
16
|
+
|
17
|
+
|
18
|
+
/*
|
19
|
+
* Performs nearest neighbor interpolation on the Canvas
|
20
|
+
*/
|
21
|
+
VALUE oily_png_canvas_resample_nearest_neighbor_bang(VALUE self, VALUE new_width, VALUE new_height);
|
22
|
+
|
23
|
+
#endif
|
data/lib/oily_png.rb
CHANGED
@@ -2,17 +2,22 @@ require 'chunky_png'
|
|
2
2
|
|
3
3
|
module OilyPNG
|
4
4
|
|
5
|
-
VERSION = "1.0.
|
5
|
+
VERSION = "1.0.2"
|
6
6
|
|
7
7
|
def self.included(base)
|
8
8
|
base::Canvas.send(:extend, OilyPNG::PNGDecoding)
|
9
9
|
base::Canvas.send(:include, OilyPNG::PNGEncoding)
|
10
10
|
|
11
|
+
|
11
12
|
base::Color.send(:include, OilyPNG::Color)
|
13
|
+
|
14
|
+
base::Color.extend OilyPNG::Color
|
15
|
+
base::Canvas.send(:include, OilyPNG::Resampling)
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
15
19
|
require 'oily_png/oily_png'
|
20
|
+
require 'oily_png/canvas'
|
16
21
|
|
17
22
|
# Include mixin into ChunkyPNG
|
18
23
|
ChunkyPNG.send(:include, OilyPNG)
|
data/lib/oily_png/canvas.rb
CHANGED
data/oily_png.gemspec
CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
|
|
4
4
|
|
5
5
|
# Do not change the version and date fields by hand. This will be done
|
6
6
|
# automatically by the gem release script.
|
7
|
-
s.version = "1.0.
|
8
|
-
s.date = "2011-
|
7
|
+
s.version = "1.0.2"
|
8
|
+
s.date = "2011-08-10"
|
9
9
|
|
10
10
|
s.summary = "Native mixin to speed up ChunkyPNG"
|
11
11
|
s.description = <<-EOT
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.extensions = ["ext/oily_png/extconf.rb"]
|
20
20
|
s.require_paths = ["lib", "ext"]
|
21
21
|
|
22
|
-
s.add_runtime_dependency('chunky_png', '~> 1')
|
22
|
+
s.add_runtime_dependency('chunky_png', '~> 1.2.1')
|
23
23
|
|
24
24
|
s.add_development_dependency('rake')
|
25
25
|
s.add_development_dependency('rake-compiler')
|
@@ -30,6 +30,6 @@ Gem::Specification.new do |s|
|
|
30
30
|
|
31
31
|
# Do not change the files and test_files fields by hand. This will be done
|
32
32
|
# automatically by the gem release script.
|
33
|
-
s.files = %w(.gitignore .infinity_test Gemfile LICENSE README.rdoc Rakefile ext/oily_png/color.c ext/oily_png/color.h ext/oily_png/extconf.rb ext/oily_png/oily_png_ext.c ext/oily_png/oily_png_ext.h ext/oily_png/operations.c ext/oily_png/operations.h ext/oily_png/png_decoding.c ext/oily_png/png_decoding.h ext/oily_png/png_encoding.c ext/oily_png/png_encoding.h lib/oily_png.rb lib/oily_png/canvas.rb oily_png.gemspec spec/color_spec.rb spec/decoding_spec.rb spec/encoding_spec.rb spec/operations_spec.rb spec/resources/basi0g01.png spec/resources/basi0g02.png spec/resources/basi0g04.png spec/resources/basi0g08.png spec/resources/basi0g16.png spec/resources/basi2c08.png spec/resources/basi2c16.png spec/resources/basi3p01.png spec/resources/basi3p02.png spec/resources/basi3p04.png spec/resources/basi3p08.png spec/resources/basi4a08.png spec/resources/basi4a16.png spec/resources/basi6a08.png spec/resources/basi6a16.png spec/resources/basn0g01.png spec/resources/basn0g02.png spec/resources/basn0g04.png spec/resources/basn0g08.png spec/resources/basn0g16.png spec/resources/basn2c08.png spec/resources/basn2c16.png spec/resources/basn3p01.png spec/resources/basn3p02.png spec/resources/basn3p04.png spec/resources/basn3p08.png spec/resources/basn4a08.png spec/resources/basn4a16.png spec/resources/basn6a08.png spec/resources/basn6a16.png spec/resources/composited.png spec/resources/gray.png spec/resources/interlaced.png spec/resources/nonsquare.png spec/resources/operations.png spec/resources/replaced.png spec/resources/s01i3p01.png spec/resources/s01n3p01.png spec/resources/s02i3p01.png spec/resources/s02n3p01.png spec/resources/s03i3p01.png spec/resources/s03n3p01.png spec/resources/s04i3p01.png spec/resources/s04n3p01.png spec/resources/s05i3p02.png spec/resources/s05n3p02.png spec/resources/s06i3p02.png spec/resources/s06n3p02.png spec/resources/s07i3p02.png spec/resources/s07n3p02.png spec/resources/s08i3p02.png spec/resources/s08n3p02.png spec/resources/s09i3p02.png spec/resources/s09n3p02.png spec/resources/s32i3p04.png spec/resources/s32n3p04.png spec/resources/s33i3p04.png spec/resources/s33n3p04.png spec/resources/s34i3p04.png spec/resources/s34n3p04.png spec/resources/s35i3p04.png spec/resources/s35n3p04.png spec/resources/s36i3p04.png spec/resources/s36n3p04.png spec/resources/s37i3p04.png spec/resources/s37n3p04.png spec/resources/s38i3p04.png spec/resources/s38n3p04.png spec/resources/s39i3p04.png spec/resources/s39n3p04.png spec/resources/s40i3p04.png spec/resources/s40n3p04.png spec/resources/square.png spec/resources/tbbn1g04.png spec/resources/tbbn2c16.png spec/resources/tbbn3p08.png spec/resources/tbgn2c16.png spec/resources/tbgn3p08.png spec/resources/tbrn2c08.png spec/resources/tbwn1g16.png spec/resources/tbwn3p08.png spec/resources/tbyn3p08.png spec/resources/tp0n1g08.png spec/resources/tp0n2c08.png spec/resources/tp0n3p08.png spec/resources/tp1n3p08.png spec/spec_helper.rb tasks/github-gem.rake tasks/testing.rake)
|
34
|
-
s.test_files = %w(spec/color_spec.rb spec/decoding_spec.rb spec/encoding_spec.rb spec/operations_spec.rb)
|
33
|
+
s.files = %w(.gitignore .infinity_test .travis.yml Gemfile LICENSE README.rdoc Rakefile ext/oily_png/color.c ext/oily_png/color.h ext/oily_png/extconf.rb ext/oily_png/oily_png_ext.c ext/oily_png/oily_png_ext.h ext/oily_png/operations.c ext/oily_png/operations.h ext/oily_png/png_decoding.c ext/oily_png/png_decoding.h ext/oily_png/png_encoding.c ext/oily_png/png_encoding.h ext/oily_png/resampling.c ext/oily_png/resampling.h lib/oily_png.rb lib/oily_png/canvas.rb oily_png.gemspec spec/color_spec.rb spec/decoding_spec.rb spec/encoding_spec.rb spec/operations_spec.rb spec/resampling_spec.rb spec/resources/basi0g01.png spec/resources/basi0g02.png spec/resources/basi0g04.png spec/resources/basi0g08.png spec/resources/basi0g16.png spec/resources/basi2c08.png spec/resources/basi2c16.png spec/resources/basi3p01.png spec/resources/basi3p02.png spec/resources/basi3p04.png spec/resources/basi3p08.png spec/resources/basi4a08.png spec/resources/basi4a16.png spec/resources/basi6a08.png spec/resources/basi6a16.png spec/resources/basn0g01.png spec/resources/basn0g02.png spec/resources/basn0g04.png spec/resources/basn0g08.png spec/resources/basn0g16.png spec/resources/basn2c08.png spec/resources/basn2c16.png spec/resources/basn3p01.png spec/resources/basn3p02.png spec/resources/basn3p04.png spec/resources/basn3p08.png spec/resources/basn4a08.png spec/resources/basn4a16.png spec/resources/basn6a08.png spec/resources/basn6a16.png spec/resources/composited.png spec/resources/gray.png spec/resources/interlaced.png spec/resources/nonsquare.png spec/resources/operations.png spec/resources/replaced.png spec/resources/s01i3p01.png spec/resources/s01n3p01.png spec/resources/s02i3p01.png spec/resources/s02n3p01.png spec/resources/s03i3p01.png spec/resources/s03n3p01.png spec/resources/s04i3p01.png spec/resources/s04n3p01.png spec/resources/s05i3p02.png spec/resources/s05n3p02.png spec/resources/s06i3p02.png spec/resources/s06n3p02.png spec/resources/s07i3p02.png spec/resources/s07n3p02.png spec/resources/s08i3p02.png spec/resources/s08n3p02.png spec/resources/s09i3p02.png spec/resources/s09n3p02.png spec/resources/s32i3p04.png spec/resources/s32n3p04.png spec/resources/s33i3p04.png spec/resources/s33n3p04.png spec/resources/s34i3p04.png spec/resources/s34n3p04.png spec/resources/s35i3p04.png spec/resources/s35n3p04.png spec/resources/s36i3p04.png spec/resources/s36n3p04.png spec/resources/s37i3p04.png spec/resources/s37n3p04.png spec/resources/s38i3p04.png spec/resources/s38n3p04.png spec/resources/s39i3p04.png spec/resources/s39n3p04.png spec/resources/s40i3p04.png spec/resources/s40n3p04.png spec/resources/square.png spec/resources/tbbn1g04.png spec/resources/tbbn2c16.png spec/resources/tbbn3p08.png spec/resources/tbgn2c16.png spec/resources/tbgn3p08.png spec/resources/tbrn2c08.png spec/resources/tbwn1g16.png spec/resources/tbwn3p08.png spec/resources/tbyn3p08.png spec/resources/tp0n1g08.png spec/resources/tp0n2c08.png spec/resources/tp0n3p08.png spec/resources/tp1n3p08.png spec/spec_helper.rb tasks/github-gem.rake tasks/testing.rake)
|
34
|
+
s.test_files = %w(spec/color_spec.rb spec/decoding_spec.rb spec/encoding_spec.rb spec/operations_spec.rb spec/resampling_spec.rb)
|
35
35
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OilyPNG::Resampling do
|
4
|
+
|
5
|
+
include OilyPNG::Resampling
|
6
|
+
|
7
|
+
describe '#steps' do
|
8
|
+
it "should generate the steps from 4 to 8 as [0,0,1,1,2,2,3,3]" do
|
9
|
+
steps(4,8).should == [0,0,1,1,2,2,3,3]
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should generate the steps the same as ChunkyPNG" do
|
13
|
+
image = ChunkyPNG::Image.new(1,1)
|
14
|
+
steps(2,8).should == image.send(:steps,2,8)
|
15
|
+
steps(2,11).should == image.send(:steps,2,11)
|
16
|
+
steps(11,5).should == image.send(:steps,11,5)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#resample_nearest_neighbor!' do
|
21
|
+
before(:all) { @reference = ChunkyPNG::Canvas.from_file(resource_file('nonsquare.png'))}
|
22
|
+
|
23
|
+
it "should resample [0,1,2,3] to 4x4 properly" do
|
24
|
+
OilyPNG::Canvas.new(2,2,[0,1,2,3]).resample_nearest_neighbor(4,4).should == OilyPNG::Canvas.new(4,4,[0,0,1,1,0,0,1,1,2,2,3,3,2,2,3,3])
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should resample [0,1,2,3] to 99x45 as ChunkyPNG does" do
|
28
|
+
ChunkyPNG::Canvas.new(2,2,[0,1,2,3]).resample_nearest_neighbor(99,45).should == OilyPNG::Canvas.new(2,2,[0,1,2,3]).resample_nearest_neighbor(99,45)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should resample an image to 10x20 as ChunkyPNG does" do
|
32
|
+
@reference.resample_nearest_neighbor(10,20).should == OilyPNG::Canvas.from_canvas(@reference).resample_nearest_neighbor(10,20)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should resample an image to 11x19 as ChunkyPNG does" do
|
36
|
+
@reference.resample_nearest_neighbor(11,19).should == OilyPNG::Canvas.from_canvas(@reference).resample_nearest_neighbor(11,19)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/tasks/github-gem.rake
CHANGED
@@ -13,8 +13,8 @@ module GithubGem
|
|
13
13
|
|
14
14
|
# Detects the main include file of this project using heuristics
|
15
15
|
def self.detect_main_include
|
16
|
-
if
|
17
|
-
"lib/#{
|
16
|
+
if File.exist?(File.expand_path("../lib/#{File.basename(detect_gemspec_file, '.gemspec').gsub(/-/, '/')}.rb", detect_gemspec_file))
|
17
|
+
"lib/#{File.basename(detect_gemspec_file, '.gemspec').gsub(/-/, '/')}.rb"
|
18
18
|
elsif FileList['lib/*.rb'].length == 1
|
19
19
|
FileList['lib/*.rb'].first
|
20
20
|
else
|
@@ -24,6 +24,8 @@ module GithubGem
|
|
24
24
|
|
25
25
|
class RakeTasks
|
26
26
|
|
27
|
+
include Rake::DSL if Rake.const_defined?('DSL')
|
28
|
+
|
27
29
|
attr_reader :gemspec, :modified_files
|
28
30
|
attr_accessor :gemspec_file, :task_namespace, :main_include, :root_dir, :spec_pattern, :test_pattern, :remote, :remote_branch, :local_branch
|
29
31
|
|
@@ -342,7 +344,7 @@ module GithubGem
|
|
342
344
|
require 'net/https'
|
343
345
|
require 'uri'
|
344
346
|
|
345
|
-
uri = URI.parse('https://github.com/wvanbergen/github-gem/
|
347
|
+
uri = URI.parse('https://raw.github.com/wvanbergen/github-gem/master/tasks/github-gem.rake')
|
346
348
|
http = Net::HTTP.new(uri.host, uri.port)
|
347
349
|
http.use_ssl = true
|
348
350
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 2
|
9
|
+
version: 1.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Willem van Bergen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-08-10 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -27,7 +27,9 @@ dependencies:
|
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
segments:
|
29
29
|
- 1
|
30
|
-
|
30
|
+
- 2
|
31
|
+
- 1
|
32
|
+
version: 1.2.1
|
31
33
|
type: :runtime
|
32
34
|
version_requirements: *id001
|
33
35
|
- !ruby/object:Gem::Dependency
|
@@ -81,6 +83,7 @@ extra_rdoc_files:
|
|
81
83
|
files:
|
82
84
|
- .gitignore
|
83
85
|
- .infinity_test
|
86
|
+
- .travis.yml
|
84
87
|
- Gemfile
|
85
88
|
- LICENSE
|
86
89
|
- README.rdoc
|
@@ -96,6 +99,8 @@ files:
|
|
96
99
|
- ext/oily_png/png_decoding.h
|
97
100
|
- ext/oily_png/png_encoding.c
|
98
101
|
- ext/oily_png/png_encoding.h
|
102
|
+
- ext/oily_png/resampling.c
|
103
|
+
- ext/oily_png/resampling.h
|
99
104
|
- lib/oily_png.rb
|
100
105
|
- lib/oily_png/canvas.rb
|
101
106
|
- oily_png.gemspec
|
@@ -103,6 +108,7 @@ files:
|
|
103
108
|
- spec/decoding_spec.rb
|
104
109
|
- spec/encoding_spec.rb
|
105
110
|
- spec/operations_spec.rb
|
111
|
+
- spec/resampling_spec.rb
|
106
112
|
- spec/resources/basi0g01.png
|
107
113
|
- spec/resources/basi0g02.png
|
108
114
|
- spec/resources/basi0g04.png
|
@@ -235,3 +241,4 @@ test_files:
|
|
235
241
|
- spec/decoding_spec.rb
|
236
242
|
- spec/encoding_spec.rb
|
237
243
|
- spec/operations_spec.rb
|
244
|
+
- spec/resampling_spec.rb
|