Subject: Re: bug#10397: [PATCH] Under Remote Desktop, NUMCOLORS is unreliable; workaround

From: Daniel Colascione <[email-masked]>
Date: Thu, 29 Dec 2011 19:18:13 -0800

On 12/29/11 7:07 PM, Juanma Barranquero wrote:
> On Thu, Dec 29, 2011 at 23:59, Daniel Colascione <[email-masked]> wrote:
> 
>> What about this: we'll distrust any NUMCOLORS response less than 256.
>> You'll never use direct color with a bit depth that small, so any answer
>> in that range must be bogus.
> 
> Hmm. Shouldn't in fact GetDeviceCaps (hdc, NUMCOLORS) always be <= 256?
> 
> According to http://msdn.microsoft.com/en-us/library/dd144877(v=vs.85).aspx
> 
>   NUMCOLORS
>   Number of entries in the device's color table, if the device has a
> color depth of no more than 8 bits per pixel. For devices with greater
> color depths, 1 is returned.
> 
> (It says "1", but it's a typo for "-1".)

Good catch. What about this (untested) code?

  hdc = GetDC (dpyinfo->root_window);
  if (dpyinfo->has_palette)
    cap = GetDeviceCaps (hdc, SIZEPALETTE);
  else if (dpyinfo->n_cbits <= 8)
    /* According to the MSDN, GetDeviceCaps (NUMCOLORS) is valid only
       for devices with at most eight bits per pixel.  It's supposed
       to return -1 for other displays, but because it actually
       returns other, incorrect values under some conditions (e.g.,
       remote desktop), only use it when we know it's valid.  */
    cap = GetDeviceCaps (hdc, NUMCOLORS);
  else
    cap = -1;