Skip to content

Commit

Permalink
Changed not to raise error for wrong filter type
Browse files Browse the repository at this point in the history
  • Loading branch information
ucnv committed Sep 10, 2023
1 parent b611493 commit a0c1bea
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 27 deletions.
7 changes: 0 additions & 7 deletions lib/pnglitch/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,4 @@ def initialize filename
super m
end
end

class FilterTypeError < TypeError
def initialize filter_type, scanline_no
m = filter_type.to_s + ' is not a valid filter type, at scanline no ' + scanline_no.to_s + '.'
super m
end
end
end
6 changes: 4 additions & 2 deletions lib/pnglitch/scanline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ def register_filter_decoder decoder = nil, &block
def save
pos = @io.pos
@io.pos = @start_at
filter = Filter.guess(@filter_type)
raise FilterTypeError.new(@filter_type, @index) if filter.nil?
filter = Filter.guess @filter_type
if filter.nil?
filter = @filter_type.to_i
end
@io << [filter].pack('C')
@io << self.data.slice(0, @data_size).ljust(@data_size, "\0")
@io.pos = pos
Expand Down
18 changes: 0 additions & 18 deletions spec/pnglitch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -561,24 +561,6 @@
end
}.not_to raise_error
end

it 'should raise an error when it drops the filters' do
expect {
PNGlitch.open infile do |png|
png.filtered_data.pos = png.filtered_data.size / png.height * 96.3
chunk = png.filtered_data.read
png.filtered_data.rewind
10.times do
png.filtered_data << chunk
end
png.each_scanline do |line|
line.gsub! /\d/, 'x'
line.filter_type = rand(4)
end
png.output outfile
end
}.to raise_error PNGlitch::FilterTypeError
end
end

context 'when re-filtering with same filters' do
Expand Down

0 comments on commit a0c1bea

Please sign in to comment.