oily_png 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,6 +2,7 @@ Makefile
2
2
  /conftest.dSYM
3
3
  *.bundle
4
4
  *.o
5
+ *.rbc
5
6
  /.bundle/
6
7
  /pkg
7
8
  oily_png-*.gem
data/.infinity_test ADDED
@@ -0,0 +1,9 @@
1
+ infinity_test do
2
+
3
+ use :rubies => %w(1.8.7 1.9.2 ree rbx), :test_framework => :rspec
4
+
5
+ before(:each_ruby) do |environment|
6
+ environment.system('bundle install')
7
+ environment.system('rake compile')
8
+ end
9
+ end
data/Gemfile CHANGED
@@ -1,10 +1,11 @@
1
1
  source :rubyforge
2
- gemspec
3
2
 
4
- # # Use the following gem specification instead of the 'gemspec' statement
5
- # # to develop with a local chunky_png copy
6
-
7
- # gem 'chunky_png', :path => File.expand_path('../chunky_png', File.dirname(__FILE__))
8
- # gem 'oily_png', :path => File.dirname(__FILE__)
9
- # gem 'rake'
10
- # gem 'rspec'
3
+ if ENV['CHUNKY_PNG']
4
+ gem 'chunky_png', :path => ENV['CHUNKY_PNG']
5
+ gem 'oily_png', :path => File.dirname(__FILE__)
6
+ gem 'rake'
7
+ gem 'rake-compiler'
8
+ gem 'rspec'
9
+ else
10
+ gemspec
11
+ end
data/Gemfile.lock CHANGED
@@ -1,31 +1,32 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oily_png (0.2.0)
5
- chunky_png (~> 0.11)
4
+ oily_png (0.3.0)
5
+ chunky_png (~> 0.12)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- chunky_png (0.11.0)
10
+ chunky_png (0.12.0)
11
11
  diff-lcs (1.1.2)
12
12
  rake (0.8.7)
13
- rspec (2.0.0)
14
- rspec-core (= 2.0.0)
15
- rspec-expectations (= 2.0.0)
16
- rspec-mocks (= 2.0.0)
17
- rspec-core (2.0.0)
18
- rspec-expectations (2.0.0)
19
- diff-lcs (>= 1.1.2)
20
- rspec-mocks (2.0.0)
21
- rspec-core (= 2.0.0)
22
- rspec-expectations (= 2.0.0)
13
+ rake-compiler (0.7.5)
14
+ rake
15
+ rspec (2.2.0)
16
+ rspec-core (~> 2.2)
17
+ rspec-expectations (~> 2.2)
18
+ rspec-mocks (~> 2.2)
19
+ rspec-core (2.2.1)
20
+ rspec-expectations (2.2.0)
21
+ diff-lcs (~> 1.1.2)
22
+ rspec-mocks (2.2.0)
23
23
 
24
24
  PLATFORMS
25
25
  ruby
26
26
 
27
27
  DEPENDENCIES
28
- chunky_png (~> 0.11)
28
+ chunky_png (~> 0.12)
29
29
  oily_png!
30
30
  rake
31
- rspec (~> 2.0)
31
+ rake-compiler
32
+ rspec (~> 2)
data/Rakefile CHANGED
@@ -5,5 +5,20 @@ Bundler.setup
5
5
 
6
6
  Dir['tasks/*.rake'].each { |file| load(file) }
7
7
 
8
+ require 'rake/extensiontask'
9
+
10
+ def gemspec
11
+ @clean_gemspec ||= eval(File.read(File.expand_path('../oily_png.gemspec', __FILE__)))
12
+ end
13
+
8
14
  GithubGem::RakeTasks.new(:gem)
15
+
16
+ Rake::ExtensionTask.new('oily_png', gemspec) do |ext|
17
+ ext.lib_dir = File.join('lib', 'oily_png')
18
+ end
19
+
20
+ Rake::Task['spec:basic'].prerequisites << :compile
21
+ Rake::Task['spec:rcov'].prerequisites << :compile
22
+ Rake::Task['spec:specdoc'].prerequisites << :compile
23
+
9
24
  task :default => [:spec]
@@ -1,3 +1,3 @@
1
1
  require 'mkmf'
2
2
  $CFLAGS << ' -Wall'
3
- create_makefile('oily_png/oily_png_ext')
3
+ create_makefile('oily_png/oily_png')
@@ -1,6 +1,6 @@
1
1
  #include "oily_png_ext.h"
2
2
 
3
- void Init_oily_png_ext() {
3
+ void Init_oily_png() {
4
4
  VALUE OilyPNG = rb_define_module("OilyPNG");
5
5
 
6
6
  // Setup decoding
@@ -9,7 +9,7 @@ void Init_oily_png_ext() {
9
9
 
10
10
  // Setup encoding
11
11
  VALUE OilyPNG_PNGEncoding = rb_define_module_under(OilyPNG, "PNGEncoding");
12
- rb_define_method(OilyPNG_PNGEncoding, "encode_png_image_pass_to_stream", oily_png_encode_png_image_pass_to_stream, 3);
12
+ rb_define_method(OilyPNG_PNGEncoding, "encode_png_image_pass_to_stream", oily_png_encode_png_image_pass_to_stream, 4);
13
13
  }
14
14
 
15
15
  char oily_png_samples_per_pixel(char color_mode) {
@@ -21,8 +21,10 @@
21
21
  #define PIXEL unsigned int // Pixels use 32 bits unsigned integers
22
22
  #define BYTE unsigned char // Bytes use 8 bits unsigned integers
23
23
 
24
- #include "png_decoding.h"
25
- #include "png_encoding.h"
24
+ #define UNUSED_PARAMETER(param) (void) param
25
+
26
+ #include <png_decoding.h>
27
+ #include <png_encoding.h>
26
28
 
27
29
 
28
30
  /*
@@ -34,7 +36,7 @@
34
36
  speed up decoding, and include OilyPNG::PNGEncoding into the same class to speed
35
37
  up encoding. This is done in lib/oily_png.rb
36
38
  */
37
- void Init_oily_png_ext();
39
+ void Init_oily_png();
38
40
 
39
41
  /*
40
42
  Returns the number of samples per pixel for a given color mode
@@ -1,4 +1,4 @@
1
- #include "oily_png_ext.h"
1
+ #include <oily_png_ext.h>
2
2
 
3
3
 
4
4
  // Decodes a SUB filtered scanline at the given position in the byte array
@@ -11,9 +11,9 @@ void oily_png_decode_filter_sub(BYTE* bytes, long pos, long line_length, char pi
11
11
 
12
12
  // Decodes an UP filtered scanline at the given position in the byte array
13
13
  void oily_png_decode_filter_up(BYTE* bytes, long pos, long line_size, char pixel_size) {
14
+ UNUSED_PARAMETER(pixel_size);
14
15
  long i;
15
- // The first line is not filtered because there is no privous line
16
- if (pos >= line_size) {
16
+ if (pos >= line_size) { // The first line is not filtered because there is no privous line
17
17
  for (i = 1; i < line_size; i++) {
18
18
  UNFILTER_BYTE(bytes[pos + i], bytes[pos + i - line_size]);
19
19
  }
@@ -119,6 +119,7 @@ PIXEL oily_png_decode_pixel_indexed_1bit(BYTE* bytes, long start, long x, VALUE
119
119
 
120
120
 
121
121
  PIXEL oily_png_decode_pixel_grayscale_8bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
122
+ UNUSED_PARAMETER(decoding_palette);
122
123
  return BUILD_PIXEL( bytes[start + 1 + x],
123
124
  bytes[start + 1 + x],
124
125
  bytes[start + 1 + x],
@@ -126,6 +127,7 @@ PIXEL oily_png_decode_pixel_grayscale_8bit(BYTE* bytes, long start, long x, VALU
126
127
  }
127
128
 
128
129
  PIXEL oily_png_decode_pixel_grayscale_1bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
130
+ UNUSED_PARAMETER(decoding_palette);
129
131
  return BUILD_PIXEL( oily_png_resample_1bit_element(bytes, start, x),
130
132
  oily_png_resample_1bit_element(bytes, start, x),
131
133
  oily_png_resample_1bit_element(bytes, start, x),
@@ -133,6 +135,7 @@ PIXEL oily_png_decode_pixel_grayscale_1bit(BYTE* bytes, long start, long x, VALU
133
135
  }
134
136
 
135
137
  PIXEL oily_png_decode_pixel_grayscale_2bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
138
+ UNUSED_PARAMETER(decoding_palette);
136
139
  return BUILD_PIXEL( oily_png_resample_2bit_element(bytes, start, x),
137
140
  oily_png_resample_2bit_element(bytes, start, x),
138
141
  oily_png_resample_2bit_element(bytes, start, x),
@@ -140,6 +143,7 @@ PIXEL oily_png_decode_pixel_grayscale_2bit(BYTE* bytes, long start, long x, VALU
140
143
  }
141
144
 
142
145
  PIXEL oily_png_decode_pixel_grayscale_4bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
146
+ UNUSED_PARAMETER(decoding_palette);
143
147
  return BUILD_PIXEL( oily_png_resample_4bit_element(bytes, start, x),
144
148
  oily_png_resample_4bit_element(bytes, start, x),
145
149
  oily_png_resample_4bit_element(bytes, start, x),
@@ -147,6 +151,7 @@ PIXEL oily_png_decode_pixel_grayscale_4bit(BYTE* bytes, long start, long x, VALU
147
151
  }
148
152
 
149
153
  PIXEL oily_png_decode_pixel_truecolor_8bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
154
+ UNUSED_PARAMETER(decoding_palette);
150
155
  return BUILD_PIXEL( bytes[start + 1 + (x * 3) + 0],
151
156
  bytes[start + 1 + (x * 3) + 1],
152
157
  bytes[start + 1 + (x * 3) + 2],
@@ -154,6 +159,7 @@ PIXEL oily_png_decode_pixel_truecolor_8bit(BYTE* bytes, long start, long x, VALU
154
159
  }
155
160
 
156
161
  PIXEL oily_png_decode_pixel_grayscale_alpha_8bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
162
+ UNUSED_PARAMETER(decoding_palette);
157
163
  return BUILD_PIXEL( bytes[start + 1 + (x * 2) + 0],
158
164
  bytes[start + 1 + (x * 2) + 0],
159
165
  bytes[start + 1 + (x * 2) + 0],
@@ -161,6 +167,7 @@ PIXEL oily_png_decode_pixel_grayscale_alpha_8bit(BYTE* bytes, long start, long x
161
167
  }
162
168
 
163
169
  PIXEL oily_png_decode_pixel_truecolor_alpha_8bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
170
+ UNUSED_PARAMETER(decoding_palette);
164
171
  return BUILD_PIXEL( bytes[start + 1 + (x * 4) + 0],
165
172
  bytes[start + 1 + (x * 4) + 1],
166
173
  bytes[start + 1 + (x * 4) + 2],
@@ -168,6 +175,7 @@ PIXEL oily_png_decode_pixel_truecolor_alpha_8bit(BYTE* bytes, long start, long x
168
175
  }
169
176
 
170
177
  PIXEL oily_png_decode_pixel_grayscale_16bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
178
+ UNUSED_PARAMETER(decoding_palette);
171
179
  return BUILD_PIXEL( bytes[start + 1 + (x * 2)],
172
180
  bytes[start + 1 + (x * 2)],
173
181
  bytes[start + 1 + (x * 2)],
@@ -175,6 +183,7 @@ PIXEL oily_png_decode_pixel_grayscale_16bit(BYTE* bytes, long start, long x, VAL
175
183
  }
176
184
 
177
185
  PIXEL oily_png_decode_pixel_truecolor_16bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
186
+ UNUSED_PARAMETER(decoding_palette);
178
187
  return BUILD_PIXEL( bytes[start + 1 + (x * 6) + 0],
179
188
  bytes[start + 1 + (x * 6) + 2],
180
189
  bytes[start + 1 + (x * 6) + 4],
@@ -182,6 +191,7 @@ PIXEL oily_png_decode_pixel_truecolor_16bit(BYTE* bytes, long start, long x, VAL
182
191
  }
183
192
 
184
193
  PIXEL oily_png_decode_pixel_grayscale_alpha_16bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
194
+ UNUSED_PARAMETER(decoding_palette);
185
195
  return BUILD_PIXEL( bytes[start + 1 + (x * 4) + 0],
186
196
  bytes[start + 1 + (x * 4) + 0],
187
197
  bytes[start + 1 + (x * 4) + 0],
@@ -189,6 +199,7 @@ PIXEL oily_png_decode_pixel_grayscale_alpha_16bit(BYTE* bytes, long start, long
189
199
  }
190
200
 
191
201
  PIXEL oily_png_decode_pixel_truecolor_alpha_16bit(BYTE* bytes, long start, long x, VALUE decoding_palette) {
202
+ UNUSED_PARAMETER(decoding_palette);
192
203
  return BUILD_PIXEL( bytes[start + 1 + (x * 8) + 0],
193
204
  bytes[start + 1 + (x * 8) + 2],
194
205
  bytes[start + 1 + (x * 8) + 4],
@@ -1,36 +1,4 @@
1
- #include "oily_png_ext.h"
2
-
3
- ///// Pixel encoding functions //////////////////////////////////////////
4
-
5
- void oily_png_encode_pixel_grayscale(PIXEL pixel, BYTE* bytes, long pos, VALUE palette) {
6
- // Assume R == G == B. ChunkyPNG uses the B byte fot performance reasons.
7
- // We'll uses the same to reomain compatible with ChunkyPNG.
8
- bytes[pos] = B_BYTE(pixel);
9
- }
10
-
11
- void oily_png_encode_pixel_grayscale_alpha(PIXEL pixel, BYTE* bytes, long pos, VALUE palette) {
12
- // Assume R == G == B. ChunkyPNG uses the B byte fot performance reasons.
13
- // We'll uses the same to reomain compatible with ChunkyPNG.
14
- bytes[pos + 0] = B_BYTE(pixel);
15
- bytes[pos + 1] = A_BYTE(pixel);
16
- }
17
-
18
- void oily_png_encode_pixel_truecolor(PIXEL pixel, BYTE* bytes, long pos, VALUE palette) {
19
- bytes[pos + 0] = R_BYTE(pixel);
20
- bytes[pos + 1] = G_BYTE(pixel);
21
- bytes[pos + 2] = B_BYTE(pixel);
22
- }
23
-
24
- void oily_png_encode_pixel_truecolor_alpha(PIXEL pixel, BYTE* bytes, long pos, VALUE palette) {
25
- bytes[pos + 0] = R_BYTE(pixel);
26
- bytes[pos + 1] = G_BYTE(pixel);
27
- bytes[pos + 2] = B_BYTE(pixel);
28
- bytes[pos + 3] = A_BYTE(pixel);
29
- }
30
-
31
- void oily_png_encode_pixel_indexed(PIXEL pixel, BYTE* bytes, long pos, VALUE palette) {
32
- bytes[pos] = (BYTE) NUM2UINT(rb_funcall(palette, rb_intern("index"), 1, UINT2NUM(pixel)));
33
- }
1
+ #include <oily_png_ext.h>
34
2
 
35
3
  ///// Scanline filtering functions //////////////////////////////////////////
36
4
 
@@ -42,6 +10,8 @@ void oily_png_encode_filter_sub(BYTE* bytes, long pos, long line_size, char pixe
42
10
  }
43
11
 
44
12
  void oily_png_encode_filter_up(BYTE* bytes, long pos, long line_size, char pixel_size) {
13
+ UNUSED_PARAMETER(pixel_size);
14
+
45
15
  long x;
46
16
  if (pos >= line_size) {
47
17
  for (x = line_size - 1; x > 0; x--) {
@@ -74,22 +44,155 @@ void oily_png_encode_filter_paeth(BYTE* bytes, long pos, long line_size, char pi
74
44
  }
75
45
  }
76
46
 
77
- VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE color_mode, VALUE filtering) {
47
+ ///// Scanline encoding functions //////////////////////////////////////////
48
+
49
+ // Assume R == G == B. ChunkyPNG uses the B byte fot performance reasons.
50
+ // We'll uses the same to reomain compatible with ChunkyPNG.
51
+ void oily_png_encode_scanline_grayscale_8bit(BYTE* bytes, VALUE pixels, long y, long width, VALUE encoding_palette) {
52
+ UNUSED_PARAMETER(encoding_palette);
53
+ long x; PIXEL pixel;
54
+ for (x = 0; x < width; x++) {
55
+ pixel = NUM2UINT(rb_ary_entry(pixels, y * width + x));
56
+ bytes[x] = B_BYTE(pixel);
57
+ }
58
+ }
59
+
60
+ // Assume R == G == B. ChunkyPNG uses the B byte fot performance reasons.
61
+ // We'll uses the same to reomain compatible with ChunkyPNG.
62
+ void oily_png_encode_scanline_grayscale_alpha_8bit(BYTE* bytes, VALUE pixels, long y, long width, VALUE encoding_palette) {
63
+ UNUSED_PARAMETER(encoding_palette);
64
+ long x; PIXEL pixel;
65
+ for (x = 0; x < width; x++) {
66
+ pixel = NUM2UINT(rb_ary_entry(pixels, y * width + x));
67
+ bytes[x * 2 + 0] = B_BYTE(pixel);
68
+ bytes[x * 2 + 1] = A_BYTE(pixel);
69
+ }
70
+ }
71
+
72
+ void oily_png_encode_scanline_indexed_8bit(BYTE* bytes, VALUE pixels, long y, long width, VALUE encoding_palette) {
73
+ long x;
74
+ for (x = 0; x < width; x++) {
75
+ bytes[x] = (BYTE) NUM2UINT(rb_funcall(encoding_palette, rb_intern("index"), 1, rb_ary_entry(pixels, y * width + x)));
76
+ }
77
+ }
78
+
79
+ void oily_png_encode_scanline_indexed_4bit(BYTE* bytes, VALUE pixels, long y, long width, VALUE encoding_palette) {
80
+ long x; BYTE p1, p2;
81
+ for (x = 0; x < width; x += 2) {
82
+ p1 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 0);
83
+ p2 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 1);
84
+ bytes[x >> 1] = (BYTE) ((p1 << 4) | (p2));
85
+ }
86
+ }
87
+
88
+ void oily_png_encode_scanline_indexed_2bit(BYTE* bytes, VALUE pixels, long y, long width, VALUE encoding_palette) {
89
+ long x; BYTE p1, p2, p3, p4;
90
+ for (x = 0; x < width; x += 4) {
91
+ p1 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 0);
92
+ p2 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 1);
93
+ p3 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 2);
94
+ p4 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 3);
95
+ bytes[x >> 2] = (BYTE) ((p1 << 6) | (p2 << 4) | (p3 << 2) | (p4));
96
+ }
97
+ }
98
+
99
+ void oily_png_encode_scanline_indexed_1bit(BYTE* bytes, VALUE pixels, long y, long width, VALUE encoding_palette) {
100
+ long x; BYTE p1, p2, p3, p4, p5, p6, p7, p8;
101
+ for (x = 0; x < width; x += 8) {
102
+ p1 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 0);
103
+ p2 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 1);
104
+ p3 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 2);
105
+ p4 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 3);
106
+ p5 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 4);
107
+ p6 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 5);
108
+ p7 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 6);
109
+ p8 = ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x + 7);
110
+ bytes[x >> 3] = (BYTE) ((p1 << 7) | (p2 << 6) | (p3 << 5) | (p4 << 4) | (p5 << 3) | (p6 << 2) | (p7 << 1) | (p8));
111
+ }
112
+ }
113
+
114
+ void oily_png_encode_scanline_truecolor_8bit(BYTE* bytes, VALUE pixels, long y, long width, VALUE encoding_palette) {
115
+ UNUSED_PARAMETER(encoding_palette);
116
+ long x; PIXEL pixel;
117
+ for (x = 0; x < width; x++) {
118
+ pixel = NUM2UINT(rb_ary_entry(pixels, y * width + x));
119
+ bytes[x * 3 + 0] = R_BYTE(pixel);
120
+ bytes[x * 3 + 1] = G_BYTE(pixel);
121
+ bytes[x * 3 + 2] = B_BYTE(pixel);
122
+ }
123
+ }
124
+
125
+ void oily_png_encode_scanline_truecolor_alpha_8bit(BYTE* bytes, VALUE pixels, long y, long width, VALUE encoding_palette) {
126
+ UNUSED_PARAMETER(encoding_palette);
127
+ long x; PIXEL pixel;
128
+ for (x = 0; x < width; x++) {
129
+ pixel = NUM2UINT(rb_ary_entry(pixels, y * width + x));
130
+ bytes[x * 4 + 0] = R_BYTE(pixel);
131
+ bytes[x * 4 + 1] = G_BYTE(pixel);
132
+ bytes[x * 4 + 2] = B_BYTE(pixel);
133
+ bytes[x * 4 + 3] = A_BYTE(pixel);
134
+ }
135
+ }
136
+
137
+
138
+ scanline_encoder_func oily_png_encode_scanline_func(char color_mode, char bit_depth) {
139
+ switch (color_mode) {
140
+
141
+ case OILY_PNG_COLOR_GRAYSCALE:
142
+ switch (bit_depth) {
143
+ case 8: return &oily_png_encode_scanline_grayscale_8bit;
144
+ default: return NULL;
145
+ }
146
+
147
+ case OILY_PNG_COLOR_GRAYSCALE_ALPHA:
148
+ switch (bit_depth) {
149
+ case 8: return &oily_png_encode_scanline_grayscale_alpha_8bit;
150
+ default: return NULL;
151
+ }
152
+
153
+ case OILY_PNG_COLOR_INDEXED:
154
+ switch (bit_depth) {
155
+ case 8: return &oily_png_encode_scanline_indexed_8bit;
156
+ case 4: return &oily_png_encode_scanline_indexed_4bit;
157
+ case 2: return &oily_png_encode_scanline_indexed_2bit;
158
+ case 1: return &oily_png_encode_scanline_indexed_1bit;
159
+ default: return NULL;
160
+ }
161
+
162
+ case OILY_PNG_COLOR_TRUECOLOR:
163
+ switch (bit_depth) {
164
+ case 8: return &oily_png_encode_scanline_truecolor_8bit;
165
+ default: return NULL;
166
+ }
167
+
168
+ case OILY_PNG_COLOR_TRUECOLOR_ALPHA:
169
+ switch (bit_depth) {
170
+ case 8: return &oily_png_encode_scanline_truecolor_alpha_8bit;
171
+ default: return NULL;
172
+ }
173
+
174
+ default: return NULL;
175
+ }
176
+ }
177
+
178
+ VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE color_mode, VALUE bit_depth, VALUE filtering) {
179
+
180
+ UNUSED_PARAMETER(bit_depth);
78
181
 
79
182
  // Get the data
80
- char depth = 8;
183
+ char depth = (char) FIX2INT(bit_depth);
81
184
  long width = FIX2LONG(rb_funcall(self, rb_intern("width"), 0));
82
185
  long height = FIX2LONG(rb_funcall(self, rb_intern("height"), 0));
83
- VALUE pixels = rb_funcall(self, rb_intern("pixels"), 0);
186
+ VALUE pixels = rb_funcall(self, rb_intern("pixels"), 0);
84
187
 
85
188
  if (RARRAY_LEN(pixels) != width * height) {
86
189
  rb_raise(rb_eRuntimeError, "The number of pixels does not match the canvas dimensions.");
87
190
  }
88
191
 
89
192
  // Get the encoding palette if we're encoding to an indexed bytestream.
90
- VALUE palette = Qnil;
193
+ VALUE encoding_palette = Qnil;
91
194
  if (FIX2INT(color_mode) == OILY_PNG_COLOR_INDEXED) {
92
- palette = rb_funcall(self, rb_intern("encoding_palette"), 0);
195
+ encoding_palette = rb_funcall(self, rb_intern("encoding_palette"), 0);
93
196
  }
94
197
 
95
198
  char pixel_size = oily_png_pixel_bytesize(FIX2INT(color_mode), depth);
@@ -98,35 +201,24 @@ VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE c
98
201
 
99
202
  // Allocate memory for the byte array.
100
203
  BYTE* bytes = ALLOCA_N(BYTE, pass_size);
204
+
205
+ // Get the scanline encoder function.
206
+ void (*scanline_encoder)(BYTE*, VALUE, long, long, VALUE) = NULL;
207
+ scanline_encoder = oily_png_encode_scanline_func(FIX2INT(color_mode), depth);
208
+ if (scanline_encoder == NULL) {
209
+ rb_raise(rb_eRuntimeError, "No encoder for color mode %d and bit depth %d", FIX2INT(color_mode), depth);
210
+ }
101
211
 
102
- // Select out pixel encoder function based on the color mode.
103
- void (*pixel_encoder)(PIXEL, BYTE*, long, VALUE) = NULL;
104
- switch (FIX2INT(color_mode)) {
105
- case OILY_PNG_COLOR_GRAYSCALE: pixel_encoder = &oily_png_encode_pixel_grayscale; break;
106
- case OILY_PNG_COLOR_TRUECOLOR: pixel_encoder = &oily_png_encode_pixel_truecolor; break;
107
- case OILY_PNG_COLOR_INDEXED: pixel_encoder = &oily_png_encode_pixel_indexed; break;
108
- case OILY_PNG_COLOR_GRAYSCALE_ALPHA: pixel_encoder = &oily_png_encode_pixel_grayscale_alpha; break;
109
- case OILY_PNG_COLOR_TRUECOLOR_ALPHA: pixel_encoder = &oily_png_encode_pixel_truecolor_alpha; break;
110
- default: rb_raise(rb_eRuntimeError, "Unsupported color mode: %d", FIX2INT(color_mode));
111
- }
112
-
113
- // Loop over all the pixels to encode them into the byte array.
114
- PIXEL pixel;
115
- long x, y, pos;
116
- for (y = 0; y < height; y++) {
117
- bytes[line_size * y] = (BYTE) FIX2INT(filtering);
118
-
119
- for (x = 0; x < width; x++) {
120
- pixel = NUM2UINT(rb_ary_entry(pixels, y * width + x));
121
- pos = (line_size * y) + (pixel_size * x) + 1;
122
- pixel_encoder(pixel, bytes, pos, palette);
123
- }
212
+ long y, pos;
213
+ for (y = height - 1; y >= 0; y--) {
214
+ pos = line_size * y;
215
+ bytes[pos] = (BYTE) FIX2INT(filtering);
216
+ scanline_encoder(bytes + pos + 1, pixels, y, width, encoding_palette);
124
217
  }
125
218
 
126
- // Check if we are going to apply any filtering
127
219
  if (FIX2INT(filtering) != OILY_PNG_FILTER_NONE) {
128
-
129
- // Assign the chosen filter function to the scanline_filter variable.
220
+
221
+ // Get the scanline filter function
130
222
  void (*scanline_filter)(BYTE*, long, long, char) = NULL;
131
223
  switch (FIX2INT(filtering)) {
132
224
  case OILY_PNG_FILTER_SUB: scanline_filter = &oily_png_encode_filter_sub; break;
@@ -135,8 +227,7 @@ VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE c
135
227
  case OILY_PNG_FILTER_PAETH: scanline_filter = &oily_png_encode_filter_paeth; break;
136
228
  default: rb_raise(rb_eRuntimeError, "Unsupported filter type: %d", FIX2INT(filtering));
137
229
  }
138
-
139
- // Now, apply the scanline_filter function to every line, backwards.
230
+
140
231
  for (y = height - 1; y >= 0; y--) {
141
232
  scanline_filter(bytes, line_size * y, line_size, pixel_size);
142
233
  }
@@ -7,6 +7,9 @@
7
7
  #define A_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x000000ff)))
8
8
 
9
9
  #define FILTER_BYTE(byte, adjustment) byte = (BYTE) (((byte) - (adjustment)) & 0x000000ff)
10
+ #define ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x) ((x < width) ? ((BYTE) NUM2UINT(rb_funcall(encoding_palette, rb_intern("index"), 1, rb_ary_entry(pixels, y * width + x)))) : 0)
11
+
12
+ typedef void(*scanline_encoder_func)(BYTE*, VALUE, long, long, VALUE);
10
13
 
11
14
  /*
12
15
  Encodes an image and append it to the stream.
@@ -16,6 +19,6 @@
16
19
 
17
20
  This function should replace ChunkyPNG::Canvas::PNGEncoding.encode_png_image_pass_to_stream
18
21
  */
19
- VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE color_mode, VALUE filtering);
22
+ VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE color_mode, VALUE bit_depth, VALUE filtering);
20
23
 
21
24
  #endif
data/lib/oily_png.rb CHANGED
@@ -2,7 +2,7 @@ require 'chunky_png'
2
2
 
3
3
  module OilyPNG
4
4
 
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
 
7
7
  def self.included(base)
8
8
  base::Canvas.send(:extend, OilyPNG::PNGDecoding)
@@ -11,7 +11,7 @@ module OilyPNG
11
11
 
12
12
  end
13
13
 
14
- require 'oily_png/oily_png_ext'
14
+ require 'oily_png/oily_png'
15
15
 
16
16
  # Include mixin into ChunkyPNG
17
17
  ChunkyPNG.send(:include, OilyPNG)
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 = "0.2.0"
8
- s.date = "2010-11-01"
7
+ s.version = "0.3.0"
8
+ s.date = "2010-12-12"
9
9
 
10
10
  s.summary = "Native mixin to speed up ChunkyPNG"
11
11
  s.description = <<-EOT
@@ -19,16 +19,17 @@ 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', '~> 0.11')
22
+ s.add_runtime_dependency('chunky_png', '~> 0.12')
23
23
 
24
24
  s.add_development_dependency('rake')
25
- s.add_development_dependency('rspec', '~> 2.0')
25
+ s.add_development_dependency('rake-compiler')
26
+ s.add_development_dependency('rspec', '~> 2')
26
27
 
27
28
  s.rdoc_options << '--title' << s.name << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
28
29
  s.extra_rdoc_files = ['README.rdoc']
29
30
 
30
31
  # Do not change the files and test_files fields by hand. This will be done
31
32
  # automatically by the gem release script.
32
- s.files = %w(.gitignore Gemfile Gemfile.lock LICENSE README.rdoc Rakefile ext/oily_png/extconf.rb ext/oily_png/oily_png_ext.c ext/oily_png/oily_png_ext.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 oily_png.gemspec spec/decoding_spec.rb spec/encoding_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/gray.png spec/resources/interlaced.png spec/resources/nonsquare.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/spec_helper.rb tasks/github-gem.rake tasks/testing.rake)
33
+ s.files = %w(.gitignore .infinity_test Gemfile Gemfile.lock LICENSE README.rdoc Rakefile ext/oily_png/extconf.rb ext/oily_png/oily_png_ext.c ext/oily_png/oily_png_ext.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 oily_png.gemspec spec/decoding_spec.rb spec/encoding_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/gray.png spec/resources/interlaced.png spec/resources/nonsquare.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/spec_helper.rb tasks/github-gem.rake tasks/testing.rake)
33
34
  s.test_files = %w(spec/decoding_spec.rb spec/encoding_spec.rb)
34
35
  end
@@ -9,37 +9,65 @@ describe OilyPNG::PNGEncoding do
9
9
  end
10
10
 
11
11
  it "should encode an image using grayscale correctly" do
12
- @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_GRAYSCALE, ChunkyPNG::FILTER_NONE)
13
- @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_GRAYSCALE, ChunkyPNG::FILTER_NONE)
12
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_GRAYSCALE, 8, ChunkyPNG::FILTER_NONE)
13
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_GRAYSCALE, 8, ChunkyPNG::FILTER_NONE)
14
14
  stream1.should == stream2
15
15
  end
16
16
 
17
17
  it "should encode an image using grayscale alpha correctly" do
18
- @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_GRAYSCALE_ALPHA, ChunkyPNG::FILTER_NONE)
19
- @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_GRAYSCALE_ALPHA, ChunkyPNG::FILTER_NONE)
18
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_GRAYSCALE_ALPHA, 8, ChunkyPNG::FILTER_NONE)
19
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_GRAYSCALE_ALPHA, 8, ChunkyPNG::FILTER_NONE)
20
20
  stream1.should == stream2
21
21
  end
22
-
22
+
23
23
  it "should encode an image using truecolor correctly" do
24
- @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_NONE)
25
- @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_NONE)
24
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_NONE)
25
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_NONE)
26
26
  stream1.should == stream2
27
27
  end
28
28
 
29
29
  it "should encode an image using truecolor alpha correctly" do
30
- @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR_ALPHA, ChunkyPNG::FILTER_NONE)
31
- @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR_ALPHA, ChunkyPNG::FILTER_NONE)
30
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR_ALPHA, 8, ChunkyPNG::FILTER_NONE)
31
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR_ALPHA, 8, ChunkyPNG::FILTER_NONE)
32
32
  stream1.should == stream2
33
33
  end
34
-
35
- it "should encode an image using indexed colors correctly" do
36
- # Setup an encoding palette first
37
- mock_palette = mock('palette', :index => 0xab)
38
- @canvas.stub(:encoding_palette).and_return(mock_palette)
39
- @oily_canvas.stub(:encoding_palette).and_return(mock_palette)
34
+
35
+ end
36
+
37
+ context 'encoding with palette images' do
38
+ before do
39
+ @canvas = ChunkyPNG::Canvas.from_file(resource_file('gray.png'))
40
+ @oily_canvas = OilyPNG::Canvas.from_canvas(@canvas)
40
41
 
41
- @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_INDEXED, ChunkyPNG::FILTER_NONE)
42
- @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_INDEXED, ChunkyPNG::FILTER_NONE)
42
+ @palette_mock = mock('Palette')
43
+ @palette_mock.stub(:index).with(an_instance_of(Fixnum)).and_return(0x01)
44
+ @palette_mock.stub(:index).with(nil).and_return(0)
45
+
46
+ @canvas.stub(:encoding_palette).and_return(@palette_mock)
47
+ @oily_canvas.stub(:encoding_palette).and_return(@palette_mock)
48
+ end
49
+
50
+ it "should encode an image using 8-bit indexed colors correctly" do
51
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_INDEXED, 8, ChunkyPNG::FILTER_NONE)
52
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_INDEXED, 8, ChunkyPNG::FILTER_NONE)
53
+ stream1.should == stream2
54
+ end
55
+
56
+ it "should encode an image using 4-bit indexed colors correctly" do
57
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_INDEXED, 4, ChunkyPNG::FILTER_NONE)
58
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_INDEXED, 4, ChunkyPNG::FILTER_NONE)
59
+ stream1.should == stream2
60
+ end
61
+
62
+ it "should encode an image using 2-bit indexed colors correctly" do
63
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_INDEXED, 2, ChunkyPNG::FILTER_NONE)
64
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_INDEXED, 2, ChunkyPNG::FILTER_NONE)
65
+ stream1.should == stream2
66
+ end
67
+
68
+ it "should encode an image using 1-bit indexed colors correctly" do
69
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_INDEXED, 1, ChunkyPNG::FILTER_NONE)
70
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_INDEXED, 1, ChunkyPNG::FILTER_NONE)
43
71
  stream1.should == stream2
44
72
  end
45
73
  end
@@ -51,32 +79,32 @@ describe OilyPNG::PNGEncoding do
51
79
  end
52
80
 
53
81
  it "should encode correctly with no filtering" do
54
- @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_NONE)
55
- @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_NONE)
82
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_NONE)
83
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_NONE)
56
84
  stream1.should == stream2
57
85
  end
58
86
 
59
87
  it "should encode correctly with sub filtering" do
60
- @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_SUB)
61
- @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_SUB)
88
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_SUB)
89
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_SUB)
62
90
  stream1.should == stream2
63
91
  end
64
92
 
65
93
  it "should encode correctly with up filtering" do
66
- @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_UP)
67
- @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_UP)
94
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_UP)
95
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_UP)
68
96
  stream1.should == stream2
69
97
  end
70
-
98
+
71
99
  it "should encode correctly with average filtering" do
72
- @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_AVERAGE)
73
- @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_AVERAGE)
100
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_AVERAGE)
101
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_AVERAGE)
74
102
  stream1.should == stream2
75
103
  end
76
104
 
77
105
  it "should encode correctly with paeth filtering" do
78
- @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_PAETH)
79
- @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, ChunkyPNG::FILTER_PAETH)
106
+ @oily_canvas.send(:encode_png_image_pass_to_stream, stream1 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_PAETH)
107
+ @canvas.send(:encode_png_image_pass_to_stream, stream2 = ChunkyPNG::Datastream.empty_bytearray, ChunkyPNG::COLOR_TRUECOLOR, 8, ChunkyPNG::FILTER_PAETH)
80
108
  stream1.should == stream2
81
109
  end
82
110
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ Bundler.setup
5
5
 
6
6
  require 'rspec'
7
7
  require 'chunky_png'
8
- require 'oily_png/oily_png_ext'
8
+ require 'oily_png/oily_png'
9
9
 
10
10
 
11
11
  module OilyPNG
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
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: 2010-11-01 00:00:00 +01:00
17
+ date: 2010-12-12 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -26,8 +26,8 @@ dependencies:
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 0
29
- - 11
30
- version: "0.11"
29
+ - 12
30
+ version: "0.12"
31
31
  type: :runtime
32
32
  prerelease: false
33
33
  version_requirements: *id001
@@ -45,19 +45,31 @@ dependencies:
45
45
  prerelease: false
46
46
  version_requirements: *id002
47
47
  - !ruby/object:Gem::Dependency
48
- name: rspec
48
+ name: rake-compiler
49
49
  requirement: &id003 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
- - - ~>
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  segments:
55
- - 2
56
55
  - 0
57
- version: "2.0"
56
+ version: "0"
58
57
  type: :development
59
58
  prerelease: false
60
59
  version_requirements: *id003
60
+ - !ruby/object:Gem::Dependency
61
+ name: rspec
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 2
69
+ version: "2"
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: *id004
61
73
  description: " This Ruby C extenstion defines a module that can be included into ChunkyPNG to improve its speed.\n"
62
74
  email:
63
75
  - willem@railsdoctors.com
@@ -69,6 +81,7 @@ extra_rdoc_files:
69
81
  - README.rdoc
70
82
  files:
71
83
  - .gitignore
84
+ - .infinity_test
72
85
  - Gemfile
73
86
  - Gemfile.lock
74
87
  - LICENSE
@@ -178,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
191
  requirements:
179
192
  - - ">="
180
193
  - !ruby/object:Gem::Version
181
- hash: -58392216600872723
194
+ hash: -4404807782310531361
182
195
  segments:
183
196
  - 0
184
197
  version: "0"
@@ -187,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
200
  requirements:
188
201
  - - ">="
189
202
  - !ruby/object:Gem::Version
190
- hash: -58392216600872723
203
+ hash: -4404807782310531361
191
204
  segments:
192
205
  - 0
193
206
  version: "0"