Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
166 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
class DeInterlacer | ||
def initialize(height, width, pixel_width, raw, decoder) | ||
@height, @width, @decoder = height, width, decoder | ||
@pixel_width = pixel_width | ||
@raw = raw.dup | ||
@out = Spittle::ImageData.new :scanline_width => width, :pixel_width => pixel_width | ||
end | ||
|
||
def process | ||
pass1 | ||
pass2 | ||
@out | ||
end | ||
|
||
def pass1_height | ||
@height / 8 | ||
end | ||
|
||
def pass1_width | ||
end | ||
|
||
def pass1 | ||
sub_width = ((@width / 8) * @pixel_width) + 1 | ||
sub_height = pass1_height | ||
scanline_width = @width / 8 | ||
|
||
sub_image = Spittle::ImageData.new(:scanline_width => scanline_width, | ||
:pixel_width => @pixel_width, | ||
:data => []) | ||
sub_height.times do |line_idx| | ||
row = @raw.slice!(0, sub_width) | ||
l = @decoder.decode(line_idx, row, sub_image, @pixel_width) | ||
sub_image << l | ||
end | ||
sub_image | ||
|
||
#FUck! | ||
idxes = [0, (1..scanline_width - 1).to_a.map{ |i| (i * 8)}.map{|i| i - 1}].flatten | ||
rows = [0, (1..sub_height - 1).to_a.map{ |i| i * 8 }.map{|i| i - 1}].flatten | ||
|
||
input = sub_image.to_a | ||
rows.each do |row| | ||
idxes.each do |idx| | ||
pixel = input.take(@pixel_width) | ||
@out.set_pixel(row, idx, pixel) | ||
end | ||
end | ||
end | ||
|
||
def pass2 | ||
sub_width = ((@width / 8) * @pixel_width) + 1 | ||
sub_height = pass1_height | ||
scanline_width = @width / 8 | ||
|
||
sub_image = Spittle::ImageData.new(:scanline_width => scanline_width, | ||
:pixel_width => @pixel_width, | ||
:data => []) | ||
offset = 0 | ||
sub_height.times do |line_idx| | ||
row = @raw.slice!(0, sub_width) | ||
sub_image << @decoder.decode(line_idx, row, sub_image, @pixel_width) | ||
end | ||
sub_image | ||
|
||
#FUck! | ||
idxes = (0..scanline_width - 1).to_a.map{ |i| (i * 8) + 4}.map{|i| i - 1} | ||
rows = [0, (1..sub_height - 1).to_a.map{ |i| i * 8 }.map{|i| i - 1}].flatten | ||
|
||
input = sub_image.to_a | ||
rows.each do |row| | ||
idxes.each do |idx| | ||
pixel = input.take(@pixel_width) | ||
@out.set_pixel(row, idx, pixel) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,53 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | ||
|
||
|
||
#Interlaced Image color breakdown | ||
# | ||
# pass 1: (1,1,1) | ||
# pass 2: (42,42,42) | ||
# pass 3: (103, 103, 0) | ||
# pass 4: (104, 0, 0) | ||
# pass 5: (0, 105, 0) | ||
# pass 6: (0, 0, 106) | ||
# pass 6: (207, 207) | ||
|
||
describe "reading interlaced images" do | ||
before :all do | ||
@image_dir = File.join( File.dirname( __FILE__ ), "interlaced_images" ) | ||
end | ||
|
||
before :each do | ||
@image = PNG::Image.open( @image_dir + "/interlaced-16x16-first-image.png" ) | ||
before do | ||
begin | ||
@image_dir = File.join( File.dirname( __FILE__ ), "interlaced_images" ) | ||
@image = PNG::Image.open( @image_dir + "/interlaced-16x16.png" ) | ||
@result = @image.to_image | ||
rescue Exception => e | ||
puts e.backtrace.join("\n") | ||
raise e | ||
end | ||
end | ||
|
||
describe "sanity checks" do | ||
it "knows the images width" do | ||
@image.width.should == 16 | ||
end | ||
|
||
it "knows the images height" do | ||
@image.height.should == 16 | ||
end | ||
end | ||
|
||
it "can read the first sub-image from an interlaced image" do | ||
# should be the only colored pixels in the image.. with four different colors | ||
@image.to_image.should == [[255, 127, 63, 63, 127, 255], [33, 66, 99, 192, 255, 127]] | ||
|
||
describe "pass extraction" do | ||
it "can read the first sub-image from an interlaced image" do | ||
@result.fetch_pixel(0).should == [1,1,1] | ||
@result.fetch_pixel(7).should == [1,1,1] | ||
|
||
@result.fetch_pixel(0, 7).should == [1,1,1] | ||
@result.fetch_pixel(7, 7).should == [1,1,1] | ||
end | ||
|
||
it "can read the second sub-image" do | ||
@result.fetch_pixel(3).should == [42,42,42] | ||
@result.fetch_pixel(11).should == [42,42,42] | ||
|
||
@result.fetch_pixel(3, 7).should == [42,42,42] | ||
@result.fetch_pixel(11, 7).should == [42,42,42] | ||
end | ||
end | ||
end | ||
end |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters