Cannot get floodFillOpacity to work
Posted: 2011-08-06T08:03:28-07:00
I am new to (Image)Magick++, so please forgive blunders, impatience, etc etc
I am trying to do some low-level pixel twiddling; I took most of last weekend to get to the point where I can read and write individual pixel RGB values. Now I want to handle the alpha channel directly, but to save reinventing the wheel, I tried to use the floodfill methods. First, this works as expected:
(3, 3) is on the white background, which gets filled with (whatever) colour.
The documentation is incredibly inexplicit about how the flood fill replaces pixel values, but I discovered by experiment that any opacity value in the colour parameter is ignored. So next I try:
The manual says: "Floodfill pixels matching color (within fuzz factor) of target pixel(x,y) with replacement opacity value using method." See: http://www.imagemagick.org/Magick++/Ima ... %20Methods
PaintMethod is an enumeration: http://www.imagemagick.org/Magick++/Enu ... aintMethod
(I expected that PaintMethod would include things like: write alpha value, write value if less than existing value, etc etc, being pixel combination methods) But actually these are things like "replace just the pixel in question" which make no sense at all (that I can see) in the context of a function which is doing flood fill already. In the interests of not just whining, I persevered, and found the following experimental results:
When fourth argument is:
ReplaceMethod: the entire image goes black (??)
PointMethod: the entire image goes black (??)
FloodfillMethod: flood fills... (ah! what we wanted)
But this does not appear to set the opacity at all. The manual is silent about just what the opacity argument is, but it's an int, so I tried 0, 1, then maxRGB, and eventually discovered the following:
If the value is 0-692: flood fills with black
If the value is 693-100%: flood fills with white
At this point I decided it will be quicker to make my own wheel, but I wonder if there is some monumental misunderstanding I am labouring under...?
(I mean, 692? It's not as if it were 42^2 or anything...)
I am trying to do some low-level pixel twiddling; I took most of last weekend to get to the point where I can read and write individual pixel RGB values. Now I want to handle the alpha channel directly, but to save reinventing the wheel, I tried to use the floodfill methods. First, this works as expected:
Code: Select all
image.floodFillColor(3, 3, Color(40*Percent, 90*Percent, 30*Percent));
The documentation is incredibly inexplicit about how the flood fill replaces pixel values, but I discovered by experiment that any opacity value in the colour parameter is ignored. So next I try:
Code: Select all
// arguments: x, y, opacity, "paint method"
image.floodFillOpacity(3, 3, 692, FloodfillMethod);
PaintMethod is an enumeration: http://www.imagemagick.org/Magick++/Enu ... aintMethod
(I expected that PaintMethod would include things like: write alpha value, write value if less than existing value, etc etc, being pixel combination methods) But actually these are things like "replace just the pixel in question" which make no sense at all (that I can see) in the context of a function which is doing flood fill already. In the interests of not just whining, I persevered, and found the following experimental results:
When fourth argument is:
ReplaceMethod: the entire image goes black (??)
PointMethod: the entire image goes black (??)
FloodfillMethod: flood fills... (ah! what we wanted)
But this does not appear to set the opacity at all. The manual is silent about just what the opacity argument is, but it's an int, so I tried 0, 1, then maxRGB, and eventually discovered the following:
If the value is 0-692: flood fills with black
If the value is 693-100%: flood fills with white
At this point I decided it will be quicker to make my own wheel, but I wonder if there is some monumental misunderstanding I am labouring under...?
(I mean, 692? It's not as if it were 42^2 or anything...)