Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 553 % p4 diff lib/...
- diff -r old/lib/png.rb#14 new/lib/png.rb#have
- --- old/lib/png.rb
- +++ new/lib/png.rb
- @@ -1,16 +1,19 @@
- +# encoding: BINARY
- +
- require 'rubygems'
- require 'zlib'
- require 'inline'
- +if RUBY_VERSION =~ /1\.9/ then
- + Encoding.default_external = "BINARY"
- +else
- + class Fixnum
- + def ord; self; end
- + end
- +end
- +
- class String # :nodoc: # ZenTest SKIP
- inline do |builder|
- - if RUBY_VERSION < "1.8.6" then
- - builder.prefix <<-EOM
- - #define RSTRING_PTR(s) (RSTRING(s)->ptr)
- - #define RSTRING_LEN(s) (RSTRING(s)->len)
- - EOM
- - end
- -
- builder.c <<-EOM
- unsigned long png_crc() {
- static unsigned long crc[256];
- @@ -31,8 +34,8 @@
- }
- unsigned long c = 0xffffffff;
- - unsigned len = RSTRING_LEN(self);
- - char * s = StringValuePtr(self);
- + unsigned len = RSTRING_LEN(self);
- + char * s = StringValuePtr(self);
- unsigned i;
- for (i = 0; i < len; i++) {
- @@ -43,7 +46,9 @@
- }
- EOM
- end
- -rescue CompilationError
- +rescue CompilationError => e
- + warn "COMPLIATION ERROR: #{e}"
- +
- unless defined? @@crc then
- @@crc = Array.new(256)
- 256.times do |n|
- @@ -264,28 +269,28 @@
- # Return an array of RGB
- def rgb # TODO: rgba?
- - return @values[0], @values[1], @values[2]
- + return r, g, b
- end
- ##
- # Red component
- - def r; @values[0]; end
- + def r; @values[0].ord; end
- ##
- # Green component
- - def g; @values[1]; end
- + def g; @values[1].ord; end
- ##
- # Blue component
- - def b; @values[2]; end
- + def b; @values[2].ord; end
- ##
- # Alpha transparency component
- - def a; @values[3]; end
- + def a; @values[3].ord; end
- ##
- # Blends +color+ into this color returning a new blended color.
- @@ -316,6 +321,7 @@
- def to_ascii
- return ' ' if a == 0x00
- +
- brightness = (((r + g + b) / 3) * a) / 0xFF
- %w(.. ,, ++ 00)[brightness / 64]
- 554 %
Add Comment
Please, Sign In to add comment