Skip to content

Commit

Permalink
Fix opacity of grayscale images
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Zhigalkin committed Mar 9, 2023
1 parent b50dfae commit 4f3e81f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion spec/pluto/format/png_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe Pluto::Format::PNG do
io = IO::Memory.new
image.to_png(io)

digest(io.to_s).should eq "944007df754a5737485981612977ce3d365ccb54"
digest(io.to_s).should eq "5fc8ce7e9d94d4b3ceb5d2216cf66e90e03c66e0"
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/pluto/format/webp_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe Pluto::Format::WebP do
io = IO::Memory.new
image.to_webp(io)

digest(io.to_s).should eq "92678d201760ee50929ea344a81c76d5f61e70e6"
digest(io.to_s).should eq "4a23dfdec161349c163c0a17a6af4cf94e1807d7"
end
end

Expand Down
8 changes: 3 additions & 5 deletions src/pluto/grayscale_image.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require "./image"

class Pluto::GrayscaleImage < Pluto::Image
property gray : Array(UInt8)
property alpha : Array(UInt8)
property width : Int32
property height : Int32

Expand All @@ -16,12 +17,13 @@ class Pluto::GrayscaleImage < Pluto::Image
RGBAImage.new(red, green, blue, alpha, width, height).to_gray
end

def initialize(@gray, @width, @height)
def initialize(@gray, @alpha, @width, @height)
end

def clone : GrayscaleImage
self.class.new(
@gray.clone,
@alpha.clone,
@width,
@height
)
Expand All @@ -39,10 +41,6 @@ class Pluto::GrayscaleImage < Pluto::Image
@gray
end

def alpha : Array(UInt8)
@gray
end

def each_channel(& : (Array(UInt8), ChannelType) -> Nil) : Nil
yield @gray, ChannelType::Gray
nil
Expand Down
1 change: 1 addition & 0 deletions src/pluto/rgba_image.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Pluto::RGBAImage < Pluto::Image
(red_pixel * red_multiplier + @green[index] * green_multiplier + @blue[index] * blue_multiplier).to_u8
)
end,
alpha,
width,
height
)
Expand Down

0 comments on commit 4f3e81f

Please sign in to comment.