Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Bug reports ➜ WindowDrawImageAlpha wrong color in 0 alpha regions at certain blend opacities

WindowDrawImageAlpha wrong color in 0 alpha regions at certain blend opacities

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Fiendish   USA  (2,551 posts)  Bio   Global Moderator
Date Wed 10 Jan 2018 06:07 AM (UTC)

Amended on Wed 10 Jan 2018 06:36 AM (UTC) by Fiendish

Message
At certain blend opacities, WindowDrawImageAlpha (and probably also WindowMergeImageAlpha) is generating the wrong blend color for 0 alpha areas.

I made a 500x500 completely empty (add alpha channel, select all, delete) png in GIMP and saved it as MUSHclient/pure_alpha.png and then used the following.
The lower half of the miniwindow visibly blinks, but the lower half shouldn't be different than the upper half because the image is completely empty.

(You might have to squint or mess with your display brightness)

As you can see in the code below, the color displayed should be 0x1c1c0c, but the bad region is showing 0x1b1b0b.


<aliases>
  <alias
   match="hst"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
   require "wait"

   bga = "win_"..GetPluginID().."_test"
   WindowDelete(bga)

   local bgcolor = 0x1c1c0c
   WindowCreate (bga, 0, 0, 0, 0, 12, 2, bgcolor)
   WindowShow(bga, true)

   if WindowLoadImage (bga, "pure_alpha", GetInfo(66).."pure_alpha.png") == 0 then
      WindowResize(bga, WindowImageInfo(bga, "pure_alpha", 2), WindowImageInfo(bga, "pure_alpha", 3), bgcolor)
      wait.make(function()
         for i=1,100 do
            WindowRectOp(bga, 2, 0, 0, 0, 0, bgcolor, bgcolor)
            WindowDrawImageAlpha(bga, "pure_alpha", 0, 250, 0, 0, 0.0499) -- good
            Repaint()
            wait.time(0.5)
            WindowRectOp(bga, 2, 0, 0, 0, 0, bgcolor, bgcolor)
            WindowDrawImageAlpha(bga, "pure_alpha", 0, 250, 0, 0, 0.05) -- bad
            Repaint()
            wait.time(0.5)
            WindowRectOp(bga, 2, 0, 0, 0, 0, bgcolor, bgcolor)
            WindowDrawImageAlpha(bga, "pure_alpha", 0, 250, 0, 0, 0.0501) -- good
            Repaint()
            wait.time(0.5)
            WindowRectOp(bga, 2, 0, 0, 0, 0, bgcolor, bgcolor)
            WindowDrawImageAlpha(bga, "pure_alpha", 0, 250, 0, 0, 0.0157) -- bad
            Repaint()
            wait.time(0.5)
            -- WindowRectOp(bga, 2, 0, 0, 0, 0, bgcolor, bgcolor)
            -- WindowDrawImageAlpha(bga, "pure_alpha", 0, 250, 0, 0, 0.0158) -- good
            -- Repaint()
            -- wait.time(0.3)
         end
      end)
   end
</send>
</alias>
</aliases>

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Fiendish   USA  (2,551 posts)  Bio   Global Moderator
Date Reply #1 on Wed 10 Jan 2018 06:47 AM (UTC)

Amended on Wed 10 Jan 2018 07:14 AM (UTC) by Fiendish

Message
And, indeed,
    printf("%x", (uint8_t)(0.05 * 0xc + (1 - 0.05) * 0xc));

prints b instead of c


( https://github.com/nickgammon/mushclient/blob/master/blending.h#L45 )

How do you feel about rounding instead of truncating in those blending functions?
https://github.com/nickgammon/mushclient/pull/40

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #2 on Wed 10 Jan 2018 09:41 PM (UTC)
Message
It looks OK to me. I also added it to Blend_Opacity.

See: https://github.com/nickgammon/mushclient/commit/5411e4895a3b6338

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #3 on Wed 10 Jan 2018 10:41 PM (UTC)
Message
How did you even discover this, anyway? The difference is so slight it is hard to spot. I mean I think we are talking 1/256 of a colour code difference (as in red/blue/green). If only red changed then the difference is very small.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Fiendish   USA  (2,551 posts)  Bio   Global Moderator
Date Reply #4 on Thu 11 Jan 2018 04:42 AM (UTC)

Amended on Thu 11 Jan 2018 04:45 AM (UTC) by Fiendish

Message
In the process of making a miniwindow color themes framework, I decided that I'd like to let the themes tint the main output background color. But the Aardwolf MUSHclient package already has an image of the Aardwolf logo darkly blended into the background sort of like a watermark, which it places there with a miniwindow flagged as underneath, and I don't want to get rid of that. So to make the main output correspondingly tint with the theme, I slightly adjusted the plugin that embeds the logo to make the background a different color than black just before blending. But the logo image was originally itself very darkly blended with black[0] (I'm not sure why I did that), so blending it with other colors was turning tricky and looked pretty bad on some colors. So I changed the logo image to be normal with a transparent background[1] instead of very black colors on a black background, because then the blending would be easier for me to figure out. But then with one of my color themes the 8% opacity blend that I'd decided on for most of the themes was still visually too bright, so I decided to lower it to 5% opacity, and then at 5% opacity I noticed (just barely) that the image didn't overlay/merge seamlessly.

[0] - https://raw.githubusercontent.com/fiendish/aardwolfclientpackage/2097ebaff6a23df38eb370d0de161c269bfd5485/MUSHclient/worlds/plugins/images/aardbg13.png
[1] - https://i.imgur.com/nzj5cb6.png

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #5 on Thu 11 Jan 2018 06:55 AM (UTC)
Message
And this, Ladies and Gentlemen, is how a bug report should be submitted.


  • A Minimal, Complete, and Verifiable example.

    That is: code that reproduces the problem and doesn't do anything else. (Although I notice I had to make the pure_alpha.png file myself).

  • A description about what actually happened.

  • A description about what was expected.

  • A speculation about what the problem might be.

  • Suggested code to fix it - if that is something you are comfortable about doing.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


19,331 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.