Changeset 60458 in webkit


Ignore:
Timestamp:
May 31, 2010 6:23:52 PM (14 years ago)
Author:
weinig@apple.com
Message:

Fix canvas.toDataURL(type, quality, ...) to let it support quality parameter.
And implement it in Qt port.
https://bugs.webkit.org/show_bug.cgi?id=37304

Patch by Leo Yang <leo.yang@torchmobile.com.cn> on 2010-05-31
Reviewed by George Staikos.

WebCore:

Tests: platform/qt/fast/canvas/toDataURL-jpeg-alpha.html

platform/qt/fast/canvas/toDataURL-jpeg-primarycolors.html
platform/qt/fast/canvas/toDataURL-jpeg-quality-basic.html
platform/qt/fast/canvas/toDataURL-jpeg-quality-notnumber.html
platform/qt/fast/canvas/toDataURL-jpeg-quality-outsiderange.html

  • bindings/js/JSHTMLCanvasElementCustom.cpp:

(WebCore::JSHTMLCanvasElement::toDataURL):

  • bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:

(WebCore::V8HTMLCanvasElement::toDataURLCallback):

  • dom/CanvasSurface.cpp:

(WebCore::CanvasSurface::toDataURL):

  • dom/CanvasSurface.h:

(WebCore::CanvasSurface::toDataURL):

  • html/HTMLCanvasElement.idl:
  • platform/graphics/ImageBuffer.h:
  • platform/graphics/cairo/ImageBufferCairo.cpp:

(WebCore::ImageBuffer::toDataURL):

  • platform/graphics/cg/ImageBufferCG.cpp:

(WebCore::ImageBuffer::toDataURL):

  • platform/graphics/haiku/ImageBufferHaiku.cpp:

(WebCore::ImageBuffer::toDataURL):

  • platform/graphics/qt/ImageBufferQt.cpp:

(WebCore::ImageBuffer::toDataURL):

  • platform/graphics/skia/ImageBufferSkia.cpp:

(WebCore::ImageBuffer::toDataURL):

  • platform/graphics/wince/ImageBufferWince.cpp:

(WebCore::ImageBuffer::toDataURL):

  • platform/graphics/wx/ImageBufferWx.cpp:

(WebCore::ImageBuffer::toDataURL):

LayoutTests:

  • platform/qt/fast/canvas/toDataURL-jpeg-alpha-expected.txt: Added.
  • platform/qt/fast/canvas/toDataURL-jpeg-alpha.html: Added.
  • platform/qt/fast/canvas/toDataURL-jpeg-primarycolors-expected.txt: Added.
  • platform/qt/fast/canvas/toDataURL-jpeg-primarycolors.html: Added.
  • platform/qt/fast/canvas/toDataURL-jpeg-quality-basic-expected.txt: Added.
  • platform/qt/fast/canvas/toDataURL-jpeg-quality-basic.html: Added.
  • platform/qt/fast/canvas/toDataURL-jpeg-quality-notnumber-expected.txt: Added.
  • platform/qt/fast/canvas/toDataURL-jpeg-quality-notnumber.html: Added.
  • platform/qt/fast/canvas/toDataURL-jpeg-quality-outsiderange-expected.txt: Added.
  • platform/qt/fast/canvas/toDataURL-jpeg-quality-outsiderange.html: Added.
  • platform/qt/fast/canvas/toDataURL-jpeg.js: Added.
Location:
trunk
Files:
11 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r60453 r60458  
     12010-05-31  Leo Yang  <leo.yang@torchmobile.com.cn>
     2
     3        Reviewed by George Staikos.
     4
     5        Fix canvas.toDataURL(type, quality, ...) to let it support quality parameter.
     6        And implement it in Qt port.
     7        https://bugs.webkit.org/show_bug.cgi?id=37304
     8
     9        * platform/qt/fast/canvas/toDataURL-jpeg-alpha-expected.txt: Added.
     10        * platform/qt/fast/canvas/toDataURL-jpeg-alpha.html: Added.
     11        * platform/qt/fast/canvas/toDataURL-jpeg-primarycolors-expected.txt: Added.
     12        * platform/qt/fast/canvas/toDataURL-jpeg-primarycolors.html: Added.
     13        * platform/qt/fast/canvas/toDataURL-jpeg-quality-basic-expected.txt: Added.
     14        * platform/qt/fast/canvas/toDataURL-jpeg-quality-basic.html: Added.
     15        * platform/qt/fast/canvas/toDataURL-jpeg-quality-notnumber-expected.txt: Added.
     16        * platform/qt/fast/canvas/toDataURL-jpeg-quality-notnumber.html: Added.
     17        * platform/qt/fast/canvas/toDataURL-jpeg-quality-outsiderange-expected.txt: Added.
     18        * platform/qt/fast/canvas/toDataURL-jpeg-quality-outsiderange.html: Added.
     19        * platform/qt/fast/canvas/toDataURL-jpeg.js: Added.
     20
    1212010-05-31  Stephen White  <senorblanco@chromium.org>
    222
  • trunk/WebCore/ChangeLog

    r60454 r60458  
     12010-05-31  Leo Yang  <leo.yang@torchmobile.com.cn>
     2
     3        Reviewed by George Staikos.
     4
     5        Fix canvas.toDataURL(type, quality, ...) to let it support quality parameter.
     6        And implement it in Qt port.
     7        https://bugs.webkit.org/show_bug.cgi?id=37304
     8
     9        Tests: platform/qt/fast/canvas/toDataURL-jpeg-alpha.html
     10               platform/qt/fast/canvas/toDataURL-jpeg-primarycolors.html
     11               platform/qt/fast/canvas/toDataURL-jpeg-quality-basic.html
     12               platform/qt/fast/canvas/toDataURL-jpeg-quality-notnumber.html
     13               platform/qt/fast/canvas/toDataURL-jpeg-quality-outsiderange.html
     14
     15        * bindings/js/JSHTMLCanvasElementCustom.cpp:
     16        (WebCore::JSHTMLCanvasElement::toDataURL):
     17        * bindings/v8/custom/V8HTMLCanvasElementCustom.cpp:
     18        (WebCore::V8HTMLCanvasElement::toDataURLCallback):
     19        * dom/CanvasSurface.cpp:
     20        (WebCore::CanvasSurface::toDataURL):
     21        * dom/CanvasSurface.h:
     22        (WebCore::CanvasSurface::toDataURL):
     23        * html/HTMLCanvasElement.idl:
     24        * platform/graphics/ImageBuffer.h:
     25        * platform/graphics/cairo/ImageBufferCairo.cpp:
     26        (WebCore::ImageBuffer::toDataURL):
     27        * platform/graphics/cg/ImageBufferCG.cpp:
     28        (WebCore::ImageBuffer::toDataURL):
     29        * platform/graphics/haiku/ImageBufferHaiku.cpp:
     30        (WebCore::ImageBuffer::toDataURL):
     31        * platform/graphics/qt/ImageBufferQt.cpp:
     32        (WebCore::ImageBuffer::toDataURL):
     33        * platform/graphics/skia/ImageBufferSkia.cpp:
     34        (WebCore::ImageBuffer::toDataURL):
     35        * platform/graphics/wince/ImageBufferWince.cpp:
     36        (WebCore::ImageBuffer::toDataURL):
     37        * platform/graphics/wx/ImageBufferWx.cpp:
     38        (WebCore::ImageBuffer::toDataURL):
     39
    1402010-05-31  Lucas De Marchi  <lucas.demarchi@profusion.mobi>
    241
  • trunk/WebCore/bindings/js/JSHTMLCanvasElementCustom.cpp

    r60392 r60458  
    11/*
    22 * Copyright (C) 2007 Apple Inc. All rights reserved.
     3 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    8586}
    8687
     88JSValue JSHTMLCanvasElement::toDataURL(ExecState* exec)
     89{
     90    const String& type = valueToStringWithUndefinedOrNullCheck(exec, exec->argument(0));
     91    double quality = 1.0;
     92    if (exec->argumentCount() > 1) {
     93        JSValue v = exec->argument(1);
     94        if (v.isNumber())
     95            quality = v.toNumber(exec);
     96        if (!(0.0 <= quality && quality <= 1.0))
     97            quality = 1.0;
     98    }
     99    HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(impl());
     100    ExceptionCode ec = 0;
     101    JSC::JSValue result = jsString(exec, canvas->toDataURL(type, quality, ec));
     102    setDOMException(exec, ec);
     103    return result;
     104}
     105
    87106} // namespace WebCore
  • trunk/WebCore/bindings/v8/custom/V8HTMLCanvasElementCustom.cpp

    r59569 r60458  
    11/*
    22 * Copyright (C) 2007-2009 Google Inc. All rights reserved.
     3 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3536#include "CanvasRenderingContext.h"
    3637#include "HTMLCanvasElement.h"
     38#include "PlatformString.h"
    3739#include "WebGLContextAttributes.h"
    3840#include "V8Binding.h"
     
    4345#include "V8WebGLRenderingContext.h"
    4446#endif
     47#include <wtf/MathExtras.h>
    4548
    4649namespace WebCore {
     
    9093}
    9194
     95v8::Handle<v8::Value> V8HTMLCanvasElement::toDataURLCallback(const v8::Arguments& args)
     96{
     97    double quality = 1.0;
     98    if (args.Length() > 1) {
     99        if (args[1]->IsNumber())
     100            quality = args[1]->NumberValue();
     101        if (!(0.0 <= quality && quality <= 1.0))
     102            quality = 1.0;
     103    }
     104    v8::Handle<v8::Object> holder = args.Holder();
     105    HTMLCanvasElement* canvas = V8HTMLCanvasElement::toNative(holder);
     106    String type = toWebCoreString(args[0]);
     107    ExceptionCode ec = 0;
     108    String result = canvas->toDataURL(type, quality, ec);
     109    V8Proxy::setDOMException(ec);
     110    return v8StringOrUndefined(result);
     111}
     112
    92113} // namespace WebCore
  • trunk/WebCore/dom/CanvasSurface.cpp

    r59581 r60458  
    11/*
    22 * Copyright (C) 2010 Google Inc. All rights reserved.
     3 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    6566}
    6667
    67 String CanvasSurface::toDataURL(const String& mimeType, ExceptionCode& ec)
     68String CanvasSurface::toDataURL(const String& mimeType, double quality, ExceptionCode& ec)
    6869{
    6970    if (!m_originClean) {
     
    8182        return buffer()->toDataURL("image/png");
    8283
    83     return buffer()->toDataURL(lowercaseMimeType);
     84    return buffer()->toDataURL(lowercaseMimeType, quality);
    8485}
    8586
  • trunk/WebCore/dom/CanvasSurface.h

    r57020 r60458  
    11/*
    22 * Copyright (C) 2010 Google Inc. All rights reserved.
     3 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2930#include "AffineTransform.h"
    3031#include "IntSize.h"
     32#include "PlatformString.h"
    3133
    3234#include <wtf/OwnPtr.h>
     
    4244class ImageBuffer;
    4345class IntPoint;
    44 class String;
    4546
    4647class CSSStyleSelector;
     
    5960    int height() const { return m_size.height(); }
    6061
    61     String toDataURL(const String& mimeType, ExceptionCode&);
     62    String toDataURL(const String& mimeType, double quality, ExceptionCode&);
     63
     64    String toDataURL(const String& mimeType, ExceptionCode& ec) { return toDataURL(mimeType, 1.0, ec); }
    6265
    6366    const IntSize& size() const { return m_size; }
  • trunk/WebCore/html/HTMLCanvasElement.idl

    r53238 r60458  
    11/*
    22 * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved.
     3 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3334        attribute long height;
    3435
    35         DOMString toDataURL(in [ConvertUndefinedOrNullToNullString] DOMString type)
     36        [Custom] DOMString toDataURL(in [ConvertUndefinedOrNullToNullString] DOMString type)
    3637            raises(DOMException);
    3738
  • trunk/WebCore/platform/graphics/ImageBuffer.h

    r54503 r60458  
    22 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
    33 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
     4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    8384        void putPremultipliedImageData(ImageData*, const IntRect& sourceRect, const IntPoint& destPoint);
    8485
    85         String toDataURL(const String& mimeType) const;
     86        String toDataURL(const String& mimeType, double quality = 1.0) const;
    8687#if !PLATFORM(CG)
    8788        AffineTransform baseTransform() const { return AffineTransform(); }
  • trunk/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp

    r52049 r60458  
    33 * Copyright (C) 2007 Holger Hans Peter Freyther <zecke@selfish.org>
    44 * Copyright (C) 2008, 2009 Dirk Schulze <krit@webkit.org>
     5 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    56 *
    67 * Redistribution and use in source and binary forms, with or without
     
    284285}
    285286
    286 String ImageBuffer::toDataURL(const String& mimeType) const
     287String ImageBuffer::toDataURL(const String& mimeType, double) const
    287288{
    288289    cairo_surface_t* image = cairo_get_target(context()->platformContext());
  • trunk/WebCore/platform/graphics/cg/ImageBufferCG.cpp

    r56825 r60458  
    22 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
    33 * Copyright (C) 2008 Apple Inc. All rights reserved.
     4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    276277}
    277278
    278 String ImageBuffer::toDataURL(const String& mimeType) const
     279String ImageBuffer::toDataURL(const String& mimeType, double) const
    279280{
    280281    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
  • trunk/WebCore/platform/graphics/haiku/ImageBufferHaiku.cpp

    r58078 r60458  
    11/*
    22 * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
     3 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    310311}
    311312
    312 String ImageBuffer::toDataURL(const String& mimeType) const
     313String ImageBuffer::toDataURL(const String& mimeType, double) const
    313314{
    314315    if (!MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType))
  • trunk/WebCore/platform/graphics/qt/ImageBufferQt.cpp

    r59713 r60458  
    33 * Copyright (C) 2008 Holger Hans Peter Freyther
    44 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
     5 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    56 *
    67 * Redistribution and use in source and binary forms, with or without
     
    276277// only formats (png, gif, jpeg..., xpm). So assume we get image/ as image
    277278// mimetypes and then remove the image/ to get the Qt format.
    278 String ImageBuffer::toDataURL(const String& mimeType) const
     279String ImageBuffer::toDataURL(const String& mimeType, double quality) const
    279280{
    280281    ASSERT(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType));
     282    ASSERT(0.0 <= quality && quality <= 1.0);
    281283
    282284    if (!mimeType.startsWith("image/"))
     
    288290    buffer.open(QBuffer::WriteOnly);
    289291
    290     if (!m_data.m_pixmap.save(&buffer, mimeType.substring(sizeof "image").utf8().data()))
     292    if (!m_data.m_pixmap.save(&buffer, mimeType.substring(sizeof "image").utf8().data(), quality * 100 + 0.5)) {
     293        buffer.close();
    291294        return "data:,";
     295    }
    292296
    293297    buffer.close();
  • trunk/WebCore/platform/graphics/skia/ImageBufferSkia.cpp

    r52791 r60458  
    22 * Copyright (c) 2008, Google Inc. All rights reserved.
    33 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
     4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    45 *
    56 * Redistribution and use in source and binary forms, with or without
     
    261262}
    262263
    263 String ImageBuffer::toDataURL(const String&) const
     264String ImageBuffer::toDataURL(const String&, double) const
    264265{
    265266    // Encode the image into a vector.
  • trunk/WebCore/platform/graphics/wince/ImageBufferWince.cpp

    r57273 r60458  
    11/*
    22 * Copyright (C) 2009 Torch Mobile, Inc. All rights reserved.
     3 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    34 *
    45 *  This library is free software; you can redistribute it and/or
     
    216217}
    217218
    218 String ImageBuffer::toDataURL(const String& mimeType) const
     219String ImageBuffer::toDataURL(const String& mimeType, double) const
    219220{
    220221    if (!m_data.m_bitmap->bytes())
  • trunk/WebCore/platform/graphics/wx/ImageBufferWx.cpp

    r57404 r60458  
    11/*
    22 * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com>
     3 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    7677}
    7778
    78 String ImageBuffer::toDataURL(const String&) const
     79String ImageBuffer::toDataURL(const String&, double) const
    7980{
    8081    notImplemented();
Note: See TracChangeset for help on using the changeset viewer.