Skip to content

Commit

Permalink
Fix for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ucnv committed Apr 22, 2016
1 parent 19926f9 commit 6730e65
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/pnglitch/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ def initialize file, limit_of_decompressed_data_size = nil
@filtered_data = Tempfile.new 'filtered', encoding: 'ascii-8bit'
@idat_chunk_size = nil

@head_data.binmode
@tail_data.binmode
@compressed_data.binmode
@filtered_data.binmode

open(path, 'rb') do |io|
idat_sizes = []
@head_data << io.read(8) # signature
while bytes = io.read(8)
length, type = bytes.unpack 'Na*'
if length > io.size - io.pos
raise FormatError.new path.to_s
end
if type == 'IHDR'
ihdr = {
width: io.read(4).unpack('N').first,
Expand Down Expand Up @@ -123,7 +131,7 @@ def filter_types
# glitching but some viewer applications might deny to process those results.
# To be polite to the filter types, use +each_scanline+ instead.
#
# Since this method sets the decompressed data into String, it may use a massive amount of
# Since this method sets the decompressed data into String, it may use a massive amount of
# memory. To decrease the memory usage, treat the data as IO through +glitch_as_io+ instead.
#
def glitch &block # :yield: data
Expand Down Expand Up @@ -158,8 +166,8 @@ def glitch_as_io &block # :yield: data
# To set a glitched result, return the modified value in the block.
#
# Once the compressed data is glitched, PNGlitch will warn about modifications to
# filtered (decompressed) data because this method does not decompress the glitched
# compressed data again. It means that calling +glitch+ after +glitch_after_compress+
# filtered (decompressed) data because this method does not decompress the glitched
# compressed data again. It means that calling +glitch+ after +glitch_after_compress+
# will make the result overwritten and forgotten.
#
# This operation will often destroy PNG image completely.
Expand Down Expand Up @@ -276,7 +284,7 @@ def compress(
end

#
# Process each scanlines.
# Process each scanline.
#
# It takes a block with a parameter. The parameter must be an instance of
# PNGlitch::Scanline and it provides ways to edit the filter type and the data
Expand Down Expand Up @@ -449,7 +457,7 @@ def height= h
#
def save file
wrap_with_rewind(@head_data, @tail_data, @compressed_data) do
open(file, 'w') do |io|
open(file, 'wb') do |io|
io << @head_data.read
chunk_size = @idat_chunk_size || @compressed_data.size
type = 'IDAT'
Expand Down Expand Up @@ -552,7 +560,7 @@ def warn_if_compressed_data_modified # :nodoc:
message = <<-EOL.gsub(/^\s*/, '')
WARNING: `#{trace.first.label}' is called after a modification to the compressed data.
With this operation, your changes on the compressed data will be reverted.
Note that a modification to the compressed data does not reflect to the
Note that a modification to the compressed data does not reflect to the
filtered (decompressed) data.
It's happened around #{trace.last.to_s}
EOL
Expand Down

0 comments on commit 6730e65

Please sign in to comment.