slight inconsistency converting alpha in txt: IM 6.4.3-6

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

slight inconsistency converting alpha in txt: IM 6.4.3-6

Post by fmw42 »

IM 6.4.3-6 Q16 Mac OSX Tiger

This is not critical, but I just wanted to point it out. There seems to be a slight inconsistency in converting alpha values in the range 0-1 to 8-bit values relative how rgb values in range 0-100% are converted to 8-bit values.

For example:

convert -size 1x1 xc:"rgba(100%,75%,50%,0.5)" -depth 8 txt: | \
sed -n 's/ //g; s/^.*[^(]\((.*)\)[^)].*$/\1/p'
(255,191,127,128)

The rgb value of 50% goes to 127, but the alpha value of .5 goes to 128

On the other hand, the following is consistent due to the consistent use of floor()

convert -size 1x1 xc:"rgba(100%,75%,50%,0.5)" \
-format "(%[fx:floor(255*r)],%[fx:floor(255*g)],%[fx:floor(255*b)],%[fx:floor(255*a)])" info:
(255,191,127,127)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: slight inconsistency converting alpha in txt: IM 6.4.3-6

Post by magick »

The TXT format looks like this:
  • 0,0: (255,191,127,128) #FFBF7F80 rgba(255,191,127,0.501961)
The values inside the rgba() container is RGB with alpha. Values in the first set of parenthesis is RGB with opacity. If alpha is 127, opacity is 255-alpha or 255-128 is 127 as expected.
Post Reply