<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>12824</bug_id>
          
          <creation_ts>2011-05-30 22:11:46 +0000</creation_ts>
          <short_desc>This doesn&apos;t say how to serialize non-zero alpha values: how many digits should be used?  The correct answer is the minimum number necessary so that the resulting string evaluates to the same floating-point number as you started with.</short_desc>
          <delta_ts>2011-08-10 22:34:12 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>HTML WG</product>
          <component>LC1 HTML Canvas 2D Context</component>
          <version>unspecified</version>
          <rep_platform>Other</rep_platform>
          <op_sys>other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.whatwg.org/specs/web-apps/current-work/#colors-and-styles</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>contributor</reporter>
          <assigned_to name="Ian &apos;Hixie&apos; Hickson">ian</assigned_to>
          <cc>ayg</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>public-html-admin</cc>
    
    <cc>public-html-wg-issue-tracking</cc>
          
          <qa_contact name="HTML WG Bugzilla archive list">public-html-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>48936</commentid>
    <comment_count>0</comment_count>
    <who name="">contributor</who>
    <bug_when>2011-05-30 22:11:46 +0000</bug_when>
    <thetext>Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html
Section: http://www.whatwg.org/specs/web-apps/current-work/complete.html#colors-and-styles

Comment:
This doesn&apos;t say how to serialize non-zero alpha values: how many digits
should be used?  The correct answer is the minimum number necessary so that
the resulting string evaluates to the same floating-point number as you
started with.

Posted from: 68.175.61.233
User agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.772.0 Safari/535.1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48941</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-05-31 02:09:56 +0000</bug_when>
    <thetext>Actually, the correct answer may be to use however many are needed to ensure that your round-trip back to the same value you have now if you parse the result.

For example, consider a UA that stores alpha internally as an integer in the range [0, 255] (a very common thing to do; Presto, WebKit nightly, and Gecko all do it).  It most certainly cannot produce the original floating-point number when asked.  What it _can_ produce is a floating-point number which when parsed and converted to an integer in that range will produce the integer you start with.  In practice that means either 2 or 3 digits of precision.

I agree that this should be specified.

I&apos;ll attach a simple testcase that tests what browsers do right now for alpha values of 0 to 1 in steps of 0.001; it shows that Presto, Gecko, and WebKit all step up their serialized value only once every 0.004 or so, which means they&apos;re storing 250-ish distinct values, as I said above.

Note that of the three Gecko is the only one that even tries to make the serialized value look &quot;nice&quot; (in the sense of using the smallest number of digits that will round-trip to the same integer; this means that 0.1 ends up serialized as &quot;0.1&quot; and not &quot;0.09804&quot; (Chrome) or &quot;0.10196&quot; (Presto and Safari)).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48942</commentid>
    <comment_count>2</comment_count>
      <attachid>991</attachid>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-05-31 02:10:21 +0000</bug_when>
    <thetext>Created attachment 991
Testcase</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48956</commentid>
    <comment_count>3</comment_count>
    <who name="Aryeh Gregor">ayg</who>
    <bug_when>2011-05-31 14:20:49 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; Actually, the correct answer may be to use however many are needed to ensure
&gt; that your round-trip back to the same value you have now if you parse the
&gt; result.

Good catch.

&gt; For example, consider a UA that stores alpha internally as an integer in the
&gt; range [0, 255] (a very common thing to do; Presto, WebKit nightly, and Gecko
&gt; all do it).

Should this be standardized?  It has some author-visible implications.  To start with, if alpha values are serialized as you suggest, setting and then reading back strokeStyle or fillStyle will give you a different number of digits in different UAs for the alpha, depending on how much internal precision they have.

More than that, presumably it will also be detectable by drawing some non-opaque things on top of each other and measuring the exact color of the result.  If everything gets clamped to 8-bit integers, the rounding will be different from if you use actual floats.

&gt; Note that of the three Gecko is the only one that even tries to make the
&gt; serialized value look &quot;nice&quot; (in the sense of using the smallest number of
&gt; digits that will round-trip to the same integer; this means that 0.1 ends up
&gt; serialized as &quot;0.1&quot; and not &quot;0.09804&quot; (Chrome) or &quot;0.10196&quot; (Presto and
&gt; Safari)).

Actually, this bug was prompted by the fact that WebKit just changed to more Gecko-like behavior here:

http://trac.webkit.org/changeset/87512

The commit summary said &quot;The number of decimals for alpha values between 0 and 1 is not specified, so match Gecko and Presto by returning the lowest number of decimals needed to represent the number&quot;, so my immediate reaction was to get the number of decimal places standardized.  (I don&apos;t know why it says &quot;and Presto&quot; -- I get the same results in Opera as you do.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48961</commentid>
    <comment_count>4</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2011-05-31 15:58:36 +0000</bug_when>
    <thetext>&gt; setting and then reading back strokeStyle or fillStyle will give you a
&gt; different number of digits in different UAs for the alpha, depending on how
&gt; much internal precision they have.

Yep.  And if you required the same number of digits, then you could still detect the limited internal precision.

If you&apos;re asking whether the fact that alpha is stored as an integer in the range 0-255 should be standardized, the answer is &quot;maybe&quot;.  Right now the way floats are converted to such integers is not the same across UAs either, last I checked...  Standardizing makes some sense, but we need to be careful to not overconstrain future implementations that may want to allow a wider range of alpha values, assuming anyone would want that.  Worth a mailing list thread.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>52635</commentid>
    <comment_count>5</comment_count>
    <who name="Michael[tm] Smith">mike</who>
    <bug_when>2011-08-04 05:03:18 +0000</bug_when>
    <thetext>mass-move component to LC1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>54643</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2011-08-10 22:34:01 +0000</bug_when>
    <thetext>EDITOR&apos;S RESPONSE: This is an Editor&apos;s Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Accepted
Change Description: see diff given below
Rationale: Concurred with comments above.

I tried. Not sure I like the result.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>54644</commentid>
    <comment_count>7</comment_count>
    <who name="">contributor</who>
    <bug_when>2011-08-10 22:34:12 +0000</bug_when>
    <thetext>Checked in as WHATWG revision r6411.
Check-in comment: Try to tighten up the definition of how to serialise rgba() in canvas.
http://html5.org/tools/web-apps-tracker?from=6410&amp;to=6411</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>991</attachid>
            <date>2011-05-31 02:10:21 +0000</date>
            <delta_ts>2011-05-31 02:10:21 +0000</delta_ts>
            <desc>Testcase</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>485</size>
            <attacher name="Boris Zbarsky">bzbarsky</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgogIDxjYW52YXMgaWQ9ImMiIHdpZHRoPSIxIiBoZWlnaHQ9
IjEiPjwvY2FudmFzPgogIDx0YWJsZT4KICAgIDx0cj48dGg+U2V0PC90aD48dGg+U2VyaWFsaXpl
ZDwvdGg+PC90cj4KCiAgICA8c2NyaXB0PgogICAgICB2YXIgYyA9IGRvY3VtZW50LmdldEVsZW1l
bnRCeUlkKCJjIikuZ2V0Q29udGV4dCgiMmQiKTsKICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCAx
OyBpICs9IDAuMDAxKSB7CiAgICAgICAgYy5maWxsU3R5bGU9InJnYmEoMCwgMCwgMCwgIiArIGkg
KyAiKSIKICAgICAgICBkb2N1bWVudC53cml0ZSgiPHRyPjx0ZD4iICsgaSArICI8L3RkPjx0ZD4i
ICsgCiAgICAgICAgICAgICAgICAgICAgICAgYy5maWxsU3R5bGUucmVwbGFjZSgvLiosLywgIiIp
LnJlcGxhY2UoIikiLCAiIikgKwogICAgICAgICAgICAgICAgICAgICAgICI8L3RkPjwvdHI+Iik7
CiAgICAgIH0KICA8L3NjcmlwdD4KPC9odG1sPgo=
</data>

          </attachment>
      

    </bug>

</bugzilla>