elixir-image / image

Image processing for Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect alpha value when drawing line

andreyuhai opened this issue · comments

commented

I've just realized while testing for #22 that when the image has alpha band, the colors don't work properly.

I believe that's because the alpha values should be between [0, 255] and we're passing a value between [0, 1], though I couldn't really find anything concrete in libvips documentation.

Only mention of alpha value I could find is here where they say

The alpha channel is 0 - max_alpha , where 1 means 100% image and 0 means 100% background. Non-complex images only. background defaults to zero (black).

max_alpha has the default value 255, or 65535 for images tagged as VIPS_INTERPRETATION_RGB16 or VIPS_INTERPRETATION_GREY16.


How I've tested is basically I've used the maze png that I've shared which we know has 4 bands.

    image = Image.open! image_path("/2x2-maze.png")
    {:ok, diagonal} = Image.Draw.line(image, 0, 0, 34, 34, color: :red)
    Image.write!(diagonal, "diagonal.png")

I've seen that after I've manually passed an alpha value of 255, I got the red line properly drawn.

I believe you are right. Some operations (compose) appear to require 0.1..1.0 but mostly it should be 0..255. When I used 0..255 some tests failed so I have additional work to do. Will work on this. Thanks for sticking with me, its helping work some of these kinks out. Drawing isn't the biggest strength of libvips but at least its enough for what you need.

I'm on it, day job definitely getting in the way. Should have a fix in the next few hours from this message.

commented

Alright, no worries. I really appreciate it! 🙇

I believe I have fixed the issue of specifying color transparency. Would you check if that's now working ok from your perspective, using the main branch on GitHub?

Closing for now since I've published Image version 0.15.0. Please reopen if you still see any issues of course.