Guest User

Untitled

a guest
Jun 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1.  
  2. 553 % p4 diff lib/...
  3. diff -r old/lib/png.rb#14 new/lib/png.rb#have
  4. --- old/lib/png.rb
  5. +++ new/lib/png.rb
  6. @@ -1,16 +1,19 @@
  7. +# encoding: BINARY
  8. +
  9. require 'rubygems'
  10. require 'zlib'
  11. require 'inline'
  12.  
  13. +if RUBY_VERSION =~ /1\.9/ then
  14. + Encoding.default_external = "BINARY"
  15. +else
  16. + class Fixnum
  17. + def ord; self; end
  18. + end
  19. +end
  20. +
  21. class String # :nodoc: # ZenTest SKIP
  22. inline do |builder|
  23. - if RUBY_VERSION < "1.8.6" then
  24. - builder.prefix <<-EOM
  25. - #define RSTRING_PTR(s) (RSTRING(s)->ptr)
  26. - #define RSTRING_LEN(s) (RSTRING(s)->len)
  27. - EOM
  28. - end
  29. -
  30. builder.c <<-EOM
  31. unsigned long png_crc() {
  32. static unsigned long crc[256];
  33. @@ -31,8 +34,8 @@
  34. }
  35.  
  36. unsigned long c = 0xffffffff;
  37. - unsigned len = RSTRING_LEN(self);
  38. - char * s = StringValuePtr(self);
  39. + unsigned len = RSTRING_LEN(self);
  40. + char * s = StringValuePtr(self);
  41. unsigned i;
  42.  
  43. for (i = 0; i < len; i++) {
  44. @@ -43,7 +46,9 @@
  45. }
  46. EOM
  47. end
  48. -rescue CompilationError
  49. +rescue CompilationError => e
  50. + warn "COMPLIATION ERROR: #{e}"
  51. +
  52. unless defined? @@crc then
  53. @@crc = Array.new(256)
  54. 256.times do |n|
  55. @@ -264,28 +269,28 @@
  56. # Return an array of RGB
  57.  
  58. def rgb # TODO: rgba?
  59. - return @values[0], @values[1], @values[2]
  60. + return r, g, b
  61. end
  62.  
  63. ##
  64. # Red component
  65.  
  66. - def r; @values[0]; end
  67. + def r; @values[0].ord; end
  68.  
  69. ##
  70. # Green component
  71.  
  72. - def g; @values[1]; end
  73. + def g; @values[1].ord; end
  74.  
  75. ##
  76. # Blue component
  77.  
  78. - def b; @values[2]; end
  79. + def b; @values[2].ord; end
  80.  
  81. ##
  82. # Alpha transparency component
  83.  
  84. - def a; @values[3]; end
  85. + def a; @values[3].ord; end
  86.  
  87. ##
  88. # Blends +color+ into this color returning a new blended color.
  89. @@ -316,6 +321,7 @@
  90.  
  91. def to_ascii
  92. return ' ' if a == 0x00
  93. +
  94. brightness = (((r + g + b) / 3) * a) / 0xFF
  95.  
  96. %w(.. ,, ++ 00)[brightness / 64]
  97. 554 %
Add Comment
Please, Sign In to add comment