Color is not saved properly

Bug #273684 reported by Hans de Graaff
4
Affects Status Importance Assigned to Milestone
ScreenRuler
Fix Released
High
Ian McIntosh

Bug Description

The color of the screen ruler is not properly saved, and in fact even changes without going to the preferences pane on each different startup. It seems that only the saturation of the color is affected. Just starting screen ruler repeatedly is enough to get a paler color every time.

This happens with Screen Ruler 0.85 and compositing throught metacity enabled. I haven't seen this behaviour with older versions of Screen Ruler.

Changed in screenruler:
assignee: nobody → ian-mcintosh
importance: Undecided → High
status: New → Fix Committed
Changed in screenruler:
status: Fix Committed → Fix Released
Revision history for this message
Ian McIntosh (ian-mcintosh) wrote :

The problem was incorrectly assuming that color components were 8-bit (as they appear in the color chooser dialog):

class Gdk::Color
  def to_hex
    sprintf('#%x%x%x', red, green, blue)
  end
end

Gdk::Color components are in fact 16-bit.

Revision 12 looks like this:

class Gdk::Color
  def to_hex
    sprintf('#%02x%02x%02x', red / 257, green / 257, blue / 257) # because 255 * 257 == 65535
  end
end

Revision history for this message
wouter bolsterlee (wbolster) wrote :

Using 257 does not look like it's correct. Are you really sure it is?

Revision history for this message
Ian McIntosh (ian-mcintosh) wrote :
Revision history for this message
h1repp (heinz-repp) wrote :

just my 2 pence:
seems to be a common misapprehension: as 255 times 257 is 65535, some believe that by dividing 16 bit numbers by 257 they receive 8 bit numbers - but that's wrong. As integer division discards the remainder, what you get in fact is a mapping of 1 single 16 bit number (65535) to one 8 bit number and 255 mappings of 257 16 bit numbers each to one 8 bit number. This is wanted only in rare cases, where you want to make sure that only the maximum 16 bit number maps to the maximum a bit number. The common way to reduce 16 bit numbers to 8 bit is just to discard the lower 8 bits, and this is done by dividing by 256. This way 256 16 bit numbers always evenly map to one 8 bit number.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.