Skip to content
Browse files

more rgb to rgba conversion

  • Loading branch information...
1 parent 8793420 commit 247133867f927e1d54a7bd63ecb273160080fdea @aberant committed
Showing with 22 additions and 3 deletions.
  1. +7 −2 lib/spittle/image_data.rb
  2. +1 −1 lib/spittle/png/image.rb
  3. +14 −0 spec/image_data_spec.rb
View
9 lib/spittle/image_data.rb
@@ -51,7 +51,9 @@ def fill_to_height( desired_height )
img
end
- def to_rgba( alpha_value=0 )
+ def to_rgba( alpha_value=255 )
+ # test that conversion updates pixel width, scanline width
+
return self if pixel_width == RGBA_WIDTH
# so ruby 1.9 has different ideas then 1.8 on how Enumerable should work
@@ -64,7 +66,10 @@ def to_rgba( alpha_value=0 )
pixels.inject([]){|result, pixel| result + pixel + [alpha_value] }
end
- ImageData.new(@properties.merge(:data => rgba_data))
+ ImageData.new( :data => rgba_data,
+ :pixel_width => 4,
+ :scanline_width => (@properties[:scanline_width] / RGB_WIDTH) * RGBA_WIDTH,
+ :name => name)
end
def [](row)
View
2 lib/spittle/png/image.rb
@@ -2,7 +2,7 @@ module PNG
class Image
#color types
RGB = 2
- RGBA = 3
+ RGBA = 6
class << self
def image_data( file_name, options={} )
View
14 spec/image_data_spec.rb
@@ -46,4 +46,18 @@
it "will return the last scanline given a current index" do
@id.last_scanline(1).should == [1,2,3]
end
+
+ describe "RGBA conversion" do
+ it "updates pixel width" do
+ @id.to_rgba.pixel_width.should == 4 # RGBA pixel width
+ end
+
+ it "updates scanline width" do
+ @id.to_rgba.scanline_width.should == 4
+ end
+
+ it "puts in an alpha byte with a default value of 255" do
+ @id.to_rgba[0].should == [1,2,3,255]
+ end
+ end
end

0 comments on commit 2471338

Please sign in to comment.
Something went wrong with that request. Please try again.