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

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>54256</bug_id>
          
          <creation_ts>2011-02-10 16:05:40 -0800</creation_ts>
          <short_desc>Improve the compression of Canvas&apos;s toDataURL function</short_desc>
          <delta_ts>2012-03-02 23:45:05 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Canvas</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Tab Atkins">tabatkins</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>guanqun.lu</cc>
    
    <cc>mdelaney7</cc>
    
    <cc>sam</cc>
    
    <cc>scottmg</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>349478</commentid>
    <comment_count>0</comment_count>
    <who name="Tab Atkins">tabatkins</who>
    <bug_when>2011-02-10 16:05:40 -0800</bug_when>
    <thetext>Canvas&apos;s toDataURL function has horrible PNG compression for simple images.  For example, running the following page gets me a data url 2.8kb in size:

&lt;!doctype html&gt;
&lt;script&gt;
var x = document.createElement(&apos;canvas&apos;);
x.width = 500;
x.height = 500;
var y = x.getContext(&apos;2d&apos;);
y.fillRect(0,0,500,500);
alert(x.toDataURL().length);
&lt;/script&gt;

Saving the generated image and running it through http://www.pngoptimizer.com/ gives me an equivalent image that is only 125 bytes in size.  We should be able to generate images similar in size.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>349531</commentid>
    <comment_count>1</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2011-02-10 17:34:37 -0800</bug_when>
    <thetext>Tab, what platform are you testing on? I believe each port uses its own encoders for this so the knowing the platform is important.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>349792</commentid>
    <comment_count>2</comment_count>
    <who name="Tab Atkins">tabatkins</who>
    <bug_when>2011-02-11 08:48:39 -0800</bug_when>
    <thetext>I&apos;m not sure of exactly what info you need, so I&apos;ll dump it all.  I&apos;m running Chrome 9.0.597.94 beta on the modified Ubuntu we use in the office.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>349814</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2011-02-11 09:55:04 -0800</bug_when>
    <thetext>On Snow Leopard Safari, I get an alert saying 7274, so I guess that this should be split into at least two bugs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>432929</commentid>
    <comment_count>4</comment_count>
    <who name="Scott Graham">scottmg</who>
    <bug_when>2011-07-06 12:15:19 -0700</bug_when>
    <thetext>I get a similar size (7270) now on Ubuntu as of Chrome 13.0.782.41.

The Skia path goes through PNGImageEncoder::encode, which contains the following:

    // Optimize compression for speed.
    // The parameters are the same as what libpng uses by default for RGB and RGBA images, except:
    // - the zlib compression level is 3 instead of 6, to avoid the lazy Ziv-Lempel match searching;
    // - the delta filter is 1 (&quot;sub&quot;) instead of 5 (&quot;all&quot;), to reduce the filter computations.
    // The zlib memory level (8) and strategy (Z_FILTERED) will be set inside libpng.
    //
    // Avoid the zlib strategies Z_HUFFMAN_ONLY or Z_RLE.
    // Although they are the fastest for poorly-compressible images (e.g. photographs),
    // they are very slow for highly-compressible images (e.g. text, drawings or business graphics).

It seems sensible to sacrifice base64 size in exchange for encoding speed for cases where the data url is passed directly back into an img tag or similar.

That said, I&apos;m not sure what a good benchmark would be to decide whether the parameters used currently are a good tradeoff.

http://philip.html5.org/tests/canvas/misc/todataurl-args.html hints that adding extra args such as &quot;compression=9&quot; after the MIME type might make sense to influence the compression, but that&apos;d be purely ad hoc.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>