Curious IM7 behavior with "-gamma"

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
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Curious IM7 behavior with "-gamma"

Post by GeeMack »

Using IM 7.0.5-3 HDRI on Windows 10 64, I've come across a combination of operations that creates an odd result. If I run this command...

Code: Select all

magick -size 400x100 gradient: -fill #FFFF00 -tint 100% -gamma 0.99 ^
   -gravity center -fill #FFFFFF -pointsize 48 -annotate +0+0 "TESTING 123" v7_099.png
... it creates this image with the text colored yellow, even though I changed the "-fill" color to white before the "-annotate" operation.

Image

(https://www.dropbox.com/s/s0ex05me0at3g ... .png?raw=1)

Notice the "-gamma" value is 0.99, barely below 1, but any value greater or less than 1 will result in yellow text. Here are some things I tried to narrow the source of the issue.

If I set the gamma to 1 using "-gamma 1.00", the result is white text as expected.

If I put "-gamma" operation before the "-tint" instead of after it, the text will be white.

If I substitute "-level 0%,100%,0.99" for the "-gamma 0.99" operation, the text will be white.

Some tint colors will create this effect and others don't. If I use "-fill #FF00FF" before the tint, the text in the output will be white as expected. If I do "-fill #00FFFF" before the tint, the resulting text will be cyan. It doesn't seem to matter if I designate the colors by name, percentages, etc.

If I run the exact same command only using "convert" from IM 6.9.7-6 HDRI, the text is white.

Obviously there are several ways to bypass the problem, but I wonder if it's something that might need some attention from the developers in order to avoid some other possible side effects.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Curious IM7 behavior with "-gamma"

Post by fmw42 »

I can confirm on my IM 7.0.5-2 Q16 vs IM 6.9.8-0 Q16 Mac OSX

IM 7 produces yellow text and IM 6 produces white text. So far the only way I can make it work is

Code: Select all

magick -size 400x100 gradient: -fill "#FFFF00" -tint 100% -gamma 0.99 miff:- |\
magick - -gravity center -fill "#FFFFFF" -pointsize 48 -annotate +0+0 "TESTING 123" v7_099.png
I have tried -channel rgb, -alpha off, -compose over to reset the settings, but so far I have not figured out what will make it work.

It also works fine by putting -gamma right after the gradient:

Code: Select all

im7 magick -size 400x100 gradient: -gamma 0.99 -fill "#FFFF00" -tint 100% \
-gravity center -fill "#FFFFFF" -pointsize 48 -annotate +0+0 "TESTING 123" v7_099.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Curious IM7 behavior with "-gamma"

Post by snibgo »

With the OP command and IM v7.0.3-5, I get white text.

I suspect this is a side-effect (possibly a buggy side-effect) of setting the gamma metadata. This can be tested: what happens if you "-set gamma 0.45455" after "-gamma 0.99"?

Remember that "-gamma" does two things: it changes pixel values, and also the metadata setting (in some versions of IM).

By contrast, "-evaluate Pow" changes pixels but not metadata.

EDIT: I got that wrong, I didn't mean "-set gamma 1.0" but "-set gamma 0.45455", now corrrected.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Curious IM7 behavior with "-gamma"

Post by fmw42 »

I think snibgo is correct. I was just about to suggest the use of -evaluate pow rather than -gamma.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Curious IM7 behavior with "-gamma"

Post by fmw42 »

I still get the bad result using IM 7.0.5.3. Snibgo, did you mean 7.0.3.5 or 7.0.5.3?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Curious IM7 behavior with "-gamma"

Post by snibgo »

Yes, I meant 7.0.3-5, which is now quite old.

I think "+gamma N" is a synonym for "-set gamma N". They both set metadata without changing pixels.

Changing gamma with "-level" changes the pixels, but not the metadata.

Personally, I always use "-evaluate Pow", never "-gamma".
snibgo's IM pages: im.snibgo.com
Post Reply