Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/PatchedPNG.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#png_crc ⇒ Object
Calculates a CRC using the algorithm in the PNG specification.
Instance Method Details
#png_crc ⇒ Object
Calculates a CRC using the algorithm in the PNG specification.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/PatchedPNG.rb', line 11 def png_crc unless defined? @@crc then @@crc = Array.new(256) 256.times do |n| c = n 8.times do c = (c & 1 == 1) ? 0xedb88320 ^ (c >> 1) : c >> 1 end @@crc[n] = c end end c = 0xffffffff each_byte do |b| c = @@crc[(c^b) & 0xff] ^ (c >> 8) end return c ^ 0xffffffff end |