[Webkit-unassigned] [Bug 37304] WebKit does not support jpeg qulaity in canvas.toDataURL

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Apr 26 09:55:08 PDT 2010


https://bugs.webkit.org/show_bug.cgi?id=37304


Darin Adler <darin at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #54253|review?                     |review-
               Flag|                            |




--- Comment #18 from Darin Adler <darin at apple.com>  2010-04-26 09:55:07 PST ---
(From update of attachment 54253)
> +#include <wtf/MathExtras.h>

No need for MathExtras.h (see below).

> +    double quality = 1.0;
> +    if (args.size() > 1) {
> +        JSValue v = args.at(1);
> +        if (v.isNumber())
> +            quality = v.toNumber(exec);
> +        if (quality > 1.0 || quality < 0.0 || !isfinite(quality))
> +            quality = 1.0;
> +    }

There is a simpler, cleaner way to write this.

    double quality = args.at(1).toNumber(exec);
    if (!(quality >= 0 && quality < 1))
        quality = 1;

You don't need all those if statements. This correctly handles NAN, infinity,
missing arguments, and the like. A NAN will return false from any comparison.

> +#include "PlatformString.h"
>  
>  #include <wtf/OwnPtr.h>
>  #include <wtf/Noncopyable.h>
> @@ -41,7 +43,6 @@ class FloatSize;
>  class GraphicsContext;
>  class ImageBuffer;
>  class IntPoint;
> -class String;

There is no need to include the header here in CanvasSurface.h. You can pass a
const String& through to another const String& without including the definition
of the String class.

> -        DOMString toDataURL(in [ConvertUndefinedOrNullToNullString] DOMString type)
> +        // HTML5 draft spec: DOMString toDataURL(DOMString type, ...);
> +        [Custom] DOMString toDataURL(in [ConvertUndefinedOrNullToNullString] DOMString type)
>              raises(DOMException);

I don't understand this comment. You should leave it out unless it has
something specific to say.

> -    if (!m_data.m_pixmap.save(&buffer, mimeType.substring(sizeof "image").utf8().data()))
> +    if (!m_data.m_pixmap.save(&buffer, mimeType.substring(sizeof "image").utf8().data(), quality*100+0.5))

This is not the correct way to scale a [0,1] floating point value to a [0,100]
integer value. The correct way is "quality * nextafter(100, 0)".

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list