none
Problem with testing WPF UI in Windows 7 due to antialiasing

    Question

  • The application I'm developing has a WPF user interface.  We are targeting deployment on Windows XP, Vista, and 7.  As part of our testing, we use TestComplete to run automated UI tests, many of which include taking screenshots of our application and comparing them to reference screenshots.  (TestComplete captures the screenshots.)

    I was able to ensure that the screenshots for Windows XP and Vista matched pixel-by-pixel by disabling all anti-aliasing.  However, despite doing the same thing on Windows 7, the screenshots for Windows 7 do not match and appear to be antialiased.

    Just to be clear, I'm not complaining about antialiasing in general, I just want to know how to set my Windows 7 machine up so that I can consistently test my application across multiple OS's.  Here is what I have done, which is the same as what I did in Vista:

    - disable ClearType

    - disable font smoothing in advanced system settings portion of control panel

    - disabled all antialiasing options on my video card's display driver

    - set the theme to Windows Classic with a few modifications to match the sizing of text, scrollbars, etc. from Windows XP (BTW, it would be nice if there was a Windows XP theme, but that's a different issue)

    - added these registry keys in HKEY_CURRENT_USER/Software/Microsoft/Avalon.Graphics: DisableHWAcceleration = 1, MaxMultisampleType = 0

    - made sure my other registry keys were set the same as for my other test machines, including the following keys in HKEY_CURRENT_USER/Control Panel/Desktop: FontSmoothing = 0, FontSmoothingGamma = 0, FontSmoothingOrientation = 1, FontSmoothingType = 0

    On my Vista machine, that was enough to make it match the screenshots from my XP machine.  However, when I run under Windows 7, if I zoom in on the screenshots I can see that there are colored pixels around the text.  These pixels are grayscale in my reference screenshot.

    I would really like to avoid having to maintain an entirely separate set of screenshots for Windows 7 (since we have several thousand reference screenshots).  Is there a way to resolve this so that I can have my screenshots on Windows 7 match pixel-by-pixel?

    Monday, March 22, 2010 2:56 PM

Answers

  • I tried setting up a second Win7 machine, and setting all the registry keys to their default values and the values I listed above without touching anything through the Control Panel first.   This machine appears to match just fine (it has the same hardware as the first one).  Given that, I suspect some other setting was changed on the first machine.  I will wipe the machine and reinstall Windows and hopefully that will fix the problem.  Thanks for your help!

    For the record, this is how I got the machines to match:

    • Use the same saved windows theme that I had on my Vista server
    • Disabled all antialiasing in the video card's driver utilities app
    • Created or set the following registry keys:
    • HKEY_CURRENT_USER/Software/Microsoft/Avalon.Graphics: DisableHWAcceleration = 1, MaxMultisampleType = 0
    • HKEY_CURRENT_USER/Control Panel/Desktop: FontSmoothing = 0, FontSmoothingGamma = 0, FontSmoothingOrientation = 1, FontSmoothingType = 1
    • HKEY_CURRENT_USER/Software/Microsoft/Avalon.Graphics/DISPLAY1: ClearTypeLevel = 0, EnhancedContrastLevel = 0, TextContrastLevel = 1
    • HKEY_LOCAL_MACHINE/Software/Microsoft/Avalon.Graphics/DISPLAY1: GammaLevel = 1900 (decimal), PixelStructure = 1
    • Marked as answer by jzeckel Friday, March 26, 2010 1:03 PM
    Friday, March 26, 2010 1:03 PM

All replies

  • Usually, most visual verification test frameworks will provide a tolerance function that can let you specify how many pixels are allowed to differ and by what values. Check out TestComplete documentation, it should provide such feature. Another feature that is usually used to facilitate visual verification robustness is image masks, which basically blacks out certain regions of the rendered and expected images (usually the regions that will differ on different OS's, themes, or video cards, like the Window chrome, scrollbars, some text, etc...)

    Also, pre-WPF 4.0 (which is still in RC), ClearType text cannot be turned off for WPF apps.

    Monday, March 22, 2010 10:27 PM
  • Unfortunately due to the nature of the screenshots we cannot allow a tolerance (if we did, we could not claim that the software was providing the expected result because there is no way to know if the differing pixels were spread across the image or all in one place, indicating a difference).  If we blacked out all the text areas, we also would not be able to conclude that our software was functioning correctly.

    If ClearType is enforced in WPF, can you tell me what settings to use for the ClearType registry keys in Windows 7 to make it appear the same as in XP and Vista?  Like I said before, I don't really care if antialiasing is occurring or not, I just need to make sure that the *same* antialiasing is being used everywhere.  I know where the registry keys are for the ClearType settings in Win7 but there are so many possible values that it would take months to figure out which ones might make it look the same by trial and error.  I am using the same hardware and the same graphics card for all OS's.

    Tuesday, March 23, 2010 1:40 PM
  • Tuesday, March 23, 2010 9:09 PM
  • Hi,

    Is your application using the exact same font for UI on all those different systems? I believe different fonts can have different ClearType behavior. And on those systems, usually the system default font for the UI are different. This can also introduce differences.

    Regards,
    Jie
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    If you have any feedback, please tell us.

    The All-In-One Code Framework Project
    My Blog (in Simplified Chinese)
    Wednesday, March 24, 2010 11:30 AM
  • Jie, yes, we are using the same font.  Inside our application all fonts are Trebuchet MS, and I have ensured that the fonts in the Windows Theme are also all matched across systems (they are all either Trebuchet MS or Tahoma).

    Ahmad, I see that if I set the ClearTypeLevel to 0 that the rendering should be grayscale from that post, but can you provide me with any information about what to set the EnhancedContrastLevel, TextContrastLevel, and GammaLevel to?

    Wednesday, March 24, 2010 12:33 PM
  • Download the ClearType power toy on one of your XP test machines http://www.microsoft.com/typography/ClearTypePowerToy.mspx then use it to get the Contrast and Gamma level values, then on your Win 7 test machines, use the "built-in ClearType tuner found in the Windows Control Panel under Appearance and Personalization." to update the ClearType settings

    Wednesday, March 24, 2010 10:54 PM
  • Could you give me a little more information about how to get those values out of the tuner?  The last thing I want to do is change the settings on my XP and Vista machines which are currently working.  I just need to know what the default values are on Vista and on XP, and I will then copy those default values over to Windows 7.  I would think those default values would be hardcoded into XP/Vista somewhere so I don't understand how the tuner will help me discover them -- it seems to me I am more likely to accidentally change them with the tuner and cause my working machines to stop working.
    Thursday, March 25, 2010 1:34 PM
  • With some experimenting I have managed to get my results to be very close by setting ClearTypeLevel to 0, GammaLevel to 1900, PixelFormat to 1, TextContrastLevel to 1, and EnhancedContrastLevel to 0.  However, the RGB values of the pixels in the fonts are still slightly off from what I am getting on XP/Vista.  For example, some of the black portions of the font text are R=11, G=11, B=11 on XP and Vista, but R=12, G=12, B=12 on Windows 7.  Which one of those registry keys do I need to play with to get this to match?  They are now both rendering in grayscale with very similar colored pixels in the same locations, but the colors are just slightly off.
    Thursday, March 25, 2010 3:26 PM
  • For what it's worth, I also tried adding all of the ClearType registry keys to my XP machine to ensure they had the same values, but the colors are still off as I described.
    Thursday, March 25, 2010 5:37 PM
  • Hmm, it looks like the PowerToy doesn't let you tweek or quesry the values directly. I haven't tried it, but I thought it would. Apparently I was wrong.

    Try setting PixelStructure to 0, and see if that fixes your problem. Here's a list of the WPF ClearType registry settings with their default values:

    http://msdn.microsoft.com/en-us/library/aa970267.aspx

    Thursday, March 25, 2010 7:13 PM
  • I tried setting up a second Win7 machine, and setting all the registry keys to their default values and the values I listed above without touching anything through the Control Panel first.   This machine appears to match just fine (it has the same hardware as the first one).  Given that, I suspect some other setting was changed on the first machine.  I will wipe the machine and reinstall Windows and hopefully that will fix the problem.  Thanks for your help!

    For the record, this is how I got the machines to match:

    • Use the same saved windows theme that I had on my Vista server
    • Disabled all antialiasing in the video card's driver utilities app
    • Created or set the following registry keys:
    • HKEY_CURRENT_USER/Software/Microsoft/Avalon.Graphics: DisableHWAcceleration = 1, MaxMultisampleType = 0
    • HKEY_CURRENT_USER/Control Panel/Desktop: FontSmoothing = 0, FontSmoothingGamma = 0, FontSmoothingOrientation = 1, FontSmoothingType = 1
    • HKEY_CURRENT_USER/Software/Microsoft/Avalon.Graphics/DISPLAY1: ClearTypeLevel = 0, EnhancedContrastLevel = 0, TextContrastLevel = 1
    • HKEY_LOCAL_MACHINE/Software/Microsoft/Avalon.Graphics/DISPLAY1: GammaLevel = 1900 (decimal), PixelStructure = 1
    • Marked as answer by jzeckel Friday, March 26, 2010 1:03 PM
    Friday, March 26, 2010 1:03 PM
  • Okay, so I thought this problem was solved.  My machines were running, my screenshots were matching.  However, while my tests ran successfully on March 29, they have started failing as of March 31 -- but ONLY on the 32-bit Win7 machines, the 64-bit machines are still fine, and ONLY on the colored fonts, the black fonts are still fine.  The only thing I could find that changed was that update KB980182 was installed, but even after uninstalling it, rebooting, then when that didn't work wiping the machine and reinstalling Win7 32-bit, I am still having this problem.  I'm totally at a loss here.  Even some of the scroll bar thumbs look different.  I made sure that I had the same video driver as my Vista machines, and I tried with the same video driver as the Win7 64 machines, but no luck.  Ran a full virus scan, no viruses.  Anyone have any advice?  This is extremely frustrating.

    To reiterate, my Win7 64-bit machines have matching screenshots.  I had one Win7 32-bit machine which had matching screenshots on 3/29.  On 3/31, the 32-bit machine stopped matching, and the mismatches are *only in colored text.*  I had another Win7 32-bit machine which I set up on 3/31 and it has never matched with the same error.

    Before you ask, I checked out all of the test code, screenshots, and our application the way they were on 3/29, which had passed before, and they fail now, so it is not due to a change in our application or test code.

    Friday, April 02, 2010 3:21 PM
  • I tracked down this issue -- it is a problem with the display driver, not with Windows or WPF.
    Monday, April 05, 2010 1:26 PM