Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. AlphaBlend() strange colors.

AlphaBlend() strange colors.

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PatrykDabrowski
    wrote on last edited by
    #1

    Hello:) I have a gradient-like background with an owner drawn button. I use AlphaBlend() to draw button's image. Now, the strange thing is: Background pixel = RGB(168,168,168) Source pixel = 0xFFFF0000 (AARRGGBB) After AlphaBlend() with SourceConstantAlpha=0xff the output is RGB(255,0,0) - that's correct but when I change a bit the source pixel to Source pixel = 0x00FF0000 (AARRGGBB) I receive pixel RGB(255,168,168)?!?! I should get RGB(168,168,168) because the source alpha is 0x00?!?!? After some tests with different RGB values, I noticed that my blending works like it 'thinks' that my background is white (255,255,255)?!? When I make all source pixels to have 0xFF alpha value and just play with SourceConstantAlpha value, it's working fine!?! - my button is drawn with proper transparency?!? I need to play a bit with the source pixels' alpha value for 'soft' button's border. Does anyone know what could be wrong?? I'm using winxp/vs2003 Thanks a lot!!

    M 1 Reply Last reply
    0
    • P PatrykDabrowski

      Hello:) I have a gradient-like background with an owner drawn button. I use AlphaBlend() to draw button's image. Now, the strange thing is: Background pixel = RGB(168,168,168) Source pixel = 0xFFFF0000 (AARRGGBB) After AlphaBlend() with SourceConstantAlpha=0xff the output is RGB(255,0,0) - that's correct but when I change a bit the source pixel to Source pixel = 0x00FF0000 (AARRGGBB) I receive pixel RGB(255,168,168)?!?! I should get RGB(168,168,168) because the source alpha is 0x00?!?!? After some tests with different RGB values, I noticed that my blending works like it 'thinks' that my background is white (255,255,255)?!? When I make all source pixels to have 0xFF alpha value and just play with SourceConstantAlpha value, it's working fine!?! - my button is drawn with proper transparency?!? I need to play a bit with the source pixels' alpha value for 'soft' button's border. Does anyone know what could be wrong?? I'm using winxp/vs2003 Thanks a lot!!

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      AlphaBlend() from which class?

      "Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")

      P 1 Reply Last reply
      0
      • M Mark Salsbery

        AlphaBlend() from which class?

        "Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")

        P Offline
        P Offline
        PatrykDabrowski
        wrote on last edited by
        #3

        Sorry, I couldn't reply as I was offline for couple of days. I was trying CDC::AlphaBlend(), CImage::AlphaBlend() and global ::AlphaBlend() with the same results. I discovered that I should premultiply r/g/b values by alpha channel. Now it works fine, but I wonder how to cope with the situation when You have very small r/g/b values and small alpha channel. When You premultiply those small values and divide by 255, You will get zeroes...Now if You want to recover almost transparent pixels by increasing their alpha value, You will get black color instead of original one?!?!? Am I correct?? Simple example: Source bitmap: ARGB(10,20,0,0) ; DARK RED After premultiply: ARGB(10,20*10/255,0,0) = ARGB(10,0,0,0); BLACK Now try to recover original color by increasing alpha ARGB(255,0,0,0) and You receive black instead of ARGB(255,20,0,0); Thanks for Your attention.

        M 1 Reply Last reply
        0
        • P PatrykDabrowski

          Sorry, I couldn't reply as I was offline for couple of days. I was trying CDC::AlphaBlend(), CImage::AlphaBlend() and global ::AlphaBlend() with the same results. I discovered that I should premultiply r/g/b values by alpha channel. Now it works fine, but I wonder how to cope with the situation when You have very small r/g/b values and small alpha channel. When You premultiply those small values and divide by 255, You will get zeroes...Now if You want to recover almost transparent pixels by increasing their alpha value, You will get black color instead of original one?!?!? Am I correct?? Simple example: Source bitmap: ARGB(10,20,0,0) ; DARK RED After premultiply: ARGB(10,20*10/255,0,0) = ARGB(10,0,0,0); BLACK Now try to recover original color by increasing alpha ARGB(255,0,0,0) and You receive black instead of ARGB(255,20,0,0); Thanks for Your attention.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Since you're essentially dividing pixel RGB values by 25.5 then yes, any values less than 25 are going to end up being 0. There's still something strange - I'm going to try your original code so I can see it. I'll be back. Mark

          "Great job, team. Head back to base for debriefing and cocktails." (Spottswoode "Team America")

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups