Bug 62141 - Incorrect rounding of color values during transitions
Summary: Incorrect rounding of color values during transitions
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Simon Fraser (smfr)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-06 13:11 PDT by Boris Zbarsky
Modified: 2011-06-06 21:13 PDT (History)
2 users (show)

See Also:


Attachments
Testcase (939 bytes, text/html)
2011-06-06 13:11 PDT, Boris Zbarsky
no flags Details
Better testcase (1.11 KB, text/html)
2011-06-06 20:28 PDT, Simon Fraser (smfr)
no flags Details
Patch (4.20 KB, patch)
2011-06-06 20:54 PDT, Simon Fraser (smfr)
mitz: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Zbarsky 2011-06-06 13:11:53 PDT
Created attachment 96114 [details]
Testcase

BUILD: Current WebKit nightly (or current Chrome dev)

STEPS TO REPRODUCE:
1)  Load attached testcase.
2)  Examine the sum of the "r" and "b" values in the printed rgb() triplets.

EXPECTED RESULTS: Sum is always 255.

ACTUAL RESULTS: Sum is 254 for most of them.

ADDITIONAL NOTES: This is a regression from Safari 5.

To see why the expected results are expected, note that at time t/5s in the range [0, 1] in the transition the computed color should be:

  rgb(255*(1-t), 0, 255*t);

Now the color components will be rounded, but, for example, if 255*(1-t) is rounding to 254 then 255*t > 0.5.  And therefore 255*t should be rounding to 1, not to 0.

It looks like WebKit is just truncating the floating-point color values to get the interpolated color value instead of correctly rounding.
Comment 1 Simon Fraser (smfr) 2011-06-06 17:12:35 PDT
Color values are stored as unsigned bytes, so rounding is unsurprising.
Comment 2 Boris Zbarsky 2011-06-06 17:26:42 PDT
Rounding is unsurprising, but my point is that your rounding is wrong.  You're rounding down instead of rounding to nearest.
Comment 3 Simon Fraser (smfr) 2011-06-06 20:28:06 PDT
Created attachment 96187 [details]
Better testcase
Comment 4 Simon Fraser (smfr) 2011-06-06 20:54:03 PDT
Created attachment 96190 [details]
Patch
Comment 5 Simon Fraser (smfr) 2011-06-06 21:13:08 PDT
http://trac.webkit.org/changeset/88214