oily_png 1.0.0.beta1 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/.infinity_test CHANGED
@@ -1,6 +1,6 @@
1
1
  infinity_test do
2
2
 
3
- use :rubies => %w(1.8.7 1.9.2 ree rbx), :test_framework => :rspec
3
+ use :rubies => %w(1.8.6 1.8.7 1.9.2 ree rbx), :test_framework => :rspec
4
4
 
5
5
  before(:each_ruby) do |environment|
6
6
  environment.system('bundle install')
@@ -0,0 +1,21 @@
1
+ #include "oily_png_ext.h"
2
+
3
+ PIXEL oily_png_compose_color(PIXEL fg, PIXEL bg) {
4
+
5
+ // Check for simple cases first
6
+ if ((A_BYTE(fg) == 0xff) || (A_BYTE(bg) == 0x00)) return fg;
7
+ if (A_BYTE(fg) == 0x00) return bg;
8
+
9
+ // Calculate the new values using fast 8-bit multiplication
10
+ BYTE a_com = INT8_MULTIPLY(0xff - A_BYTE(fg), A_BYTE(bg));
11
+ BYTE new_r = INT8_MULTIPLY(A_BYTE(fg), R_BYTE(fg)) + INT8_MULTIPLY(a_com, R_BYTE(bg));
12
+ BYTE new_g = INT8_MULTIPLY(A_BYTE(fg), G_BYTE(fg)) + INT8_MULTIPLY(a_com, G_BYTE(bg));
13
+ BYTE new_b = INT8_MULTIPLY(A_BYTE(fg), B_BYTE(fg)) + INT8_MULTIPLY(a_com, B_BYTE(bg));
14
+ BYTE new_a = A_BYTE(fg) + a_com;
15
+
16
+ return BUILD_PIXEL(new_r, new_g, new_b, new_a);
17
+ }
18
+
19
+ VALUE oily_png_color_compose_quick(VALUE self, VALUE fg_color, VALUE bg_color) {
20
+ return UINT2NUM(oily_png_compose_color(NUM2UINT(fg_color), NUM2UINT(bg_color)));
21
+ }
@@ -0,0 +1,22 @@
1
+ #ifndef OILY_PNG_COLOR_H
2
+ #define OILY_PNG_COLOR_H
3
+
4
+ #define R_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0xff000000) >> 24))
5
+ #define G_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x00ff0000) >> 16))
6
+ #define B_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x0000ff00) >> 8))
7
+ #define A_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x000000ff)))
8
+
9
+ #define BUILD_PIXEL(r, g, b, a) (((PIXEL) (r) << 24) + ((PIXEL) (g) << 16) + ((PIXEL) (b) << 8) + (PIXEL) (a))
10
+ #define INT8_MULTIPLY(a, b) (((((a) * (b) + 0x80) >> 8) + ((a) * (b) + 0x80)) >> 8)
11
+
12
+ /*
13
+ Ruby replacement method for color composition using alpha transparency.
14
+
15
+ This method should replace ChunkyPNG::Color.compose_quick
16
+ */
17
+ VALUE oily_png_color_compose_quick(VALUE self, VALUE fg_color, VALUE bg_color);
18
+
19
+ /* Color composition using alpha transparency. */
20
+ PIXEL oily_png_compose_color(PIXEL fg, PIXEL bg);
21
+
22
+ #endif
@@ -3,13 +3,17 @@
3
3
  void Init_oily_png() {
4
4
  VALUE OilyPNG = rb_define_module("OilyPNG");
5
5
 
6
- // Setup decoding
6
+ // Setup decoding module
7
7
  VALUE OilyPNG_PNGDecoding = rb_define_module_under(OilyPNG, "PNGDecoding");
8
8
  rb_define_method(OilyPNG_PNGDecoding, "decode_png_image_pass", oily_png_decode_png_image_pass, 6);
9
9
 
10
- // Setup encoding
10
+ // Setup encoding module
11
11
  VALUE OilyPNG_PNGEncoding = rb_define_module_under(OilyPNG, "PNGEncoding");
12
12
  rb_define_method(OilyPNG_PNGEncoding, "encode_png_image_pass_to_stream", oily_png_encode_png_image_pass_to_stream, 4);
13
+
14
+ // Setup Color module
15
+ VALUE OilyPNG_Color = rb_define_module_under(OilyPNG, "Color");
16
+ rb_define_method(OilyPNG_Color, "compose_quick", oily_png_color_compose_quick, 2);
13
17
  }
14
18
 
15
19
  char oily_png_samples_per_pixel(char color_mode) {
@@ -1,5 +1,5 @@
1
- #ifndef OILY_PNG_EXT
2
- #define OILY_PNG_EXT
1
+ #ifndef OILY_PNG_OILY_PNG_EXT
2
+ #define OILY_PNG_OILY_PNG_EXT
3
3
 
4
4
  #include "ruby.h"
5
5
 
@@ -24,9 +24,10 @@
24
24
  typedef unsigned int PIXEL; // Pixels use 32 bits unsigned integers
25
25
  typedef unsigned char BYTE; // Bytes use 8 bits unsigned integers
26
26
 
27
+
27
28
  #include "png_decoding.h"
28
29
  #include "png_encoding.h"
29
-
30
+ #include "color.h"
30
31
 
31
32
  /*
32
33
  Initialize the extension by creating the OilyPNG modules, and registering
@@ -1,7 +1,6 @@
1
- #ifndef PNG_DECODING_H
2
- #define PNG_DECODING_H
1
+ #ifndef OILY_PNG_PNG_DECODING_H
2
+ #define OILY_PNG_PNG_DECODING_H
3
3
 
4
- #define BUILD_PIXEL(r, g, b, a) (((PIXEL) (r) << 24) + ((PIXEL) (g) << 16) + ((PIXEL) (b) << 8) + (PIXEL) (a))
5
4
  #define UNFILTER_BYTE(byte, adjustment) byte = (BYTE) (((byte) + (adjustment)) & 0x000000ff)
6
5
 
7
6
  #define ADD_PIXEL_FROM_PALLETE(pixels, decoding_palette, palette_entry) \
@@ -263,7 +263,7 @@ VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE c
263
263
  long pass_size = oily_png_pass_bytesize(FIX2INT(color_mode), depth, width, height);
264
264
 
265
265
  // Allocate memory for the byte array.
266
- BYTE* bytes = ALLOCA_N(BYTE, pass_size);
266
+ BYTE* bytes = ALLOC_N(BYTE, pass_size);
267
267
 
268
268
  // Get the scanline encoder function.
269
269
  scanline_encoder_func scanline_encoder = oily_png_encode_scanline_func(FIX2INT(color_mode), depth);
@@ -297,5 +297,6 @@ VALUE oily_png_encode_png_image_pass_to_stream(VALUE self, VALUE stream, VALUE c
297
297
 
298
298
  // Append to encoded image pass to the output stream.
299
299
  rb_str_cat(stream, (char*) bytes, pass_size);
300
+ xfree(bytes);
300
301
  return Qnil;
301
302
  }
@@ -1,10 +1,5 @@
1
- #ifndef PNG_ENCODING_H
2
- #define PNG_ENCODING_H
3
-
4
- #define R_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0xff000000) >> 24))
5
- #define G_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x00ff0000) >> 16))
6
- #define B_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x0000ff00) >> 8))
7
- #define A_BYTE(pixel) ((BYTE) (((pixel) & (PIXEL) 0x000000ff)))
1
+ #ifndef OILY_PNG_PNG_ENCODING_H
2
+ #define OILY_PNG_PNG_ENCODING_H
8
3
 
9
4
  #define FILTER_BYTE(byte, adjustment) byte = (BYTE) (((byte) - (adjustment)) & 0x000000ff)
10
5
  #define ENCODING_PALETTE_INDEX(encoding_palette, pixels, width, y, x) (((x) < (width)) ? ((BYTE) NUM2UINT(rb_hash_aref(encoding_palette, rb_ary_entry(pixels, (y) * (width) + (x))))) : 0)
data/lib/oily_png.rb CHANGED
@@ -2,11 +2,13 @@ require 'chunky_png'
2
2
 
3
3
  module OilyPNG
4
4
 
5
- VERSION = "1.0.0.beta1"
5
+ VERSION = "1.0.0.rc1"
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
+
11
+ base::Color.send(:include, OilyPNG::Color)
10
12
  end
11
13
  end
12
14
 
@@ -6,4 +6,8 @@ module OilyPNG
6
6
  extend OilyPNG::PNGDecoding
7
7
  include OilyPNG::PNGEncoding
8
8
  end
9
+
10
+ module Color
11
+ extend self
12
+ end
9
13
  end
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.0.beta1"
8
- s.date = "2011-01-24"
7
+ s.version = "1.0.0.rc1"
8
+ s.date = "2011-02-24"
9
9
 
10
10
  s.summary = "Native mixin to speed up ChunkyPNG"
11
11
  s.description = <<-EOT
@@ -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/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 lib/oily_png/canvas.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)
34
- s.test_files = %w(spec/decoding_spec.rb spec/encoding_spec.rb)
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/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/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)
34
+ s.test_files = %w(spec/color_spec.rb spec/decoding_spec.rb spec/encoding_spec.rb)
35
35
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe OilyPNG::Color do
4
+
5
+ include OilyPNG::Color
6
+
7
+ before(:each) do
8
+ @white = 0xffffffff
9
+ @black = 0x000000ff
10
+ @opaque = 0x0a6496ff
11
+ @non_opaque = 0x0a649664
12
+ @fully_transparent = 0x0a649600
13
+ end
14
+
15
+ describe '#compose_quick' do
16
+
17
+ it "should use the foregorund color as is when the background color is fully transparent" do
18
+ compose_quick(@non_opaque, @fully_transparent).should == @non_opaque
19
+ end
20
+
21
+ it "should use the foregorund color as is when an opaque color is given as foreground color" do
22
+ compose_quick(@opaque, @white).should == @opaque
23
+ end
24
+
25
+ it "should use the background color as is when a fully transparent pixel is given as foreground color" do
26
+ compose_quick(@fully_transparent, @white).should == @white
27
+ end
28
+
29
+ it "should compose pixels correctly" do
30
+ compose_quick(@non_opaque, @white).should == 0x9fc2d6ff
31
+ end
32
+
33
+ it "should compose colors exactly the same as ChunkyPNG" do
34
+ fg, bg = rand(0xffffffff), rand(0xffffffff)
35
+ compose_quick(fg, bg).should == ChunkyPNG::Color.compose_quick(fg, bg)
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 0
9
- - beta1
10
- version: 1.0.0.beta1
9
+ - rc1
10
+ version: 1.0.0.rc1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Willem van Bergen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-24 00:00:00 -05:00
18
+ date: 2011-02-24 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -89,6 +89,8 @@ files:
89
89
  - LICENSE
90
90
  - README.rdoc
91
91
  - Rakefile
92
+ - ext/oily_png/color.c
93
+ - ext/oily_png/color.h
92
94
  - ext/oily_png/extconf.rb
93
95
  - ext/oily_png/oily_png_ext.c
94
96
  - ext/oily_png/oily_png_ext.h
@@ -99,6 +101,7 @@ files:
99
101
  - lib/oily_png.rb
100
102
  - lib/oily_png/canvas.rb
101
103
  - oily_png.gemspec
104
+ - spec/color_spec.rb
102
105
  - spec/decoding_spec.rb
103
106
  - spec/encoding_spec.rb
104
107
  - spec/resources/basi0g01.png
@@ -215,5 +218,6 @@ signing_key:
215
218
  specification_version: 3
216
219
  summary: Native mixin to speed up ChunkyPNG
217
220
  test_files:
221
+ - spec/color_spec.rb
218
222
  - spec/decoding_spec.rb
219
223
  - spec/encoding_spec.rb